• 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])
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 Check if the flag is supported by compiler
33dnl CC_CHECK_CFLAGS_SILENT([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
34AC_DEFUN([CC_CHECK_CFLAGS_SILENT], [
35  AC_CACHE_VAL(AS_TR_SH([cc_cv_cflags_$1]),
36    [ac_save_CFLAGS="$CFLAGS"
37     CFLAGS="$CFLAGS $1"
38     AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])],
39       [eval "AS_TR_SH([cc_cv_cflags_$1])='yes'"],
40       [eval "AS_TR_SH([cc_cv_cflags_$1])='no'"])
41     CFLAGS="$ac_save_CFLAGS"
42    ])
43
44  AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
45    [$2], [$3])
46])
47
48dnl Check if the flag is supported by compiler (cacheable)
49dnl CC_CHECK_CFLAG([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
50AC_DEFUN([CC_CHECK_CFLAG], [
51  AC_CACHE_CHECK([if $CC supports $1 flag],
52    AS_TR_SH([cc_cv_cflags_$1]),
53    CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here!
54  )
55
56  AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
57    [$2], [$3])
58])
59
60dnl CC_CHECK_CFLAGS([FLAG1 FLAG2], [action-if-found], [action-if-not])
61AC_DEFUN([CC_CHECK_CFLAGS], [
62  for flag in $1; do
63    CC_CHECK_CFLAG($flag, [$2], [$3])
64  done
65])
66
67dnl EROFS_UTILS_PARSE_DIRECTORY
68dnl Input:  $1 = a string to a relative or absolute directory
69dnl Output: $2 = the variable to set with the absolute directory
70AC_DEFUN([EROFS_UTILS_PARSE_DIRECTORY],
71[
72 dnl Check if argument is a directory
73 if test -d $1 ; then
74    dnl Get the absolute path of the directory
75    dnl in case of relative directory.
76    dnl If realpath is not a valid command,
77    dnl an error is produced and we keep the given path.
78    local_tmp=`realpath $1 2>/dev/null`
79    if test "$local_tmp" != "" ; then
80       if test -d "$local_tmp" ; then
81           $2="$local_tmp"
82       else
83           $2=$1
84       fi
85    else
86       $2=$1
87    fi
88    dnl Check for space in the directory
89    if test `echo $1|cut -d' ' -f1` != $1 ; then
90        AC_MSG_ERROR($1 directory shall not contain any space.)
91    fi
92 else
93    AC_MSG_ERROR($1 shall be a valid directory)
94 fi
95])
96
97AC_ARG_VAR([MAX_BLOCK_SIZE], [The maximum block size which erofs-utils supports])
98
99AC_ARG_ENABLE([debug],
100    [AS_HELP_STRING([--enable-debug],
101                    [enable debugging mode @<:@default=no@:>@])],
102    [enable_debug="$enableval"],
103    [enable_debug="no"])
104
105AC_ARG_ENABLE([werror],
106    [AS_HELP_STRING([--enable-werror],
107                    [enable -Werror @<:@default=no@:>@])],
108    [enable_werror="$enableval"],
109    [enable_werror="no"])
110
111AC_ARG_ENABLE([fuzzing],
112    [AS_HELP_STRING([--enable-fuzzing],
113                    [set up fuzzing mode @<:@default=no@:>@])],
114    [enable_fuzzing="$enableval"],
115    [enable_fuzzing="no"])
116
117AC_ARG_ENABLE(lz4,
118   [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])],
119   [enable_lz4="$enableval"], [enable_lz4="yes"])
120
121AC_ARG_ENABLE(lzma,
122   [AS_HELP_STRING([--enable-lzma], [enable LZMA compression support @<:@default=no@:>@])],
123   [enable_lzma="$enableval"], [enable_lzma="no"])
124
125AC_ARG_WITH(zlib,
126   [AS_HELP_STRING([--without-zlib],
127      [Ignore presence of zlib inflate support @<:@default=enabled@:>@])])
128
129AC_ARG_WITH(libdeflate,
130   [AS_HELP_STRING([--with-libdeflate],
131      [Enable and build with libdeflate inflate support @<:@default=disabled@:>@])], [],
132      [with_libdeflate="no"])
133
134AC_ARG_ENABLE(fuse,
135   [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
136   [enable_fuse="$enableval"], [enable_fuse="no"])
137
138AC_ARG_WITH(uuid,
139   [AS_HELP_STRING([--without-uuid],
140      [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])])
141
142AC_ARG_WITH(selinux,
143   [AS_HELP_STRING([--with-selinux],
144      [enable and build with selinux support @<:@default=no@:>@])],
145   [case "$with_selinux" in
146      yes|no) ;;
147      *) AC_MSG_ERROR([invalid argument to --with-selinux])
148      ;;
149    esac], [with_selinux=no])
150
151# Checks for libraries.
152# Use customized LZ4 library path when specified.
153AC_ARG_WITH(lz4-incdir,
154   [AS_HELP_STRING([--with-lz4-incdir=DIR], [LZ4 include directory])], [
155   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
156
157AC_ARG_WITH(lz4-libdir,
158   [AS_HELP_STRING([--with-lz4-libdir=DIR], [LZ4 lib directory])], [
159   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
160
161AC_ARG_VAR([LZ4_CFLAGS], [C compiler flags for lz4])
162AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
163
164AC_ARG_WITH(liblzma-incdir,
165   [AS_HELP_STRING([--with-liblzma-incdir=DIR], [liblzma include directory])], [
166   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
167
168AC_ARG_WITH(liblzma-libdir,
169   [AS_HELP_STRING([--with-liblzma-libdir=DIR], [liblzma lib directory])], [
170   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
171
172# Checks for header files.
173AC_CHECK_HEADERS(m4_flatten([
174	dirent.h
175	execinfo.h
176	fcntl.h
177	getopt.h
178	inttypes.h
179	linux/aufs_type.h
180	linux/falloc.h
181	linux/fs.h
182	linux/types.h
183	linux/xattr.h
184	limits.h
185	stddef.h
186	stdint.h
187	stdlib.h
188	string.h
189	sys/ioctl.h
190	sys/mman.h
191	sys/random.h
192	sys/stat.h
193	sys/statfs.h
194	sys/sysmacros.h
195	sys/time.h
196	unistd.h
197]))
198
199AC_HEADER_TIOCGWINSZ
200
201# Checks for typedefs, structures, and compiler characteristics.
202AC_C_INLINE
203AC_TYPE_INT64_T
204AC_TYPE_SIZE_T
205AC_TYPE_SSIZE_T
206AC_CHECK_MEMBERS([struct stat.st_rdev])
207AC_CHECK_MEMBERS([struct stat.st_atim])
208AC_CHECK_MEMBERS([struct stat.st_atimensec])
209AC_TYPE_UINT64_T
210
211#
212# Check to see if llseek() is declared in unistd.h.  On some libc's
213# it is, and on others it isn't..... Thank you glibc developers....
214#
215AC_CHECK_DECL(llseek,
216  [AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
217    [Define to 1 if llseek declared in unistd.h])],,
218  [#include <unistd.h>])
219
220#
221# Check to see if lseek64() is declared in unistd.h.  Glibc's header files
222# are so convoluted that I can't tell whether it will always be defined,
223# and if it isn't defined while lseek64 is defined in the library,
224# disaster will strike.
225#
226# Warning!  Use of --enable-gcc-wall may throw off this test.
227#
228AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
229  [Define to 1 if lseek64 declared in unistd.h])],,
230  [#define _LARGEFILE_SOURCE
231   #define _LARGEFILE64_SOURCE
232   #include <unistd.h>])
233
234AC_CHECK_DECL(memrchr,[AC_DEFINE(HAVE_MEMRCHR, 1,
235  [Define to 1 if memrchr declared in string.h])],,
236  [#define _GNU_SOURCE
237   #include <string.h>])
238
239# Checks for library functions.
240AC_CHECK_FUNCS(m4_flatten([
241	backtrace
242	copy_file_range
243	fallocate
244	gettimeofday
245	lgetxattr
246	llistxattr
247	memset
248	realpath
249	lseek64
250	ftello64
251	pread64
252	pwrite64
253	posix_fadvise
254	fstatfs
255	strdup
256	strerror
257	strrchr
258	strtoull
259	tmpfile64
260	utimensat]))
261
262# Detect maximum block size if necessary
263AS_IF([test "x$MAX_BLOCK_SIZE" = "x"], [
264  AC_CACHE_CHECK([sysconf (_SC_PAGESIZE)], [erofs_cv_max_block_size],
265               AC_RUN_IFELSE([AC_LANG_PROGRAM(
266[[
267#include <unistd.h>
268#include <stdio.h>
269]],
270[[
271    int result;
272    FILE *f;
273
274    result = sysconf(_SC_PAGESIZE);
275    if (result < 0)
276	return 1;
277
278    f = fopen("conftest.out", "w");
279    if (!f)
280	return 1;
281
282    fprintf(f, "%d", result);
283    fclose(f);
284    return 0;
285]])],
286                             [erofs_cv_max_block_size=`cat conftest.out`],
287                             [erofs_cv_max_block_size=4096],
288                             [erofs_cv_max_block_size=4096]))
289], [erofs_cv_max_block_size=$MAX_BLOCK_SIZE])
290
291# Configure debug mode
292AS_IF([test "x$enable_debug" != "xno"], [], [
293  dnl Turn off all assert checking.
294  CPPFLAGS="$CPPFLAGS -DNDEBUG"
295])
296
297# Configure -Werror
298AS_IF([test "x$enable_werror" != "xyes"], [], [
299  CPPFLAGS="$CPPFLAGS -Werror"
300])
301
302# Configure libuuid
303AS_IF([test "x$with_uuid" != "xno"], [
304  PKG_CHECK_MODULES([libuuid], [uuid])
305  # Paranoia: don't trust the result reported by pkgconfig before trying out
306  saved_LIBS="$LIBS"
307  saved_CPPFLAGS=${CPPFLAGS}
308  CPPFLAGS="${libuuid_CFLAGS} ${CPPFLAGS}"
309  LIBS="${libuuid_LIBS} $LIBS"
310  AC_MSG_CHECKING([libuuid usability])
311  AC_TRY_LINK([
312#include <uuid.h>
313], [
314uuid_t tmp;
315
316uuid_generate(tmp);
317return 0;
318], [have_uuid="yes"
319    AC_MSG_RESULT([yes])], [
320    have_uuid="no"
321    AC_MSG_RESULT([no])
322    AC_MSG_ERROR([libuuid doesn't work properly])])
323  LIBS="${saved_LIBS}"
324  CPPFLAGS="${saved_CPPFLAGS}"], [have_uuid="no"])
325
326# Configure selinux
327AS_IF([test "x$with_selinux" != "xno"], [
328  PKG_CHECK_MODULES([libselinux], [libselinux])
329  # Paranoia: don't trust the result reported by pkgconfig before trying out
330  saved_LIBS="$LIBS"
331  saved_CPPFLAGS=${CPPFLAGS}
332  CPPFLAGS="${libselinux_CFLAGS} ${CPPFLAGS}"
333  LIBS="${libselinux_LIBS} $LIBS"
334  AC_CHECK_LIB(selinux, selabel_lookup, [
335    have_selinux="yes" ], [
336    AC_MSG_ERROR([libselinux doesn't work properly])])
337  LIBS="${saved_LIBS}"
338  CPPFLAGS="${saved_CPPFLAGS}"], [have_selinux="no"])
339
340# Configure fuse
341AS_IF([test "x$enable_fuse" != "xno"], [
342  PKG_CHECK_MODULES([libfuse], [fuse >= 2.6])
343  # Paranoia: don't trust the result reported by pkgconfig before trying out
344  saved_LIBS="$LIBS"
345  saved_CPPFLAGS=${CPPFLAGS}
346  CPPFLAGS="${libfuse_CFLAGS} ${CPPFLAGS}"
347  LIBS="${libfuse_LIBS} $LIBS"
348  AC_CHECK_LIB(fuse, fuse_main, [
349    have_fuse="yes" ], [
350    AC_MSG_ERROR([libfuse (>= 2.6) doesn't work properly])])
351  LIBS="${saved_LIBS}"
352  CPPFLAGS="${saved_CPPFLAGS}"], [have_fuse="no"])
353
354# Configure lz4
355test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
356
357if test "x$enable_lz4" = "xyes"; then
358  test -z "${with_lz4_incdir}" || LZ4_CFLAGS="-I$with_lz4_incdir $LZ4_CFLAGS"
359
360  saved_CPPFLAGS=${CPPFLAGS}
361  CPPFLAGS="${LZ4_CFLAGS} ${CPPFLAGS}"
362
363  AC_CHECK_HEADERS([lz4.h],[have_lz4h="yes"], [])
364
365  if test "x${have_lz4h}" = "xyes" ; then
366    saved_LIBS="$LIBS"
367    saved_LDFLAGS=${LDFLAGS}
368    test -z "${with_lz4_libdir}" || LDFLAGS="-L$with_lz4_libdir ${LDFLAGS}"
369    AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
370      have_lz4="yes"
371      have_lz4hc="yes"
372      AC_CHECK_LIB(lz4, LZ4_compress_HC_destSize, [], [
373        AC_CHECK_DECL(LZ4_compress_HC_destSize, [lz4_force_static="yes"],
374          [have_lz4hc="no"], [[
375#define LZ4_HC_STATIC_LINKING_ONLY (1)
376#include <lz4hc.h>
377        ]])
378      ])
379    ], [AC_MSG_ERROR([Cannot find proper lz4 version (>= 1.8.0)])])
380    LDFLAGS=${saved_LDFLAGS}
381    LIBS="${saved_LIBS}"
382  fi
383  CPPFLAGS=${saved_CPPFLAGS}
384fi
385
386if test "x$enable_lzma" = "xyes"; then
387  saved_CPPFLAGS=${CPPFLAGS}
388  test -z "${with_liblzma_incdir}" ||
389    CPPFLAGS="-I$with_liblzma_incdir $CPPFLAGS"
390  AC_CHECK_HEADERS([lzma.h],[have_lzmah="yes"], [])
391
392  if test "x${have_lzmah}" = "xyes" ; then
393    saved_LIBS="$LIBS"
394    saved_LDFLAGS="$LDFLAGS"
395
396    test -z "${with_liblzma_libdir}" ||
397      LDFLAGS="-L$with_liblzma_libdir ${LDFLAGS}"
398    AC_CHECK_LIB(lzma, lzma_microlzma_encoder, [],
399      [AC_MSG_ERROR([Cannot find proper liblzma])])
400
401    AC_CHECK_DECL(lzma_microlzma_encoder, [have_liblzma="yes"],
402      [AC_MSG_ERROR([Cannot find proper liblzma])], [[
403#include <lzma.h>
404    ]])
405    LDFLAGS="${saved_LDFLAGS}"
406    LIBS="${saved_LIBS}"
407  fi
408  CPPFLAGS="${saved_CPPFLAGS}"
409fi
410
411# Configure zlib
412AS_IF([test "x$with_zlib" != "xno"], [
413  PKG_CHECK_MODULES([zlib], [zlib])
414  # Paranoia: don't trust the result reported by pkgconfig before trying out
415  saved_LIBS="$LIBS"
416  saved_CPPFLAGS=${CPPFLAGS}
417  CPPFLAGS="${zlib_CFLAGS} ${CPPFLAGS}"
418  LIBS="${zlib_LIBS} $LIBS"
419  AC_CHECK_LIB(z, inflate, [
420    have_zlib="yes" ], [
421    AC_MSG_ERROR([zlib doesn't work properly])])
422  LIBS="${saved_LIBS}"
423  CPPFLAGS="${saved_CPPFLAGS}"], [have_zlib="no"])
424
425# Configure libdeflate
426AS_IF([test "x$with_libdeflate" != "xno"], [
427  PKG_CHECK_MODULES([libdeflate], [libdeflate])
428  # Paranoia: don't trust the result reported by pkgconfig before trying out
429  saved_LIBS="$LIBS"
430  saved_CPPFLAGS=${CPPFLAGS}
431  CPPFLAGS="${libdeflate_CFLAGS} ${CPPFLAGS}"
432  LIBS="${libdeflate_LIBS} $LIBS"
433  AC_CHECK_LIB(deflate, libdeflate_deflate_decompress, [
434    have_libdeflate="yes" ], [
435    AC_MSG_ERROR([libdeflate doesn't work properly])])
436  LIBS="${saved_LIBS}"
437  CPPFLAGS="${saved_CPPFLAGS}"], [have_libdeflate="no"])
438
439# Enable 64-bit off_t
440CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
441
442# Configure fuzzing mode
443AS_IF([test "x$enable_fuzzing" != "xyes"], [], [
444  CC_CHECK_CFLAGS(["-fsanitize=address,fuzzer-no-link"], [
445    CFLAGS="$CFLAGS -g -O1 -fsanitize=address,fuzzer-no-link"
446  ], [
447    AC_MSG_ERROR([Compiler doesn't support `-fsanitize=address,fuzzer-no-link`])
448  ])
449])
450AM_CONDITIONAL([ENABLE_FUZZING], [test "x${enable_fuzzing}" = "xyes"])
451
452# Set up needed symbols, conditionals and compiler/linker flags
453AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"])
454AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
455AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"])
456AM_CONDITIONAL([ENABLE_LIBLZMA], [test "x${have_liblzma}" = "xyes"])
457AM_CONDITIONAL([ENABLE_LIBDEFLATE], [test "x${have_libdeflate}" = "xyes"])
458
459if test "x$have_uuid" = "xyes"; then
460  AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
461fi
462
463if test "x$have_selinux" = "xyes"; then
464  AC_DEFINE([HAVE_LIBSELINUX], 1, [Define to 1 if libselinux is found])
465fi
466
467if test "x${have_lz4}" = "xyes"; then
468  AC_DEFINE([LZ4_ENABLED], [1], [Define to 1 if lz4 is enabled.])
469
470  if test "x${have_lz4hc}" = "xyes"; then
471    AC_DEFINE([LZ4HC_ENABLED], [1], [Define to 1 if lz4hc is enabled.])
472  fi
473
474  if test "x${lz4_force_static}" = "xyes"; then
475    LZ4_LIBS="-Wl,-Bstatic -Wl,-whole-archive -Xlinker ${LZ4_LIBS} -Wl,-no-whole-archive -Wl,-Bdynamic"
476    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} $LZ4_LIBS"
477  else
478    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} -R${with_lz4_libdir} $LZ4_LIBS"
479  fi
480  liblz4_LIBS="${LZ4_LIBS}"
481fi
482AC_SUBST([liblz4_LIBS])
483
484if test "x${have_liblzma}" = "xyes"; then
485  AC_DEFINE([HAVE_LIBLZMA], [1], [Define to 1 if liblzma is enabled.])
486  liblzma_LIBS="-llzma"
487  test -z "${with_liblzma_libdir}" ||
488    liblzma_LIBS="-L${with_liblzma_libdir} $liblzma_LIBS"
489  test -z "${with_liblzma_incdir}" ||
490    liblzma_CFLAGS="-I${with_liblzma_incdir}"
491  AC_SUBST([liblzma_LIBS])
492  AC_SUBST([liblzma_CFLAGS])
493fi
494
495if test "x$have_zlib" = "xyes"; then
496  AC_DEFINE([HAVE_ZLIB], 1, [Define to 1 if zlib is found])
497fi
498
499if test "x$have_libdeflate" = "xyes"; then
500  AC_DEFINE([HAVE_LIBDEFLATE], 1, [Define to 1 if libdeflate is found])
501fi
502
503# Dump maximum block size
504AS_IF([test "x$erofs_cv_max_block_size" = "x"],
505      [$erofs_cv_max_block_size = 4096], [])
506
507AC_DEFINE_UNQUOTED([EROFS_MAX_BLOCK_SIZE], [$erofs_cv_max_block_size],
508		   [The maximum block size which erofs-utils supports])
509
510AC_CONFIG_FILES([Makefile
511		 man/Makefile
512		 lib/Makefile
513		 mkfs/Makefile
514		 dump/Makefile
515		 fuse/Makefile
516		 fsck/Makefile])
517AC_OUTPUT
518