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([sed -n '1p' VERSION | tr -d '\n']))
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(lz4,
63   [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])],
64   [enable_lz4="$enableval"], [enable_lz4="yes"])
65
66AC_ARG_ENABLE(fuse,
67   [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])],
68   [enable_fuse="$enableval"], [enable_fuse="no"])
69
70AC_ARG_WITH(uuid,
71   [AS_HELP_STRING([--without-uuid],
72      [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])])
73
74AC_ARG_WITH(selinux,
75   [AS_HELP_STRING([--with-selinux],
76      [enable and build with selinux support @<:@default=no@:>@])],
77   [case "$with_selinux" in
78      yes|no) ;;
79      *) AC_MSG_ERROR([invalid argument to --with-selinux])
80      ;;
81    esac], [with_selinux=no])
82
83# Checks for libraries.
84# Use customized LZ4 library path when specified.
85AC_ARG_WITH(lz4-incdir,
86   [AS_HELP_STRING([--with-lz4-incdir=DIR], [LZ4 include directory])], [
87   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
88
89AC_ARG_WITH(lz4-libdir,
90   [AS_HELP_STRING([--with-lz4-libdir=DIR], [LZ4 lib directory])], [
91   EROFS_UTILS_PARSE_DIRECTORY(["$withval"],[withval])])
92
93AC_ARG_VAR([LZ4_CFLAGS], [C compiler flags for lz4])
94AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
95
96# Checks for header files.
97AC_CHECK_HEADERS(m4_flatten([
98	dirent.h
99	execinfo.h
100	fcntl.h
101	getopt.h
102	inttypes.h
103	linux/falloc.h
104	linux/fs.h
105	linux/types.h
106	linux/xattr.h
107	limits.h
108	stddef.h
109	stdint.h
110	stdlib.h
111	string.h
112	sys/ioctl.h
113	sys/stat.h
114	sys/sysmacros.h
115	sys/time.h
116	unistd.h
117]))
118
119# Checks for typedefs, structures, and compiler characteristics.
120AC_C_INLINE
121AC_TYPE_INT64_T
122AC_TYPE_SIZE_T
123AC_TYPE_SSIZE_T
124AC_CHECK_MEMBERS([struct stat.st_rdev])
125AC_TYPE_UINT64_T
126
127#
128# Check to see if llseek() is declared in unistd.h.  On some libc's
129# it is, and on others it isn't..... Thank you glibc developers....
130#
131AC_CHECK_DECL(llseek,
132  [AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
133    [Define to 1 if llseek declared in unistd.h])],,
134  [#include <unistd.h>])
135
136#
137# Check to see if lseek64() is declared in unistd.h.  Glibc's header files
138# are so convoluted that I can't tell whether it will always be defined,
139# and if it isn't defined while lseek64 is defined in the library,
140# disaster will strike.
141#
142# Warning!  Use of --enable-gcc-wall may throw off this test.
143#
144AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
145  [Define to 1 if lseek64 declared in unistd.h])],,
146  [#define _LARGEFILE_SOURCE
147   #define _LARGEFILE64_SOURCE
148   #include <unistd.h>])
149
150# Checks for library functions.
151AC_CHECK_FUNCS([backtrace fallocate gettimeofday memset realpath strdup strerror strrchr strtoull])
152
153# Configure libuuid
154AS_IF([test "x$with_uuid" != "xno"], [
155  PKG_CHECK_MODULES([libuuid], [uuid])
156  # Paranoia: don't trust the result reported by pkgconfig before trying out
157  saved_LIBS="$LIBS"
158  saved_CPPFLAGS=${CPPFLAGS}
159  CPPFLAGS="${libuuid_CFLAGS} ${CPPFLAGS}"
160  LIBS="${libuuid_LIBS} $LIBS"
161  AC_MSG_CHECKING([libuuid usability])
162  AC_TRY_LINK([
163#include <uuid.h>
164], [
165uuid_t tmp;
166
167uuid_generate(tmp);
168return 0;
169], [have_uuid="yes"
170    AC_MSG_RESULT([yes])], [
171    have_uuid="no"
172    AC_MSG_RESULT([no])
173    AC_MSG_ERROR([libuuid doesn't work properly])])
174  LIBS="${saved_LIBS}"
175  CPPFLAGS="${saved_CPPFLAGS}"], [have_uuid="no"])
176
177# Configure selinux
178AS_IF([test "x$with_selinux" != "xno"], [
179  PKG_CHECK_MODULES([libselinux], [libselinux])
180  # Paranoia: don't trust the result reported by pkgconfig before trying out
181  saved_LIBS="$LIBS"
182  saved_CPPFLAGS=${CPPFLAGS}
183  CPPFLAGS="${libselinux_CFLAGS} ${CPPFLAGS}"
184  LIBS="${libselinux_LIBS} $LIBS"
185  AC_CHECK_LIB(selinux, selabel_lookup, [
186    have_selinux="yes" ], [
187    AC_MSG_ERROR([libselinux doesn't work properly])])
188  LIBS="${saved_LIBS}"
189  CPPFLAGS="${saved_CPPFLAGS}"], [have_selinux="no"])
190
191# Configure fuse
192AS_IF([test "x$enable_fuse" != "xno"], [
193  PKG_CHECK_MODULES([libfuse], [fuse >= 2.6])
194  # Paranoia: don't trust the result reported by pkgconfig before trying out
195  saved_LIBS="$LIBS"
196  saved_CPPFLAGS=${CPPFLAGS}
197  CPPFLAGS="${libfuse_CFLAGS} ${CPPFLAGS}"
198  LIBS="${libfuse_LIBS} $LIBS"
199  AC_CHECK_LIB(fuse, fuse_main, [
200    have_fuse="yes" ], [
201    AC_MSG_ERROR([libfuse (>= 2.6) doesn't work properly])])
202  LIBS="${saved_LIBS}"
203  CPPFLAGS="${saved_CPPFLAGS}"], [have_fuse="no"])
204
205# Configure lz4
206test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
207
208if test "x$enable_lz4" = "xyes"; then
209  test -z "${with_lz4_incdir}" || LZ4_CFLAGS="-I$with_lz4_incdir $LZ4_CFLAGS"
210
211  saved_CPPFLAGS=${CPPFLAGS}
212  CPPFLAGS="${LZ4_CFLAGS} ${CPPFLAGS}"
213
214  AC_CHECK_HEADERS([lz4.h],[have_lz4h="yes"], [])
215
216  if test "x${have_lz4h}" = "xyes" ; then
217    saved_LIBS="$LIBS"
218    saved_LDFLAGS=${LDFLAGS}
219    test -z "${with_lz4_libdir}" || LDFLAGS="-L$with_lz4_libdir ${LDFLAGS}"
220    AC_CHECK_LIB(lz4, LZ4_compress_destSize, [
221      have_lz4="yes"
222      have_lz4hc="yes"
223      AC_CHECK_LIB(lz4, LZ4_compress_HC_destSize, [], [
224        AC_CHECK_DECL(LZ4_compress_HC_destSize, [lz4_force_static="yes"],
225          [have_lz4hc="no"], [[
226#define LZ4_HC_STATIC_LINKING_ONLY (1)
227#include <lz4hc.h>
228        ]])
229      ])
230    ], [AC_MSG_ERROR([Cannot find proper lz4 version (>= 1.8.0)])])
231    LDFLAGS=${saved_LDFLAGS}
232    LIBS="${saved_LIBS}"
233  fi
234  CPPFLAGS=${saved_CPPFLAGS}
235fi
236
237# Set up needed symbols, conditionals and compiler/linker flags
238AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"])
239AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"])
240AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"])
241
242if test "x$have_uuid" = "xyes"; then
243  AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
244fi
245
246if test "x$have_selinux" = "xyes"; then
247  AC_DEFINE([HAVE_LIBSELINUX], 1, [Define to 1 if libselinux is found])
248fi
249
250if test "x${have_lz4}" = "xyes"; then
251  AC_DEFINE([LZ4_ENABLED], [1], [Define to 1 if lz4 is enabled.])
252
253  if test "x${have_lz4hc}" = "xyes"; then
254    AC_DEFINE([LZ4HC_ENABLED], [1], [Define to 1 if lz4hc is enabled.])
255  fi
256
257  if test "x${lz4_force_static}" = "xyes"; then
258    LZ4_LIBS="-Wl,-Bstatic -Wl,-whole-archive -Xlinker ${LZ4_LIBS} -Wl,-no-whole-archive -Wl,-Bdynamic"
259    test -z "${with_lz4_libdir}" || LZ4_LIBS="-L${with_lz4_libdir} $LZ4_LIBS"
260  else
261    test -z "${with_lz4_libdir}" || LZ4_LIBS="-R${with_lz4_libdir} $LZ4_LIBS"
262  fi
263  liblz4_LIBS="${LZ4_LIBS}"
264fi
265AC_SUBST([liblz4_LIBS])
266
267AC_CONFIG_FILES([Makefile
268		 man/Makefile
269		 lib/Makefile
270		 mkfs/Makefile
271		 fuse/Makefile])
272AC_OUTPUT
273
274