debian/rules: Use /bin/sh as POSIX shell regardless of build environment
[xz/debian.git] / configure.ac
blob9697fbd9ab7b9dca20337b5fcd9c13c10192f894
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 ###############################################################################
6 # Author: Lasse Collin
8 # This file has been put into the public domain.
9 # You can do whatever you want with this file.
11 ###############################################################################
13 # NOTE: Don't add useless checks. autoscan detects this and that, but don't
14 # let it confuse you. For example, we don't care about checking for behavior
15 # of malloc(), stat(), or lstat(), since we don't use those functions in
16 # a way that would cause the problems the autoconf macros check.
18 AC_PREREQ([2.64])
20 AC_INIT([XZ Utils], m4_esyscmd([/bin/sh build-aux/version.sh]),
21         [lasse.collin@tukaani.org], [xz], [http://tukaani.org/xz/])
22 AC_CONFIG_SRCDIR([src/liblzma/common/common.h])
23 AC_CONFIG_AUX_DIR([build-aux])
24 AC_CONFIG_MACRO_DIR([m4])
25 AC_CONFIG_HEADER([config.h])
27 echo
28 echo "$PACKAGE_STRING"
30 echo
31 echo "System type:"
32 # This is needed to know if assembler optimizations can be used.
33 AC_CANONICAL_HOST
35 # We do some special things on Windows (32-bit or 64-bit) builds.
36 case $host_os in
37         mingw* | cygwin | msys) is_w32=yes ;;
38         *)                      is_w32=no ;;
39 esac
40 AM_CONDITIONAL([COND_W32], [test "$is_w32" = yes])
42 # We need -lfreebsd-glue on kfreebsd
43 case $host_os in
44         kfreebsd*-gnu* ) is_kfreebsd=yes ;;
45         *)               is_kfreebsd=no ;;
46 esac
47 AM_CONDITIONAL([COND_NEED_FREEBSD_GLUE], [test "$is_kfreebsd" = yes])
49 # We need to use $EXEEXT with $(LN_S) when creating symlinks to
50 # executables. Cygwin is an exception to this, since it is recommended
51 # that symlinks don't have the .exe suffix. To make this work, we
52 # define LN_EXEEXT.
54 # MSYS2 is treated the same way as Cygwin. It uses plain "msys" like
55 # the original MSYS when building MSYS/MSYS2-binaries. Hopefully this
56 # doesn't break things for the original MSYS developers. Note that this
57 # doesn't affect normal MSYS/MSYS2 users building non-MSYS/MSYS2 binaries
58 # since in that case the $host_os is usually mingw32.
59 case $host_os in
60         cygwin | msys)  LN_EXEEXT= ;;
61         *)              LN_EXEEXT='$(EXEEXT)' ;;
62 esac
63 AC_SUBST([LN_EXEEXT])
65 echo
66 echo "Configure options:"
67 AM_CFLAGS=
70 #############
71 # Debugging #
72 #############
74 AC_MSG_CHECKING([if debugging code should be compiled])
75 AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debugging code.]),
76         [], enable_debug=no)
77 if test "x$enable_debug" = xyes; then
78         AC_MSG_RESULT([yes])
79 else
80         AC_DEFINE([NDEBUG], [1], [Define to 1 to disable debugging code.])
81         AC_MSG_RESULT([no])
85 ###########
86 # Filters #
87 ###########
89 m4_define([SUPPORTED_FILTERS], [lzma1,lzma2,delta,x86,powerpc,ia64,arm,armthumb,sparc])dnl
90 m4_define([SIMPLE_FILTERS], [x86,powerpc,ia64,arm,armthumb,sparc])
91 m4_define([LZ_FILTERS], [lzma1,lzma2])
93 m4_foreach([NAME], [SUPPORTED_FILTERS],
94 [enable_filter_[]NAME=no
95 enable_encoder_[]NAME=no
96 enable_decoder_[]NAME=no
97 ])dnl
99 AC_MSG_CHECKING([which encoders to build])
100 AC_ARG_ENABLE([encoders], AS_HELP_STRING([--enable-encoders=LIST],
101                 [Comma-separated list of encoders to build. Default=all.
102                 Available encoders:]
103                         m4_translit(m4_defn([SUPPORTED_FILTERS]), [,], [ ])),
104         [], [enable_encoders=SUPPORTED_FILTERS])
105 enable_encoders=`echo "$enable_encoders" | sed 's/,/ /g'`
106 if test "x$enable_encoders" = xno || test "x$enable_encoders" = x; then
107         AC_MSG_RESULT([(none)])
108 else
109         for arg in $enable_encoders
110         do
111                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
112                         NAME)
113                                 enable_filter_[]NAME=yes
114                                 enable_encoder_[]NAME=yes
115                                 AC_DEFINE(HAVE_ENCODER_[]m4_toupper(NAME), [1],
116                                 [Define to 1 if] NAME [encoder is enabled.])
117                                 ;;])
118                         *)
119                                 AC_MSG_RESULT([])
120                                 AC_MSG_ERROR([unknown filter: $arg])
121                                 ;;
122                 esac
123         done
124         AC_MSG_RESULT([$enable_encoders])
127 AC_MSG_CHECKING([which decoders to build])
128 AC_ARG_ENABLE([decoders], AS_HELP_STRING([--enable-decoders=LIST],
129                 [Comma-separated list of decoders to build. Default=all.
130                 Available decoders are the same as available encoders.]),
131         [], [enable_decoders=SUPPORTED_FILTERS])
132 enable_decoders=`echo "$enable_decoders" | sed 's/,/ /g'`
133 if test "x$enable_decoders" = xno || test "x$enable_decoders" = x; then
134         AC_MSG_RESULT([(none)])
135 else
136         for arg in $enable_decoders
137         do
138                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
139                         NAME)
140                                 enable_filter_[]NAME=yes
141                                 enable_decoder_[]NAME=yes
142                                 AC_DEFINE(HAVE_DECODER_[]m4_toupper(NAME), [1],
143                                 [Define to 1 if] NAME [decoder is enabled.])
144                                 ;;])
145                         *)
146                                 AC_MSG_RESULT([])
147                                 AC_MSG_ERROR([unknown filter: $arg])
148                                 ;;
149                 esac
150         done
152         # LZMA2 requires that LZMA1 is enabled.
153         test "x$enable_encoder_lzma2" = xyes && enable_encoder_lzma1=yes
154         test "x$enable_decoder_lzma2" = xyes && enable_decoder_lzma1=yes
156         AC_MSG_RESULT([$enable_decoders])
159 if test "x$enable_encoder_lzma2$enable_encoder_lzma1" = xyesno \
160                 || test "x$enable_decoder_lzma2$enable_decoder_lzma1" = xyesno; then
161         AC_MSG_ERROR([LZMA2 requires that LZMA1 is also enabled.])
164 AM_CONDITIONAL(COND_MAIN_ENCODER, test "x$enable_encoders" != xno && test "x$enable_encoders" != x)
165 AM_CONDITIONAL(COND_MAIN_DECODER, test "x$enable_decoders" != xno && test "x$enable_decoders" != x)
167 m4_foreach([NAME], [SUPPORTED_FILTERS],
168 [AM_CONDITIONAL(COND_FILTER_[]m4_toupper(NAME), test "x$enable_filter_[]NAME" = xyes)
169 AM_CONDITIONAL(COND_ENCODER_[]m4_toupper(NAME), test "x$enable_encoder_[]NAME" = xyes)
170 AM_CONDITIONAL(COND_DECODER_[]m4_toupper(NAME), test "x$enable_decoder_[]NAME" = xyes)
171 ])dnl
173 # The so called "simple filters" share common code.
174 enable_filter_simple=no
175 enable_encoder_simple=no
176 enable_decoder_simple=no
177 m4_foreach([NAME], [SIMPLE_FILTERS],
178 [test "x$enable_filter_[]NAME" = xyes && enable_filter_simple=yes
179 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_simple=yes
180 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_simple=yes
181 ])dnl
182 AM_CONDITIONAL(COND_FILTER_SIMPLE, test "x$enable_filter_simple" = xyes)
183 AM_CONDITIONAL(COND_ENCODER_SIMPLE, test "x$enable_encoder_simple" = xyes)
184 AM_CONDITIONAL(COND_DECODER_SIMPLE, test "x$enable_decoder_simple" = xyes)
186 # LZ-based filters share common code.
187 enable_filter_lz=no
188 enable_encoder_lz=no
189 enable_decoder_lz=no
190 m4_foreach([NAME], [LZ_FILTERS],
191 [test "x$enable_filter_[]NAME" = xyes && enable_filter_lz=yes
192 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_lz=yes
193 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_lz=yes
194 ])dnl
195 AM_CONDITIONAL(COND_FILTER_LZ, test "x$enable_filter_lz" = xyes)
196 AM_CONDITIONAL(COND_ENCODER_LZ, test "x$enable_encoder_lz" = xyes)
197 AM_CONDITIONAL(COND_DECODER_LZ, test "x$enable_decoder_lz" = xyes)
200 #################
201 # Match finders #
202 #################
204 m4_define([SUPPORTED_MATCH_FINDERS], [hc3,hc4,bt2,bt3,bt4])
206 m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS],
207 [enable_match_finder_[]NAME=no
210 AC_MSG_CHECKING([which match finders to build])
211 AC_ARG_ENABLE([match-finders], AS_HELP_STRING([--enable-match-finders=LIST],
212                 [Comma-separated list of match finders to build. Default=all.
213                 At least one match finder is required for encoding with
214                 the LZMA1 and LZMA2 filters. Available match finders:]
215                 m4_translit(m4_defn([SUPPORTED_MATCH_FINDERS]), [,], [ ])), [],
216         [enable_match_finders=SUPPORTED_MATCH_FINDERS])
217 enable_match_finders=`echo "$enable_match_finders" | sed 's/,/ /g'`
218 if test "x$enable_encoder_lz" = xyes ; then
219         for arg in $enable_match_finders
220                 do
221                 case $arg in m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS], [
222                         NAME)
223                                 enable_match_finder_[]NAME=yes
224                                 AC_DEFINE(HAVE_MF_[]m4_toupper(NAME), [1],
225                                 [Define to 1 to enable] NAME [match finder.])
226                                 ;;])
227                         *)
228                                 AC_MSG_RESULT([])
229                                 AC_MSG_ERROR([unknown match finder: $arg])
230                                 ;;
231                 esac
232         done
233         AC_MSG_RESULT([$enable_match_finders])
234 else
235         AC_MSG_RESULT([(none because not building any LZ-based encoder)])
239 ####################
240 # Integrity checks #
241 ####################
243 m4_define([SUPPORTED_CHECKS], [crc32,crc64,sha256])
245 m4_foreach([NAME], [SUPPORTED_CHECKS],
246 [enable_check_[]NAME=no
247 ])dnl
249 AC_MSG_CHECKING([which integrity checks to build])
250 AC_ARG_ENABLE([checks], AS_HELP_STRING([--enable-checks=LIST],
251                 [Comma-separated list of integrity checks to build.
252                 Default=all. Available integrity checks:]
253                 m4_translit(m4_defn([SUPPORTED_CHECKS]), [,], [ ])),
254         [], [enable_checks=SUPPORTED_CHECKS])
255 enable_checks=`echo "$enable_checks" | sed 's/,/ /g'`
256 if test "x$enable_checks" = xno || test "x$enable_checks" = x; then
257         AC_MSG_RESULT([(none)])
258 else
259         for arg in $enable_checks
260         do
261                 case $arg in m4_foreach([NAME], [SUPPORTED_CHECKS], [
262                         NAME)
263                                 enable_check_[]NAME=yes
264                                 AC_DEFINE(HAVE_CHECK_[]m4_toupper(NAME), [1],
265                                 [Define to 1 if] NAME
266                                 [integrity check is enabled.])
267                                 ;;])
268                         *)
269                                 AC_MSG_RESULT([])
270                                 AC_MSG_ERROR([unknown integrity check: $arg])
271                                 ;;
272                 esac
273         done
274         AC_MSG_RESULT([$enable_checks])
276 if test "x$enable_check_crc32" = xno ; then
277         AC_MSG_ERROR([For now, the CRC32 check must always be enabled.])
280 m4_foreach([NAME], [SUPPORTED_CHECKS],
281 [AM_CONDITIONAL(COND_CHECK_[]m4_toupper(NAME), test "x$enable_check_[]NAME" = xyes)
282 ])dnl
285 ###########################
286 # Assembler optimizations #
287 ###########################
289 AC_MSG_CHECKING([if assembler optimizations should be used])
290 AC_ARG_ENABLE([assembler], AS_HELP_STRING([--disable-assembler],
291                 [Do not use assembler optimizations even if such exist
292                 for the architecture.]),
293         [], [enable_assembler=yes])
294 if test "x$enable_assembler" = xyes; then
295         enable_assembler=no
296         case $host_os in
297                 # Darwin should work too but only if not creating universal
298                 # binaries. Solaris x86 could work too but I cannot test.
299                 linux* | *bsd* | mingw* | cygwin | msys | *djgpp*)
300                         case $host_cpu in
301                                 i?86)   enable_assembler=x86 ;;
302                                 x86_64) enable_assembler=x86_64 ;;
303                         esac
304                         ;;
305         esac
307 case $enable_assembler in
308         x86 | x86_64 | no)
309                 AC_MSG_RESULT([$enable_assembler])
310                 ;;
311         *)
312                 AC_MSG_RESULT([])
313                 AC_MSG_ERROR([--enable-assembler accepts only `yes', `no', `x86', or `x86_64'.])
314                 ;;
315 esac
316 AM_CONDITIONAL(COND_ASM_X86, test "x$enable_assembler" = xx86)
317 AM_CONDITIONAL(COND_ASM_X86_64, test "x$enable_assembler" = xx86_64)
320 #####################
321 # Size optimization #
322 #####################
324 AC_MSG_CHECKING([if small size is preferred over speed])
325 AC_ARG_ENABLE([small], AS_HELP_STRING([--enable-small],
326                 [Make liblzma smaller and a little slower.
327                 This is disabled by default to optimize for speed.]),
328         [], [enable_small=no])
329 if test "x$enable_small" = xyes; then
330         AC_DEFINE([HAVE_SMALL], [1], [Define to 1 if optimizing for size.])
331 elif test "x$enable_small" != xno; then
332         AC_MSG_RESULT([])
333         AC_MSG_ERROR([--enable-small accepts only `yes' or `no'])
335 AC_MSG_RESULT([$enable_small])
336 AM_CONDITIONAL(COND_SMALL, test "x$enable_small" = xyes)
339 #############
340 # Threading #
341 #############
343 AC_MSG_CHECKING([if threading support is wanted])
344 AC_ARG_ENABLE([threads], AS_HELP_STRING([--enable-threads=METHOD],
345                 [Supported METHODS are `yes', `no', `posix', `win95', and
346                 `vista'. The default is `yes'. Using `no' together with
347                 --enable-small makes liblzma thread unsafe.]),
348         [], [enable_threads=yes])
350 if test "x$enable_threads" = xyes; then
351         case $host_os in
352                 mingw*)
353                         case $host_cpu in
354                                 i?86)   enable_threads=win95 ;;
355                                 *)      enable_threads=vista ;;
356                         esac
357                         ;;
358                 *)
359                         enable_threads=posix
360                         ;;
361         esac
364 case $enable_threads in
365         posix | win95 | vista)
366                 AC_MSG_RESULT([yes, $enable_threads])
367                 ;;
368         no)
369                 AC_MSG_RESULT([no])
370                 ;;
371         *)
372                 AC_MSG_RESULT([])
373                 AC_MSG_ERROR([--enable-threads only accepts `yes', `no', `posix', `win95', or `vista'])
374                 ;;
375 esac
377 # The Win95 threading lacks thread-safe one-time initialization function.
378 # It's better to disallow it instead of allowing threaded but thread-unsafe
379 # build.
380 if test "x$enable_small$enable_threads" = xyeswin95; then
381         AC_MSG_ERROR([--enable-threads=win95 and --enable-small cannot be
382                 used at the same time])
385 # We use the actual result a little later.
388 #########################
389 # Assumed amount of RAM #
390 #########################
392 # We use 128 MiB as default, because it will allow decompressing files
393 # created with "xz -9". It would be slightly safer to guess a lower value,
394 # but most systems, on which we don't have any way to determine the amount
395 # of RAM, will probably have at least 128 MiB of RAM.
396 AC_MSG_CHECKING([how much RAM to assume if the real amount is unknown])
397 AC_ARG_ENABLE([assume-ram], AS_HELP_STRING([--enable-assume-ram=SIZE],
398                 [If and only if the real amount of RAM cannot be determined,
399                 assume SIZE MiB. The default is 128 MiB. This affects the
400                 default memory usage limit.]),
401         [], [enable_assume_ram=128])
402 assume_ram_check=`echo "$enable_assume_ram" | tr -d 0123456789`
403 if test -z "$enable_assume_ram" || test -n "$assume_ram_check"; then
404         AC_MSG_RESULT([])
405         AC_MSG_ERROR([--enable-assume-ram accepts only an integer argument])
407 AC_MSG_RESULT([$enable_assume_ram MiB])
408 AC_DEFINE_UNQUOTED([ASSUME_RAM], [$enable_assume_ram],
409                 [How many MiB of RAM to assume if the real amount cannot
410                 be determined.])
413 #########################
414 # Components to install #
415 #########################
417 AC_ARG_ENABLE([xz], [AS_HELP_STRING([--disable-xz],
418                 [do not build the xz tool])],
419         [], [enable_xz=yes])
420 AM_CONDITIONAL([COND_XZ], [test x$enable_xz != xno])
422 AC_ARG_ENABLE([xzdec], [AS_HELP_STRING([--disable-xzdec],
423                 [do not build xzdec])],
424         [], [enable_xzdec=yes])
425 AM_CONDITIONAL([COND_XZDEC], [test x$enable_xzdec != xno])
427 AC_ARG_ENABLE([lzmadec], [AS_HELP_STRING([--disable-lzmadec],
428                 [do not build lzmadec
429                 (it exists primarily for LZMA Utils compatibility)])],
430         [], [enable_lzmadec=yes])
431 AM_CONDITIONAL([COND_LZMADEC], [test x$enable_lzmadec != xno])
433 AC_ARG_ENABLE([lzmainfo], [AS_HELP_STRING([--disable-lzmainfo],
434                 [do not build lzmainfo
435                 (it exists primarily for LZMA Utils compatibility)])],
436         [], [enable_lzmainfo=yes])
437 AM_CONDITIONAL([COND_LZMAINFO], [test x$enable_lzmainfo != xno])
439 AC_ARG_ENABLE([lzma-links], [AS_HELP_STRING([--disable-lzma-links],
440                 [do not create symlinks for LZMA Utils compatibility])],
441         [], [enable_lzma_links=yes])
442 AM_CONDITIONAL([COND_LZMALINKS], [test x$enable_lzma_links != xno])
444 AC_ARG_ENABLE([scripts], [AS_HELP_STRING([--disable-scripts],
445                 [do not install the scripts xzdiff, xzgrep, xzless, xzmore,
446                 and their symlinks])],
447         [], [enable_scripts=yes])
448 AM_CONDITIONAL([COND_SCRIPTS], [test x$enable_scripts != xno])
450 AC_ARG_ENABLE([doc], [AS_HELP_STRING([--disable-doc],
451                 [do not install documentation files to docdir
452                 (man pages will still be installed)])],
453         [], [enable_doc=yes])
454 AM_CONDITIONAL([COND_DOC], [test x$enable_doc != xno])
457 #####################
458 # Symbol versioning #
459 #####################
461 AC_MSG_CHECKING([if library symbol versioning should be used])
462 AC_ARG_ENABLE([symbol-versions], [AS_HELP_STRING([--enable-symbol-versions],
463                 [Use symbol versioning for liblzma. Enabled by default on
464                 GNU/Linux, other GNU-based systems, and FreeBSD.])],
465         [], [enable_symbol_versions=auto])
466 if test "x$enable_symbol_versions" = xauto; then
467         case $host_os in
468                 # NOTE: Even if one omits -gnu on GNU/Linux (e.g.
469                 # i486-slackware-linux), configure will (via config.sub)
470                 # append -gnu (e.g. i486-slackware-linux-gnu), and this
471                 # test will work correctly.
472                 gnu* | *-gnu* | freebsd*)
473                         enable_symbol_versions=yes
474                         ;;
475                 *)
476                         enable_symbol_versions=no
477                         ;;
478         esac
480 AC_MSG_RESULT([$enable_symbol_versions])
481 AM_CONDITIONAL([COND_SYMVERS], [test "x$enable_symbol_versions" = xyes])
484 ###############################################################################
485 # Checks for programs.
486 ###############################################################################
488 echo
489 gl_POSIX_SHELL
490 if test -z "$POSIX_SHELL" && test "x$enable_scripts" = xyes ; then
491         AC_MSG_ERROR([No POSIX conforming shell (sh) was found.])
494 echo
495 echo "Initializing Automake:"
497 # We don't use "subdir-objects" yet because it breaks "make distclean" when
498 # dependencies are enabled (as of Automake 1.14.1) due to this bug:
499 # http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17354
500 # The -Wno-unsupported is used to silence warnings about missing
501 # "subdir-objects".
502 AM_INIT_AUTOMAKE([1.12 foreign tar-v7 filename-length-max=99 serial-tests -Wno-unsupported])
503 AC_PROG_LN_S
505 AC_PROG_CC_C99
506 if test x$ac_cv_prog_cc_c99 = xno ; then
507         AC_MSG_ERROR([No C99 compiler was found.])
510 AM_PROG_CC_C_O
511 AM_PROG_AS
512 AC_USE_SYSTEM_EXTENSIONS
514 case $enable_threads in
515         posix)
516                 echo
517                 echo "POSIX threading support:"
518                 AX_PTHREAD([:]) dnl We don't need the HAVE_PTHREAD macro.
519                 LIBS="$LIBS $PTHREAD_LIBS"
520                 AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"
522                 dnl NOTE: PTHREAD_CC is ignored. It would be useful on AIX,
523                 dnl but it's tricky to get it right together with
524                 dnl AC_PROG_CC_C99. Thus, this is handled by telling the
525                 dnl user in INSTALL to set the correct CC manually.
527                 AC_DEFINE([MYTHREAD_POSIX], [1],
528                         [Define to 1 when using POSIX threads (pthreads).])
530                 # These are nice to have but not mandatory.
531                 #
532                 # FIXME: xz uses clock_gettime if it is available and can do
533                 # it even when threading is disabled. Moving this outside
534                 # of pthread detection may be undesirable because then
535                 # liblzma may get linked against librt even when librt isn't
536                 # needed by liblzma.
537                 OLD_CFLAGS=$CFLAGS
538                 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
539                 AC_SEARCH_LIBS([clock_gettime], [rt])
540                 AC_CHECK_FUNCS([clock_gettime pthread_condattr_setclock])
541                 AC_CHECK_DECLS([CLOCK_MONOTONIC], [], [], [[#include <time.h>]])
542                 CFLAGS=$OLD_CFLAGS
543                 ;;
544         win95)
545                 AC_DEFINE([MYTHREAD_WIN95], [1], [Define to 1 when using
546                         Windows 95 (and thus XP) compatible threads.
547                         This avoids use of features that were added in
548                         Windows Vista.])
549                 ;;
550         vista)
551                 AC_DEFINE([MYTHREAD_VISTA], [1], [Define to 1 when using
552                         Windows Vista compatible threads. This uses
553                         features that are not available on Windows XP.])
554                 ;;
555 esac
556 AM_CONDITIONAL([COND_THREADS], [test "x$enable_threads" != xno])
558 # As a Debian-specific hack, liblzma can use dlopen() to check if extra
559 # paranoia is needed because unversioned symbols from liblzma.so.2 are
560 # present in the same process.  See src/liblzma/common/common.c.
561 AC_MSG_CHECKING([if lzma_code checks should be relaxed for compatibility])
562 AC_ARG_ENABLE([liblzma2-compat], [AC_HELP_STRING([--enable-liblzma2-compat],
563                 [Relax run-time checks to accomodate old binaries built
564                 with smaller sizeof(lzma_stream).  The default is "dynamic",
565                 which means to only use the relaxed checks when the dynamic
566                 loader reports that liblzma.so.2 is loaded in the same process.])],
567         [], [enable_liblzma2_compat=dynamic])
568 case $enable_liblzma2_compat in
569 dynamic)
570         AC_SEARCH_LIBS([dlopen], [dl])
571         AC_DEFINE([LIBLZMA2_COMPAT_DYNAMIC], [1],
572                 [Define to 1 to use dlopen() to check if lzma_code() checks
573                 should be more tolerant because the process is also linked to
574                 liblzma from Debian 6.0.])
575         AC_MSG_RESULT([auto])
576         ;;
577 yes)
578         AC_DEFINE([LIBLZMA2_COMPAT], [1],
579                 [Define to 1 to unconditionally make lzma_code() checks tolerant
580                 to accomodate callers built against liblzma from Debian 6.0.])
581         AC_MSG_RESULT([yes])
582         ;;
584         AC_MSG_RESULT([no])
585         ;;
587         AC_MSG_RESULT([])
588         AC_MSG_ERROR([--enable-liblzma2: unrecognized value $enable_liblzma2_compat])
589         ;;
590 esac
592 echo
593 echo "Initializing Libtool:"
594 LT_PREREQ([2.2])
595 LT_INIT([win32-dll])
596 LT_LANG([Windows Resource])
598 # This is a bit wrong since it is possible to request that only some libs
599 # are built as shared. Using that feature isn't so common though, and this
600 # breaks only on Windows (at least for now) if the user enables only some
601 # libs as shared.
602 AM_CONDITIONAL([COND_SHARED], [test "x$enable_shared" != xno])
605 ###############################################################################
606 # Checks for libraries.
607 ###############################################################################
609 echo
610 echo "Initializing gettext:"
611 AM_GNU_GETTEXT_VERSION([0.18])
612 AM_GNU_GETTEXT([external])
615 ###############################################################################
616 # Checks for header files.
617 ###############################################################################
619 echo
620 echo "System headers and functions:"
622 # There is currently no workarounds in this package if some of
623 # these headers are missing.
624 AC_CHECK_HEADERS([fcntl.h limits.h sys/time.h],
625         [],
626         [AC_MSG_ERROR([Required header file(s) are missing.])])
628 # This allows the use of the intrinsic functions if they are available.
629 AC_CHECK_HEADERS([immintrin.h])
632 ###############################################################################
633 # Checks for typedefs, structures, and compiler characteristics.
634 ###############################################################################
636 dnl We don't need these as long as we need a C99 compiler anyway.
637 dnl AC_C_INLINE
638 dnl AC_C_RESTRICT
640 AC_HEADER_STDBOOL
642 AC_TYPE_UINT8_T
643 AC_TYPE_UINT16_T
644 AC_TYPE_INT32_T
645 AC_TYPE_UINT32_T
646 AC_TYPE_INT64_T
647 AC_TYPE_UINT64_T
648 AC_TYPE_UINTPTR_T
650 AC_CHECK_SIZEOF([size_t])
652 # The command line tool can copy high resolution timestamps if such
653 # information is available in struct stat. Otherwise one second accuracy
654 # is used.
655 AC_CHECK_MEMBERS([
656         struct stat.st_atim.tv_nsec,
657         struct stat.st_atimespec.tv_nsec,
658         struct stat.st_atimensec,
659         struct stat.st_uatime,
660         struct stat.st_atim.st__tim.tv_nsec])
662 AC_SYS_LARGEFILE
663 AC_C_BIGENDIAN
666 ###############################################################################
667 # Checks for library functions.
668 ###############################################################################
670 # Gnulib replacements as needed
671 gl_GETOPT
673 # Find the best function to set timestamps.
674 AC_CHECK_FUNCS([futimens futimes futimesat utimes utime], [break])
676 # This is nice to have but not mandatory.
677 AC_CHECK_FUNCS([posix_fadvise])
679 TUKLIB_PROGNAME
680 TUKLIB_INTEGER
681 TUKLIB_PHYSMEM
682 TUKLIB_CPUCORES
683 TUKLIB_MBSTR
685 # Check for system-provided SHA-256. At least the following is supported:
687 # OS       Headers                     Library  Type           Function
688 # FreeBSD  sys/types.h + sha256.h      libmd    SHA256_CTX     SHA256_Init
689 # NetBSD   sys/types.h + sha2.h                 SHA256_CTX     SHA256_Init
690 # OpenBSD  sys/types.h + sha2.h                 SHA2_CTX       SHA256Init
691 # Solaris  sys/types.h + sha2.h        libmd    SHA256_CTX     SHA256Init
692 # MINIX 3  sys/types.h + minix/sha2.h  libutil  SHA256_CTX     SHA256_Init
693 # Darwin   CommonCrypto/CommonDigest.h          CC_SHA256_CTX  CC_SHA256_Init
695 # Note that Darwin's CC_SHA256_Update takes buffer size as uint32_t instead
696 # of size_t.
698 # We don't check for e.g. OpenSSL or libgcrypt because we don't want
699 # to introduce dependencies to other packages by default. Maybe such
700 # libraries could be supported via additional configure options though.
702 if test "x$enable_check_sha256" = "xyes"; then
703         # Test for Common Crypto before others, because Darwin has sha256.h
704         # too and we don't want to use that, because on older versions it
705         # uses OpenSSL functions, whose SHA256_Init is not guaranteed to
706         # succeed.
707         sha256_header_found=no
708         AC_CHECK_HEADERS(
709                 [CommonCrypto/CommonDigest.h sha256.h sha2.h minix/sha2.h],
710                 [sha256_header_found=yes ; break])
711         if test "x$sha256_header_found" = xyes; then
712                 AC_CHECK_TYPES([CC_SHA256_CTX, SHA256_CTX, SHA2_CTX], [], [],
713                         [[#ifdef HAVE_SYS_TYPES_H
714                           # include <sys/types.h>
715                           #endif
716                           #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
717                           # include <CommonCrypto/CommonDigest.h>
718                           #endif
719                           #ifdef HAVE_SHA256_H
720                           # include <sha256.h>
721                           #endif
722                           #ifdef HAVE_SHA2_H
723                           # include <sha2.h>
724                           #endif
725                           #ifdef HAVE_MINIX_SHA2_H
726                           # include <minix/sha2.h>
727                           #endif]])
728                 AC_SEARCH_LIBS([SHA256_Init], [md util])
729                 AC_SEARCH_LIBS([SHA256Init], [md])
730                 AC_CHECK_FUNCS([CC_SHA256_Init SHA256_Init SHA256Init],
731                         [break])
732         fi
734 AM_CONDITIONAL([COND_INTERNAL_SHA256],
735         [test "x$ac_cv_func_SHA256_Init" != xyes \
736                 && test "x$ac_cv_func_SHA256Init" != xyes \
737                 && test "x$ac_cv_func_CC_SHA256_Init" != xyes])
739 # Check for SSE2 intrinsics.
740 AC_CHECK_DECL([_mm_movemask_epi8],
741         [AC_DEFINE([HAVE__MM_MOVEMASK_EPI8], [1],
742                 [Define to 1 if _mm_movemask_epi8 is available.])],
743         [],
744 [#ifdef HAVE_IMMINTRIN_H
745 #include <immintrin.h>
746 #endif])
749 ###############################################################################
750 # If using GCC, set some additional AM_CFLAGS:
751 ###############################################################################
753 if test "$GCC" = yes ; then
754         echo
755         echo "GCC extensions:"
758 # Always do the visibility check but don't set AM_CFLAGS on Windows.
759 # This way things get set properly even on Windows.
760 gl_VISIBILITY
761 if test -n "$CFLAG_VISIBILITY" && test "$is_w32" = no; then
762         AM_CFLAGS="$AM_CFLAGS $CFLAG_VISIBILITY"
765 if test "$GCC" = yes ; then
766         # Enable as much warnings as possible. These commented warnings won't
767         # work for this package though:
768         #   * -Wunreachable-code breaks several assert(0) cases, which are
769         #     backed up with "return LZMA_PROG_ERROR".
770         #   * -Wcast-qual would break various things where we need a non-const
771         #     pointer although we don't modify anything through it.
772         #   * -Wcast-align breaks optimized CRC32 and CRC64 implementation
773         #     on some architectures (not on x86), where this warning is bogus,
774         #     because we take care of correct alignment.
775         #   * -Winline, -Wdisabled-optimization, -Wunsafe-loop-optimizations
776         #     don't seem so useful here; at least the last one gives some
777         #     warnings which are not bugs.
778         for NEW_FLAG in \
779                         -Wall \
780                         -Wextra \
781                         -Wvla \
782                         -Wformat=2 \
783                         -Winit-self \
784                         -Wmissing-include-dirs \
785                         -Wstrict-aliasing \
786                         -Wfloat-equal \
787                         -Wundef \
788                         -Wshadow \
789                         -Wpointer-arith \
790                         -Wbad-function-cast \
791                         -Wwrite-strings \
792                         -Wlogical-op \
793                         -Waggregate-return \
794                         -Wstrict-prototypes \
795                         -Wold-style-definition \
796                         -Wmissing-prototypes \
797                         -Wmissing-declarations \
798                         -Wmissing-noreturn \
799                         -Wredundant-decls
800         do
801                 AC_MSG_CHECKING([if $CC accepts $NEW_FLAG])
802                 OLD_CFLAGS="$CFLAGS"
803                 CFLAGS="$CFLAGS $NEW_FLAG -Werror"
804                 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
805                                 [void foo(void); void foo(void) { }])], [
806                         AM_CFLAGS="$AM_CFLAGS $NEW_FLAG"
807                         AC_MSG_RESULT([yes])
808                 ], [
809                         AC_MSG_RESULT([no])
810                 ])
811                 CFLAGS="$OLD_CFLAGS"
812         done
814         AC_ARG_ENABLE([werror],
815                 AS_HELP_STRING([--enable-werror], [Enable -Werror to abort
816                         compilation on all compiler warnings.]),
817                 [], [enable_werror=no])
818         if test "x$enable_werror" = "xyes"; then
819                 AM_CFLAGS="$AM_CFLAGS -Werror"
820         fi
824 ###############################################################################
825 # Create the makefiles and config.h
826 ###############################################################################
828 echo
830 # Don't build the lib directory at all if we don't need any replacement
831 # functions.
832 AM_CONDITIONAL([COND_GNULIB], test -n "$LIBOBJS")
834 # Add default AM_CFLAGS.
835 AC_SUBST([AM_CFLAGS])
837 # This is needed for src/scripts.
838 xz=`echo xz | sed "$program_transform_name"`
839 AC_SUBST([xz])
841 AC_CONFIG_FILES([
842         Doxyfile
843         Makefile
844         po/Makefile.in
845         lib/Makefile
846         src/Makefile
847         src/liblzma/Makefile
848         src/liblzma/api/Makefile
849         src/xz/Makefile
850         src/xzdec/Makefile
851         src/lzmainfo/Makefile
852         src/scripts/Makefile
853         tests/Makefile
854         debug/Makefile
856 AC_CONFIG_FILES([src/scripts/xzdiff], [chmod +x src/scripts/xzdiff])
857 AC_CONFIG_FILES([src/scripts/xzgrep], [chmod +x src/scripts/xzgrep])
858 AC_CONFIG_FILES([src/scripts/xzmore], [chmod +x src/scripts/xzmore])
859 AC_CONFIG_FILES([src/scripts/xzless], [chmod +x src/scripts/xzless])
861 AC_OUTPUT
863 # Some warnings
864 if test x$tuklib_cv_physmem_method = xunknown; then
865         echo
866         echo "WARNING:"
867         echo "No supported method to detect the amount of RAM."
868         echo "Consider using --enable-assume-ram (if you didn't already)"
869         echo "or make a patch to add support for this operating system."
872 if test x$tuklib_cv_cpucores_method = xunknown; then
873         echo
874         echo "WARNING:"
875         echo "No supported method to detect the number of CPU cores."
878 if test "x$enable_threads$enable_small" = xnoyes; then
879         echo
880         echo "NOTE:"
881         echo "liblzma will be thread unsafe due the combination"
882         echo "of --disable-threads --enable-small."