Update THANKS
[xz.git] / configure.ac
blob57831048536057bc9125591d80fc9a49d037204b
1 #                                               -*- Autoconf -*-
2 # SPDX-License-Identifier: 0BSD
4 ###############################################################################
6 # Process this file with autoconf to produce a configure script.
8 # Author: Lasse Collin
10 ###############################################################################
12 # NOTE: Don't add useless checks. autoscan detects this and that, but don't
13 # let it confuse you. For example, we don't care about checking for behavior
14 # of malloc(), stat(), or lstat(), since we don't use those functions in
15 # a way that would cause the problems the autoconf macros check.
17 AC_PREREQ([2.69])
19 AC_INIT([XZ Utils], m4_esyscmd([/bin/sh build-aux/version.sh]),
20         [xz@tukaani.org], [xz], [https://tukaani.org/xz/])
21 AC_CONFIG_SRCDIR([src/liblzma/common/common.h])
22 AC_CONFIG_AUX_DIR([build-aux])
23 AC_CONFIG_MACRO_DIR([m4])
24 AC_CONFIG_HEADERS([config.h])
26 echo
27 echo "$PACKAGE_STRING"
29 echo
30 echo "System type:"
31 # This is needed to know if assembler optimizations can be used.
32 AC_CANONICAL_HOST
34 # We do some special things on Windows (32-bit or 64-bit) builds.
35 case $host_os in
36         mingw* | cygwin | msys) is_w32=yes ;;
37         *)                      is_w32=no ;;
38 esac
39 AM_CONDITIONAL([COND_W32], [test "$is_w32" = yes])
41 # We need to use $EXEEXT with $(LN_S) when creating symlinks to
42 # executables. Cygwin is an exception to this, since it is recommended
43 # that symlinks don't have the .exe suffix. To make this work, we
44 # define LN_EXEEXT.
46 # MSYS2 is treated the same way as Cygwin. It uses plain "msys" like
47 # the original MSYS when building MSYS/MSYS2-binaries. Hopefully this
48 # doesn't break things for the original MSYS developers. Note that this
49 # doesn't affect normal MSYS/MSYS2 users building non-MSYS/MSYS2 binaries
50 # since in that case the $host_os is usually mingw32.
51 case $host_os in
52         cygwin | msys)  LN_EXEEXT= ;;
53         *)              LN_EXEEXT='$(EXEEXT)' ;;
54 esac
55 AC_SUBST([LN_EXEEXT])
57 echo
58 echo "Configure options:"
59 AM_CFLAGS=
62 #############
63 # Debugging #
64 #############
66 AC_MSG_CHECKING([if debugging code should be compiled])
67 AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [Enable debugging code.]),
68         [], enable_debug=no)
69 if test "x$enable_debug" = xyes; then
70         AC_MSG_RESULT([yes])
71 else
72         AC_DEFINE([NDEBUG], [1], [Define to 1 to disable debugging code.])
73         AC_MSG_RESULT([no])
77 ###########
78 # Filters #
79 ###########
81 m4_define([SUPPORTED_FILTERS], [lzma1,lzma2,delta,x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv])dnl
82 m4_define([SIMPLE_FILTERS], [x86,powerpc,ia64,arm,armthumb,arm64,sparc,riscv])
83 m4_define([LZ_FILTERS], [lzma1,lzma2])
85 m4_foreach([NAME], [SUPPORTED_FILTERS],
86 [enable_filter_[]NAME=no
87 enable_encoder_[]NAME=no
88 enable_decoder_[]NAME=no
89 ])dnl
91 AC_MSG_CHECKING([which encoders to build])
92 AC_ARG_ENABLE([encoders], AS_HELP_STRING([--enable-encoders=LIST],
93                 [Comma-separated list of encoders to build. Default=all.
94                 Available encoders:]
95                         m4_translit(m4_defn([SUPPORTED_FILTERS]), [,], [ ])),
96         [], [enable_encoders=SUPPORTED_FILTERS])
97 enable_encoders=`echo "$enable_encoders" | sed 's/,/ /g'`
98 if test "x$enable_encoders" = xno || test "x$enable_encoders" = x; then
99         enable_encoders=no
100         AC_MSG_RESULT([(none)])
101 else
102         for arg in $enable_encoders
103         do
104                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
105                         NAME)
106                                 enable_filter_[]NAME=yes
107                                 enable_encoder_[]NAME=yes
108                                 AC_DEFINE(HAVE_ENCODER_[]m4_toupper(NAME), [1],
109                                 [Define to 1 if] NAME [encoder is enabled.])
110                                 ;;])
111                         *)
112                                 AC_MSG_RESULT([])
113                                 AC_MSG_ERROR([unknown filter: $arg])
114                                 ;;
115                 esac
116         done
117         AC_DEFINE([HAVE_ENCODERS], [1],
118                 [Define to 1 if any of HAVE_ENCODER_foo have been defined.])
119         AC_MSG_RESULT([$enable_encoders])
122 AC_MSG_CHECKING([which decoders to build])
123 AC_ARG_ENABLE([decoders], AS_HELP_STRING([--enable-decoders=LIST],
124                 [Comma-separated list of decoders to build. Default=all.
125                 Available decoders are the same as available encoders.]),
126         [], [enable_decoders=SUPPORTED_FILTERS])
127 enable_decoders=`echo "$enable_decoders" | sed 's/,/ /g'`
128 if test "x$enable_decoders" = xno || test "x$enable_decoders" = x; then
129         enable_decoders=no
130         AC_MSG_RESULT([(none)])
131 else
132         for arg in $enable_decoders
133         do
134                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
135                         NAME)
136                                 enable_filter_[]NAME=yes
137                                 enable_decoder_[]NAME=yes
138                                 AC_DEFINE(HAVE_DECODER_[]m4_toupper(NAME), [1],
139                                 [Define to 1 if] NAME [decoder is enabled.])
140                                 ;;])
141                         *)
142                                 AC_MSG_RESULT([])
143                                 AC_MSG_ERROR([unknown filter: $arg])
144                                 ;;
145                 esac
146         done
147         AC_DEFINE([HAVE_DECODERS], [1],
148                 [Define to 1 if any of HAVE_DECODER_foo have been defined.])
149         AC_MSG_RESULT([$enable_decoders])
152 if test "x$enable_encoder_lzma2$enable_encoder_lzma1" = xyesno \
153                 || test "x$enable_decoder_lzma2$enable_decoder_lzma1" = xyesno; then
154         AC_MSG_ERROR([LZMA2 requires that LZMA1 is also enabled.])
157 AM_CONDITIONAL(COND_MAIN_ENCODER, test "x$enable_encoders" != xno)
158 AM_CONDITIONAL(COND_MAIN_DECODER, test "x$enable_decoders" != xno)
160 m4_foreach([NAME], [SUPPORTED_FILTERS],
161 [AM_CONDITIONAL(COND_FILTER_[]m4_toupper(NAME), test "x$enable_filter_[]NAME" = xyes)
162 AM_CONDITIONAL(COND_ENCODER_[]m4_toupper(NAME), test "x$enable_encoder_[]NAME" = xyes)
163 AM_CONDITIONAL(COND_DECODER_[]m4_toupper(NAME), test "x$enable_decoder_[]NAME" = xyes)
164 ])dnl
166 # The so called "simple filters" share common code.
167 enable_filter_simple=no
168 enable_encoder_simple=no
169 enable_decoder_simple=no
170 m4_foreach([NAME], [SIMPLE_FILTERS],
171 [test "x$enable_filter_[]NAME" = xyes && enable_filter_simple=yes
172 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_simple=yes
173 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_simple=yes
174 ])dnl
175 AM_CONDITIONAL(COND_FILTER_SIMPLE, test "x$enable_filter_simple" = xyes)
176 AM_CONDITIONAL(COND_ENCODER_SIMPLE, test "x$enable_encoder_simple" = xyes)
177 AM_CONDITIONAL(COND_DECODER_SIMPLE, test "x$enable_decoder_simple" = xyes)
179 # LZ-based filters share common code.
180 enable_filter_lz=no
181 enable_encoder_lz=no
182 enable_decoder_lz=no
183 m4_foreach([NAME], [LZ_FILTERS],
184 [test "x$enable_filter_[]NAME" = xyes && enable_filter_lz=yes
185 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_lz=yes
186 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_lz=yes
187 ])dnl
188 AM_CONDITIONAL(COND_FILTER_LZ, test "x$enable_filter_lz" = xyes)
189 AM_CONDITIONAL(COND_ENCODER_LZ, test "x$enable_encoder_lz" = xyes)
190 AM_CONDITIONAL(COND_DECODER_LZ, test "x$enable_decoder_lz" = xyes)
193 #################
194 # Match finders #
195 #################
197 m4_define([SUPPORTED_MATCH_FINDERS], [hc3,hc4,bt2,bt3,bt4])
199 m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS],
200 [enable_match_finder_[]NAME=no
203 AC_MSG_CHECKING([which match finders to build])
204 AC_ARG_ENABLE([match-finders], AS_HELP_STRING([--enable-match-finders=LIST],
205                 [Comma-separated list of match finders to build. Default=all.
206                 At least one match finder is required for encoding with
207                 the LZMA1 and LZMA2 filters. Available match finders:]
208                 m4_translit(m4_defn([SUPPORTED_MATCH_FINDERS]), [,], [ ])), [],
209         [enable_match_finders=SUPPORTED_MATCH_FINDERS])
210 enable_match_finders=`echo "$enable_match_finders" | sed 's/,/ /g'`
211 if test "x$enable_encoder_lz" = xyes ; then
212         if test -z "$enable_match_finders"; then
213                 AC_MSG_ERROR([At least one match finder is required for an LZ-based encoder.])
214         fi
216         for arg in $enable_match_finders
217                 do
218                 case $arg in m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS], [
219                         NAME)
220                                 enable_match_finder_[]NAME=yes
221                                 AC_DEFINE(HAVE_MF_[]m4_toupper(NAME), [1],
222                                 [Define to 1 to enable] NAME [match finder.])
223                                 ;;])
224                         *)
225                                 AC_MSG_RESULT([])
226                                 AC_MSG_ERROR([unknown match finder: $arg])
227                                 ;;
228                 esac
229         done
230         AC_MSG_RESULT([$enable_match_finders])
231 else
232         AC_MSG_RESULT([(none because not building any LZ-based encoder)])
236 ####################
237 # Integrity checks #
238 ####################
240 m4_define([SUPPORTED_CHECKS], [crc32,crc64,sha256])
242 m4_foreach([NAME], [SUPPORTED_CHECKS],
243 [enable_check_[]NAME=no
244 ])dnl
246 AC_MSG_CHECKING([which integrity checks to build])
247 AC_ARG_ENABLE([checks], AS_HELP_STRING([--enable-checks=LIST],
248                 [Comma-separated list of integrity checks to build.
249                 Default=all. Available integrity checks:]
250                 m4_translit(m4_defn([SUPPORTED_CHECKS]), [,], [ ])),
251         [], [enable_checks=SUPPORTED_CHECKS])
252 enable_checks=`echo "$enable_checks" | sed 's/,/ /g'`
253 if test "x$enable_checks" = xno || test "x$enable_checks" = x; then
254         AC_MSG_RESULT([(none)])
255 else
256         for arg in $enable_checks
257         do
258                 case $arg in m4_foreach([NAME], [SUPPORTED_CHECKS], [
259                         NAME)
260                                 enable_check_[]NAME=yes
261                                 AC_DEFINE(HAVE_CHECK_[]m4_toupper(NAME), [1],
262                                 [Define to 1 if] NAME
263                                 [integrity check is enabled.])
264                                 ;;])
265                         *)
266                                 AC_MSG_RESULT([])
267                                 AC_MSG_ERROR([unknown integrity check: $arg])
268                                 ;;
269                 esac
270         done
271         AC_MSG_RESULT([$enable_checks])
273 if test "x$enable_check_crc32" = xno ; then
274         AC_MSG_ERROR([For now, the CRC32 check must always be enabled.])
277 m4_foreach([NAME], [SUPPORTED_CHECKS],
278 [AM_CONDITIONAL(COND_CHECK_[]m4_toupper(NAME), test "x$enable_check_[]NAME" = xyes)
279 ])dnl
281 AC_MSG_CHECKING([if external SHA-256 should be used])
282 AC_ARG_ENABLE([external-sha256], AS_HELP_STRING([--enable-external-sha256],
283                 [Use SHA-256 code from the operating system.
284                 See INSTALL for possible subtle problems.]),
285                 [], [enable_external_sha256=no])
286 if test "x$enable_check_sha256" != "xyes"; then
287         enable_external_sha256=no
289 if test "x$enable_external_sha256" = xyes; then
290         AC_MSG_RESULT([yes])
291 else
292         AC_MSG_RESULT([no])
296 #############
297 # MicroLZMA #
298 #############
300 AC_MSG_CHECKING([if MicroLZMA support should be built])
301 AC_ARG_ENABLE([microlzma], AS_HELP_STRING([--disable-microlzma],
302                 [Do not build MicroLZMA encoder and decoder.
303                 It is needed by specific applications only,
304                 for example, erofs-utils.]),
305         [], [enable_microlzma=yes])
306 case $enable_microlzma in
307         yes | no)
308                 AC_MSG_RESULT([$enable_microlzma])
309                 ;;
310         *)
311                 AC_MSG_RESULT([])
312                 AC_MSG_ERROR([--enable-microlzma accepts only 'yes' or 'no'.])
313                 ;;
314 esac
315 AM_CONDITIONAL(COND_MICROLZMA, test "x$enable_microlzma" = xyes)
318 #############################
319 # .lz (lzip) format support #
320 #############################
322 AC_MSG_CHECKING([if .lz (lzip) decompression support should be built])
323 AC_ARG_ENABLE([lzip-decoder], AS_HELP_STRING([--disable-lzip-decoder],
324                 [Disable decompression support for .lz (lzip) files.]),
325         [], [enable_lzip_decoder=yes])
326 if test "x$enable_decoder_lzma1" != xyes; then
327         enable_lzip_decoder=no
328         AC_MSG_RESULT([no because LZMA1 decoder is disabled])
329 elif test "x$enable_lzip_decoder" = xyes; then
330         AC_DEFINE([HAVE_LZIP_DECODER], [1],
331                 [Define to 1 if .lz (lzip) decompression support is enabled.])
332         AC_MSG_RESULT([yes])
333 else
334         AC_MSG_RESULT([no])
336 AM_CONDITIONAL(COND_LZIP_DECODER, test "x$enable_lzip_decoder" = xyes)
339 ###########################
340 # Assembler optimizations #
341 ###########################
343 AC_MSG_CHECKING([if assembler optimizations should be used])
344 AC_ARG_ENABLE([assembler], AS_HELP_STRING([--disable-assembler],
345                 [Do not use assembler optimizations even if such exist
346                 for the architecture.]),
347         [], [enable_assembler=yes])
348 if test "x$enable_assembler" = xyes; then
349         enable_assembler=no
350         case $host_os in
351                 # Darwin should work too but only if not creating universal
352                 # binaries. Solaris x86 could work too but I cannot test.
353                 linux* | *bsd* | mingw* | cygwin | msys | *djgpp*)
354                         case $host_cpu in
355                                 i?86)   enable_assembler=x86 ;;
356                         esac
357                         ;;
358         esac
360 case $enable_assembler in
361         x86 | no)
362                 AC_MSG_RESULT([$enable_assembler])
363                 ;;
364         *)
365                 AC_MSG_RESULT([])
366                 AC_MSG_ERROR([--enable-assembler accepts only 'yes', 'no', or 'x86' (32-bit).])
367                 ;;
368 esac
369 AM_CONDITIONAL(COND_ASM_X86, test "x$enable_assembler" = xx86)
372 #############
373 # CLMUL CRC #
374 #############
376 # FIXME: Turn it back on by default once the code has been revised
377 # to not cause false alarms in sanitizers and thus in OSS Fuzz.
378 AC_ARG_ENABLE([clmul-crc], AS_HELP_STRING([--disable-clmul-crc],
379                 [Do not use carryless multiplication for CRC calculation
380                 even if support for it is detected.]),
381         [], [enable_clmul_crc=no])
384 ############################
385 # ARM64 CRC32 Instructions #
386 ############################
388 AC_ARG_ENABLE([arm64-crc32], AS_HELP_STRING([--disable-arm64-crc32],
389                 [Do not use ARM64 CRC32 instructions even if support for it
390                 is detected.]),
391         [], [enable_arm64_crc32=yes])
394 #####################
395 # Size optimization #
396 #####################
398 AC_MSG_CHECKING([if small size is preferred over speed])
399 AC_ARG_ENABLE([small], AS_HELP_STRING([--enable-small],
400                 [Make liblzma smaller and a little slower.
401                 This is disabled by default to optimize for speed.]),
402         [], [enable_small=no])
403 if test "x$enable_small" = xyes; then
404         AC_DEFINE([HAVE_SMALL], [1], [Define to 1 if optimizing for size.])
405 elif test "x$enable_small" != xno; then
406         AC_MSG_RESULT([])
407         AC_MSG_ERROR([--enable-small accepts only 'yes' or 'no'])
409 AC_MSG_RESULT([$enable_small])
410 AM_CONDITIONAL(COND_SMALL, test "x$enable_small" = xyes)
413 #############
414 # Threading #
415 #############
417 AC_MSG_CHECKING([if threading support is wanted])
418 AC_ARG_ENABLE([threads], AS_HELP_STRING([--enable-threads=METHOD],
419                 [Supported METHODS are 'yes', 'no', 'posix', 'win95', and
420                 'vista'. The default is 'yes'. Using 'no' together with
421                 --enable-small makes liblzma thread unsafe.]),
422         [], [enable_threads=yes])
424 if test "x$enable_threads" = xyes; then
425         case $host_os in
426                 mingw*)
427                         case $host_cpu in
428                                 i?86)   enable_threads=win95 ;;
429                                 *)      enable_threads=vista ;;
430                         esac
431                         ;;
432                 *)
433                         enable_threads=posix
434                         ;;
435         esac
438 case $enable_threads in
439         posix | win95 | vista)
440                 AC_MSG_RESULT([yes, $enable_threads])
441                 ;;
442         no)
443                 AC_MSG_RESULT([no])
444                 ;;
445         *)
446                 AC_MSG_RESULT([])
447                 AC_MSG_ERROR([--enable-threads only accepts 'yes', 'no', 'posix', 'win95', or 'vista'])
448                 ;;
449 esac
451 # We use the actual result a little later.
454 #########################
455 # Assumed amount of RAM #
456 #########################
458 # We use 128 MiB as default, because it will allow decompressing files
459 # created with "xz -9". It would be slightly safer to guess a lower value,
460 # but most systems, on which we don't have any way to determine the amount
461 # of RAM, will probably have at least 128 MiB of RAM.
462 AC_MSG_CHECKING([how much RAM to assume if the real amount is unknown])
463 AC_ARG_ENABLE([assume-ram], AS_HELP_STRING([--enable-assume-ram=SIZE],
464                 [If and only if the real amount of RAM cannot be determined,
465                 assume SIZE MiB. The default is 128 MiB. This affects the
466                 default memory usage limit.]),
467         [], [enable_assume_ram=128])
468 assume_ram_check=`echo "$enable_assume_ram" | tr -d 0123456789`
469 if test -z "$enable_assume_ram" || test -n "$assume_ram_check"; then
470         AC_MSG_RESULT([])
471         AC_MSG_ERROR([--enable-assume-ram accepts only an integer argument])
473 AC_MSG_RESULT([$enable_assume_ram MiB])
474 AC_DEFINE_UNQUOTED([ASSUME_RAM], [$enable_assume_ram],
475                 [How many MiB of RAM to assume if the real amount cannot
476                 be determined.])
479 #########################
480 # Components to install #
481 #########################
483 AC_ARG_ENABLE([xz], [AS_HELP_STRING([--disable-xz],
484                 [do not build the xz tool])],
485         [], [enable_xz=yes])
486 AM_CONDITIONAL([COND_XZ], [test x$enable_xz != xno])
488 AC_ARG_ENABLE([xzdec], [AS_HELP_STRING([--disable-xzdec],
489                 [do not build xzdec])],
490         [], [enable_xzdec=yes])
491 test "x$enable_decoders" = xno && enable_xzdec=no
492 AM_CONDITIONAL([COND_XZDEC], [test x$enable_xzdec != xno])
494 AC_ARG_ENABLE([lzmadec], [AS_HELP_STRING([--disable-lzmadec],
495                 [do not build lzmadec
496                 (it exists primarily for LZMA Utils compatibility)])],
497         [], [enable_lzmadec=yes])
498 test "x$enable_decoder_lzma1" = xno && enable_lzmadec=no
499 AM_CONDITIONAL([COND_LZMADEC], [test x$enable_lzmadec != xno])
501 AC_ARG_ENABLE([lzmainfo], [AS_HELP_STRING([--disable-lzmainfo],
502                 [do not build lzmainfo
503                 (it exists primarily for LZMA Utils compatibility)])],
504         [], [enable_lzmainfo=yes])
505 test "x$enable_decoder_lzma1" = xno && enable_lzmainfo=no
506 AM_CONDITIONAL([COND_LZMAINFO], [test x$enable_lzmainfo != xno])
508 AC_ARG_ENABLE([lzma-links], [AS_HELP_STRING([--disable-lzma-links],
509                 [do not create symlinks for LZMA Utils compatibility])],
510         [], [enable_lzma_links=yes])
511 AM_CONDITIONAL([COND_LZMALINKS], [test x$enable_lzma_links != xno])
513 AC_ARG_ENABLE([scripts], [AS_HELP_STRING([--disable-scripts],
514                 [do not install the scripts xzdiff, xzgrep, xzless, xzmore,
515                 and their symlinks])],
516         [], [enable_scripts=yes])
517 AM_CONDITIONAL([COND_SCRIPTS], [test x$enable_scripts != xno])
519 AC_ARG_ENABLE([doc], [AS_HELP_STRING([--disable-doc],
520                 [do not install documentation files to docdir
521                 (man pages are still installed and,
522                 if --enable-doxygen is used,
523                 liblzma API documentation is installed too)])],
524         [], [enable_doc=yes])
525 AM_CONDITIONAL([COND_DOC], [test x$enable_doc != xno])
527 AC_ARG_ENABLE([doxygen], [AS_HELP_STRING([--enable-doxygen],
528                 [generate HTML version of the liblzma API documentation
529                 using Doxygen and install the result to docdir])],
530         [], [enable_doxygen=no])
531 AM_CONDITIONAL([COND_DOXYGEN], [test x$enable_doxygen != xno])
534 ##############
535 # Sandboxing #
536 ##############
538 AC_MSG_CHECKING([if sandboxing should be used])
539 AC_ARG_ENABLE([sandbox], [AS_HELP_STRING([--enable-sandbox=METHOD],
540                 [Sandboxing METHOD can be
541                 'auto', 'no', 'capsicum', 'pledge', or 'landlock'.
542                 The default is 'auto' which enables sandboxing if
543                 a supported sandboxing method is found.])],
544         [], [enable_sandbox=auto])
545 case $enable_xzdec-$enable_xz-$enable_sandbox in
546         no-no-*)
547                 enable_sandbox=no
548                 AC_MSG_RESULT([no, --disable-xz and --disable-xzdec was used])
549                 ;;
550         *-*-auto)
551                 AC_MSG_RESULT([maybe (autodetect)])
552                 ;;
553         *-*-no | *-*-capsicum | *-*-pledge | *-*-landlock)
554                 AC_MSG_RESULT([$enable_sandbox])
555                 ;;
556         *)
557                 AC_MSG_RESULT([])
558                 AC_MSG_ERROR([--enable-sandbox only accepts 'auto', 'no', 'capsicum', 'pledge', or 'landlock'.])
559                 ;;
560 esac
563 ###########################
564 # PATH prefix for scripts #
565 ###########################
567 # The scripts can add a prefix to the search PATH so that POSIX tools
568 # or the xz binary is always in the PATH.
569 AC_ARG_ENABLE([path-for-scripts],
570         [AS_HELP_STRING([--enable-path-for-scripts=PREFIX],
571                 [If PREFIX isn't empty, PATH=PREFIX:$PATH will be set in
572                 the beginning of the scripts (xzgrep and others).
573                 The default is empty except on Solaris the default is
574                 /usr/xpg4/bin.])],
575         [], [
576                 case $host_os in
577                         solaris*) enable_path_for_scripts=/usr/xpg4/bin ;;
578                         *)        enable_path_for_scripts= ;;
579                 esac
580         ])
581 if test -n "$enable_path_for_scripts" && test "x$enable_path_for_scripts" != xno ; then
582         enable_path_for_scripts="PATH=$enable_path_for_scripts:\$PATH"
583 else
584         enable_path_for_scripts=
586 AC_SUBST([enable_path_for_scripts])
589 ###############################################################################
590 # Checks for programs.
591 ###############################################################################
593 echo
594 case $host_os in
595         solaris*)
596                 # The gnulib POSIX shell macro below may pick a shell that
597                 # doesn't work with xzgrep. Workaround by picking a shell
598                 # that is known to work.
599                 if test -z "$gl_cv_posix_shell" && test -x /usr/xpg4/bin/sh; then
600                         gl_cv_posix_shell=/usr/xpg4/bin/sh
601                 fi
602                 ;;
603 esac
604 gl_POSIX_SHELL
605 if test -z "$POSIX_SHELL" && test "x$enable_scripts" = xyes ; then
606         AC_MSG_ERROR([No POSIX conforming shell (sh) was found.])
609 echo
610 echo "Initializing Automake:"
612 # We don't use "subdir-objects" yet because it breaks "make distclean" when
613 # dependencies are enabled (as of Automake 1.14.1) due to this bug:
614 # https://debbugs.gnu.org/cgi/bugreport.cgi?bug=17354
615 # The -Wno-unsupported is used to silence warnings about missing
616 # "subdir-objects".
617 AM_INIT_AUTOMAKE([1.12 foreign tar-v7 filename-length-max=99 -Wno-unsupported])
618 AC_PROG_LN_S
620 dnl # Autoconf >= 2.70 warns that AC_PROG_CC_C99 is obsolete. However,
621 dnl # we have to keep using AC_PROG_CC_C99 instead of AC_PROG_CC
622 dnl # as long as we try to be compatible with Autoconf 2.69.
623 AC_PROG_CC_C99
624 if test x$ac_cv_prog_cc_c99 = xno ; then
625         AC_MSG_ERROR([No C99 compiler was found.])
628 AM_PROG_CC_C_O
629 AM_PROG_AS
630 AC_USE_SYSTEM_EXTENSIONS
632 AS_CASE([$enable_threads],
633         [posix], [
634                 echo
635                 echo "POSIX threading support:"
636                 AX_PTHREAD([:]) dnl We don't need the HAVE_PTHREAD macro.
637                 LIBS="$LIBS $PTHREAD_LIBS"
638                 AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"
640                 dnl NOTE: PTHREAD_CC is ignored. It would be useful on AIX,
641                 dnl but it's tricky to get it right together with
642                 dnl AC_PROG_CC_C99. Thus, this is handled by telling the
643                 dnl user in INSTALL to set the correct CC manually.
645                 AC_DEFINE([MYTHREAD_POSIX], [1],
646                         [Define to 1 when using POSIX threads (pthreads).])
648                 # This is nice to have but not mandatory.
649                 OLD_CFLAGS=$CFLAGS
650                 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
651                 AC_CHECK_FUNCS([pthread_condattr_setclock])
652                 CFLAGS=$OLD_CFLAGS
653         ],
654         [win95], [
655                 AC_DEFINE([MYTHREAD_WIN95], [1], [Define to 1 when using
656                         Windows 95 (and thus XP) compatible threads.
657                         This avoids use of features that were added in
658                         Windows Vista.])
659         ],
660         [vista], [
661                 AC_DEFINE([MYTHREAD_VISTA], [1], [Define to 1 when using
662                         Windows Vista compatible threads. This uses
663                         features that are not available on Windows XP.])
664         ]
666 AM_CONDITIONAL([COND_THREADS], [test "x$enable_threads" != xno])
668 echo
669 echo "Initializing Libtool:"
670 LT_PREREQ([2.4])
671 LT_INIT([win32-dll])
672 LT_LANG([Windows Resource])
674 # This is a bit wrong since it is possible to request that only some libs
675 # are built as shared. Using that feature isn't so common though, and this
676 # breaks only on Windows (at least for now) if the user enables only some
677 # libs as shared.
678 AM_CONDITIONAL([COND_SHARED], [test "x$enable_shared" != xno])
680 #####################
681 # Symbol versioning #
682 #####################
684 # NOTE: This checks if we are building shared or static library
685 # and if --with-pic or --without-pic was used. Thus this check
686 # must be after Libtool initialization.
687 AC_MSG_CHECKING([if library symbol versioning should be used])
688 AC_ARG_ENABLE([symbol-versions], [AS_HELP_STRING([--enable-symbol-versions],
689                 [Use symbol versioning for liblzma. Enabled by default on
690                 GNU/Linux, other GNU-based systems, and FreeBSD.])],
691         [], [enable_symbol_versions=auto])
692 if test "x$enable_symbol_versions" = xauto; then
693         case $host_os in
694                 # NOTE: Even if one omits -gnu on GNU/Linux (e.g.
695                 # i486-slackware-linux), configure will (via config.sub)
696                 # append -gnu (e.g. i486-slackware-linux-gnu), and this
697                 # test will work correctly.
698                 gnu* | *-gnu* | freebsd*)
699                         enable_symbol_versions=yes
700                         ;;
701                 *)
702                         enable_symbol_versions=no
703                         ;;
704         esac
707 # There are two variants for symbol versioning.
708 # See src/liblzma/validate_map.sh for details.
710 # On GNU/Linux, extra symbols are added in the C code. These extra symbols
711 # must not be put into a static library as they can cause problems (and
712 # even if they didn't cause problems, they would be useless). On other
713 # systems symbol versioning may be used too but there is no problem as only
714 # a linker script is specified in src/liblzma/Makefile.am and that isn't
715 # used when creating a static library.
717 # Libtool always uses -DPIC when building shared libraries by default and
718 # doesn't use it for static libs by default. This can be overridden with
719 # --with-pic and --without-pic though. As long as neither --with-pic nor
720 # --without-pic is used then we can use #ifdef PIC to detect if the file is
721 # being built for a shared library.
722 AS_IF([test "x$enable_symbol_versions" = xno], [
723         enable_symbol_versions=no
724         AC_MSG_RESULT([no])
725 ], [test "x$enable_shared" = xno], [
726         enable_symbol_versions=no
727         AC_MSG_RESULT([no (not building a shared library)])
728 ], [
729         # "yes" means that symbol version are to be used but we need to
730         # autodetect which variant to use.
731         if test "x$enable_symbol_versions" = xyes ; then
732                 case "$host_cpu-$host_os" in
733                         microblaze*)
734                                 # GCC 12 on MicroBlaze doesn't support
735                                 # __symver__ attribute. It's simplest and
736                                 # safest to use the generic version on that
737                                 # platform since then only the linker script
738                                 # is needed. The RHEL/CentOS 7 compatibility
739                                 # symbols don't matter on MicroBlaze.
740                                 enable_symbol_versions=generic
741                                 ;;
742                         *-linux*)
743                                 # NVIDIA HPC Compiler doesn't support symbol
744                                 # versioning but the linker script can still
745                                 # be used.
746                                 AC_EGREP_CPP([use_generic_symbol_versioning],
747                                         [#ifdef __NVCOMPILER
748                                         use_generic_symbol_versioning
749                                         #endif],
750                                         [enable_symbol_versions=generic],
751                                         [enable_symbol_versions=linux])
752                                 ;;
753                         *)
754                                 enable_symbol_versions=generic
755                                 ;;
756                 esac
757         fi
759         if test "x$enable_symbol_versions" = xlinux ; then
760                 case "$pic_mode-$enable_static" in
761                         default-*)
762                                 # Use symvers if PIC is defined.
763                                 have_symbol_versions_linux=2
764                                 ;;
765                         *-no)
766                                 # Not building static library.
767                                 # Use symvers unconditionally.
768                                 have_symbol_versions_linux=1
769                                 ;;
770                         *)
771                                 AC_MSG_RESULT([])
772                                 AC_MSG_ERROR([
773     On GNU/Linux, building both shared and static library at the same time
774     is not supported if --with-pic or --without-pic is used.
775     Use either --disable-shared or --disable-static to build one type
776     of library at a time. If both types are needed, build one at a time,
777     possibly picking only src/liblzma/.libs/liblzma.a from the static build.])
778                                 ;;
779                 esac
780                 AC_DEFINE_UNQUOTED([HAVE_SYMBOL_VERSIONS_LINUX],
781                         [$have_symbol_versions_linux],
782                         [Define to 1 to if GNU/Linux-specific details
783                         are unconditionally wanted for symbol
784                         versioning. Define to 2 to if these are wanted
785                         only if also PIC is defined (allows building
786                         both shared and static liblzma at the same
787                         time with Libtool if neither --with-pic nor
788                         --without-pic is used). This define must be
789                         used together with liblzma_linux.map.])
790         elif test "x$enable_symbol_versions" != xgeneric ; then
791                 AC_MSG_RESULT([])
792                 AC_MSG_ERROR([unknown symbol versioning variant '$enable_symbol_versions'])
793         fi
794         AC_MSG_RESULT([yes ($enable_symbol_versions)])
797 AM_CONDITIONAL([COND_SYMVERS_LINUX],
798         [test "x$enable_symbol_versions" = xlinux])
799 AM_CONDITIONAL([COND_SYMVERS_GENERIC],
800         [test "x$enable_symbol_versions" = xgeneric])
803 ###############################################################################
804 # Checks for libraries.
805 ###############################################################################
807 dnl Support for _REQUIRE_VERSION was added in gettext 0.19.6. If both
808 dnl _REQUIRE_VERSION and _VERSION are present, the _VERSION is ignored.
809 dnl We use both for compatibility with other programs in the Autotools family.
810 echo
811 echo "Initializing gettext:"
812 AM_GNU_GETTEXT_REQUIRE_VERSION([0.19.6])
813 AM_GNU_GETTEXT_VERSION([0.19.6])
814 AM_GNU_GETTEXT([external])
817 ###############################################################################
818 # Checks for header files.
819 ###############################################################################
821 echo
822 echo "System headers and functions:"
824 # immintrin.h allows the use of the intrinsic functions if they are available.
825 # cpuid.h may be used for detecting x86 processor features at runtime.
826 AC_CHECK_HEADERS([immintrin.h cpuid.h])
829 ###############################################################################
830 # Checks for typedefs, structures, and compiler characteristics.
831 ###############################################################################
833 AC_HEADER_STDBOOL
835 AC_TYPE_UINT8_T
836 AC_TYPE_UINT16_T
837 AC_TYPE_INT32_T
838 AC_TYPE_UINT32_T
839 AC_TYPE_INT64_T
840 AC_TYPE_UINT64_T
841 AC_TYPE_UINTPTR_T
843 AC_CHECK_SIZEOF([size_t])
845 # The command line tool can copy high resolution timestamps if such
846 # information is available in struct stat. Otherwise one second accuracy
847 # is used.
848 AC_CHECK_MEMBERS([
849         struct stat.st_atim.tv_nsec,
850         struct stat.st_atimespec.tv_nsec,
851         struct stat.st_atimensec,
852         struct stat.st_uatime,
853         struct stat.st_atim.st__tim.tv_nsec])
855 AC_SYS_LARGEFILE
856 AC_C_BIGENDIAN
858 # __attribute__((__constructor__)) can be used for one-time initializations.
859 # Use -Werror because some compilers accept unknown attributes and just
860 # give a warning.
862 # FIXME? Unfortunately -Werror can cause trouble if CFLAGS contains options
863 # that produce warnings for unrelated reasons. For example, GCC and Clang
864 # support -Wunused-macros which will warn about "#define _GNU_SOURCE 1"
865 # which will be among the #defines that Autoconf inserts to the beginning of
866 # the test program. There seems to be no nice way to prevent Autoconf from
867 # inserting the any defines to the test program.
868 AC_MSG_CHECKING([if __attribute__((__constructor__)) can be used])
869 have_func_attribute_constructor=no
870 OLD_CFLAGS="$CFLAGS"
871 CFLAGS="$CFLAGS -Werror"
872 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
873         __attribute__((__constructor__))
874         static void my_constructor_func(void) { return; }
875 ]])], [
876         AC_DEFINE([HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR], [1],
877                 [Define to 1 if __attribute__((__constructor__))
878                 is supported for functions.])
879         have_func_attribute_constructor=yes
880         AC_MSG_RESULT([yes])
881 ], [
882         AC_MSG_RESULT([no])
884 CFLAGS="$OLD_CFLAGS"
886 # The Win95 threading lacks a thread-safe one-time initialization function.
887 # The one-time initialization is needed for crc32_small.c and crc64_small.c
888 # create the CRC tables. So if small mode is enabled, the threading mode is
889 # win95, and the compiler does not support attribute constructor, then we
890 # would end up with a multithreaded build that is thread-unsafe. As a
891 # result this configuration is not allowed.
892 if test "x$enable_small$enable_threads$have_func_attribute_constructor" \
893                 = xyeswin95no; then
894         AC_MSG_ERROR([
895     --enable-threads=win95 and --enable-small cannot be used
896     at the same time with a compiler that doesn't support
897     __attribute__((__constructor__))])
901 ###############################################################################
902 # Checks for library functions.
903 ###############################################################################
905 # Gnulib replacements as needed
906 gl_GETOPT
908 # If clock_gettime() is available, liblzma with pthreads may use it, and
909 # xz may use it even when threading support is disabled. In XZ Utils 5.4.x
910 # and older, configure checked for clock_gettime() only when using pthreads.
911 # This way non-threaded builds of liblzma didn't get a useless dependency on
912 # librt which further had a dependency on libpthread. Avoiding these was
913 # useful when a small build was needed, for example, for initramfs use.
915 # The above reasoning is thoroughly obsolete: On GNU/Linux, librt hasn't
916 # been needed for clock_gettime() since glibc 2.17 (2012-12-25).
917 # Solaris 10 needs librt but Solaris 11 doesn't anymore.
918 AC_SEARCH_LIBS([clock_gettime], [rt])
919 AC_CHECK_FUNCS([clock_gettime])
920 AC_CHECK_DECL([CLOCK_MONOTONIC], [AC_DEFINE([HAVE_CLOCK_MONOTONIC], [1],
921         [Define to 1 if 'CLOCK_MONOTONIC' is declared in <time.h>.])], [],
922         [[#include <time.h>]])
924 # Find the best function to set timestamps.
925 AC_CHECK_FUNCS([futimens futimes futimesat utimes _futime utime], [break])
927 # This is nice to have but not mandatory.
928 AC_CHECK_FUNCS([posix_fadvise])
930 TUKLIB_PROGNAME
931 TUKLIB_INTEGER
932 TUKLIB_PHYSMEM
933 TUKLIB_CPUCORES
934 TUKLIB_MBSTR
936 # If requested, check for system-provided SHA-256. At least the following
937 # implementations are supported:
939 # OS       Headers                     Library  Type           Function
940 # FreeBSD  sys/types.h + sha256.h      libmd    SHA256_CTX     SHA256_Init
941 # NetBSD   sys/types.h + sha2.h                 SHA256_CTX     SHA256_Init
942 # OpenBSD  sys/types.h + sha2.h                 SHA2_CTX       SHA256Init
943 # Solaris  sys/types.h + sha2.h        libmd    SHA256_CTX     SHA256Init
944 # MINIX 3  sys/types.h + sha2.h                 SHA256_CTX     SHA256_Init
945 # Darwin   CommonCrypto/CommonDigest.h          CC_SHA256_CTX  CC_SHA256_Init
947 # Note that Darwin's CC_SHA256_Update takes buffer size as uint32_t instead
948 # of size_t.
950 sha256_header_found=no
951 sha256_type_found=no
952 sha256_func_found=no
953 AS_IF([test "x$enable_external_sha256" = "xyes"], [
954         # Test for Common Crypto before others, because Darwin has sha256.h
955         # too and we don't want to use that, because on older versions it
956         # uses OpenSSL functions, whose SHA256_Init is not guaranteed to
957         # succeed.
958         AC_CHECK_HEADERS(
959                 [CommonCrypto/CommonDigest.h sha256.h sha2.h],
960                 [sha256_header_found=yes ; break])
961         if test "x$sha256_header_found" = xyes; then
962                 AC_CHECK_TYPES([CC_SHA256_CTX, SHA256_CTX, SHA2_CTX],
963                         [sha256_type_found=yes], [],
964                         [[#ifdef HAVE_SYS_TYPES_H
965                           # include <sys/types.h>
966                           #endif
967                           #ifdef HAVE_COMMONCRYPTO_COMMONDIGEST_H
968                           # include <CommonCrypto/CommonDigest.h>
969                           #endif
970                           #ifdef HAVE_SHA256_H
971                           # include <sha256.h>
972                           #endif
973                           #ifdef HAVE_SHA2_H
974                           # include <sha2.h>
975                           #endif]])
976                 if test "x$sha256_type_found" = xyes ; then
977                         AC_SEARCH_LIBS([SHA256Init], [md])
978                         AC_SEARCH_LIBS([SHA256_Init], [md])
979                         AC_CHECK_FUNCS([CC_SHA256_Init SHA256Init SHA256_Init],
980                                 [sha256_func_found=yes ; break])
981                 fi
982         fi
984 AM_CONDITIONAL([COND_INTERNAL_SHA256], [test "x$sha256_func_found" = xno])
985 if test "x$enable_external_sha256$sha256_func_found" = xyesno; then
986         AC_MSG_ERROR([--enable-external-sha256 was specified but no supported external SHA-256 implementation was found])
989 # Check for SSE2 intrinsics. There is no run-time detection for SSE2 so if
990 # compiler options enable SSE2 then SSE2 support is required by the binaries.
991 # The compile-time check for SSE2 is done with #ifdefs because some compilers
992 # (ICC, MSVC) allow SSE2 intrinsics even when SSE2 isn't enabled.
993 AC_CHECK_DECL([_mm_movemask_epi8],
994         [AC_DEFINE([HAVE__MM_MOVEMASK_EPI8], [1],
995                 [Define to 1 if _mm_movemask_epi8 is available.])],
996         [],
997 [#ifdef HAVE_IMMINTRIN_H
998 #include <immintrin.h>
999 #endif])
1001 # For faster CRC on 32/64-bit x86 and E2K (see also crc64_fast.c):
1003 #   - Check for the CLMUL intrinsic _mm_clmulepi64_si128 in <immintrin.h>.
1004 #     Check also for _mm_set_epi64x for consistency with CMake build
1005 #     where it's needed to disable CLMUL with VS2013.
1007 #   - Check that __attribute__((__target__("ssse3,sse4.1,pclmul"))) works
1008 #     together with _mm_clmulepi64_si128 from <immintrin.h>. The attribute
1009 #     was added in GCC 4.4 but some GCC 4.x versions don't allow intrinsics
1010 #     with it. Exception: it must be not be used with EDG-based compilers
1011 #     like ICC and the compiler on E2K.
1013 # If everything above is supported, runtime detection will be used to keep the
1014 # binaries working on systems that don't support the required extensions.
1015 AC_MSG_CHECKING([if _mm_clmulepi64_si128 is usable])
1016 AS_IF([test "x$enable_clmul_crc" = xno], [
1017         AC_MSG_RESULT([no, --disable-clmul-crc was used])
1018 ], [
1019         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1020 #include <immintrin.h>
1022 // CLMUL works on older E2K instruction set but it is slow due to emulation.
1023 #if defined(__e2k__) && __iset__ < 6
1024 #       error
1025 #endif
1027 // Intel's old compiler (ICC) can define __GNUC__ but the attribute must not
1028 // be used with it. The new Clang-based ICX needs the attribute.
1029 // Checking for !defined(__EDG__) catches ICC and other EDG-based compilers.
1030 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
1031 __attribute__((__target__("ssse3,sse4.1,pclmul")))
1032 #endif
1033 __m128i my_clmul(__m128i a)
1035         const __m128i b = _mm_set_epi64x(1, 2);
1036         return _mm_clmulepi64_si128(a, b, 0);
1038         ]])], [
1039                 AC_DEFINE([HAVE_USABLE_CLMUL], [1],
1040                         [Define to 1 if _mm_set_epi64x and
1041                         _mm_clmulepi64_si128 are usable.
1042                         See configure.ac for details.])
1043                 enable_clmul_crc=yes
1044         ], [
1045                 enable_clmul_crc=no
1046         ])
1047         AC_MSG_RESULT([$enable_clmul_crc])
1050 # ARM64 C Language Extensions define CRC32 functions in arm_acle.h.
1051 # These are supported by at least GCC and Clang which both need
1052 # __attribute__((__target__("+crc"))), unless the needed compiler flags
1053 # are used to support the CRC instruction.
1054 AC_MSG_CHECKING([if ARM64 CRC32 instruction is usable])
1055 AS_IF([test "x$enable_arm64_crc32" = xno], [
1056         AC_MSG_RESULT([no, --disable-arm64-crc32 was used])
1057 ], [
1058         # Set -Werror here because some versions of Clang (14 and older)
1059         # do not report the unsupported __attribute__((__target__("+crc")))
1060         # or __crc32d() as an error, only as a warning. This does not need
1061         # to be done with CMake because tests will attempt to link and the
1062         # error will be reported then.
1063         OLD_CFLAGS="$CFLAGS"
1064         CFLAGS="$CFLAGS -Werror"
1066         AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1067 #include <arm_acle.h>
1068 #include <stdint.h>
1070 #if (defined(__GNUC__) || defined(__clang__)) && !defined(__EDG__)
1071 __attribute__((__target__("+crc")))
1072 #endif
1073 uint32_t my_crc(uint32_t a, uint64_t b)
1075         return __crc32d(a, b);
1077         ]])], [
1078                 AC_DEFINE([HAVE_ARM64_CRC32], [1],
1079                         [Define to 1 if ARM64 CRC32 instruction is supported.
1080                         See configure.ac for details.])
1081                 enable_arm64_crc32=yes
1082         ], [
1083                 enable_arm64_crc32=no
1084         ])
1085         AC_MSG_RESULT([$enable_arm64_crc32])
1087         CFLAGS="$OLD_CFLAGS"
1090 # Check for ARM64 CRC32 instruction runtime detection.
1091 # getauxval() is supported on Linux, elf_aux_info() on FreeBSD, and
1092 # sysctlbyname("hw.optional.armv8_crc32", ...) is supported on Darwin
1093 # (macOS, iOS, etc.). Note that sysctlbyname() is supported on FreeBSD,
1094 # NetBSD, and possibly others too but the string is specific to Apple OSes.
1095 # The C code is responsible for checking defined(__APPLE__) before using
1096 # sysctlbyname("hw.optional.armv8_crc32", ...).
1097 AS_IF([test "x$enable_arm64_crc32" = xyes], [
1098         AC_CHECK_FUNCS([getauxval elf_aux_info sysctlbyname], [break])
1102 # Check for sandbox support. If one is found, set enable_sandbox=found.
1104 # About -fsanitize: Of our three sandbox methods, only Landlock is
1105 # incompatible with -fsanitize. FreeBSD 13.2 with Capsicum was tested with
1106 # -fsanitize=address,undefined and had no issues. OpenBSD (as of version
1107 # 7.4) has minimal support for process instrumentation. OpenBSD does not
1108 # distribute the additional libraries needed (libasan, libubsan, etc.) with
1109 # GCC or Clang needed for runtime sanitization support and instead only
1110 # support -fsanitize-minimal-runtime for minimal undefined behavior
1111 # sanitization. This minimal support is compatible with our use of the
1112 # Pledge sandbox. So only Landlock will result in a build that cannot
1113 # compress or decompress a single file to standard out.
1114 AS_CASE([$enable_sandbox],
1115         [auto | capsicum], [
1116                 AC_CHECK_FUNCS([cap_rights_limit], [enable_sandbox=found])
1117         ]
1119 AS_CASE([$enable_sandbox],
1120         [auto | pledge], [
1121                 AC_CHECK_FUNCS([pledge], [enable_sandbox=found])
1122         ]
1124 AS_CASE([$enable_sandbox],
1125         [auto | landlock], [
1126                 AC_MSG_CHECKING([if Linux Landlock is usable])
1128                 # A compile check is done here because some systems have
1129                 # linux/landlock.h, but do not have the syscalls defined
1130                 # in order to actually use Linux Landlock.
1131                 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1132                         #include <linux/landlock.h>
1133                         #include <sys/syscall.h>
1134                         #include <sys/prctl.h>
1136                         void my_sandbox(void)
1137                         {
1138                                 (void)prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
1139                                 (void)SYS_landlock_create_ruleset;
1140                                 (void)SYS_landlock_restrict_self;
1141                                 (void)LANDLOCK_CREATE_RULESET_VERSION;
1142                                 return;
1143                         }
1144                 ]])], [
1145                         enable_sandbox=found
1147                         AS_CASE([$CFLAGS], [*-fsanitize=*], [AC_MSG_ERROR([
1148     CFLAGS contains '-fsanitize=' which is incompatible with the Landlock
1149     sandboxing. Use --disable-sandbox when using '-fsanitize'.])])
1151                         AC_DEFINE([HAVE_LINUX_LANDLOCK], [1],
1152                                 [Define to 1 if Linux Landlock is supported.
1153                                 See configure.ac for details.])
1154                         AC_MSG_RESULT([yes])
1155                 ], [
1156                         AC_MSG_RESULT([no])
1157                 ])
1158         ]
1161 # If a specific sandboxing method was explicitly requested and it wasn't
1162 # found, give an error.
1163 case $enable_sandbox in
1164         auto | no | found)
1165                 ;;
1166         *)
1167                 AC_MSG_ERROR([$enable_sandbox support not found])
1168                 ;;
1169 esac
1172 ###############################################################################
1173 # If using GCC, set some additional AM_CFLAGS:
1174 ###############################################################################
1176 if test "$GCC" = yes ; then
1177         echo
1178         echo "GCC extensions:"
1181 # Always do the visibility check but don't set AM_CFLAGS on Windows.
1182 # This way things get set properly even on Windows.
1183 gl_VISIBILITY
1184 if test -n "$CFLAG_VISIBILITY" && test "$is_w32" = no; then
1185         AM_CFLAGS="$AM_CFLAGS $CFLAG_VISIBILITY"
1188 AS_IF([test "$GCC" = yes], [
1189         # Enable as much warnings as possible. These commented warnings won't
1190         # work for this package though:
1191         #   * -Wunreachable-code breaks several assert(0) cases, which are
1192         #     backed up with "return LZMA_PROG_ERROR".
1193         #   * -Wcast-qual would break various things where we need a non-const
1194         #     pointer although we don't modify anything through it.
1195         #   * -Winline, -Wdisabled-optimization, -Wunsafe-loop-optimizations
1196         #     don't seem so useful here; at least the last one gives some
1197         #     warnings which are not bugs.
1198         #   * -Wconversion still shows too many warnings.
1199         #
1200         # The flags before the empty line are for GCC and many of them
1201         # are supported by Clang too. The flags after the empty line are
1202         # for Clang.
1203         for NEW_FLAG in \
1204                         -Wall \
1205                         -Wextra \
1206                         -Wvla \
1207                         -Wformat=2 \
1208                         -Winit-self \
1209                         -Wmissing-include-dirs \
1210                         -Wshift-overflow=2 \
1211                         -Wstrict-overflow=3 \
1212                         -Walloc-zero \
1213                         -Wduplicated-cond \
1214                         -Wfloat-equal \
1215                         -Wundef \
1216                         -Wshadow \
1217                         -Wpointer-arith \
1218                         -Wbad-function-cast \
1219                         -Wwrite-strings \
1220                         -Wdate-time \
1221                         -Wsign-conversion \
1222                         -Wfloat-conversion \
1223                         -Wlogical-op \
1224                         -Waggregate-return \
1225                         -Wstrict-prototypes \
1226                         -Wold-style-definition \
1227                         -Wmissing-prototypes \
1228                         -Wmissing-declarations \
1229                         -Wredundant-decls \
1230                         \
1231                         -Wc99-compat \
1232                         -Wc11-extensions \
1233                         -Wc2x-compat \
1234                         -Wc2x-extensions \
1235                         -Wpre-c2x-compat \
1236                         -Warray-bounds-pointer-arithmetic \
1237                         -Wassign-enum \
1238                         -Wconditional-uninitialized \
1239                         -Wdocumentation \
1240                         -Wduplicate-enum \
1241                         -Wempty-translation-unit \
1242                         -Wflexible-array-extensions \
1243                         -Wmissing-variable-declarations \
1244                         -Wnewline-eof \
1245                         -Wshift-sign-overflow \
1246                         -Wstring-conversion
1247         do
1248                 AC_MSG_CHECKING([if $CC accepts $NEW_FLAG])
1249                 OLD_CFLAGS="$CFLAGS"
1250                 CFLAGS="$CFLAGS $NEW_FLAG -Werror"
1251                 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
1252                                 [[void foo(void); void foo(void) { }]])], [
1253                         AM_CFLAGS="$AM_CFLAGS $NEW_FLAG"
1254                         AC_MSG_RESULT([yes])
1255                 ], [
1256                         AC_MSG_RESULT([no])
1257                 ])
1258                 CFLAGS="$OLD_CFLAGS"
1259         done
1261         AC_ARG_ENABLE([werror],
1262                 AS_HELP_STRING([--enable-werror], [Enable -Werror to abort
1263                         compilation on all compiler warnings.]),
1264                 [], [enable_werror=no])
1265         if test "x$enable_werror" = "xyes"; then
1266                 AM_CFLAGS="$AM_CFLAGS -Werror"
1267         fi
1271 ###############################################################################
1272 # Create the makefiles and config.h
1273 ###############################################################################
1275 echo
1277 # Don't build the lib directory at all if we don't need any replacement
1278 # functions.
1279 AM_CONDITIONAL([COND_GNULIB], test -n "$LIBOBJS")
1281 # Add default AM_CFLAGS.
1282 AC_SUBST([AM_CFLAGS])
1284 # This is needed for src/scripts.
1285 xz=`echo xz | sed "$program_transform_name"`
1286 AC_SUBST([xz])
1288 AC_CONFIG_FILES([
1289         Makefile
1290         po/Makefile.in
1291         lib/Makefile
1292         src/Makefile
1293         src/liblzma/Makefile
1294         src/liblzma/api/Makefile
1295         src/xz/Makefile
1296         src/xzdec/Makefile
1297         src/lzmainfo/Makefile
1298         src/scripts/Makefile
1299         tests/Makefile
1300         debug/Makefile
1302 AC_CONFIG_FILES([src/scripts/xzdiff], [chmod +x src/scripts/xzdiff])
1303 AC_CONFIG_FILES([src/scripts/xzgrep], [chmod +x src/scripts/xzgrep])
1304 AC_CONFIG_FILES([src/scripts/xzmore], [chmod +x src/scripts/xzmore])
1305 AC_CONFIG_FILES([src/scripts/xzless], [chmod +x src/scripts/xzless])
1307 AC_OUTPUT
1309 # Some warnings
1310 if test x$tuklib_cv_physmem_method = xunknown; then
1311         echo
1312         echo "WARNING:"
1313         echo "No supported method to detect the amount of RAM."
1314         echo "Consider using --enable-assume-ram (if you didn't already)"
1315         echo "or make a patch to add support for this operating system."
1318 if test x$tuklib_cv_cpucores_method = xunknown; then
1319         echo
1320         echo "WARNING:"
1321         echo "No supported method to detect the number of CPU cores."
1324 if test "x$enable_threads$enable_small$have_func_attribute_constructor" \
1325                 = xnoyesno; then
1326         echo
1327         echo "NOTE:"
1328         echo "liblzma will be thread-unsafe due to the combination"
1329         echo "of --disable-threads --enable-small when using a compiler"
1330         echo "that doesn't support __attribute__((__constructor__))."