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