Imported Upstream version 3.4.2
[platform/upstream/libarchive.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 dnl First, define all of the version numbers up front.
4 dnl In particular, this allows the version macro to be used in AC_INIT
5
6 dnl These first two version numbers are updated automatically on each release.
7 m4_define([LIBARCHIVE_VERSION_S],[3.4.2])
8 m4_define([LIBARCHIVE_VERSION_N],[3004002])
9
10 dnl bsdtar and bsdcpio versioning tracks libarchive
11 m4_define([BSDTAR_VERSION_S],LIBARCHIVE_VERSION_S())
12 m4_define([BSDCPIO_VERSION_S],LIBARCHIVE_VERSION_S())
13 m4_define([BSDCAT_VERSION_S],LIBARCHIVE_VERSION_S())
14
15 AC_PREREQ([2.69])
16
17 #
18 # Now starts the "real" configure script.
19 #
20
21 AC_INIT([libarchive],[LIBARCHIVE_VERSION_S()],[libarchive-discuss@googlegroups.com])
22 # Make sure the srcdir contains "libarchive" directory
23 AC_CONFIG_SRCDIR([libarchive])
24 # Use auxiliary subscripts from this subdirectory (cleans up root)
25 AC_CONFIG_AUX_DIR([build/autoconf])
26 # M4 scripts
27 AC_CONFIG_MACRO_DIR([build/autoconf])
28 # Must follow AC_CONFIG macros above...
29 AM_INIT_AUTOMAKE([1.11 dist-xz dist-zip])
30 AM_MAINTAINER_MODE([enable])
31 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
32
33 # Libtool's "interface version" can be computed from the libarchive version.
34
35 # Libtool interface version bumps on any API change, so increments
36 # whenever libarchive minor version does.
37 ARCHIVE_MINOR=$(( (LIBARCHIVE_VERSION_N() / 1000) % 1000 ))
38 # Libarchive 2.7 == libtool interface 9 = 2 + 7
39 # Libarchive 2.8 == libtool interface 10 = 2 + 8
40 # Libarchive 2.9 == libtool interface 11 = 2 + 8
41 # Libarchive 3.0 == libtool interface 12
42 # Libarchive 3.1 == libtool interface 13
43 ARCHIVE_INTERFACE=`echo $((13 + ${ARCHIVE_MINOR}))`
44 # Libarchive revision is bumped on any source change === libtool revision
45 ARCHIVE_REVISION=$(( LIBARCHIVE_VERSION_N() % 1000 ))
46 # Libarchive minor is bumped on any interface addition === libtool age
47 ARCHIVE_LIBTOOL_VERSION=$ARCHIVE_INTERFACE:$ARCHIVE_REVISION:$ARCHIVE_MINOR
48
49 # Stick the version numbers into config.h
50 AC_DEFINE([LIBARCHIVE_VERSION_STRING],"LIBARCHIVE_VERSION_S()",
51         [Version number of libarchive])
52 AC_DEFINE_UNQUOTED([LIBARCHIVE_VERSION_NUMBER],"LIBARCHIVE_VERSION_N()",
53         [Version number of libarchive as a single integer])
54 AC_DEFINE([BSDCPIO_VERSION_STRING],"BSDCPIO_VERSION_S()",
55         [Version number of bsdcpio])
56 AC_DEFINE([BSDTAR_VERSION_STRING],"BSDTAR_VERSION_S()",
57         [Version number of bsdtar])
58 AC_DEFINE([BSDCAT_VERSION_STRING],"BSDTAR_VERSION_S()",
59         [Version number of bsdcat])
60
61 # The shell variables here must be the same as the AC_SUBST() variables
62 # below, but the shell variable names apparently cannot be the same as
63 # the m4 macro names above.  Why?  Ask autoconf.
64 BSDCPIO_VERSION_STRING=BSDCPIO_VERSION_S()
65 BSDTAR_VERSION_STRING=BSDTAR_VERSION_S()
66 BSDCAT_VERSION_STRING=BSDCAT_VERSION_S()
67 LIBARCHIVE_VERSION_STRING=LIBARCHIVE_VERSION_S()
68 LIBARCHIVE_VERSION_NUMBER=LIBARCHIVE_VERSION_N()
69
70 # Substitute the above version numbers into the various files below.
71 # Yes, I believe this is the fourth time we define what are essentially
72 # the same symbols.  Why? Ask autoconf.
73 AC_SUBST(ARCHIVE_LIBTOOL_VERSION)
74 AC_SUBST(BSDCPIO_VERSION_STRING)
75 AC_SUBST(BSDTAR_VERSION_STRING)
76 AC_SUBST(BSDCAT_VERSION_STRING)
77 AC_SUBST(LIBARCHIVE_VERSION_STRING)
78 AC_SUBST(LIBARCHIVE_VERSION_NUMBER)
79
80 AC_CONFIG_HEADERS([config.h])
81 AC_CONFIG_FILES([Makefile])
82 AC_CONFIG_FILES([build/pkgconfig/libarchive.pc])
83
84 # Check for host type
85 AC_CANONICAL_HOST
86
87 dnl Compilation on mingw and Cygwin needs special Makefile rules
88 inc_windows_files=no
89 inc_cygwin_files=no
90 case "$host_os" in
91   *mingw* ) inc_windows_files=yes ;;
92   *cygwin* | *msys*) inc_cygwin_files=yes ;;
93 esac
94 AM_CONDITIONAL([INC_WINDOWS_FILES], [test $inc_windows_files = yes])
95 AM_CONDITIONAL([INC_CYGWIN_FILES], [test $inc_cygwin_files = yes])
96
97 dnl Defines that are required for specific platforms (e.g. -D_POSIX_SOURCE, etc)
98 PLATFORMCPPFLAGS=
99 case "$host_os" in
100   *mingw* ) PLATFORMCPPFLAGS=-D__USE_MINGW_ANSI_STDIO ;;
101 esac
102 AC_SUBST(PLATFORMCPPFLAGS)
103
104 # Checks for programs.
105 AC_PROG_CC
106 AM_PROG_CC_C_O
107 AC_USE_SYSTEM_EXTENSIONS
108 AC_LIBTOOL_WIN32_DLL
109 AC_PROG_LIBTOOL
110 AC_CHECK_TOOL([STRIP],[strip])
111 AC_PROG_MKDIR_P
112
113 #
114 # Options for building bsdtar.
115 #
116 # Default is to build bsdtar, but allow people to override that.
117 #
118 AC_ARG_ENABLE([bsdtar],
119         [AS_HELP_STRING([--enable-bsdtar], [enable build of bsdtar (default)])
120         AS_HELP_STRING([--enable-bsdtar=static], [force static build of bsdtar])
121         AS_HELP_STRING([--enable-bsdtar=shared], [force dynamic build of bsdtar])
122 AS_HELP_STRING([--disable-bsdtar], [disable build of bsdtar])],
123         [], [enable_bsdtar=yes])
124
125 case "$enable_bsdtar" in
126 yes)
127         if test "$enable_static" = "no"; then
128                 static_bsdtar=no
129         else
130                 static_bsdtar=yes
131         fi
132         build_bsdtar=yes
133         ;;
134 dynamic|shared)
135         if test "$enable_shared" = "no"; then
136                 AC_MSG_FAILURE([Shared linking of bsdtar requires shared libarchive])
137         fi
138         build_bsdtar=yes
139         static_bsdtar=no
140         ;;
141 static)
142         build_bsdtar=yes
143         static_bsdtar=yes
144         ;;
145 no)
146         build_bsdtar=no
147         static_bsdtar=no
148         ;;
149 *)
150         AC_MSG_FAILURE([Unsupported value for --enable-bsdtar])
151         ;;
152 esac
153
154 AM_CONDITIONAL([BUILD_BSDTAR], [ test "$build_bsdtar" = yes ])
155 AM_CONDITIONAL([STATIC_BSDTAR], [ test "$static_bsdtar" = yes ])
156
157 #
158 # Options for building bsdcat.
159 #
160 # Default is to build bsdcat, but allow people to override that.
161 #
162 AC_ARG_ENABLE([bsdcat],
163         [AS_HELP_STRING([--enable-bsdcat], [enable build of bsdcat (default)])
164         AS_HELP_STRING([--enable-bsdcat=static], [force static build of bsdcat])
165         AS_HELP_STRING([--enable-bsdcat=shared], [force dynamic build of bsdcat])
166 AS_HELP_STRING([--disable-bsdcat], [disable build of bsdcat])],
167         [], [enable_bsdcat=yes])
168
169 case "$enable_bsdcat" in
170 yes)
171         if test "$enable_static" = "no"; then
172                 static_bsdcat=no
173         else
174                 static_bsdcat=yes
175         fi
176         build_bsdcat=yes
177         ;;
178 dynamic|shared)
179         if test "$enable_shared" = "no"; then
180                 AC_MSG_FAILURE([Shared linking of bsdcat requires shared libarchive])
181         fi
182         build_bsdcat=yes
183         static_bsdcat=no
184         ;;
185 static)
186         build_bsdcat=yes
187         static_bsdcat=yes
188         ;;
189 no)
190         build_bsdcat=no
191         static_bsdcat=no
192         ;;
193 *)
194         AC_MSG_FAILURE([Unsupported value for --enable-bsdcat])
195         ;;
196 esac
197
198 AM_CONDITIONAL([BUILD_BSDCAT], [ test "$build_bsdcat" = yes ])
199 AM_CONDITIONAL([STATIC_BSDCAT], [ test "$static_bsdcat" = yes ])
200
201 #
202 # Options for building bsdcpio.
203 #
204 # Default is not to build bsdcpio, but that can be overridden.
205 #
206 AC_ARG_ENABLE([bsdcpio],
207         [AS_HELP_STRING([--enable-bsdcpio], [enable build of bsdcpio (default)])
208         AS_HELP_STRING([--enable-bsdcpio=static], [static build of bsdcpio])
209         AS_HELP_STRING([--enable-bsdcpio=shared], [dynamic build of bsdcpio])
210 AS_HELP_STRING([--disable-bsdcpio], [disable build of bsdcpio])],
211         [], [enable_bsdcpio=yes])
212
213 case "$enable_bsdcpio" in
214 yes)
215         if test "$enable_static" = "no"; then
216            static_bsdcpio=no
217         else
218            static_bsdcpio=yes
219         fi
220         build_bsdcpio=yes
221         ;;
222 dynamic|shared)
223         if test "$enabled_shared" = "no"; then
224            AC_MSG_FAILURE([Shared linking of bsdcpio requires shared libarchive])
225         fi
226         build_bsdcpio=yes
227         ;;
228 static)
229         build_bsdcpio=yes
230         static_bsdcpio=yes
231         ;;
232 no)
233         build_bsdcpio=no
234         static_bsdcpio=no
235         ;;
236 *)
237         AC_MSG_FAILURE([Unsupported value for --enable-bsdcpio])
238         ;;
239 esac
240
241 AM_CONDITIONAL([BUILD_BSDCPIO], [ test "$build_bsdcpio" = yes ])
242 AM_CONDITIONAL([STATIC_BSDCPIO], [ test "$static_bsdcpio" = yes ])
243
244 # Set up defines needed before including any headers
245 case $host in
246   *mingw* | *cygwin* | *msys*  )
247   AC_DEFINE([_WIN32_WINNT], 0x0502, [Define to '0x0502' for Windows Server 2003 APIs.])
248   AC_DEFINE([WINVER], 0x0502, [Define to '0x0502' for Windows Server 2003 APIs.])
249   AC_DEFINE([NTDDI_VERSION], 0x05020000, [Define to '0x05020000' for Windows Server 2003 APIs.])
250   ;;
251 esac
252
253 # Checks for header files.
254 AC_HEADER_DIRENT
255 AC_HEADER_SYS_WAIT
256 AC_CHECK_HEADERS([acl/libacl.h attr/xattr.h])
257 AC_CHECK_HEADERS([copyfile.h ctype.h])
258 AC_CHECK_HEADERS([errno.h ext2fs/ext2_fs.h fcntl.h grp.h])
259
260 AC_CACHE_CHECK([whether EXT2_IOC_GETFLAGS is usable],
261     [ac_cv_have_decl_EXT2_IOC_GETFLAGS],
262     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@include <sys/ioctl.h>
263 @%:@include <ext2fs/ext2_fs.h>],
264                                    [int x = EXT2_IOC_GETFLAGS])],
265                   [AS_VAR_SET([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [yes])],
266                   [AS_VAR_SET([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [no])])])
267
268 AS_VAR_IF([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [yes],
269     [AC_DEFINE_UNQUOTED([HAVE_WORKING_EXT2_IOC_GETFLAGS], [1],
270                     [Define to 1 if you have a working EXT2_IOC_GETFLAGS])])
271
272 AC_CHECK_HEADERS([inttypes.h io.h langinfo.h limits.h])
273 AC_CHECK_HEADERS([linux/fiemap.h linux/fs.h linux/magic.h linux/types.h])
274
275 AC_CACHE_CHECK([whether FS_IOC_GETFLAGS is usable],
276     [ac_cv_have_decl_FS_IOC_GETFLAGS],
277     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@include <sys/ioctl.h>
278 @%:@include <linux/fs.h>],
279                                    [int x = FS_IOC_GETFLAGS])],
280                   [AS_VAR_SET([ac_cv_have_decl_FS_IOC_GETFLAGS], [yes])],
281                   [AS_VAR_SET([ac_cv_have_decl_FS_IOC_GETFLAGS], [no])])])
282
283 AS_VAR_IF([ac_cv_have_decl_FS_IOC_GETFLAGS], [yes],
284     [AC_DEFINE_UNQUOTED([HAVE_WORKING_FS_IOC_GETFLAGS], [1],
285                     [Define to 1 if you have a working FS_IOC_GETFLAGS])])
286
287 AC_CHECK_HEADERS([locale.h membership.h paths.h poll.h pthread.h pwd.h])
288 AC_CHECK_HEADERS([readpassphrase.h signal.h spawn.h])
289 AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h])
290 AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/ea.h sys/extattr.h])
291 AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h])
292 AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/richacl.h])
293 AC_CHECK_HEADERS([sys/select.h sys/statfs.h sys/statvfs.h sys/sysmacros.h])
294 AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h sys/xattr.h])
295 AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h])
296 AC_CHECK_HEADERS([windows.h])
297 # check windows.h first; the other headers require it.
298 AC_CHECK_HEADERS([wincrypt.h winioctl.h],[],[],
299 [[#ifdef HAVE_WINDOWS_H
300 # include <windows.h>
301 #endif
302 ]])
303
304 # Checks for libraries.
305 AC_ARG_WITH([zlib],
306   AS_HELP_STRING([--without-zlib], [Don't build support for gzip through zlib]))
307
308 if test "x$with_zlib" != "xno"; then
309   AC_CHECK_HEADERS([zlib.h])
310   AC_CHECK_LIB(z,inflate)
311 fi
312
313 AC_ARG_WITH([bz2lib],
314   AS_HELP_STRING([--without-bz2lib], [Don't build support for bzip2 through bz2lib]))
315
316 if test "x$with_bz2lib" != "xno"; then
317   AC_CHECK_HEADERS([bzlib.h])
318   case "$host_os" in
319     *mingw* | *cygwin* | *msys*)
320       dnl AC_CHECK_LIB cannot be used on the Windows port of libbz2, therefore
321           dnl use AC_LINK_IFELSE.
322           AC_MSG_CHECKING([for BZ2_bzDecompressInit in -lbz2])
323       old_LIBS="$LIBS"
324       LIBS="-lbz2 $LIBS"
325       AC_LINK_IFELSE(
326         [AC_LANG_SOURCE(#include <bzlib.h>
327           int main() { return BZ2_bzDecompressInit(NULL, 0, 0); })],
328         [ac_cv_lib_bz2_BZ2_bzDecompressInit=yes],
329         [ac_cv_lib_bz2_BZ2_bzDecompressInit=no])
330       LIBS="$old_LIBS"
331           AC_MSG_RESULT($ac_cv_lib_bz2_BZ2_bzDecompressInit)
332       if test "x$ac_cv_lib_bz2_BZ2_bzDecompressInit" = xyes; then
333         AC_DEFINE([HAVE_LIBBZ2], [1], [Define to 1 if you have the `bz2' library (-lbz2).])
334         LIBS="-lbz2 $LIBS"
335       fi
336     ;;
337     *)
338       AC_CHECK_LIB(bz2,BZ2_bzDecompressInit)
339     ;;
340   esac
341 fi
342
343 AC_ARG_WITH([libb2],
344   AS_HELP_STRING([--without-libb2], [Don't build support for BLAKE2 through libb2]))
345
346 if test "x$with_libb2" != "xno"; then
347   AC_CHECK_HEADERS([blake2.h])
348   AC_CHECK_LIB(b2,blake2sp_init)
349 fi
350
351 AM_CONDITIONAL([INC_BLAKE2], [test "x$ac_cv_lib_b2_blake2sp_init" != "xyes"])
352
353 AC_ARG_WITH([iconv],
354   AS_HELP_STRING([--without-iconv], [Don't try to link against iconv]))
355
356 if test "x$with_iconv" != "xno"; then
357   AM_ICONV
358   AC_CHECK_HEADERS([iconv.h],[],[],[#include <stdlib.h>])
359   if test "x$am_cv_func_iconv" = "xyes"; then
360     AC_CHECK_HEADERS([localcharset.h])
361     am_save_LIBS="$LIBS"
362     LIBS="${LIBS} ${LIBICONV}"
363     AC_CHECK_FUNCS([locale_charset])
364     LIBS="${am_save_LIBS}"
365     if test "x$ac_cv_func_locale_charset" != "xyes"; then
366       # If locale_charset() is not in libiconv, we have to find libcharset. 
367       AC_CHECK_LIB(charset,locale_charset)
368     fi
369   fi
370 fi
371
372 AC_ARG_WITH([lz4],
373   AS_HELP_STRING([--without-lz4], [Don't build support for lz4 through liblz4]))
374
375 if test "x$with_lz4" != "xno"; then
376   AC_CHECK_HEADERS([lz4.h lz4hc.h])
377   AC_CHECK_LIB(lz4,LZ4_decompress_safe)
378 fi
379
380 AC_ARG_WITH([zstd],
381   AS_HELP_STRING([--without-zstd], [Don't build support for zstd through libzstd]))
382
383 if test "x$with_zstd" != "xno"; then
384   AC_CHECK_HEADERS([zstd.h])
385   AC_CHECK_LIB(zstd,ZSTD_compressStream)
386 fi
387
388 AC_ARG_WITH([lzma],
389   AS_HELP_STRING([--without-lzma], [Don't build support for xz through lzma]))
390
391 if test "x$with_lzma" != "xno"; then
392   AC_CHECK_HEADERS([lzma.h])
393   AC_CHECK_LIB(lzma,lzma_stream_decoder)
394   # Some pre-release (but widely distributed) versions of liblzma
395   # included a disabled version of lzma_stream_encoder_mt that
396   # fools a naive AC_CHECK_LIB or AC_CHECK_FUNC, so we need
397   # to do something more complex here:
398   AC_CACHE_CHECK(
399     [whether we have multithread support in lzma],
400     ac_cv_lzma_has_mt,
401     [AC_LINK_IFELSE([
402       AC_LANG_PROGRAM([[#include <lzma.h>]
403                        [#if LZMA_VERSION < 50020000]
404                        [#error unsupported]
405                        [#endif]],
406                       [[lzma_stream_encoder_mt(0, 0);]])],
407       [ac_cv_lzma_has_mt=yes], [ac_cv_lzma_has_mt=no])])
408   if test "x$ac_cv_lzma_has_mt" != xno; then
409           AC_DEFINE([HAVE_LZMA_STREAM_ENCODER_MT], [1], [Define to 1 if you have the `lzma_stream_encoder_mt' function.])
410   fi
411 fi
412
413 AC_ARG_WITH([lzo2],
414   AS_HELP_STRING([--with-lzo2], [Build with LZO support from liblzo2]))
415
416 if test "x$with_lzo2" = "xyes"; then
417   AC_CHECK_HEADERS([lzo/lzoconf.h lzo/lzo1x.h])
418   AC_CHECK_LIB(lzo2,lzo1x_decompress_safe)
419 fi
420
421 AC_ARG_WITH([cng],
422   AS_HELP_STRING([--without-cng], [Don't build support of CNG(Crypto Next Generation)]))
423
424 AC_ARG_WITH([mbedtls],
425   AS_HELP_STRING([--with-mbedtls], [Build with crypto support from mbed TLS]))
426 AC_ARG_WITH([nettle],
427   AS_HELP_STRING([--with-nettle], [Build with crypto support from Nettle]))
428 AC_ARG_WITH([openssl],
429   AS_HELP_STRING([--without-openssl], [Don't build support for mtree and xar hashes through openssl]))
430 case "$host_os" in
431   *darwin* ) with_openssl=no ;;
432 esac
433
434 AC_ARG_WITH([xml2],
435   AS_HELP_STRING([--without-xml2], [Don't build support for xar through libxml2]))
436 AC_ARG_WITH([expat],
437   AS_HELP_STRING([--without-expat], [Don't build support for xar through expat]))
438
439 if test "x$with_xml2" != "xno"; then
440   PKG_PROG_PKG_CONFIG
441   PKG_CHECK_MODULES(LIBXML2_PC, [libxml-2.0], [
442     CPPFLAGS="${CPPFLAGS} ${LIBXML2_PC_CFLAGS}"
443     LIBS="${LIBS} ${LIBXML2_PC_LIBS}"
444     AC_CHECK_LIB(xml2,xmlInitParser,[true],AC_MSG_FAILURE(Missing xml2 library))
445   ], [
446     AC_CHECK_LIB(xml2,xmlInitParser)
447   ])
448   AC_CHECK_HEADERS([libxml/xmlreader.h libxml/xmlwriter.h])
449 fi
450 if test "x$ac_cv_header_libxml_xmlreader_h" != "xyes"; then
451   if test "x$with_expat" != "xno"; then
452     AC_CHECK_HEADERS([expat.h])
453     AC_CHECK_LIB(expat,XML_ParserCreate)
454   fi
455 fi
456
457 AC_ARG_ENABLE([posix-regex-lib],
458   [AS_HELP_STRING([--enable-posix-regex-lib],
459     [choose what library to use for POSIX regular expression support (default: auto)])
460   AS_HELP_STRING([--enable-posix-regex-lib=libc], [use libc POSIX regular expression support])
461   AS_HELP_STRING([--enable-posix-regex-lib=libregex], [use libregex POSIX regular expression support])
462   AS_HELP_STRING([--enable-posix-regex-lib=libpcreposix], [use libpcreposix POSIX regular expression support])
463   AS_HELP_STRING([--disable-posix-regex-lib], [don't enable POSIX regular expression support])],
464   [], [enable_posix_regex_lib=auto])
465
466 posix_regex_lib_found=
467 if test "$enable_posix_regex_lib" = "auto" || test "$enable_posix_regex_lib" = "libc" || test "$enable_posix_regex_lib" = "libregex"; then
468   AC_CHECK_HEADERS([regex.h])
469   if test "x$ac_cv_header_regex_h" != "xno"; then
470     AC_CHECK_FUNC(regcomp)
471     if test "x$ac_cv_func_regcomp" = xyes; then
472       posix_regex_lib_found=1
473     else
474       AC_CHECK_LIB(regex,regcomp)
475       if test "x$ac_cv_lib_regex_regcomp" = xyes; then
476         posix_regex_lib_found=1
477       fi
478     fi
479   fi
480 fi
481 if test -z $posix_regex_lib_found && (test "$enable_posix_regex_lib" = "auto" || test "$enable_posix_regex_lib" = "libpcreposix"); then
482   AC_CHECK_HEADERS([pcreposix.h])
483   AC_CHECK_LIB(pcreposix,regcomp)
484   if test "x$ac_cv_lib_pcreposix_regcomp" != xyes; then
485     AC_MSG_NOTICE(trying libpcreposix check again with libpcre)
486         unset ac_cv_lib_pcreposix_regcomp
487         AC_CHECK_LIB(pcre,pcre_exec)
488     AC_CHECK_LIB(pcreposix,regcomp)
489     if test "x$ac_cv_lib_pcre_pcre_exec" = xyes && test "x$ac_cv_lib_pcreposix_regcomp" = xyes; then
490       AC_MSG_CHECKING(if PCRE_STATIC needs to be defined)
491       AC_LINK_IFELSE(
492         [AC_LANG_SOURCE(#include <pcreposix.h>
493           int main() { return regcomp(NULL, NULL, 0); })],
494         [without_pcre_static=yes],
495         [without_pcre_static=no])
496       AC_LINK_IFELSE(
497         [AC_LANG_SOURCE(#define PCRE_STATIC
498           #include <pcreposix.h>
499           int main() { return regcomp(NULL, NULL, 0); })],
500         [with_pcre_static=yes],
501         [with_pcre_static=no])
502       if test "x$without_pcre_static" != xyes && test "x$with_pcre_static" = xyes; then
503         AC_MSG_RESULT(yes)
504         AC_DEFINE([PCRE_STATIC], [1], [Define to 1 if PCRE_STATIC needs to be defined.])
505       elif test "x$without_pcre_static" = xyes || test "x$with_pcre_static" = xyes; then
506         AC_MSG_RESULT(no)
507       fi
508       posix_regex_lib_found=1
509     fi
510   else
511     posix_regex_lib_found=1
512   fi
513 fi
514
515 # TODO: Give the user the option of using a pre-existing system
516 # libarchive.  This will define HAVE_LIBARCHIVE which will cause
517 # bsdtar_platform.h to use #include <...> for the libarchive headers.
518 # Need to include Makefile.am magic to link against system
519 # -larchive in that case.
520 #AC_CHECK_LIB(archive,archive_version)
521
522 # Checks for supported compiler flags
523 AX_APPEND_COMPILE_FLAGS([-Wall -Wformat -Wformat-security])
524
525 # Checks for typedefs, structures, and compiler characteristics.
526 AC_C_CONST
527 # la_TYPE_UID_T defaults to "int", which is incorrect for MinGW
528 # and MSVC. Use a customized version.
529 la_TYPE_UID_T
530 AC_TYPE_MODE_T
531 # AC_TYPE_OFF_T defaults to "long", which limits us to 4GB files on
532 # most systems... default to "long long" instead.
533 AC_CHECK_TYPE(off_t, [long long])
534 AC_TYPE_SIZE_T
535 AC_CHECK_TYPE(id_t, [unsigned long])
536 AC_CHECK_TYPE(uintptr_t, [unsigned int])
537
538 # Check for tm_gmtoff in struct tm
539 AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,
540 [
541 #include <time.h>
542 ])
543
544 # Check for f_namemax in struct statfs
545 AC_CHECK_MEMBERS([struct statfs.f_namemax],,,
546 [
547 #include <sys/param.h>
548 #include <sys/mount.h>
549 ])
550
551 # Check for f_iosize in struct statvfs
552 AC_CHECK_MEMBERS([struct statvfs.f_iosize],,,
553 [
554 #include <sys/statvfs.h>
555 ])
556
557 # Check for birthtime in struct stat
558 AC_CHECK_MEMBERS([struct stat.st_birthtime])
559
560 # Check for high-resolution timestamps in struct stat
561 AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
562 AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
563 AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
564 AC_CHECK_MEMBERS([struct stat.st_mtime_n]) # AIX
565 AC_CHECK_MEMBERS([struct stat.st_umtime]) # Tru64
566 AC_CHECK_MEMBERS([struct stat.st_mtime_usec]) # Hurd
567 # Check for block size support in struct stat
568 AC_CHECK_MEMBERS([struct stat.st_blksize])
569 # Check for st_flags in struct stat (BSD fflags)
570 AC_CHECK_MEMBERS([struct stat.st_flags])
571
572 # If you have uintmax_t, we assume printf supports %ju
573 # If you have unsigned long long, we assume printf supports %llu
574 # TODO: Check for %ju and %llu support directly.
575 AC_CHECK_TYPES([uintmax_t, unsigned long long])
576
577 # We use C99-style integer types
578 # Declare them if the local platform doesn't already do so.
579 AC_TYPE_INTMAX_T
580 AC_TYPE_UINTMAX_T
581 AC_TYPE_INT64_T
582 AC_TYPE_UINT64_T
583 AC_TYPE_INT32_T
584 AC_TYPE_UINT32_T
585 AC_TYPE_INT16_T
586 AC_TYPE_UINT16_T
587 AC_TYPE_UINT8_T
588
589 AC_CHECK_DECLS([SIZE_MAX, INT32_MAX, INT32_MIN])
590 AC_CHECK_DECLS([INT64_MAX, INT64_MIN, UINT64_MAX, UINT32_MAX])
591 AC_CHECK_DECLS([INTMAX_MAX, INTMAX_MIN, UINTMAX_MAX])
592
593 AC_CHECK_DECL([SSIZE_MAX],
594                 [AC_DEFINE(HAVE_DECL_SSIZE_MAX, 1, [Define to 1 if you have the declaration of `SSIZE_MAX', and to 0 if you don't.])],
595                 [],
596                 [#include <limits.h>])
597
598 AC_CHECK_DECL([EFTYPE],
599                 [AC_DEFINE(HAVE_EFTYPE, 1, [A possible errno value for invalid file format errors])],
600                 [],
601                 [#include <errno.h>])
602 AC_CHECK_DECL([EILSEQ],
603                 [AC_DEFINE(HAVE_EILSEQ, 1, [A possible errno value for invalid file format errors])],
604                 [],
605                 [#include <errno.h>])
606 AC_CHECK_TYPE([wchar_t],
607                 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]wchar_t), 1, [Define to 1 if the system has the type `wchar_t'.])dnl
608                 AC_CHECK_SIZEOF([wchar_t])],
609                 [])
610
611 AC_HEADER_TIME
612
613 # Checks for library functions.
614 AC_PROG_GCC_TRADITIONAL
615 AC_HEADER_MAJOR
616 AC_FUNC_FSEEKO
617 AC_FUNC_MEMCMP
618 AC_FUNC_LSTAT
619 AC_FUNC_STAT
620 AC_FUNC_STRERROR_R
621 AC_FUNC_STRFTIME
622 AC_FUNC_VPRINTF
623 # check for:
624 #   CreateHardLinkA(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES)
625 # To avoid necessity for including windows.h or special forward declaration
626 # workarounds, we use 'void *' for 'struct SECURITY_ATTRIBUTES *'
627 AC_CHECK_STDCALL_FUNC([CreateHardLinkA],[const char *, const char *, void *])
628 AC_CHECK_FUNCS([arc4random_buf chflags chown chroot ctime_r])
629 AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fdopendir fork])
630 AC_CHECK_FUNCS([fstat fstatat fstatfs fstatvfs ftruncate])
631 AC_CHECK_FUNCS([futimens futimes futimesat])
632 AC_CHECK_FUNCS([geteuid getpid getgrgid_r getgrnam_r])
633 AC_CHECK_FUNCS([getpwnam_r getpwuid_r getvfsbyname gmtime_r])
634 AC_CHECK_FUNCS([lchflags lchmod lchown link localtime_r lstat lutimes])
635 AC_CHECK_FUNCS([mbrtowc memmove memset])
636 AC_CHECK_FUNCS([mkdir mkfifo mknod mkstemp])
637 AC_CHECK_FUNCS([nl_langinfo openat pipe poll posix_spawnp readlink readlinkat])
638 AC_CHECK_FUNCS([readpassphrase])
639 AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs])
640 AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])
641 AC_CHECK_FUNCS([tzset unlinkat unsetenv utime utimensat utimes vfork])
642 AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy wmemmove])
643 AC_CHECK_FUNCS([_ctime64_s _fseeki64])
644 AC_CHECK_FUNCS([_get_timezone _gmtime64_s _localtime64_s _mkgmtime64])
645 # detects cygwin-1.7, as opposed to older versions
646 AC_CHECK_FUNCS([cygwin_conv_path])
647
648 # DragonFly uses vfsconf, FreeBSD xvfsconf.
649 AC_CHECK_TYPES(struct vfsconf,,,
650         [#if HAVE_SYS_TYPES_H
651         #include <sys/types.h>
652         #endif
653         #include <sys/mount.h>
654         ])
655
656 AC_CHECK_TYPES(struct xvfsconf,,,
657         [#if HAVE_SYS_TYPES_H
658         #include <sys/types.h>
659         #endif
660         #include <sys/mount.h>
661         ])
662
663 # There are several variants of readdir_r around; we only
664 # accept the POSIX-compliant version.
665 AC_COMPILE_IFELSE(
666  [AC_LANG_PROGRAM([[#include <dirent.h>]],
667                   [[DIR *dir; struct dirent e, *r;
668                     return(readdir_r(dir, &e, &r));]])],
669  [AC_DEFINE(HAVE_READDIR_R,1,[Define to 1 if you have a POSIX compatible readdir_r])]
670 )
671 # dirfd can be either a function or a macro.
672 AC_COMPILE_IFELSE(
673  [AC_LANG_PROGRAM([[#include <dirent.h>
674                     DIR *dir;]],
675                   [[return(dirfd(dir));]])],
676  [AC_DEFINE(HAVE_DIRFD,1,[Define to 1 if you have a dirfd function or macro])]
677 )
678
679 # FreeBSD's nl_langinfo supports an option to specify whether the
680 # current locale uses month/day or day/month ordering.  It makes the
681 # output a little prettier...
682 AC_CHECK_DECL([D_MD_ORDER],
683 [AC_DEFINE(HAVE_D_MD_ORDER, 1, [Define to 1 if nl_langinfo supports D_MD_ORDER])],
684 [],
685 [#if HAVE_LANGINFO_H
686 #include <langinfo.h>
687 #endif
688 ])
689
690 # Check for dirent.d_namlen field explicitly
691 # (This is a bit more straightforward than, if not quite as portable as,
692 # the recipe given by the autoconf maintainers.)
693 AC_CHECK_MEMBER(struct dirent.d_namlen,,,
694 [#if HAVE_DIRENT_H
695 #include <dirent.h>
696 #endif
697 ])
698
699 # Check for Extended Attributes support
700 AC_ARG_ENABLE([xattr],
701                 AS_HELP_STRING([--disable-xattr],
702                 [Disable Extended Attributes support (default: check)]))
703
704 if test "x$enable_xattr" != "xno"; then
705     AC_SEARCH_LIBS([setxattr], [attr gnu])
706     AC_CHECK_DECLS([EXTATTR_NAMESPACE_USER], [], [], [#include <sys/types.h>
707 #include <sys/extattr.h>
708 ])
709     AC_CHECK_DECLS([XATTR_NOFOLLOW], [], [], [#include <sys/xattr.h>
710 ])
711     if test "x$ac_cv_header_sys_xattr_h" = "xyes" \
712          -a "x$ac_cv_have_decl_XATTR_NOFOLLOW" = "xyes"; then
713         # Darwin extended attributes support
714         AC_CACHE_VAL([ac_cv_archive_xattr_darwin],
715           [AC_CHECK_FUNCS(fgetxattr \
716                           flistxattr \
717                           fsetxattr \
718                           getxattr \
719                           listxattr \
720                           setxattr,
721           [ac_cv_archive_xattr_darwin=yes],
722           [ac_cv_archive_xattr_darwin=no],
723           [#include <sys/xattr.h>
724 ])
725         ]
726       )
727     elif test "x$ac_cv_header_sys_extattr_h" = "xyes" \
728            -a "x$ac_cv_have_decl_EXTATTR_NAMESPACE_USER" = "xyes"; then
729         # FreeBSD extended attributes support
730         AC_CACHE_VAL([ac_cv_archive_xattr_freebsd],
731           [AC_CHECK_FUNCS(extattr_get_fd \
732                           extattr_get_file \
733                           extattr_get_link \
734                           extattr_list_fd \
735                           extattr_list_file \
736                           extattr_list_link \
737                           extattr_set_fd \
738                           extattr_set_link,
739           [ac_cv_archive_xattr_freebsd=yes],
740           [ac_cv_archive_xattr_freebsd=no],
741           [#include <sys/types.h>
742 #include <sys/extattr.h>
743 ])
744           ]
745         )
746     elif test "x$ac_cv_header_sys_xattr_h" = "xyes" \
747            -o "x$ac_cv_header_attr_xattr_h" = "xyes"; then
748         # Linux extended attributes support
749         AC_CACHE_VAL([ac_cv_archive_xattr_linux],
750           [AC_CHECK_FUNCS(fgetxattr \
751                           flistxattr \
752                           fsetxattr \
753                           getxattr \
754                           lgetxattr \
755                           listxattr \
756                           llistxattr \
757                           lsetxattr,
758           [ac_cv_archive_xattr_linux=yes],
759           [ac_cv_archive_xattr_linux=no],
760           [#if HAVE_SYS_TYPES_H
761 #include <sys/types.h>
762 #endif
763 #if HAVE_SYS_XATTR_H
764 #include <sys/xattr.h>
765 #endif
766 #if HAVE_ATTR_XATTR_H
767 #include <attr/xatr.h>
768 #endif
769 ])
770         ]
771       )
772     elif test "x$ac_cv_header_sys_ea_h" = "xyes"; then
773         # AIX extended attributes support
774         AC_CACHE_VAL([ac_cv_archive_xattr_aix],
775           [AC_CHECK_FUNCS(fgetea \
776                           flistea \
777                           fsetea \
778                           getea \
779                           lgetea \
780                           listea \
781                           llistea \
782                           lsetea,
783           [ac_cv_archive_xattr_aix=yes],
784           [ac_cv_archive_xattr_aix=no],
785           [#include <sys/ea.h>
786 ])
787           ]
788         )
789     fi
790
791     AC_MSG_CHECKING([for extended attributes support])
792     if test "x$ac_cv_archive_xattr_linux" = "xyes"; then
793         AC_DEFINE([ARCHIVE_XATTR_LINUX], [1], [Linux xattr support])
794         AC_MSG_RESULT([Linux])
795     elif test "x$ac_cv_archive_xattr_darwin" = "xyes"; then
796         AC_DEFINE([ARCHIVE_XATTR_DARWIN], [1], [Darwin xattr support])
797         AC_MSG_RESULT([Darwin])
798     elif test "x$ac_cv_archive_xattr_freebsd" = "xyes"; then
799         AC_DEFINE([ARCHIVE_XATTR_FREEBSD], [1], [FreeBSD xattr support])
800         AC_MSG_RESULT([FreeBSD])
801     elif test "x$ac_cv_archive_xattr_aix" = "xyes"; then
802         AC_DEFINE([ARCHIVE_XATTR_AIX], [1], [AIX xattr support])
803         AC_MSG_RESULT([AIX])
804     else
805         AC_MSG_RESULT([none])
806     fi
807 fi
808
809 # Check for ACL support
810 #
811 # The ACL support in libarchive is written against the POSIX1e draft,
812 # which was never officially approved and varies quite a bit across
813 # platforms.  Worse, some systems have completely non-POSIX acl functions,
814 # which makes the following checks rather more complex than I would like.
815 #
816 AC_ARG_ENABLE([acl],
817                 AS_HELP_STRING([--disable-acl],
818                 [Disable ACL support (default: check)]))
819
820 if test "x$enable_acl" != "xno"; then
821     # Libacl
822     AC_CHECK_LIB([acl], [acl_get_file])
823
824     AC_CHECK_TYPES([acl_t, acl_entry_t, acl_permset_t, acl_tag_t], [], [], [
825       #if HAVE_SYS_TYPES_H
826       #include <sys/types.h>
827       #endif
828       #if HAVE_SYS_ACL_H
829       #include <sys/acl.h>
830       #endif
831     ])
832
833     AC_CHECK_LIB([richacl], [richacl_get_file])
834
835     AC_CHECK_TYPES([[struct richace], [struct richacl]], [], [], [
836       #if HAVE_SYS_RICHACL_H
837       #include <sys/richacl.h>
838       #endif
839     ])
840
841     # Solaris and derivates ACLs
842     AC_CHECK_FUNCS(acl facl)
843
844     if test "x$ac_cv_lib_richacl_richacl_get_file" = "xyes" \
845          -a "x$ac_cv_type_struct_richace" = "xyes" \
846          -a "x$ac_cv_type_struct_richacl" = "xyes"; then
847         AC_CACHE_VAL([ac_cv_archive_acl_librichacl],
848           [AC_CHECK_FUNCS(richacl_alloc \
849                           richacl_equiv_mode \
850                           richacl_free \
851                           richacl_get_fd \
852                           richacl_get_file \
853                           richacl_set_fd \
854                           richacl_set_file,
855           [ac_cv_archive_acl_librichacl=yes], [ac_cv_archive_acl_librichacl=no],          [#include <sys/richacl.h>])])
856     fi
857
858     if test "x$ac_cv_func_acl" = "xyes" \
859          -a "x$ac_cv_func_facl" = "xyes"; then
860         AC_CHECK_TYPES([aclent_t], [], [], [[#include <sys/acl.h>]])
861         if test "x$ac_cv_type_aclent_t" = "xyes"; then
862             AC_CACHE_VAL([ac_cv_archive_acl_sunos],
863               [AC_CHECK_DECLS([GETACL, SETACL, GETACLCNT],
864               [ac_cv_archive_acl_sunos=yes], [ac_cv_archive_acl_sunos=no],
865               [#include <sys/acl.h>])])
866             AC_CHECK_TYPES([ace_t], [], [], [[#include <sys/acl.h>]])
867             if test "x$ac_cv_type_ace_t" = "xyes"; then
868                 AC_CACHE_VAL([ac_cv_archive_acl_sunos_nfs4],
869                   [AC_CHECK_DECLS([ACE_GETACL, ACE_SETACL, ACE_GETACLCNT],
870                   [ac_cv_archive_acl_sunos_nfs4=yes],
871                   [ac_cv_archive_acl_sonos_nfs4=no],
872                   [#include <sys/acl.h>])])
873             fi
874         fi
875     elif test "x$ac_cv_type_acl_t" = "xyes" \
876          -a "x$ac_cv_type_acl_entry_t" = "xyes" \
877          -a "x$ac_cv_type_acl_permset_t" = "xyes" \
878          -a "x$ac_cv_type_acl_tag_t" = "xyes"; then
879         # POSIX.1e ACL functions
880         AC_CACHE_VAL([ac_cv_posix_acl_funcs],
881           [AC_CHECK_FUNCS(acl_add_perm \
882                           acl_clear_perms \
883                           acl_create_entry \
884                           acl_delete_def_file \
885                           acl_free \
886                           acl_get_entry \
887                           acl_get_fd \
888                           acl_get_file \
889                           acl_get_permset \
890                           acl_get_qualifier \
891                           acl_get_tag_type \
892                           acl_init \
893                           acl_set_fd \
894                           acl_set_file \
895                           acl_set_qualifier \
896                           acl_set_tag_type,
897           [ac_cv_posix_acl_funcs=yes], [ac_cv_posix_acl_funcs=no],
898           [#if HAVE_SYS_TYPES_H
899            #include <sys/types.h>
900            #endif
901            #if HAVE_SYS_ACL_H
902            #include <sys/acl.h>
903            #endif
904           ])
905         ])
906
907         AC_CHECK_FUNCS(acl_get_perm)
908
909         if test "x$ac_cv_posix_acl_funcs" = "xyes" \
910              -a "x$ac_cv_header_acl_libacl_h" = "xyes" \
911              -a "x$ac_cv_lib_acl_acl_get_file" = "xyes" \
912              -a "x$ac_cv_func_acl_get_perm"; then
913             AC_CACHE_VAL([ac_cv_archive_acl_libacl],
914               [ac_cv_archive_acl_libacl=yes])
915             AC_DEFINE([ARCHIVE_ACL_LIBACL], [1],
916               [POSIX.1e ACL support via libacl])
917         else
918              # FreeBSD/Darwin
919              AC_CHECK_FUNCS(acl_add_flag_np \
920                             acl_clear_flags_np \
921                             acl_get_brand_np \
922                             acl_get_entry_type_np \
923                             acl_get_flag_np \
924                             acl_get_flagset_np \
925                             acl_get_fd_np \
926                             acl_get_link_np \
927                             acl_get_perm_np \
928                             acl_is_trivial_np \
929                             acl_set_entry_type_np \
930                             acl_set_fd_np \
931                             acl_set_link_np,,,
932               [#include <sys/types.h>
933                #include <sys/acl.h>])
934
935             AC_CHECK_FUNCS(mbr_uid_to_uuid \
936                            mbr_uuid_to_id \
937                            mbr_gid_to_uuid,,,
938               [#include <membership.h>])
939
940             AC_CHECK_DECLS([ACL_TYPE_EXTENDED, ACL_TYPE_NFS4, ACL_USER,
941               ACL_SYNCHRONIZE], [], [],
942               [#include <sys/types.h>
943                #include <sys/acl.h>])
944             if test "x$ac_cv_posix_acl_funcs" = "xyes" \
945                  -a "x$ac_cv_func_acl_get_fd_np" = "xyes" \
946                  -a "x$ac_cv_func_acl_get_perm" != "xyes" \
947                  -a "x$ac_cv_func_acl_get_perm_np" = "xyes" \
948                  -a "x$ac_cv_func_acl_set_fd_np" = "xyes"; then
949                 if test "x$ac_cv_have_decl_ACL_USER" = "xyes"; then
950                     AC_CACHE_VAL([ac_cv_archive_acl_freebsd],
951                       [ac_cv_archive_acl_freebsd=yes])
952                     if test "x$ac_cv_have_decl_ACL_TYPE_NFS4" = "xyes" \
953                          -a "x$ac_cv_func_acl_add_flag_np" = "xyes" \
954                          -a "x$ac_cv_func_acl_get_brand_np" = "xyes" \
955                          -a "x$ac_cv_func_acl_get_entry_type_np" = "xyes" \
956                          -a "x$ac_cv_func_acl_get_flagset_np" = "xyes" \
957                          -a "x$ac_cv_func_acl_set_entry_type_np" = "xyes"; then
958                         AC_CACHE_VAL([ac_cv_archive_acl_freebsd_nfs4],
959                           [ac_cv_archive_acl_freebsd_nfs4=yes])
960                     fi
961                 elif test "x$ac_cv_have_decl_ACL_TYPE_EXTENDED" = "xyes" \
962                        -a "x$ac_cv_func_acl_add_flag_np" = "xyes" \
963                        -a "x$ac_cv_func_acl_get_flagset_np" = "xyes" \
964                        -a "x$ac_cv_func_acl_get_link_np" = "xyes" \
965                        -a "x$ac_cv_func_acl_set_link_np" = "xyes" \
966                        -a "x$ac_cv_func_mbr_uid_to_uuid" = "xyes" \
967                        -a "x$ac_cv_func_mbr_uuid_to_id" = "xyes" \
968                        -a "x$ac_cv_func_mbr_gid_to_uuid" = "xyes"; then
969                     AC_CACHE_VAL([ac_cv_archive_acl_darwin],
970                       [ac_cv_archive_acl_darwin=yes])
971                 fi
972             fi
973         fi
974     fi
975     AC_MSG_CHECKING([for ACL support])
976     if test "x$ac_cv_archive_acl_libacl" = "xyes" \
977          -a "x$ac_cv_archive_acl_librichacl" = "xyes"; then
978         AC_MSG_RESULT([libacl (POSIX.1e) + librichacl (NFSv4)])
979         AC_DEFINE([ARCHIVE_ACL_LIBACL], [1],
980           [Linux POSIX.1e ACL support via libacl])
981         AC_DEFINE([ARCHIVE_ACL_LIBRICHACL], [1],
982           [Linux NFSv4 ACL support via librichacl])
983     elif test "x$ac_cv_archive_acl_libacl" = "xyes"; then
984         AC_MSG_RESULT([libacl (POSIX.1e)])
985         AC_DEFINE([ARCHIVE_ACL_LIBACL], [1],
986           [Linux POSIX.1e ACL support via libacl])
987     elif test "x$ac_cv_archive_acl_librichacl" = "xyes"; then
988         AC_MSG_RESULT([librichacl (NFSv4)])
989         AC_DEFINE([ARCHIVE_ACL_LIBRICHACL], [1],
990           [Linux NFSv4 ACL support via librichacl])
991     elif test "x$ac_cv_archive_acl_darwin" = "xyes"; then
992         AC_DEFINE([ARCHIVE_ACL_DARWIN], [1], [Darwin ACL support])
993         AC_MSG_RESULT([Darwin (limited NFSv4)])
994     elif test "x$ac_cv_archive_acl_sunos" = "xyes"; then
995         AC_DEFINE([ARCHIVE_ACL_SUNOS], [1], [Solaris ACL support])
996         if test "x$ac_cv_archive_acl_sunos_nfs4" = "xyes"; then
997             AC_DEFINE([ARCHIVE_ACL_SUNOS_NFS4], [1],
998               [Solaris NFSv4 ACL support])
999             AC_MSG_RESULT([Solaris (POSIX.1e and NFSv4)])
1000         else
1001             AC_MSG_RESULT([Solaris (POSIX.1e)])
1002         fi
1003     elif test "x$ac_cv_archive_acl_freebsd" = "xyes"; then
1004         AC_DEFINE([ARCHIVE_ACL_FREEBSD], [1], [FreeBSD ACL support])
1005         if test "x$ac_cv_archive_acl_freebsd_nfs4" = "xyes"; then
1006             AC_DEFINE([ARCHIVE_ACL_FREEBSD_NFS4], [1],
1007               [FreeBSD NFSv4 ACL support])
1008             AC_MSG_RESULT([FreeBSD (POSIX.1e and NFSv4)])
1009         else
1010             AC_MSG_RESULT([FreeBSD (POSIX.1e)])
1011         fi
1012     else
1013         AC_MSG_RESULT([none])
1014     fi
1015 fi
1016
1017
1018 AM_CONDITIONAL([INC_LINUX_ACL],
1019   [test "x$ac_cv_archive_acl_libacl" = "xyes" \
1020      -o "x$ac_cv_archive_acl_librichacl" = "xyes"])
1021 AM_CONDITIONAL([INC_SUNOS_ACL], [test "x$ac_cv_archive_acl_sunos" = "xyes"])
1022 AM_CONDITIONAL([INC_DARWIN_ACL],
1023           [test "x$ac_cv_archive_acl_darwin" = "xyes"])
1024 AM_CONDITIONAL([INC_FREEBSD_ACL],
1025           [test "x$ac_cv_archive_acl_freebsd" = "xyes"])
1026
1027 # Additional requirements
1028 AC_SYS_LARGEFILE
1029
1030 dnl NOTE: Crypto checks must run last.
1031 AC_DEFUN([CRYPTO_CHECK], [
1032   if test "$found_$1" != yes; then
1033     saved_CPPFLAGS="$CPPFLAGS"
1034     CPPFLAGS="$CPPFLAGS -I. -I$srcdir -I$srcdir/libarchive"
1035     touch "check_crypto_md.h"
1036     AC_MSG_CHECKING([support for ARCHIVE_CRYPTO_$1_$2])
1037     AC_LINK_IFELSE([AC_LANG_SOURCE([
1038 #define ARCHIVE_$1_COMPILE_TEST
1039 #define ARCHIVE_CRYPTO_$1_$2
1040 #define PLATFORM_CONFIG_H "check_crypto_md.h"
1041
1042 $(cat "$srcdir/libarchive/archive_digest.c")
1043
1044 int
1045 main(int argc, char **argv)
1046 {
1047   archive_$3_ctx ctx;
1048   archive_$3_init(&ctx);
1049   archive_$3_update(&ctx, *argv, argc);
1050   archive_$3_final(&ctx, NULL);
1051   return 0;
1052 }
1053 ])],
1054     [ AC_MSG_RESULT([yes])
1055       found_$1=yes
1056       found_$2=yes
1057       AC_DEFINE(ARCHIVE_CRYPTO_$1_$2, 1, [ $1 via ARCHIVE_CRYPTO_$1_$2 supported.])
1058     ],
1059     [ AC_MSG_RESULT([no])])
1060     CPPFLAGS="$saved_CPPFLAGS"
1061     rm "check_crypto_md.h"
1062   fi
1063 ])
1064
1065 AC_DEFUN([CRYPTO_CHECK_WIN], [
1066   if test "$found_$1" != yes; then
1067     AC_MSG_CHECKING([support for ARCHIVE_CRYPTO_$1_WIN])
1068     AC_LINK_IFELSE([AC_LANG_SOURCE([
1069 #define ARCHIVE_$1_COMPILE_TEST
1070 #include <windows.h>
1071 #include <wincrypt.h>
1072
1073 int
1074 main(int argc, char **argv)
1075 {
1076         (void)argc;
1077         (void)argv;
1078
1079         return ($2);
1080 }
1081 ])],
1082     [ AC_MSG_RESULT([yes])
1083       found_$1=yes
1084       found_WIN=yes
1085       AC_DEFINE(ARCHIVE_CRYPTO_$1_WIN, 1, [ $1 via ARCHIVE_CRYPTO_$1_WIN supported.])
1086     ],
1087     [ AC_MSG_RESULT([no])])
1088   fi
1089 ])
1090
1091 case "$host_os" in
1092   *mingw* | *cygwin* | *msys*)
1093         ;;
1094   *)
1095         CRYPTO_CHECK(MD5, LIBC, md5)
1096         CRYPTO_CHECK(MD5, LIBSYSTEM, md5)
1097         CRYPTO_CHECK(RMD160, LIBC, rmd160)
1098         CRYPTO_CHECK(SHA1, LIBC, sha1)
1099         CRYPTO_CHECK(SHA1, LIBSYSTEM, sha1)
1100         CRYPTO_CHECK(SHA256, LIBC, sha256)
1101         CRYPTO_CHECK(SHA256, LIBC2, sha256)
1102         CRYPTO_CHECK(SHA256, LIBC3, sha256)
1103         CRYPTO_CHECK(SHA256, LIBSYSTEM, sha256)
1104         CRYPTO_CHECK(SHA384, LIBC, sha384)
1105         CRYPTO_CHECK(SHA384, LIBC2, sha384)
1106         CRYPTO_CHECK(SHA384, LIBC3, sha384)
1107         CRYPTO_CHECK(SHA384, LIBSYSTEM, sha384)
1108         CRYPTO_CHECK(SHA512, LIBC, sha512)
1109         CRYPTO_CHECK(SHA512, LIBC2, sha512)
1110         CRYPTO_CHECK(SHA512, LIBC3, sha512)
1111         CRYPTO_CHECK(SHA512, LIBSYSTEM, sha512)
1112         ;;
1113 esac
1114
1115 if test "x$with_cng" != "xno"; then
1116     AC_CHECK_HEADERS([bcrypt.h],[
1117         LIBS="$LIBS -lbcrypt"
1118     ],[],
1119     [[#ifdef HAVE_WINDOWS_H
1120     # include <windows.h>
1121     #endif
1122     ]])
1123 fi
1124
1125 if test "x$with_mbedtls" = "xyes"; then
1126     AC_CHECK_HEADERS([mbedtls/aes.h mbedtls/md.h mbedtls/pkcs5.h])
1127     saved_LIBS=$LIBS
1128     AC_CHECK_LIB(mbedcrypto,mbedtls_sha1_init)
1129     CRYPTO_CHECK(MD5, MBEDTLS, md5)
1130     CRYPTO_CHECK(RMD160, MBEDTLS, rmd160)
1131     CRYPTO_CHECK(SHA1, MBEDTLS, sha1)
1132     CRYPTO_CHECK(SHA256, MBEDTLS, sha256)
1133     CRYPTO_CHECK(SHA384, MBEDTLS, sha384)
1134     CRYPTO_CHECK(SHA512, MBEDTLS, sha512)
1135     if test "x$found_MBEDTLS" != "xyes"; then
1136       LIBS=$saved_LIBS
1137     fi
1138 fi
1139
1140 if test "x$with_nettle" = "xyes"; then
1141     AC_CHECK_HEADERS([nettle/md5.h nettle/ripemd160.h nettle/sha.h])
1142     AC_CHECK_HEADERS([nettle/pbkdf2.h nettle/aes.h nettle/hmac.h])
1143     saved_LIBS=$LIBS
1144     AC_CHECK_LIB(nettle,nettle_sha1_init)
1145     CRYPTO_CHECK(MD5, NETTLE, md5)
1146     CRYPTO_CHECK(RMD160, NETTLE, rmd160)
1147     CRYPTO_CHECK(SHA1, NETTLE, sha1)
1148     CRYPTO_CHECK(SHA256, NETTLE, sha256)
1149     CRYPTO_CHECK(SHA384, NETTLE, sha384)
1150     CRYPTO_CHECK(SHA512, NETTLE, sha512)
1151     if test "x$found_NETTLE" != "xyes"; then
1152       LIBS=$saved_LIBS
1153     fi
1154 fi
1155
1156 if test "x$with_openssl" != "xno"; then
1157     AC_CHECK_HEADERS([openssl/evp.h])
1158     saved_LIBS=$LIBS
1159     case "$host_os" in
1160       *mingw* | *cygwin* | *msys*)
1161         case "$host_cpu" in
1162           x86_64)
1163             AC_CHECK_LIB(eay64,OPENSSL_config)
1164             if test "x$ac_cv_lib_eay64_main" != "xyes"; then
1165               AC_CHECK_LIB(eay32,OPENSSL_config)
1166             fi
1167             ;;
1168           *)
1169             AC_CHECK_LIB(eay32,OPENSSL_config)
1170             ;;
1171         esac
1172         ;;
1173       *)
1174         AC_CHECK_LIB(crypto,OPENSSL_config)
1175         ;;
1176     esac
1177     CRYPTO_CHECK(MD5, OPENSSL, md5)
1178     CRYPTO_CHECK(RMD160, OPENSSL, rmd160)
1179     CRYPTO_CHECK(SHA1, OPENSSL, sha1)
1180     CRYPTO_CHECK(SHA256, OPENSSL, sha256)
1181     CRYPTO_CHECK(SHA384, OPENSSL, sha384)
1182     CRYPTO_CHECK(SHA512, OPENSSL, sha512)
1183     AC_CHECK_FUNCS([PKCS5_PBKDF2_HMAC_SHA1])
1184 fi
1185
1186 # Probe libmd AFTER OpenSSL/libcrypto.
1187 # The two are incompatible and OpenSSL is more complete.
1188 AC_CHECK_HEADERS([md5.h ripemd.h sha.h sha256.h sha512.h])
1189 saved_LIBS=$LIBS
1190 AC_CHECK_LIB(md,MD5Init)
1191 CRYPTO_CHECK(MD5, LIBMD, md5)
1192 CRYPTO_CHECK(RMD160, LIBMD, rmd160)
1193 CRYPTO_CHECK(SHA1, LIBMD, sha1)
1194 CRYPTO_CHECK(SHA256, LIBMD, sha256)
1195 CRYPTO_CHECK(SHA512, LIBMD, sha512)
1196 if test "x$found_LIBMD" != "xyes"; then
1197   LIBS=$saved_LIBS
1198 fi
1199
1200 case "$host_os" in
1201   *mingw* | *cygwin* | *msys*)
1202         CRYPTO_CHECK_WIN(MD5, CALG_MD5)
1203         CRYPTO_CHECK_WIN(SHA1, CALG_SHA1)
1204         CRYPTO_CHECK_WIN(SHA256, CALG_SHA_256)
1205         CRYPTO_CHECK_WIN(SHA384, CALG_SHA_384)
1206         CRYPTO_CHECK_WIN(SHA512, CALG_SHA_512)
1207         ;;
1208 esac
1209
1210 # Ensure test directories are present if building out-of-tree
1211 AC_CONFIG_COMMANDS([mkdirs],
1212                    [mkdir -p libarchive/test tar/test cat/test cpio/test])
1213
1214 AC_OUTPUT