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