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