Imported Upstream version 3.1.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.1.2])
8 m4_define([LIBARCHIVE_VERSION_N],[3001002])
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
14 AC_PREREQ(2.65)
15
16 #
17 # Now starts the "real" configure script.
18 #
19
20 AC_INIT([libarchive],LIBARCHIVE_VERSION_S(),[libarchive-discuss@googlegroups.com])
21 # Make sure the srcdir contains "libarchive" directory
22 AC_CONFIG_SRCDIR([libarchive])
23 # Use auxiliary subscripts from this subdirectory (cleans up root)
24 AC_CONFIG_AUX_DIR([build/autoconf])
25 # M4 scripts
26 AC_CONFIG_MACRO_DIR([build/autoconf])
27 # Must follow AC_CONFIG macros above...
28 AM_INIT_AUTOMAKE()
29 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
30
31 # Libtool's "interface version" can be computed from the libarchive version.
32
33 # Libtool interface version bumps on any API change, so increments
34 # whenever libarchive minor version does.
35 ARCHIVE_MINOR=$(( (LIBARCHIVE_VERSION_N() / 1000) % 1000 ))
36 # Libarchive 2.7 == libtool interface 9 = 2 + 7
37 # Libarchive 2.8 == libtool interface 10 = 2 + 8
38 # Libarchive 2.9 == libtool interface 11 = 2 + 8
39 # Libarchive 3.0 == libtool interface 12
40 # Libarchive 3.1 == libtool interface 13
41 ARCHIVE_INTERFACE=`echo $((13 + ${ARCHIVE_MINOR}))`
42 # Libarchive revision is bumped on any source change === libtool revision
43 ARCHIVE_REVISION=$(( LIBARCHIVE_VERSION_N() % 1000 ))
44 # Libarchive minor is bumped on any interface addition === libtool age
45 ARCHIVE_LIBTOOL_VERSION=$ARCHIVE_INTERFACE:$ARCHIVE_REVISION:$ARCHIVE_MINOR
46
47 # Stick the version numbers into config.h
48 AC_DEFINE([LIBARCHIVE_VERSION_STRING],"LIBARCHIVE_VERSION_S()",
49         [Version number of libarchive])
50 AC_DEFINE_UNQUOTED([LIBARCHIVE_VERSION_NUMBER],"LIBARCHIVE_VERSION_N()",
51         [Version number of libarchive as a single integer])
52 AC_DEFINE([BSDCPIO_VERSION_STRING],"BSDCPIO_VERSION_S()",
53         [Version number of bsdcpio])
54 AC_DEFINE([BSDTAR_VERSION_STRING],"BSDTAR_VERSION_S()",
55         [Version number of bsdtar])
56
57 # The shell variables here must be the same as the AC_SUBST() variables
58 # below, but the shell variable names apparently cannot be the same as
59 # the m4 macro names above.  Why?  Ask autoconf.
60 BSDCPIO_VERSION_STRING=BSDCPIO_VERSION_S()
61 BSDTAR_VERSION_STRING=BSDTAR_VERSION_S()
62 LIBARCHIVE_VERSION_STRING=LIBARCHIVE_VERSION_S()
63 LIBARCHIVE_VERSION_NUMBER=LIBARCHIVE_VERSION_N()
64
65 # Substitute the above version numbers into the various files below.
66 # Yes, I believe this is the fourth time we define what are essentially
67 # the same symbols.  Why? Ask autoconf.
68 AC_SUBST(ARCHIVE_LIBTOOL_VERSION)
69 AC_SUBST(BSDCPIO_VERSION_STRING)
70 AC_SUBST(BSDTAR_VERSION_STRING)
71 AC_SUBST(LIBARCHIVE_VERSION_STRING)
72 AC_SUBST(LIBARCHIVE_VERSION_NUMBER)
73
74 AC_CONFIG_HEADERS([config.h])
75 AC_CONFIG_FILES([Makefile])
76 AC_CONFIG_FILES([build/pkgconfig/libarchive.pc])
77
78 # Check for host type
79 AC_CANONICAL_HOST
80
81 dnl Compilation on mingw and Cygwin needs special Makefile rules
82 inc_windows_files=no
83 inc_cygwin_files=no
84 case "$host_os" in
85   *mingw* ) inc_windows_files=yes ;;
86   *cygwin*) inc_cygwin_files=yes ;;
87 esac
88 AM_CONDITIONAL([INC_WINDOWS_FILES], [test $inc_windows_files = yes])
89 AM_CONDITIONAL([INC_CYGWIN_FILES], [test $inc_cygwin_files = yes])
90
91 dnl Defines that are required for specific platforms (e.g. -D_POSIX_SOURCE, etc)
92 PLATFORMCPPFLAGS=
93 case "$host_os" in
94   *mingw* ) PLATFORMCPPFLAGS=-D__USE_MINGW_ANSI_STDIO ;;
95 esac
96 AC_SUBST(PLATFORMCPPFLAGS)
97
98 # Checks for programs.
99 AC_PROG_CC
100 AM_PROG_CC_C_O
101 AC_USE_SYSTEM_EXTENSIONS
102 AC_LIBTOOL_WIN32_DLL
103 AC_PROG_LIBTOOL
104 AC_CHECK_TOOL([STRIP],[strip])
105
106 #
107 # Options for building bsdtar.
108 #
109 # Default is to build bsdtar, but allow people to override that.
110 #
111 AC_ARG_ENABLE([bsdtar],
112         [AS_HELP_STRING([--enable-bsdtar], [enable build of bsdtar (default)])
113         AS_HELP_STRING([--enable-bsdtar=static], [force static build of bsdtar])
114         AS_HELP_STRING([--enable-bsdtar=shared], [force dynamic build of bsdtar])
115 AS_HELP_STRING([--disable-bsdtar], [disable build of bsdtar])],
116         [], [enable_bsdtar=yes])
117
118 case "$enable_bsdtar" in
119 yes)
120         if test "$enable_static" = "no"; then
121                 static_bsdtar=no
122         else
123                 static_bsdtar=yes
124         fi
125         build_bsdtar=yes
126         ;;
127 dynamic|shared)
128         if test "$enable_shared" = "no"; then
129                 AC_MSG_FAILURE([Shared linking of bsdtar requires shared libarchive])
130         fi
131         build_bsdtar=yes
132         static_bsdtar=no
133         ;;
134 static)
135         build_bsdtar=yes
136         static_bsdtar=yes
137         ;;
138 no)
139         build_bsdtar=no
140         static_bsdtar=no
141         ;;
142 *)
143         AC_MSG_FAILURE([Unsupported value for --enable-bsdtar])
144         ;;
145 esac
146
147 AM_CONDITIONAL([BUILD_BSDTAR], [ test "$build_bsdtar" = yes ])
148 AM_CONDITIONAL([STATIC_BSDTAR], [ test "$static_bsdtar" = yes ])
149
150 #
151 # Options for building bsdcpio.
152 #
153 # Default is not to build bsdcpio, but that can be overridden.
154 #
155 AC_ARG_ENABLE([bsdcpio],
156         [AS_HELP_STRING([--enable-bsdcpio], [enable build of bsdcpio (default)])
157         AS_HELP_STRING([--enable-bsdcpio=static], [static build of bsdcpio])
158         AS_HELP_STRING([--enable-bsdcpio=shared], [dynamic build of bsdcpio])
159 AS_HELP_STRING([--disable-bsdcpio], [disable build of bsdcpio])],
160         [], [enable_bsdcpio=yes])
161
162 case "$enable_bsdcpio" in
163 yes)
164         if test "$enable_static" = "no"; then
165            static_bsdcpio=no
166         else
167            static_bsdcpio=yes
168         fi
169         build_bsdcpio=yes
170         ;;
171 dynamic|shared)
172         if test "$enabled_shared" = "no"; then
173            AC_MSG_FAILURE([Shared linking of bsdcpio requires shared libarchive])
174         fi
175         build_bsdcpio=yes
176         ;;
177 static)
178         build_bsdcpio=yes
179         static_bsdcpio=yes
180         ;;
181 no)
182         build_bsdcpio=no
183         static_bsdcpio=no
184         ;;
185 *)
186         AC_MSG_FAILURE([Unsupported value for --enable-bsdcpio])
187         ;;
188 esac
189
190 AM_CONDITIONAL([BUILD_BSDCPIO], [ test "$build_bsdcpio" = yes ])
191 AM_CONDITIONAL([STATIC_BSDCPIO], [ test "$static_bsdcpio" = yes ])
192
193 # Set up defines needed before including any headers
194 case $host in
195   *mingw* | *cygwin* )
196   AC_DEFINE([_WIN32_WINNT], 0x0500, [Define to '0x0500' for Windows 2000 APIs.])
197   AC_DEFINE([WINVER], 0x0500, [Define to '0x0500' for Windows 2000 APIs.])
198   ;;
199 esac
200
201 # Checks for header files.
202 AC_HEADER_DIRENT
203 AC_HEADER_SYS_WAIT
204 AC_CHECK_HEADERS([acl/libacl.h attr/xattr.h copyfile.h ctype.h])
205 AC_CHECK_HEADERS([errno.h ext2fs/ext2_fs.h fcntl.h grp.h])
206
207 AC_CACHE_CHECK([whether EXT2_IOC_GETFLAGS is usable],
208     [ac_cv_have_decl_EXT2_IOC_GETFLAGS],
209     [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([@%:@include <sys/ioctl.h>
210 @%:@include <ext2fs/ext2_fs.h>],
211                                    [int x = EXT2_IOC_GETFLAGS])],
212                   [AS_VAR_SET([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [yes])],
213                   [AS_VAR_SET([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [no])])])
214
215 AS_VAR_IF([ac_cv_have_decl_EXT2_IOC_GETFLAGS], [yes],
216     [AC_DEFINE_UNQUOTED([HAVE_WORKING_EXT2_IOC_GETFLAGS], [1],
217                     [Define to 1 if you have a working EXT2_IOC_GETFLAGS])])
218
219 AC_CHECK_HEADERS([inttypes.h io.h langinfo.h limits.h])
220 AC_CHECK_HEADERS([linux/fiemap.h linux/fs.h linux/magic.h linux/types.h])
221 AC_CHECK_HEADERS([locale.h paths.h poll.h pwd.h signal.h spawn.h])
222 AC_CHECK_HEADERS([stdarg.h stdint.h stdlib.h string.h])
223 AC_CHECK_HEADERS([sys/acl.h sys/cdefs.h sys/extattr.h])
224 AC_CHECK_HEADERS([sys/ioctl.h sys/mkdev.h sys/mount.h])
225 AC_CHECK_HEADERS([sys/param.h sys/poll.h sys/select.h sys/statfs.h sys/statvfs.h])
226 AC_CHECK_HEADERS([sys/time.h sys/utime.h sys/utsname.h sys/vfs.h])
227 AC_CHECK_HEADERS([time.h unistd.h utime.h wchar.h wctype.h])
228 AC_CHECK_HEADERS([windows.h])
229 # check windows.h first; the other headers require it.
230 AC_CHECK_HEADERS([wincrypt.h winioctl.h],[],[],
231 [[#ifdef HAVE_WINDOWS_H
232 # include <windows.h>
233 #endif
234 ]])
235
236 # Checks for libraries.
237 AC_ARG_WITH([zlib],
238   AS_HELP_STRING([--without-zlib], [Don't build support for gzip through zlib]))
239
240 if test "x$with_zlib" != "xno"; then
241   AC_CHECK_HEADERS([zlib.h])
242   AC_CHECK_LIB(z,inflate)
243 fi
244
245 AC_ARG_WITH([bz2lib],
246   AS_HELP_STRING([--without-bz2lib], [Don't build support for bzip2 through bz2lib]))
247
248 if test "x$with_bz2lib" != "xno"; then
249   AC_CHECK_HEADERS([bzlib.h])
250   case "$host_os" in
251     *mingw* | *cygwin*)
252       dnl AC_CHECK_LIB cannot be used on the Windows port of libbz2, therefore
253           dnl use AC_LINK_IFELSE.
254           AC_MSG_CHECKING([for BZ2_bzDecompressInit in -lbz2])
255       old_LIBS="$LIBS"
256       LIBS="-lbz2 $LIBS"
257       AC_LINK_IFELSE(
258         [AC_LANG_SOURCE(#include <bzlib.h>
259           int main() { return BZ2_bzDecompressInit(NULL, 0, 0); })],
260         [ac_cv_lib_bz2_BZ2_bzDecompressInit=yes],
261         [ac_cv_lib_bz2_BZ2_bzDecompressInit=no])
262       LIBS="$old_LIBS"
263           AC_MSG_RESULT($ac_cv_lib_bz2_BZ2_bzDecompressInit)
264       if test "x$ac_cv_lib_bz2_BZ2_bzDecompressInit" = xyes; then
265         AC_DEFINE([HAVE_LIBBZ2], [1], [Define to 1 if you have the `bz2' library (-lbz2).])
266         LIBS="-lbz2 $LIBS"
267       fi
268     ;;
269     *)
270       AC_CHECK_LIB(bz2,BZ2_bzDecompressInit)
271     ;;
272   esac
273 fi
274
275 AC_ARG_WITH([lzmadec],
276   AS_HELP_STRING([--without-lzmadec], [Don't build support for lzma through lzmadec]))
277
278 if test "x$with_lzmadec" != "xno"; then
279   AC_CHECK_HEADERS([lzmadec.h])
280   AC_CHECK_LIB(lzmadec,lzmadec_decode)
281 fi
282
283 AC_ARG_WITH([iconv],
284   AS_HELP_STRING([--without-iconv], [Don't try to link against iconv]))
285
286 if test "x$with_iconv" != "xno"; then
287   AM_ICONV
288   AC_CHECK_HEADERS([iconv.h],[],[],[#include <stdlib.h>])
289   if test "x$am_cv_func_iconv" = "xyes"; then
290     AC_CHECK_HEADERS([localcharset.h])
291     am_save_LIBS="$LIBS"
292     LIBS="${LIBS} ${LIBICONV}"
293     AC_CHECK_FUNCS([locale_charset])
294     LIBS="${am_save_LIBS}"
295     if test "x$ac_cv_func_locale_charset" != "xyes"; then
296       # If locale_charset() is not in libiconv, we have to find libcharset. 
297       AC_CHECK_LIB(charset,locale_charset)
298     fi
299   fi
300 fi
301
302 AC_ARG_WITH([lzma],
303   AS_HELP_STRING([--without-lzma], [Don't build support for xz through lzma]))
304
305 if test "x$with_lzma" != "xno"; then
306   AC_CHECK_HEADERS([lzma.h])
307   AC_CHECK_LIB(lzma,lzma_stream_decoder)
308 fi
309
310 AC_ARG_WITH([lzo2],
311   AS_HELP_STRING([--without-lzo2], [Don't build support for lzop through liblzo2]))
312
313 if test "x$with_lzo2" != "xno"; then
314   AC_CHECK_HEADERS([lzo/lzoconf.h lzo/lzo1x.h])
315   AC_CHECK_LIB(lzo2,lzo1x_decompress_safe)
316 fi
317
318 AC_ARG_WITH([nettle],
319   AS_HELP_STRING([--without-nettle], [Don't build with crypto support from Nettle]))
320 AC_ARG_WITH([openssl],
321   AS_HELP_STRING([--without-openssl], [Don't build support for mtree and xar hashes through openssl]))
322 case "$host_os" in
323   *darwin* ) with_openssl=no ;;
324 esac
325
326 AC_ARG_WITH([xml2],
327   AS_HELP_STRING([--without-xml2], [Don't build support for xar through libxml2]))
328 AC_ARG_WITH([expat],
329   AS_HELP_STRING([--without-expat], [Don't build support for xar through expat]))
330
331 if test "x$with_xml2" != "xno"; then
332   AC_PATH_PROG([XML2_CONFIG], [xml2-config],, [${PATH}])
333   if test "x$XML2_CONFIG" != "x"; then
334     CPPFLAGS="${CPPFLAGS} `${XML2_CONFIG} --cflags`"
335     LIBS="${LIBS} `${XML2_CONFIG} --libs`"
336     AC_CHECK_LIB(xml2,xmlInitParser,[true],AC_MSG_FAILURE(Missing xml2 library))
337   else
338     AC_CHECK_LIB(xml2,xmlInitParser)
339   fi
340   AC_CHECK_HEADERS([libxml/xmlreader.h libxml/xmlwriter.h])
341 fi
342 if test "x$ac_cv_header_libxml_xmlreader_h" != "xyes"; then
343   if test "x$with_expat" != "xno"; then
344     AC_CHECK_HEADERS([expat.h])
345     AC_CHECK_LIB(expat,XML_ParserCreate)
346   fi
347 fi
348
349 AC_ARG_ENABLE([posix-regex-lib],
350   [AS_HELP_STRING([--enable-posix-regex-lib],
351     [choose what library to use for POSIX regular expression support (default: auto)])
352   AS_HELP_STRING([--enable-posix-regex-lib=libc], [use libc POSIX regular expression support])
353   AS_HELP_STRING([--enable-posix-regex-lib=libregex], [use libregex POSIX regular expression support])
354   AS_HELP_STRING([--enable-posix-regex-lib=libpcreposix], [use libpcreposix POSIX regular expression support])
355   AS_HELP_STRING([--disable-posix-regex-lib], [don't enable POSIX regular expression support])],
356   [], [enable_posix_regex_lib=auto])
357
358 posix_regex_lib_found=
359 if test "$enable_posix_regex_lib" = "auto" || test "$enable_posix_regex_lib" = "libc" || test "$enable_posix_regex_lib" = "libregex"; then
360   AC_CHECK_HEADERS([regex.h])
361   if test "x$ac_cv_header_regex_h" != "xno"; then
362     AC_CHECK_FUNC(regcomp)
363     if test "x$ac_cv_func_regcomp" = xyes; then
364       posix_regex_lib_found=1
365     else
366       AC_CHECK_LIB(regex,regcomp)
367       if test "x$ac_cv_lib_regex_regcomp" = xyes; then
368         posix_regex_lib_found=1
369       fi
370     fi
371   fi
372 fi
373 if test -z $posix_regex_lib_found && (test "$enable_posix_regex_lib" = "auto" || test "$enable_posix_regex_lib" = "libpcreposix"); then
374   AC_CHECK_HEADERS([pcreposix.h])
375   AC_CHECK_LIB(pcreposix,regcomp)
376   if test "x$ac_cv_lib_pcreposix_regcomp" != xyes; then
377     AC_MSG_NOTICE(trying libpcreposix check again with libpcre)
378         unset ac_cv_lib_pcreposix_regcomp
379         AC_CHECK_LIB(pcre,pcre_exec)
380     AC_CHECK_LIB(pcreposix,regcomp)
381     if test "x$ac_cv_lib_pcre_pcre_exec" = xyes && test "x$ac_cv_lib_pcreposix_regcomp" = xyes; then
382       AC_MSG_CHECKING(if PCRE_STATIC needs to be defined)
383       AC_LINK_IFELSE(
384         [AC_LANG_SOURCE(#include <pcreposix.h>
385           int main() { return regcomp(NULL, NULL, 0); })],
386         [without_pcre_static=yes],
387         [without_pcre_static=no])
388       AC_LINK_IFELSE(
389         [AC_LANG_SOURCE(#define PCRE_STATIC
390           #include <pcreposix.h>
391           int main() { return regcomp(NULL, NULL, 0); })],
392         [with_pcre_static=yes],
393         [with_pcre_static=no])
394       if test "x$without_pcre_static" != xyes && test "x$with_pcre_static" = xyes; then
395         AC_MSG_RESULT(yes)
396         AC_DEFINE([PCRE_STATIC], [1], [Define to 1 if PCRE_STATIC needs to be defined.])
397       elif test "x$without_pcre_static" = xyes || test "x$with_pcre_static" = xyes; then
398         AC_MSG_RESULT(no)
399       fi
400       posix_regex_lib_found=1
401     fi
402   else
403     posix_regex_lib_found=1
404   fi
405 fi
406
407 # TODO: Give the user the option of using a pre-existing system
408 # libarchive.  This will define HAVE_LIBARCHIVE which will cause
409 # bsdtar_platform.h to use #include <...> for the libarchive headers.
410 # Need to include Makefile.am magic to link against system
411 # -larchive in that case.
412 #AC_CHECK_LIB(archive,archive_version)
413
414 # Checks for typedefs, structures, and compiler characteristics.
415 AC_C_CONST
416 # AC_TYPE_UID_T defaults to "int", which is incorrect for MinGW
417 # and MSVC. Use a customized version.
418 la_TYPE_UID_T
419 AC_TYPE_MODE_T
420 # AC_TYPE_OFF_T defaults to "long", which limits us to 4GB files on
421 # most systems... default to "long long" instead.
422 AC_CHECK_TYPE(off_t, [long long])
423 AC_TYPE_SIZE_T
424 AC_CHECK_TYPE(id_t, [unsigned long])
425 AC_CHECK_TYPE(uintptr_t, [unsigned int])
426
427 # Check for tm_gmtoff in struct tm
428 AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,
429 [
430 #include <time.h>
431 ])
432
433 # Check for f_namemax in struct statfs
434 AC_CHECK_MEMBERS([struct statfs.f_namemax],,,
435 [
436 #include <sys/param.h>
437 #include <sys/mount.h>
438 ])
439
440 # Check for f_iosize in struct statvfs
441 AC_CHECK_MEMBERS([struct statvfs.f_iosize],,,
442 [
443 #include <sys/statvfs.h>
444 ])
445
446 # Check for birthtime in struct stat
447 AC_CHECK_MEMBERS([struct stat.st_birthtime])
448
449 # Check for high-resolution timestamps in struct stat
450 AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec])
451 AC_CHECK_MEMBERS([struct stat.st_mtimespec.tv_nsec])
452 AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec])
453 AC_CHECK_MEMBERS([struct stat.st_mtime_n]) # AIX
454 AC_CHECK_MEMBERS([struct stat.st_umtime]) # Tru64
455 AC_CHECK_MEMBERS([struct stat.st_mtime_usec]) # Hurd
456 # Check for block size support in struct stat
457 AC_CHECK_MEMBERS([struct stat.st_blksize])
458 # Check for st_flags in struct stat (BSD fflags)
459 AC_CHECK_MEMBERS([struct stat.st_flags])
460
461 # If you have uintmax_t, we assume printf supports %ju
462 # If you have unsigned long long, we assume printf supports %llu
463 # TODO: Check for %ju and %llu support directly.
464 AC_CHECK_TYPES([uintmax_t, unsigned long long])
465
466 # We use C99-style integer types
467 # Declare them if the local platform doesn't already do so.
468 AC_TYPE_INTMAX_T
469 AC_TYPE_UINTMAX_T
470 AC_TYPE_INT64_T
471 AC_TYPE_UINT64_T
472 AC_TYPE_INT32_T
473 AC_TYPE_UINT32_T
474 AC_TYPE_INT16_T
475 AC_TYPE_UINT16_T
476 AC_TYPE_UINT8_T
477
478 AC_CHECK_DECLS([SIZE_MAX, INT64_MAX, INT64_MIN, UINT64_MAX, UINT32_MAX])
479
480 AC_CHECK_DECL([SSIZE_MAX],
481                 [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.])],
482                 [],
483                 [#include <limits.h>])
484
485 AC_CHECK_DECL([EFTYPE],
486                 [AC_DEFINE(HAVE_EFTYPE, 1, [A possible errno value for invalid file format errors])],
487                 [],
488                 [#include <errno.h>])
489 AC_CHECK_DECL([EILSEQ],
490                 [AC_DEFINE(HAVE_EILSEQ, 1, [A possible errno value for invalid file format errors])],
491                 [],
492                 [#include <errno.h>])
493 AC_CHECK_TYPE([wchar_t],
494                 [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]wchar_t), 1, [Define to 1 if the system has the type `wchar_t'.])dnl
495                 AC_CHECK_SIZEOF([wchar_t])],
496                 [])
497
498 AC_HEADER_TIME
499
500 # Checks for library functions.
501 AC_PROG_GCC_TRADITIONAL
502 AC_HEADER_MAJOR
503 AC_FUNC_FSEEKO
504 AC_FUNC_MEMCMP
505 AC_FUNC_LSTAT
506 AC_FUNC_STAT
507 AC_FUNC_STRERROR_R
508 AC_FUNC_STRFTIME
509 AC_FUNC_VPRINTF
510 # check for:
511 #   CreateHardLinkA(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES)
512 # To avoid necessity for including windows.h or special forward declaration
513 # workarounds, we use 'void *' for 'struct SECURITY_ATTRIBUTES *'
514 AC_CHECK_STDCALL_FUNC([CreateHardLinkA],[const char *, const char *, void *])
515 AC_CHECK_FUNCS([chflags chown chroot ctime_r dirfd])
516 AC_CHECK_FUNCS([fchdir fchflags fchmod fchown fcntl fdopendir fork])
517 AC_CHECK_FUNCS([fstat fstatat fstatfs fstatvfs ftruncate])
518 AC_CHECK_FUNCS([futimens futimes futimesat])
519 AC_CHECK_FUNCS([geteuid getpid getgrgid_r getgrnam_r])
520 AC_CHECK_FUNCS([getpwnam_r getpwuid_r getvfsbyname gmtime_r])
521 AC_CHECK_FUNCS([lchflags lchmod lchown link localtime_r lstat lutimes])
522 AC_CHECK_FUNCS([mbrtowc memmove memset])
523 AC_CHECK_FUNCS([mkdir mkfifo mknod mkstemp])
524 AC_CHECK_FUNCS([nl_langinfo openat pipe poll posix_spawnp readlink readlinkat])
525 AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs])
526 AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])
527 AC_CHECK_FUNCS([tzset unsetenv utime utimensat utimes vfork])
528 AC_CHECK_FUNCS([wcrtomb wcscmp wcscpy wcslen wctomb wmemcmp wmemcpy])
529 AC_CHECK_FUNCS([_ctime64_s _fseeki64])
530 AC_CHECK_FUNCS([_get_timezone _localtime64_s _mkgmtime64])
531 # detects cygwin-1.7, as opposed to older versions
532 AC_CHECK_FUNCS([cygwin_conv_path])
533
534 # There are several variants of readdir_r around; we only
535 # accept the POSIX-compliant version.
536 AC_COMPILE_IFELSE(
537  [AC_LANG_PROGRAM([[#include <dirent.h>]],
538                   [[DIR *dir; struct dirent e, *r;
539                     return(readdir_r(dir, &e, &r));]])],
540  [AC_DEFINE(HAVE_READDIR_R,1,[Define to 1 if you have a POSIX compatible readdir_r])]
541 )
542
543 # FreeBSD's nl_langinfo supports an option to specify whether the
544 # current locale uses month/day or day/month ordering.  It makes the
545 # output a little prettier...
546 AC_CHECK_DECL([D_MD_ORDER],
547 [AC_DEFINE(HAVE_D_MD_ORDER, 1, [Define to 1 if nl_langinfo supports D_MD_ORDER])],
548 [],
549 [#if HAVE_LANGINFO_H
550 #include <langinfo.h>
551 #endif
552 ])
553
554 # Check for dirent.d_namlen field explicitly
555 # (This is a bit more straightforward than, if not quite as portable as,
556 # the recipe given by the autoconf maintainers.)
557 AC_CHECK_MEMBER(struct dirent.d_namlen,,,
558 [#if HAVE_DIRENT_H
559 #include <dirent.h>
560 #endif
561 ])
562
563 # Check for Extended Attributes support
564 AC_ARG_ENABLE([xattr],
565                 AS_HELP_STRING([--disable-xattr],
566                 [Enable Extended Attributes support (default: check)]))
567
568 if test "x$enable_xattr" != "xno"; then
569         AC_CHECK_HEADERS([attr/xattr.h])
570         AC_CHECK_HEADERS([sys/xattr.h sys/ea.h])
571         AC_CHECK_LIB(attr,setxattr)
572         AC_CHECK_FUNCS([extattr_get_file extattr_list_file])
573         AC_CHECK_FUNCS([extattr_set_fd extattr_set_file])
574         AC_CHECK_FUNCS([fgetxattr flistxattr fsetxattr getxattr])
575         AC_CHECK_FUNCS([lgetxattr listxattr llistxattr lsetxattr])
576         AC_CHECK_FUNCS([fgetea flistea fsetea getea])
577         AC_CHECK_FUNCS([lgetea listea llistea lsetea])
578         AC_CHECK_DECLS([EXTATTR_NAMESPACE_USER], [], [], [#include <sys/types.h>
579 #include <sys/extattr.h>
580 ])
581 fi
582
583 # Check for ACL support
584 #
585 # The ACL support in libarchive is written against the POSIX1e draft,
586 # which was never officially approved and varies quite a bit across
587 # platforms.  Worse, some systems have completely non-POSIX acl functions,
588 # which makes the following checks rather more complex than I would like.
589 #
590 AC_ARG_ENABLE([acl],
591                 AS_HELP_STRING([--disable-acl],
592                 [Enable ACL support (default: check)]))
593
594 if test "x$enable_acl" != "xno"; then
595    AC_CHECK_HEADERS([sys/acl.h])
596    AC_CHECK_LIB([acl],[acl_get_file])
597    AC_CHECK_FUNCS([acl_create_entry acl_init acl_set_fd acl_set_fd_np acl_set_file])
598
599    AC_CHECK_TYPES(acl_permset_t,,,
600         [#if HAVE_SYS_TYPES_H
601         #include <sys/types.h>
602         #endif
603         #if HAVE_SYS_ACL_H
604         #include <sys/acl.h>
605         #endif
606         ])
607
608     # The "acl_get_perm()" function was omitted from the POSIX draft.
609     # (It's a pretty obvious oversight; otherwise, there's no way to
610     # test for specific permissions in a permset.)  Linux uses the obvious
611     # name, FreeBSD adds _np to mark it as "non-Posix extension."
612     # Test for both as a double-check that we really have POSIX-style ACL support.
613     AC_CHECK_FUNCS(acl_get_perm_np acl_get_perm acl_get_link acl_get_link_np,,,
614         [#if HAVE_SYS_TYPES_H
615         #include <sys/types.h>
616         #endif
617         #if HAVE_SYS_ACL_H
618         #include <sys/acl.h>
619         #endif
620         ])
621
622     # MacOS has an acl.h that isn't POSIX.  It can be detected by
623     # checking for ACL_USER
624     AC_CHECK_DECL([ACL_USER],
625                 [AC_DEFINE(HAVE_ACL_USER, 1, [True for systems with POSIX ACL support])],
626                 [],
627                 [#include <sys/acl.h>])
628 fi
629
630 # Additional requirements
631 AC_SYS_LARGEFILE
632
633 dnl NOTE: Crypto checks must run last.
634 AC_DEFUN([CRYPTO_CHECK], [
635   if test "$found_$1" != yes; then
636     saved_CPPFLAGS="$CPPFLAGS"
637     CPPFLAGS="$CPPFLAGS -I. -I$srcdir -I$srcdir/libarchive"
638     touch "check_crypto_md.h"
639     AC_MSG_CHECKING([support for ARCHIVE_CRYPTO_$1_$2])
640     AC_LINK_IFELSE([AC_LANG_SOURCE([
641 #define ARCHIVE_$1_COMPILE_TEST
642 #define ARCHIVE_CRYPTO_$1_$2
643 #define PLATFORM_CONFIG_H "check_crypto_md.h"
644
645 $(cat "$srcdir/libarchive/archive_crypto.c")
646
647 int
648 main(int argc, char **argv)
649 {
650   archive_$3_ctx ctx;
651   archive_$3_init(&ctx);
652   archive_$3_update(&ctx, *argv, argc);
653   archive_$3_final(&ctx, NULL);
654   return 0;
655 }
656 ])],
657     [ AC_MSG_RESULT([yes])
658       found_$1=yes
659       found_$2=yes
660       AC_DEFINE(ARCHIVE_CRYPTO_$1_$2, 1, [ $1 via ARCHIVE_CRYPTO_$1_$2 supported.])
661     ],
662     [ AC_MSG_RESULT([no])])
663     CPPFLAGS="$saved_CPPFLAGS"
664     rm "check_crypto_md.h"
665   fi
666 ])
667
668 AC_DEFUN([CRYPTO_CHECK_WIN], [
669   if test "$found_$1" != yes; then
670     AC_MSG_CHECKING([support for ARCHIVE_CRYPTO_$1_WIN])
671     AC_LINK_IFELSE([AC_LANG_SOURCE([
672 #define ARCHIVE_$1_COMPILE_TEST
673 #include <windows.h>
674 #include <wincrypt.h>
675
676 int
677 main(int argc, char **argv)
678 {
679         (void)argc;
680         (void)argv;
681
682         return ($2);
683 }
684 ])],
685     [ AC_MSG_RESULT([yes])
686       found_$1=yes
687       found_WIN=yes
688       AC_DEFINE(ARCHIVE_CRYPTO_$1_WIN, 1, [ $1 via ARCHIVE_CRYPTO_$1_WIN supported.])
689     ],
690     [ AC_MSG_RESULT([no])])
691   fi
692 ])
693
694 case "$host_os" in
695   *mingw* | *cygwin*)
696         ;;
697   *)
698         CRYPTO_CHECK(MD5, LIBC, md5)
699         CRYPTO_CHECK(MD5, LIBSYSTEM, md5)
700         CRYPTO_CHECK(RMD160, LIBC, rmd160)
701         CRYPTO_CHECK(SHA1, LIBC, sha1)
702         CRYPTO_CHECK(SHA1, LIBSYSTEM, sha1)
703         CRYPTO_CHECK(SHA256, LIBC, sha256)
704         CRYPTO_CHECK(SHA256, LIBC2, sha256)
705         CRYPTO_CHECK(SHA256, LIBC3, sha256)
706         CRYPTO_CHECK(SHA256, LIBSYSTEM, sha256)
707         CRYPTO_CHECK(SHA384, LIBC, sha384)
708         CRYPTO_CHECK(SHA384, LIBC2, sha384)
709         CRYPTO_CHECK(SHA384, LIBC3, sha384)
710         CRYPTO_CHECK(SHA384, LIBSYSTEM, sha384)
711         CRYPTO_CHECK(SHA512, LIBC, sha512)
712         CRYPTO_CHECK(SHA512, LIBC2, sha512)
713         CRYPTO_CHECK(SHA512, LIBC3, sha512)
714         CRYPTO_CHECK(SHA512, LIBSYSTEM, sha512)
715         ;;
716 esac
717
718 if test "x$with_nettle" != "xno"; then
719     AC_CHECK_HEADERS([nettle/md5.h nettle/ripemd160.h nettle/sha.h])
720     saved_LIBS=$LIBS
721     AC_CHECK_LIB(nettle,main)
722     CRYPTO_CHECK(MD5, NETTLE, md5)
723     CRYPTO_CHECK(RMD160, NETTLE, rmd160)
724     CRYPTO_CHECK(SHA1, NETTLE, sha1)
725     CRYPTO_CHECK(SHA256, NETTLE, sha256)
726     CRYPTO_CHECK(SHA384, NETTLE, sha384)
727     CRYPTO_CHECK(SHA512, NETTLE, sha512)
728     if test "x$found_NETTLE" != "xyes"; then
729       LIBS=$saved_LIBS
730     fi
731 fi
732 if test "x$with_openssl" != "xno"; then
733     AC_CHECK_HEADERS([openssl/evp.h])
734     saved_LIBS=$LIBS
735     case "$host_os" in
736       *mingw* | *cygwin*)
737         case "$host_cpu" in
738           x86_64)
739             AC_CHECK_LIB(eay64,main)
740             if test "x$ac_cv_lib_eay64_main" != "xyes"; then
741               AC_CHECK_LIB(eay32,main)
742             fi
743             ;;
744           *)
745             AC_CHECK_LIB(eay32,main)
746             ;;
747         esac
748         ;;
749       *)
750         AC_CHECK_LIB(crypto,main)
751         ;;
752     esac
753     CRYPTO_CHECK(MD5, OPENSSL, md5)
754     CRYPTO_CHECK(RMD160, OPENSSL, rmd160)
755     CRYPTO_CHECK(SHA1, OPENSSL, sha1)
756     CRYPTO_CHECK(SHA256, OPENSSL, sha256)
757     CRYPTO_CHECK(SHA384, OPENSSL, sha384)
758     CRYPTO_CHECK(SHA512, OPENSSL, sha512)
759     if test "x$found_OPENSSL" != "xyes"; then
760       LIBS=$saved_LIBS
761     fi
762 fi
763
764 # Probe libmd AFTER OpenSSL/libcrypto.
765 # The two are incompatible and OpenSSL is more complete.
766 AC_CHECK_HEADERS([md5.h ripemd.h sha.h sha256.h sha512.h])
767 saved_LIBS=$LIBS
768 AC_CHECK_LIB(md,main)
769 CRYPTO_CHECK(MD5, LIBMD, md5)
770 CRYPTO_CHECK(RMD160, LIBMD, rmd160)
771 CRYPTO_CHECK(SHA1, LIBMD, sha1)
772 CRYPTO_CHECK(SHA256, LIBMD, sha256)
773 CRYPTO_CHECK(SHA512, LIBMD, sha512)
774 if test "x$found_LIBMD" != "xyes"; then
775   LIBS=$saved_LIBS
776 fi
777
778 case "$host_os" in
779   *mingw* | *cygwin*)
780         CRYPTO_CHECK_WIN(MD5, CALG_MD5)
781         CRYPTO_CHECK_WIN(SHA1, CALG_SHA1)
782         CRYPTO_CHECK_WIN(SHA256, CALG_SHA_256)
783         CRYPTO_CHECK_WIN(SHA384, CALG_SHA_384)
784         CRYPTO_CHECK_WIN(SHA512, CALG_SHA_512)
785         ;;
786 esac
787
788 AC_OUTPUT