configure.ac: Don't use AC_CHECK_LIB() when PKG_CHECK_MODULES() suffices
[wimlib] / configure.ac
1 ###############################################################################
2
3 AC_INIT([wimlib], [1.8.2-BETA], [ebiggers3@gmail.com])
4 AC_CONFIG_SRCDIR([src/wim.c])
5 AC_CONFIG_MACRO_DIR([m4])
6 AC_CONFIG_AUX_DIR([build-aux])
7 AM_INIT_AUTOMAKE([-Wall -Werror subdir-objects foreign])
8 AC_C_BIGENDIAN
9 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
10 LT_INIT
11
12 AC_CONFIG_HEADERS([config.h])
13 AC_CONFIG_FILES([Makefile] [doc/Doxyfile] [wimlib.pc])
14 AC_CONFIG_FILES([programs/mkwinpeimg], [chmod +x programs/mkwinpeimg])
15
16 PKGCONFIG_PRIVATE_REQUIRES=""
17 PKGCONFIG_PRIVATE_LIBS=""
18
19 ###############################################################################
20 #                         General platform features                           #
21 ###############################################################################
22
23 AC_PROG_CC
24 AM_PROG_CC_C_O
25 AC_CANONICAL_HOST
26
27 WINDOWS_NATIVE_BUILD="no"
28 PLATFORM_CPPFLAGS=""
29 PLATFORM_CFLAGS="-fvisibility=hidden"
30 PLATFORM_LDFLAGS=""
31
32 case "$host_os" in
33 mingw*)
34         # Native Windows
35         WINDOWS_NATIVE_BUILD="yes"
36         PLATFORM_CPPFLAGS="-D_POSIX -D_POSIX_THREAD_SAFE_FUNCTIONS -DUNICODE -D_UNICODE -D_CRT_NON_CONFORMING_SWPRINTFS"
37         PLATFORM_CFLAGS="-municode -mno-ms-bitfields"
38         PLATFORM_LDFLAGS="-no-undefined"
39         WITH_NTFS_3G_DEFAULT="no"
40         WITH_FUSE_DEFAULT="no"
41         ;;
42 linux*)
43         # Linux
44         WITH_NTFS_3G_DEFAULT="yes"
45         WITH_FUSE_DEFAULT="yes"
46         ;;
47 *)
48         # Other UNIX
49         WITH_NTFS_3G_DEFAULT="yes"
50         WITH_FUSE_DEFAULT="no"
51         ;;
52 esac
53
54 AC_SUBST([PLATFORM_CPPFLAGS], [$PLATFORM_CPPFLAGS])
55 AC_SUBST([PLATFORM_CFLAGS], [$PLATFORM_CFLAGS])
56 AC_SUBST([PLATFORM_LDFLAGS], [$PLATFORM_LDFLAGS])
57 AM_CONDITIONAL([WINDOWS_NATIVE_BUILD], [test "$WINDOWS_NATIVE_BUILD" = "yes"])
58
59 # Useful functions which we can do without.
60 AC_CHECK_FUNCS([futimens utimensat flock mempcpy        \
61                 openat fstatat readlinkat fdopendir])
62
63 # Header checks, most of which are only here to satisfy conditional includes
64 # made by the libntfs-3g headers.
65 AC_CHECK_HEADERS([alloca.h              \
66                   attr/xattr.h          \
67                   byteswap.h            \
68                   endian.h              \
69                   errno.h               \
70                   glob.h                \
71                   machine/endian.h      \
72                   stdarg.h              \
73                   stddef.h              \
74                   stdlib.h              \
75                   sys/byteorder.h       \
76                   sys/endian.h          \
77                   sys/file.h            \
78                   sys/param.h           \
79                   sys/sysctl.h          \
80                   sys/times.h           \
81                   time.h                \
82                   utime.h])
83
84 # Does stat() support nanosecond-precision timestamps?  (This is relevant on
85 # UNIX but not on Windows.)
86 AC_CHECK_MEMBER([struct stat.st_mtim],
87                 [AC_DEFINE([HAVE_STAT_NANOSECOND_PRECISION], [1],
88                            [Define to 1 if stat() supports nanosecond precision
89                             timestamps])],
90                 [],
91                 [#include <sys/stat.h>])
92
93 ###############################################################################
94 #                            Required libraries                               #
95 ###############################################################################
96
97 # ------------------------------ pthreads -------------------------------------
98 AX_PTHREAD([], [AC_MSG_ERROR(["cannot find pthreads library"])])
99
100 # ------------------------------ libxml2 --------------------------------------
101 PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
102 PKGCONFIG_PRIVATE_REQUIRES="$PKGCONFIG_PRIVATE_REQUIRES libxml-2.0"
103
104 # ------------------------------ libiconv -------------------------------------
105 AM_ICONV
106 if test "$am_cv_func_iconv" != "yes"; then
107         AC_MSG_ERROR([Cannot find the iconv() function.  iconv() is used to
108                       convert between encodings of WIM filenames and XML data.
109                       wimlib cannot be compiled without it.  iconv() is
110                       available in the latest version of glibc and sometimes in
111                       other libraries.])
112 fi
113
114 ###############################################################################
115 #                         Configuration options                               #
116 ###############################################################################
117
118 # ------------------------- ntfs-3g support -----------------------------------
119
120 AC_MSG_CHECKING([whether to include support for ntfs-3g])
121 AC_ARG_WITH([ntfs-3g],
122             [AS_HELP_STRING([--without-ntfs-3g],
123                             [build without libntfs-3g.  This will disable the
124                              ability to capture or apply a WIM image directly
125                              from/to an unmounted NTFS volume.])],
126             [WITH_NTFS_3G=$withval],
127             [WITH_NTFS_3G=$WITH_NTFS_3G_DEFAULT])
128 AC_MSG_RESULT([$WITH_NTFS_3G])
129
130 if test "$WITH_NTFS_3G" = "yes"; then
131         PKG_CHECK_MODULES([LIBNTFS_3G], [libntfs-3g >= 2011.4.12], [],
132                 [AC_MSG_ERROR([Cannot find libntfs-3g version 2011-4-12 or
133                  later!  Without libntfs-3g, wimlib cannot include support for
134                  capturing or applying a WIM image directly from/to an unmounted
135                  NTFS volume while preserving NTFS-specific data such as
136                  security descriptors and named data streams.  Either install
137                  libntfs-3g, or configure --without-ntfs-3g to disable this
138                  feature.])])
139         PKGCONFIG_PRIVATE_REQUIRES="$PKGCONFIG_PRIVATE_REQUIRES libntfs-3g"
140         AC_DEFINE([WITH_NTFS_3G], [1], [Define to 1 if using NTFS-3g support])
141 fi
142 AM_CONDITIONAL([WITH_NTFS_3G], [test "$WITH_NTFS_3G" = "yes"])
143
144 # ------------------------ FUSE mount support ---------------------------------
145
146 AC_MSG_CHECKING([whether to include support for mounting WIMs])
147 AC_ARG_WITH([fuse],
148             [AS_HELP_STRING([--without-fuse],
149                             [build without libfuse.  This will disable the
150                              ability to mount WIM images.])],
151             [WITH_FUSE=$withval],
152             [WITH_FUSE=$WITH_FUSE_DEFAULT])
153 AC_MSG_RESULT([$WITH_FUSE])
154
155 if test "$WITH_FUSE" = "yes"; then
156
157         PKG_CHECK_MODULES([LIBFUSE], [fuse], [],
158                 [AC_MSG_ERROR([Cannot find libfuse!
159                 Without libfuse, wimlib cannot include support for mounting WIM
160                 images.  Either install libfuse, or configure --without-fuse to
161                 disable this feature.])])
162         PKGCONFIG_PRIVATE_REQUIRES="$PKGCONFIG_PRIVATE_REQUIRES fuse"
163         AC_DEFINE([WITH_FUSE], [1], [Define to 1 if using FUSE support])
164
165         AC_CHECK_LIB([rt], [mq_open], [],
166                      [AC_MSG_ERROR([Cannot find librt (the POSIX.1b Realtime
167         Extensions Library)!  wimlib needs this for the POSIX message queue
168         functions, which are used in the code for mounting WIM images.  Recent
169         versions of glibc include this library.  Either install this library, or
170         configure --without-fuse to disable support for mounting WIM images.])])
171
172         AC_CHECK_LIB([attr], [getxattr], [],
173                      [AC_MSG_ERROR([Cannot find libattr!
174         wimlib needs this for the extended attribute functions, which are used
175         in the code for mounting WIM images.  Either install this library, or
176         configure --without-fuse to disable support for mounting WIM images.])])
177
178         PKGCONFIG_PRIVATE_LIBS="$PKGCONFIG_PRIVATE_LIBS -lrt"
179         AC_SUBST([LIBRT_LIBS], [-lrt])
180 fi
181 AM_CONDITIONAL([WITH_FUSE], [test "$WITH_FUSE" = "yes"])
182
183 # ------------------------ SHA-1 implementation ---------------------------------
184
185 AC_MSG_CHECKING([whether to use SSSE3-accelerated SHA-1])
186 AC_ARG_ENABLE([ssse3-sha1],
187               [AS_HELP_STRING([--enable-ssse3-sha1],
188                               [Include SSSE3-accelerated SHA-1 implementation by
189                                Intel.  This implies --without-libcrypto.])],
190               [ENABLE_SSSE3_SHA1=$enableval],
191               [ENABLE_SSSE3_SHA1=no])
192 AC_MSG_RESULT([$ENABLE_SSSE3_SHA1])
193
194 if test "$ENABLE_SSSE3_SHA1" = "yes" ; then
195         AC_DEFINE([ENABLE_SSSE3_SHA1], [1],
196                   [Define to 1 if using SSSE3 implementation of SHA-1])
197         AC_PROG_NASM
198         NASM_SYMBOL_PREFIX=""
199         NASM_PLATFORM_FLAGS=""
200         if test "$WINDOWS_NATIVE_BUILD" = "yes"; then
201                 NASM_PLATFORM_FLAGS="-DWIN_ABI"
202         fi
203         case "$host_os" in
204         darwin* | rhapsody* | nextstep* | openstep* | macos*)
205                 NASM_SYMBOL_PREFIX="_"
206                 ;;
207         esac
208         AC_SUBST([NASM_PLATFORM_FLAGS], [$NASM_PLATFORM_FLAGS])
209         AC_SUBST([NASM_SYMBOL_PREFIX], [$NASM_SYMBOL_PREFIX])
210 else
211         AC_MSG_CHECKING([whether to use SHA-1 implementation from system libcrypto])
212         AC_ARG_WITH([libcrypto],
213                     [AS_HELP_STRING([--without-libcrypto],
214                                     [build in the SHA-1 algorithm, rather than
215                                      use external libcrypto from OpenSSL
216                                      (default is autodetect)])],
217                     [WITH_LIBCRYPTO=$withval],
218                     [WITH_LIBCRYPTO=auto])
219         AC_MSG_RESULT([$WITH_LIBCRYPTO])
220         if test "$WITH_LIBCRYPTO" != "no"; then
221                 PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto], [
222                         PKGCONFIG_PRIVATE_REQUIRES="$PKGCONFIG_PRIVATE_REQUIRES libcrypto"
223                         AC_DEFINE([WITH_LIBCRYPTO], [1],
224                                   [Define to 1 if using libcrypto SHA-1])
225                 ], [AC_MSG_WARN([Cannot find libcrypto: using stand-alone SHA-1 code instead])])
226         fi
227 fi
228 AM_CONDITIONAL([ENABLE_SSSE3_SHA1], [test "$ENABLE_SSSE3_SHA1" = "yes"])
229
230 # ----------------------------- Other options ---------------------------------
231
232 AC_MSG_CHECKING([whether to include error messages])
233 AC_ARG_ENABLE([error_messages],
234         AS_HELP_STRING([--disable-error-messages], [do not compile in error messsages]),
235         [ENABLE_ERROR_MESSAGES=$enableval],
236         [ENABLE_ERROR_MESSAGES=yes])
237 AC_MSG_RESULT([$ENABLE_ERROR_MESSAGES])
238 if test "$ENABLE_ERROR_MESSAGES" = "yes"; then
239         AC_DEFINE([ENABLE_ERROR_MESSAGES], [1], [Define to 1 if including error messages])
240 fi
241
242 AC_MSG_CHECKING([whether to include assertions])
243 AC_ARG_ENABLE([assertions],
244         AS_HELP_STRING([--disable-assertions], [do not include assertions]),
245         [ENABLE_ASSERTIONS=$enableval],
246         [ENABLE_ASSERTIONS=yes])
247 AC_MSG_RESULT([$ENABLE_ASSERTIONS])
248 if test "$ENABLE_ASSERTIONS" = "yes"; then
249         AC_DEFINE([ENABLE_ASSERTIONS], [1], [Define to 1 if including assertions])
250 fi
251
252 AC_MSG_CHECKING([whether to include support for multi-threaded compression])
253 AC_ARG_ENABLE([multithreaded-compression],
254         AS_HELP_STRING([--disable-multithreaded-compression],
255                        [disable support for multithreaded compression]),
256         [ENABLE_MULTITHREADED_COMPRESSION=$enableval],
257         [ENABLE_MULTITHREADED_COMPRESSION=yes])
258 AC_MSG_RESULT([$ENABLE_MULTITHREADED_COMPRESSION])
259 if test "$ENABLE_MULTITHREADED_COMPRESSION" = "yes"; then
260         AC_DEFINE([ENABLE_MULTITHREADED_COMPRESSION], [1],
261                   [Define to 1 to support multithreaded compression])
262 fi
263
264 AC_ARG_WITH(pkgconfigdir,
265             [  --with-pkgconfigdir=DIR      pkgconfig file in DIR @<:@LIBDIR/pkgconfig@:>@],
266             [pkgconfigdir=$withval],
267             [pkgconfigdir='${libdir}/pkgconfig'])
268 AC_SUBST(pkgconfigdir)
269
270 ###############################################################################
271
272 AC_SUBST([PKGCONFIG_PRIVATE_REQUIRES], [$PKGCONFIG_PRIVATE_REQUIRES])
273 AC_SUBST([PKGCONFIG_PRIVATE_LIBS], [$PKGCONFIG_PRIVATE_LIBS])
274 AC_OUTPUT