• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ([2.69])
5
6m4_define([erofs_utils_version], m4_esyscmd_s([scripts/get-version-number]))
7m4_define([erofs_utils_date], m4_esyscmd([sed -n '2p' VERSION | tr -d '\n']))
8
9AC_INIT([erofs-utils], [erofs_utils_version], [linux-erofs@lists.ozlabs.org])
10AC_CONFIG_SRCDIR([config.h.in])
11AC_CONFIG_HEADERS([config.h])
12AC_CONFIG_MACRO_DIR([m4])
13AC_CONFIG_AUX_DIR(config)
14AM_INIT_AUTOMAKE([foreign -Wall -Werror])
15
16# Checks for programs.
17AM_PROG_AR
18AC_PROG_CC
19AC_PROG_INSTALL
20
21LT_INIT
22
23# Test presence of pkg-config
24AC_MSG_CHECKING([pkg-config m4 macros])
25if test m4_ifdef([PKG_CHECK_MODULES], [yes], [no]) = "yes"; then
26  AC_MSG_RESULT([yes]);
27else
28  AC_MSG_RESULT([no]);
29  AC_MSG_ERROR([pkg-config is required. See pkg-config.freedesktop.org])
30fi
31
32dnl EROFS_UTILS_PARSE_DIRECTORY
33dnl Input:  $1 = a string to a relative or absolute directory
34dnl Output: $2 = the variable to set with the absolute directory
35AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
36[
37 dnl Check if argument is a directory
38 if test -d $1 ; then
39    dnl Get the absolute path of the directory
40    dnl in case of relative directory.
41    dnl If realpath is not a valid command,
42    dnl an error is produced and we keep the given path.
43    local_tmp=`realpath $1 2>/dev/null`
44    if test "$local_tmp" != "" ; then
45       if test -d "$local_tmp" ; then
46           $2="$local_tmp"
47       else
48           $2=$1
49       fi
50    else
51       $2=$1
52    fi
53    dnl Check for space in the directory
54    if test `echo $1|cut -d' ' -f1` != $1 ; then
55        AC_MSG_ERROR($1 directory shall not contain any space.)
56    fi
57 else
58    AC_MSG_ERROR($1 shall be a valid directory)
59 fi
60])
61
62AC_ARG_ENABLE([debug],
63    [AS_HELP_STRING([--enable-debug],
64                    [enable debugging mode @<:@default=no@:>@])],
65    [enable_debug="$enableval"],
66    [enable_debug="no"])
67
68AC_ARG_ENABLE(lz4,
69   [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])],
70   [enable_lz4="$enableval"], [enable_lz4="yes"])
71
72AC_ARG_ENABLE(lzma,
73   [AS_HELP_STRING([--enable-lzma], [enable LZMA compression support @<:@default=no@:>@])],
74   [enable_lzma="$enableval"], [enable_lzma="no"])
75
76AC_ARG_ENABLE(fuse,
77   [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
78   [enable_fuse="$enableval"], [enable_fuse="no"])
79
80AC_ARG_WITH(uuid,
81   [AS_HELP_STRING([--without-uuid],
82      [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])])
83
84AC_ARG_WITH(selinux,
85   [AS_HELP_STRING([--with-selinux],
86      [enable and build with selinux support @<:@default=no@:>@])],
87   [case "$with_selinux" in
88      yes|no) ;;
89      *) AC_MSG_ERROR([invalid argument to --with-selinux])
90      ;;
91    esac], [with_selinux=no])
92
93# Checks for libraries.
94# Use customized LZ4 library path when specified.
95AC_ARG_WITH(lz4-incdir,
96   [AS_HELP_STRING([--with-lz4-incdir=DIR], [LZ4 include directory])], [
97   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
98
99AC_ARG_WITH(lz4-libdir,
100   [AS_HELP_STRING([--with-lz4-libdir=DIR], [LZ4 lib directory])], [
101   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
102
103AC_ARG_VAR([LZ4_CFLAGS], [C compiler flags for lz4])
104AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
105
106AC_ARG_WITH(liblzma-incdir,
107   [AS_HELP_STRING([--with-liblzma-incdir=DIR], [liblzma include directory])], [
108   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
109
110AC_ARG_WITH(liblzma-libdir,
111   [AS_HELP_STRING([--with-liblzma-libdir=DIR], [liblzma lib directory])], [
112   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
113
114# Checks for header files.
115AC_CHECK_HEADERS(m4_flatten([
116	dirent.h
117	execinfo.h
118	fcntl.h
119	getopt.h
120	inttypes.h
121	linux/falloc.h
122	linux/fs.h
123	linux/types.h
124	linux/xattr.h
125	limits.h
126	stddef.h
127	stdint.h
128	stdlib.h
129	string.h
130	sys/ioctl.h
131	sys/stat.h
132	sys/sysmacros.h
133	sys/time.h
134	unistd.h
135]))
136
137# Checks for typedefs, structures, and compiler characteristics.
138AC_C_INLINE
139AC_TYPE_INT64_T
140AC_TYPE_SIZE_T
141AC_TYPE_SSIZE_T
142AC_CHECK_MEMBERS([struct stat.st_rdev])
143AC_CHECK_MEMBERS([struct stat.st_atim])
144AC_CHECK_MEMBERS([struct stat.st_atimensec])
145AC_TYPE_UINT64_T
146
147#
148# Check to see if llseek() is declared in unistd.h.  On some libc's
149# it is, and on others it isn't..... Thank you glibc developers....
150#
151AC_CHECK_DECL(llseek,
152  [AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
153    [Define to 1 if llseek declared in unistd.h])],,
154  [#include <unistd.h>])
155
156#
157# Check to see if lseek64() is declared in unistd.h.  Glibc's header files
158# are so convoluted that I can't tell whether it will always be defined,
159# and if it isn't defined while lseek64 is defined in the library,
160# disaster will strike.
161#
162# Warning!  Use of --enable-gcc-wall may throw off this test.
163#
164AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
165  [Define to 1 if lseek64 declared in unistd.h])],,
166  [#define _LARGEFILE_SOURCE
167   #define _LARGEFILE64_SOURCE
168   #include <unistd.h>])
169
170# Checks for library functions.
171AC_CHECK_FUNCS(m4_flatten([
172	backtrace
173	copy_file_range
174	fallocate
175	gettimeofday
176	lgetxattr
177	llistxattr
178	memset
179	realpath
180	pread64
181	pwrite64
182	strdup
183	strerror
184	strrchr
185	strtoull
186	tmpfile64
187	utimensat]))
188
189# Configure debug mode
190AS_IF([test "x$enable_debug" != "xno"], [], [
191  dnl Turn off all assert checking.
192  CPPFLAGS="$CPPFLAGS -DNDEBUG"
193])
194
195# Configure libuuid
196AS_IF([test "x$with_uuid" != "xno"], [
197  PKG_CHECK_MODULES([libuuid], [uuid])
198  # Paranoia: don't trust the result reported by pkgconfig before trying out
199  saved_LIBS="$LIBS"
200  saved_CPPFLAGS=${CPPFLAGS}
201  CPPFLAGS="${libuuid_CFLAGS} ${CPPFLAGS}"
202  LIBS="${libuuid_LIBS} $LIBS"
203  AC_MSG_CHECKING([libuuid usability])
204  AC_TRY_LINK([
205#include <uuid.h>
206], [
207uuid_t tmp;
208
209uuid_generate(tmp);
210return 0;
211], [have_uuid="yes"
212    AC_MSG_RESULT([yes])], [
213    have_uuid="no"
214    AC_MSG_RESULT([no])
215    AC_MSG_ERROR([libuuid doesn't work properly])])
216  LIBS="${saved_LIBS}"
217  CPPFLAGS="${saved_CPPFLAGS}"], [have_uuid="no"])
218
219# Configure selinux
220AS_IF([test "x$with_selinux" != "xno"], [
221  PKG_CHECK_MODULES([libselinux], [libselinux])
222  # Paranoia: don't trust the result reported by pkgconfig before trying out
223  saved_LIBS="$LIBS"
224  saved_CPPFLAGS=${CPPFLAGS}
225  CPPFLAGS="${libselinux_CFLAGS} ${CPPFLAGS}"
226  LIBS="${libselinux_LIBS} $LIBS"
227  AC_CHECK_LIB(selinux, selabel_lookup, [
228    have_selinux="yes" ], [
229    AC_MSG_ERROR([libselinux doesn't work properly])])
230  LIBS="${saved_LIBS}"
231  CPPFLAGS="${saved_CPPFLAGS}"], [have_selinux="no"])
232
233# Configure fuse
234AS_IF([test "x$enable_fuse" != "xno"], [
235  PKG_CHECK_MODULES([libfuse], [fuse >= 2.6])
236  # Paranoia: don't trust the result reported by pkgconfig before trying out
237  saved_LIBS="$LIBS"
238  saved_CPPFLAGS=${CPPFLAGS}
239  CPPFLAGS="${libfuse_CFLAGS} ${CPPFLAGS}"
240  LIBS="${libfuse_LIBS} $LIBS"
241  AC_CHECK_LIB(fuse, fuse_main, [
242    have_fuse="yes" ], [
243    AC_MSG_ERROR([libfuse (>= 2.6) doesn't work properly])])
244  LIBS="${saved_LIBS}"
245  CPPFLAGS="${saved_CPPFLAGS}"], [have_fuse="no"])
246
247# Configure lz4
248test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
249
250if test "x$enable_lz4" = "xyes"; then
251  test -z "${with_lz4_incdir}" || LZ4_CFLAGS="-I$with_lz4_incdir $LZ4_CFLAGS"
252
253  saved_CPPFLAGS=${CPPFLAGS}
254  CPPFLAGS="${LZ4_CFLAGS} ${CPPFLAGS}"
255
256  AC_CHECK_HEADERS([lz4.h],[have_lz4h="yes"], [])
257
258  if test "x${have_lz4h}" = "xyes" ; then
259    saved_LIBS="$LIBS"
260    saved_LDFLAGS=${LDFLAGS}
261    test -z "${with_lz4_libdir}" || LDFLAGS="-L$with_lz4_libdir ${LDFLAGS}"
262    AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
263      have_lz4="yes"
264      have_lz4hc="yes"
265      AC_CHECK_LIB(lz4, LZ4_compress_HC_destSize, [], [
266        AC_CHECK_DECL(LZ4_compress_HC_destSize, [lz4_force_static="yes"],
267          [have_lz4hc="no"], [[
268#define LZ4_HC_STATIC_LINKING_ONLY (1)
269#include <lz4hc.h>
270        ]])
271      ])
272    ], [AC_MSG_ERROR([Cannot find proper lz4 version (>= 1.8.0)])])
273    LDFLAGS=${saved_LDFLAGS}
274    LIBS="${saved_LIBS}"
275  fi
276  CPPFLAGS=${saved_CPPFLAGS}
277fi
278
279if test "x$enable_lzma" = "xyes"; then
280  saved_CPPFLAGS=${CPPFLAGS}
281  test -z "${with_liblzma_incdir}" ||
282    CPPFLAGS="-I$with_liblzma_incdir $CPPFLAGS"
283  AC_CHECK_HEADERS([lzma.h],[have_lzmah="yes"], [])
284
285  if test "x${have_lzmah}" = "xyes" ; then
286    saved_LIBS="$LIBS"
287    saved_LDFLAGS="$LDFLAGS"
288
289    test -z "${with_liblzma_libdir}" ||
290      LDFLAGS="-L$with_liblzma_libdir ${LDFLAGS}"
291    AC_CHECK_LIB(lzma, lzma_microlzma_encoder, [],
292      [AC_MSG_ERROR([Cannot find proper liblzma])])
293
294    AC_CHECK_DECL(lzma_microlzma_encoder, [have_liblzma="yes"],
295      [AC_MSG_ERROR([Cannot find proper liblzma])], [[
296#include <lzma.h>
297    ]])
298    LDFLAGS="${saved_LDFLAGS}"
299    LIBS="${saved_LIBS}"
300  fi
301  CPPFLAGS="${saved_CPPFLAGS}"
302fi
303
304# Set up needed symbols, conditionals and compiler/linker flags
305AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"])
306AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
307AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"])
308AM_CONDITIONAL([ENABLE_LIBLZMA], [test "x${have_liblzma}" = "xyes"])
309
310if test "x$have_uuid" = "xyes"; then
311  AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
312fi
313
314if test "x$have_selinux" = "xyes"; then
315  AC_DEFINE([HAVE_LIBSELINUX], 1, [Define to 1 if libselinux is found])
316fi
317
318if test "x${have_lz4}" = "xyes"; then
319  AC_DEFINE([LZ4_ENABLED], [1], [Define to 1 if lz4 is enabled.])
320
321  if test "x${have_lz4hc}" = "xyes"; then
322    AC_DEFINE([LZ4HC_ENABLED], [1], [Define to 1 if lz4hc is enabled.])
323  fi
324
325  if test "x${lz4_force_static}" = "xyes"; then
326    LZ4_LIBS="-Wl,-Bstatic -Wl,-whole-archive -Xlinker ${LZ4_LIBS} -Wl,-no-whole-archive -Wl,-Bdynamic"
327    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} $LZ4_LIBS"
328  else
329    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} -R${with_lz4_libdir} $LZ4_LIBS"
330  fi
331  liblz4_LIBS="${LZ4_LIBS}"
332fi
333AC_SUBST([liblz4_LIBS])
334
335if test "x${have_liblzma}" = "xyes"; then
336  AC_DEFINE([HAVE_LIBLZMA], [1], [Define to 1 if liblzma is enabled.])
337  liblzma_LIBS="-llzma"
338  test -z "${with_liblzma_libdir}" ||
339    liblzma_LIBS="-L${with_liblzma_libdir} $liblzma_LIBS"
340  test -z "${with_liblzma_incdir}" ||
341    liblzma_CFLAGS="-I${with_liblzma_incdir}"
342  AC_SUBST([liblzma_LIBS])
343  AC_SUBST([liblzma_CFLAGS])
344fi
345
346AC_CONFIG_FILES([Makefile
347		 man/Makefile
348		 lib/Makefile
349		 mkfs/Makefile
350		 dump/Makefile
351		 fuse/Makefile
352		 fsck/Makefile])
353AC_OUTPUT
354