]> icculus.org git repositories - icculus/xz.git/blob - configure.ac
Make it easy to choose if command line tools should be
[icculus/xz.git] / configure.ac
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 ###############################################################################
5 #
6 #   Copyright (C) 2007 Lasse Collin
7 #
8 #   This library is free software; you can redistribute it and/or
9 #   modify it under the terms of the GNU Lesser General Public
10 #   License as published by the Free Software Foundation; either
11 #   version 2.1 of the License, or (at your option) any later version.
12 #
13 #   This library is distributed in the hope that it will be useful,
14 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #   Lesser General Public License for more details.
17 #
18 ###############################################################################
19
20 # NOTE: Don't add useless checks. autoscan detects this and that, but don't
21 # let it confuse you. For example, we don't care about checking for behavior
22 # of malloc(), stat(), or lstat(), since we don't use those functions in
23 # a way that would cause the problems the autoconf macros check.
24
25 AC_PREREQ([2.61])
26
27 AC_INIT([XZ Utils], [4.999.8beta], [lasse.collin@tukaani.org], [xz])
28 AC_CONFIG_SRCDIR([src/liblzma/common/common.h])
29 AC_CONFIG_HEADER([config.h])
30
31 echo
32 echo "$PACKAGE_STRING"
33
34 echo
35 echo "System type:"
36 # This is needed to know if assembler optimizations can be used.
37 AC_CANONICAL_HOST
38
39
40 echo
41 echo "Configure options:"
42
43
44 #############
45 # Debugging #
46 #############
47
48 AC_MSG_CHECKING([if debugging code should be compiled])
49 AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug], [Enable debugging code.]),
50         [], enable_debug=no)
51 if test "x$enable_debug" = xyes; then
52         AC_MSG_RESULT([yes])
53 else
54         AC_DEFINE([NDEBUG], [1], [Define to 1 to disable debugging code.])
55         AC_MSG_RESULT([no])
56 fi
57
58
59 ###########
60 # Encoder #
61 ###########
62
63 AC_MSG_CHECKING([if encoder components should be built])
64 AC_ARG_ENABLE([encoder], AC_HELP_STRING([--disable-encoder],
65                 [Do not build the encoder components.]),
66         [], enable_encoder=yes)
67 if test "x$enable_encoder" = xyes; then
68         AC_DEFINE([HAVE_ENCODER], [1],
69                 [Define to 1 if encoder components are enabled.])
70         AC_MSG_RESULT([yes])
71 else
72         AC_MSG_RESULT([no])
73 fi
74 AM_CONDITIONAL(COND_MAIN_ENCODER, test "x$enable_encoder" = xyes)
75
76
77 ###########
78 # Decoder #
79 ###########
80
81 AC_MSG_CHECKING([if decoder components should be built])
82 AC_ARG_ENABLE([decoder], AC_HELP_STRING([--disable-decoder],
83                 [Do not build the decoder components.]),
84         [], enable_decoder=yes)
85 if test "x$enable_decoder" = xyes; then
86         AC_DEFINE([HAVE_DECODER], [1],
87                 [Define to 1 if decoder components are enabled.])
88         AC_MSG_RESULT([yes])
89 else
90         AC_MSG_RESULT([no])
91         if test "x$enable_encoder" = xno; then
92                 AC_MSG_ERROR([Do not disable both encoder and decoder.])
93         fi
94 fi
95 AM_CONDITIONAL(COND_MAIN_DECODER, test "x$enable_decoder" = xyes)
96
97
98 ###########
99 # Filters #
100 ###########
101
102 m4_define([SUPPORTED_FILTERS], [lzma1,lzma2,subblock,delta,x86,powerpc,ia64,arm,armthumb,sparc])dnl
103 m4_define([SIMPLE_FILTERS], [x86,powerpc,ia64,arm,armthumb,sparc])
104 m4_define([LZ_FILTERS], [lzma1,lzma2])
105
106 m4_foreach([NAME], [SUPPORTED_FILTERS],
107 [enable_filter_[]NAME=no
108 enable_encoder_[]NAME=no
109 enable_decoder_[]NAME=no
110 ])dnl
111
112 AC_MSG_CHECKING([which encoders to build])
113 AC_ARG_ENABLE([encoders], AC_HELP_STRING([--enable-encoders=LIST],
114                 [Comma-separated list of encoders to build. Default=all.
115                 Available encoders:]
116                         m4_translit(m4_defn([SUPPORTED_FILTERS]), [,], [ ])),
117         [], [enable_encoders=SUPPORTED_FILTERS])
118 enable_encoders=`echo "$enable_encoders" | sed 's/,subblock//; s/,/ /g'`
119 if test "x$enable_encoders" = xno || test "x$enable_encoders" = x; then
120         AC_MSG_RESULT([(none)])
121 else
122         for arg in $enable_encoders
123         do
124                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
125                         NAME)
126                                 enable_filter_[]NAME=yes
127                                 enable_encoder_[]NAME=yes
128                                 AC_DEFINE(HAVE_ENCODER_[]m4_toupper(NAME), [1],
129                                 [Define to 1 if] NAME [encoder is enabled.])
130                                 ;;])
131                         *)
132                                 AC_MSG_RESULT([])
133                                 AC_MSG_ERROR([unknown filter: $arg])
134                                 ;;
135                 esac
136         done
137         AC_MSG_RESULT([$enable_encoders])
138 fi
139
140 AC_MSG_CHECKING([which decoders to build])
141 AC_ARG_ENABLE([decoders], AC_HELP_STRING([--enable-decoders=LIST],
142                 [Comma-separated list of decoders to build. Default=all.
143                 Available decoders are the same as available encoders.]),
144         [], [enable_decoders=SUPPORTED_FILTERS])
145 enable_decoders=`echo "$enable_decoders" | sed 's/,subblock//; s/,/ /g'`
146 if test "x$enable_decoders" = xno || test "x$enable_decoders" = x; then
147         AC_MSG_RESULT([(none)])
148 else
149         for arg in $enable_decoders
150         do
151                 case $arg in m4_foreach([NAME], [SUPPORTED_FILTERS], [
152                         NAME)
153                                 enable_filter_[]NAME=yes
154                                 enable_decoder_[]NAME=yes
155                                 AC_DEFINE(HAVE_DECODER_[]m4_toupper(NAME), [1],
156                                 [Define to 1 if] NAME [decoder is enabled.])
157                                 ;;])
158                         *)
159                                 AC_MSG_RESULT([])
160                                 AC_MSG_ERROR([unknown filter: $arg])
161                                 ;;
162                 esac
163         done
164
165         # LZMA2 requires that LZMA1 is enabled.
166         test "x$enable_encoder_lzma2" = xyes && enable_encoder_lzma1=yes
167         test "x$enable_decoder_lzma2" = xyes && enable_decoder_lzma1=yes
168
169         AC_MSG_RESULT([$enable_decoders])
170 fi
171
172 if test "x$enable_encoder_lzma2$enable_encoder_lzma1" = xyesno \
173                 || test "x$enable_decoder_lzma2$enable_decoder_lzma1" = xyesno; then
174         AC_MSG_ERROR([LZMA2 requires that LZMA1 is also enabled.])
175 fi
176
177 m4_foreach([NAME], [SUPPORTED_FILTERS],
178 [AM_CONDITIONAL(COND_FILTER_[]m4_toupper(NAME), test "x$enable_filter_[]NAME" = xyes)
179 AM_CONDITIONAL(COND_ENCODER_[]m4_toupper(NAME), test "x$enable_encoder_[]NAME" = xyes)
180 AM_CONDITIONAL(COND_DECODER_[]m4_toupper(NAME), test "x$enable_decoder_[]NAME" = xyes)
181 ])dnl
182
183 # The so called "simple filters" share common code.
184 enable_filter_simple=no
185 enable_encoder_simple=no
186 enable_decoder_simple=no
187 m4_foreach([NAME], [SIMPLE_FILTERS],
188 [test "x$enable_filter_[]NAME" = xyes && enable_filter_simple=yes
189 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_simple=yes
190 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_simple=yes
191 ])dnl
192 AM_CONDITIONAL(COND_FILTER_SIMPLE, test "x$enable_filter_simple" = xyes)
193 AM_CONDITIONAL(COND_ENCODER_SIMPLE, test "x$enable_encoder_simple" = xyes)
194 AM_CONDITIONAL(COND_DECODER_SIMPLE, test "x$enable_decoder_simple" = xyes)
195
196 # LZ-based filters share common code.
197 enable_filter_lz=no
198 enable_encoder_lz=no
199 enable_decoder_lz=no
200 m4_foreach([NAME], [LZ_FILTERS],
201 [test "x$enable_filter_[]NAME" = xyes && enable_filter_lz=yes
202 test "x$enable_encoder_[]NAME" = xyes && enable_encoder_lz=yes
203 test "x$enable_decoder_[]NAME" = xyes && enable_decoder_lz=yes
204 ])dnl
205 AM_CONDITIONAL(COND_FILTER_LZ, test "x$enable_filter_lz" = xyes)
206 AM_CONDITIONAL(COND_ENCODER_LZ, test "x$enable_encoder_lz" = xyes)
207 AM_CONDITIONAL(COND_DECODER_LZ, test "x$enable_decoder_lz" = xyes)
208
209
210 #################
211 # Match finders #
212 #################
213
214 m4_define([SUPPORTED_MATCH_FINDERS], [hc3,hc4,bt2,bt3,bt4])
215
216 m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS],
217 [enable_match_finder_[]NAME=no
218 ])
219
220 AC_MSG_CHECKING([which match finders to build])
221 AC_ARG_ENABLE([match-finders], AC_HELP_STRING([--enable-match-finders=LIST],
222                 [Comma-separated list of match finders to build. Default=all.
223                 At least one match finder is required for encoding with
224                 the LZMA1 and LZMA2 filters. Available match finders:]
225                 m4_translit(m4_defn([SUPPORTED_MATCH_FINDERS]), [,], [ ])), [],
226         [enable_match_finders=SUPPORTED_MATCH_FINDERS])
227 enable_match_finders=`echo "$enable_match_finders" | sed 's/,/ /g'`
228 if test "x$enable_encoder" = xyes && test "x$enable_encoder_lz" = xyes ; then
229         for arg in $enable_match_finders
230                 do
231                 case $arg in m4_foreach([NAME], [SUPPORTED_MATCH_FINDERS], [
232                         NAME)
233                                 enable_match_finder_[]NAME=yes
234                                 AC_DEFINE(HAVE_MF_[]m4_toupper(NAME), [1],
235                                 [Define to 1 to enable] NAME [match finder.])
236                                 ;;])
237                         *)
238                                 AC_MSG_RESULT([])
239                                 AC_MSG_ERROR([unknown match finder: $arg])
240                                 ;;
241                 esac
242         done
243         AC_MSG_RESULT([$enable_match_finders])
244 else
245         AC_MSG_RESULT([(none because not building any LZ-based encoder)])
246 fi
247
248
249 ####################
250 # Integrity checks #
251 ####################
252
253 m4_define([SUPPORTED_CHECKS], [crc32,crc64,sha256])
254
255 m4_foreach([NAME], [SUPPORTED_FILTERS],
256 [enable_check_[]NAME=no
257 ])dnl
258
259 AC_MSG_CHECKING([which integrity checks to build])
260 AC_ARG_ENABLE([checks], AC_HELP_STRING([--enable-checks=LIST],
261                 [Comma-separated list of integrity checks to build.
262                 Default=all. Available integrity checks:]
263                 m4_translit(m4_defn([SUPPORTED_CHECKS]), [,], [ ])),
264         [], [enable_checks=SUPPORTED_CHECKS])
265 enable_checks=`echo "$enable_checks" | sed 's/,/ /g'`
266 if test "x$enable_checks" = xno || test "x$enable_checks" = x; then
267         AC_MSG_RESULT([(none)])
268 else
269         for arg in $enable_checks
270         do
271                 case $arg in m4_foreach([NAME], [SUPPORTED_CHECKS], [
272                         NAME)
273                                 enable_check_[]NAME=yes
274                                 AC_DEFINE(HAVE_CHECK_[]m4_toupper(NAME), [1],
275                                 [Define to 1 if] NAME
276                                 [integrity check is enabled.])
277                                 ;;])
278                         *)
279                                 AC_MSG_RESULT([])
280                                 AC_MSG_ERROR([unknown integrity check: $arg])
281                                 ;;
282                 esac
283         done
284         AC_MSG_RESULT([$enable_checks])
285 fi
286 if test "x$enable_checks_crc32" = xno ; then
287         AC_MSG_ERROR([For now, the CRC32 check must always be enabled.])
288 fi
289
290 m4_foreach([NAME], [SUPPORTED_CHECKS],
291 [AM_CONDITIONAL(COND_CHECK_[]m4_toupper(NAME), test "x$enable_check_[]NAME" = xyes)
292 ])dnl
293
294
295 ###########################
296 # Assembler optimizations #
297 ###########################
298
299 AC_MSG_CHECKING([if assembler optimizations should be used])
300 AC_ARG_ENABLE([assembler], AC_HELP_STRING([--disable-assembler],
301                 [Do not use assembler optimizations even if such exist
302                 for the architecture.]),
303         [], [enable_assembler=yes])
304 if test "x$enable_assembler" = xyes; then
305         case $host_cpu in
306                 i?86)   enable_assembler=x86 ;;
307                 x86_64) enable_assembler=x86_64 ;;
308                 *)      enable_assembler=no ;;
309         esac
310 fi
311 case $enable_assembler in
312         x86)
313                 AC_DEFINE([HAVE_ASM_X86], [1],
314                         [Define to 1 if using x86 assembler optimizations.])
315                 ;;
316         x86_64)
317                 AC_DEFINE([HAVE_ASM_X86_64], [1],
318                         [Define to 1 if using x86_64 assembler optimizations.])
319                 ;;
320         no)
321                 ;;
322         *)
323                 AC_MSG_RESULT([])
324                 AC_MSG_ERROR([--enable-assembler accepts only \`yes', \`no', \`x86', or \`x86_64'.])
325                 ;;
326 esac
327 AC_MSG_RESULT([$enable_assembler])
328 AM_CONDITIONAL(COND_ASM_X86, test "x$enable_assembler" = xx86)
329 AM_CONDITIONAL(COND_ASM_X86_64, test "x$enable_assembler" = xx86_64)
330
331
332 ################################
333 # Fast unaligned memory access #
334 ################################
335
336 AC_MSG_CHECKING([if unaligned memory access should be used])
337 AC_ARG_ENABLE([unaligned-access], AC_HELP_STRING([--enable-unaligned-access],
338                 [Enable if the system supports *fast* unaligned memory access
339                 with 16-bit and 32-bit integers. By default, this is enabled
340                 only on x86, x86_64, and big endian PowerPC.]),
341         [], [enable_unaligned_access=auto])
342 if test "x$enable_unaligned_access" = xauto ; then
343         case $host_cpu in
344                 i?86|x86_64|powerpc|powerpc64)
345                         enable_unaligned_access=yes
346                         ;;
347                 *)
348                         enable_unaligned_access=no
349                         ;;
350         esac
351 fi
352 if test "x$enable_unaligned_access" = xyes ; then
353         AC_DEFINE([HAVE_FAST_UNALIGNED_ACCESS], [1], [Define to 1 if
354                 the system supports fast unaligned memory access.])
355         AC_MSG_RESULT([yes])
356 else
357         AC_MSG_RESULT([no])
358 fi
359
360
361 #####################
362 # Size optimization #
363 #####################
364
365 AC_MSG_CHECKING([if small size is preferred over speed])
366 AC_ARG_ENABLE([small], AC_HELP_STRING([--enable-small],
367                 [Make liblzma smaller and a little slower.
368                 This is disabled by default to optimize for speed.]),
369         [], [enable_small=no])
370 if test "x$enable_small" = xyes; then
371         AC_DEFINE([HAVE_SMALL], [1], [Define to 1 if optimizing for size.])
372 elif test "x$enable_small" != xno; then
373         AC_MSG_RESULT([])
374         AC_MSG_ERROR([--enable-small accepts only \`yes' or \`no'])
375 fi
376 AC_MSG_RESULT([$enable_small])
377 AM_CONDITIONAL(COND_SMALL, test "x$enable_small" = xyes)
378
379
380 #############
381 # Threading #
382 #############
383
384 AC_MSG_CHECKING([if threading support is wanted])
385 AC_ARG_ENABLE([threads], AC_HELP_STRING([--disable-threads],
386                 [Disable threading support.
387                 This makes some things thread-unsafe.]),
388         [], [enable_threads=yes])
389 if test "x$enable_threads" != xyes && test "x$enable_threads" != xno; then
390         AC_MSG_RESULT([])
391         AC_MSG_ERROR([--enable-threads accepts only \`yes' or \`no'])
392 fi
393 AC_MSG_RESULT([$enable_threads])
394 # We use the actual result a little later.
395
396
397 ############################################
398 # xz/xzdec/lzmadec linkage against liblzma #
399 ############################################
400
401 # Link the command line tool statically against liblzma unless using
402 # --enable-dynamic. Using static liblzma gives a little bit faster executable
403 # on x86, because no register is wasted for PIC. We also have one dependency
404 # less, which allows users to more freely copy the xz binary to other boxes.
405 # However, I wouldn't be surprised if distro maintainers still prefer dynamic
406 # linking, so let's make it easy for them.
407
408 AC_MSG_CHECKING([how command line tools should be linked against liblzma])
409 AC_ARG_ENABLE([dynamic], [AC_HELP_STRING([--enable-dynamic],
410                         [Link command line tools dynamically against liblzma.
411                         The default is to use static liblzma if it was
412                         built.])],
413                 [], [enable_dynamic=no])
414 case $enable_dynamic in
415         yes)
416                 STATIC_CPPFLAGS=
417                 STATIC_LDFLAGS=
418                 AC_MSG_RESULT([dynamically])
419                 ;;
420         no)
421                 STATIC_CPPFLAGS="-DLZMA_API_STATIC"
422                 STATIC_LDFLAGS="-static"
423                 AC_MSG_RESULT([statically])
424                 ;;
425         *)
426                 AC_MSG_RESULT([])
427                 AC_MSG_ERROR([--enable-dynamic accepts only \`yes' or \`no'])
428                 ;;
429 esac
430 AC_SUBST([STATIC_CPPFLAGS])
431 AC_SUBST([STATIC_LDFLAGS])
432
433
434 ###############################################################################
435 # Checks for programs.
436 ###############################################################################
437
438 echo
439 echo "Initializing Automake:"
440
441 AM_INIT_AUTOMAKE([1.10 foreign tar-v7 filename-length-max=99])
442 AC_PROG_LN_S
443
444 AC_PROG_CC_C99
445 if test x$ac_cv_prog_cc_c99 = xno ; then
446         AC_MSG_ERROR([No C99 compiler was found.])
447 fi
448
449 AM_PROG_CC_C_O
450 AM_PROG_AS
451 AC_USE_SYSTEM_EXTENSIONS
452
453 if test "x$enable_threads" = xyes; then
454         echo
455         echo "Threading support:"
456         ACX_PTHREAD
457         LIBS="$LIBS $PTHREAD_LIBS"
458         CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
459         CC="$PTHREAD_CC"
460 fi
461
462 echo
463 echo "Initializing Libtool:"
464 CXX=no
465 F77=no
466 AC_PROG_LIBTOOL
467
468
469 ###############################################################################
470 # Checks for libraries.
471 ###############################################################################
472
473 echo
474 echo "Initializing gettext:"
475 AM_GNU_GETTEXT_VERSION([0.16.1])
476 AM_GNU_GETTEXT([external])
477
478 ###############################################################################
479 # Checks for header files.
480 ###############################################################################
481
482 echo
483 echo "System headers and functions:"
484
485 # There is currently no workarounds in this package if some of
486 # these headers are missing.
487 AC_CHECK_HEADERS([fcntl.h limits.h sys/time.h],
488         [],
489         [AC_MSG_ERROR([Required header file(s) are missing.])])
490
491 # If any of these headers are missing, things should still work correctly:
492 AC_CHECK_HEADERS([sys/param.h sys/sysctl.h byteswap.h],
493         [], [], [
494 #ifdef HAVE_SYS_PARAM_H
495 #       include <sys/param.h>
496 #endif
497 ])
498
499 # Even if we have byteswap.h, we may lack the specific macros/functions.
500 if test x$ac_cv_header_byteswap_h = xyes ; then
501         m4_foreach([FUNC], [bswap_16,bswap_32,bswap_64], [
502                 AC_MSG_CHECKING([if FUNC is available])
503                 AC_LINK_IFELSE([AC_LANG_SOURCE([
504 #include <byteswap.h>
505 int
506 main(void)
507 {
508         FUNC[](42);
509         return 0;
510 }
511                 ])], [
512                         AC_DEFINE(HAVE_[]m4_toupper(FUNC), [1],
513                                         [Define to 1 if] FUNC [is available.])
514                         AC_MSG_RESULT([yes])
515                 ], [AC_MSG_RESULT([no])])
516
517         ])dnl
518 fi
519
520
521 ###############################################################################
522 # Checks for typedefs, structures, and compiler characteristics.
523 ###############################################################################
524
525 dnl We don't need these as long as we need a C99 compiler anyway.
526 dnl AC_C_INLINE
527 dnl AC_C_RESTRICT
528
529 AC_HEADER_STDBOOL
530
531 AC_TYPE_UINT8_T
532 AC_TYPE_UINT16_T
533 AC_TYPE_INT32_T
534 AC_TYPE_UINT32_T
535 AC_TYPE_INT64_T
536 AC_TYPE_UINT64_T
537 AC_TYPE_UINTPTR_T
538
539 AC_CHECK_SIZEOF([size_t])
540
541 # The command line tool can copy high resolution timestamps if such
542 # information is availabe in struct stat. Otherwise one second accuracy
543 # is used.
544 AC_CHECK_MEMBERS([
545         struct stat.st_atim.tv_nsec,
546         struct stat.st_atimespec.tv_nsec,
547         struct stat.st_atimensec,
548         struct stat.st_uatime,
549         struct stat.st_atim.st__tim.tv_nsec])
550
551 AC_SYS_LARGEFILE
552 AC_C_BIGENDIAN
553
554
555 ###############################################################################
556 # Checks for library functions.
557 ###############################################################################
558
559 # Gnulib replacements as needed
560 gl_GETOPT
561
562 # Find the best function to set timestamps.
563 AC_CHECK_FUNCS([futimens futimes futimesat utimes utime], [break])
564
565 # Check how to find out the amount of physical memory in the system. The
566 # xz command line tool uses this to automatically limit its memory usage.
567 # - sysconf() gives all the needed info on GNU+Linux and Solaris.
568 # - BSDs use sysctl().
569 AC_MSG_CHECKING([how to detect the amount of physical memory])
570 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
571 #include <unistd.h>
572 int
573 main()
574 {
575         long i;
576         i = sysconf(_SC_PAGESIZE);
577         i = sysconf(_SC_PHYS_PAGES);
578         return 0;
579 }
580 ]])], [
581         AC_DEFINE([HAVE_PHYSMEM_SYSCONF], [1],
582                 [Define to 1 if the amount of physical memory can be detected
583                 with sysconf(_SC_PAGESIZE) and sysconf(_SC_PHYS_PAGES).])
584         AC_MSG_RESULT([sysconf])
585 ], [
586 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
587 #include <sys/types.h>
588 #ifdef HAVE_SYS_PARAM_H
589 #       include <sys/param.h>
590 #endif
591 #include <sys/sysctl.h>
592 int
593 main()
594 {
595         int name[2] = { CTL_HW, HW_PHYSMEM };
596         unsigned long mem;
597         size_t mem_ptr_size = sizeof(mem);
598         sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL);
599         return 0;
600 }
601 ]])], [
602         AC_DEFINE([HAVE_PHYSMEM_SYSCTL], [1],
603                 [Define to 1 if the amount of physical memory can be detected
604                 with sysctl().])
605         AC_MSG_RESULT([sysctl])
606 ], [
607         AC_MSG_RESULT([unknown])
608 ])])
609
610 # Check how to find out the number of available CPU cores in the system.
611 # sysconf(_SC_NPROCESSORS_ONLN) works on most systems, except that BSDs
612 # use sysctl().
613 AC_MSG_CHECKING([how to detect the number of available CPU cores])
614 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
615 #include <unistd.h>
616 int
617 main()
618 {
619         long i;
620         i = sysconf(_SC_NPROCESSORS_ONLN);
621         return 0;
622 }
623 ]])], [
624         AC_DEFINE([HAVE_NCPU_SYSCONF], [1],
625                 [Define to 1 if the number of available CPU cores can be
626                 detected with sysconf(_SC_NPROCESSORS_ONLN).])
627         AC_MSG_RESULT([sysconf])
628 ], [
629 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
630 #include <sys/types.h>
631 #ifdef HAVE_SYS_PARAM_H
632 #       include <sys/param.h>
633 #endif
634 #include <sys/sysctl.h>
635 int
636 main()
637 {
638         int name[2] = { CTL_HW, HW_NCPU };
639         int cpus;
640         size_t cpus_size = sizeof(cpus);
641         sysctl(name, 2, &cpus, &cpus_size, NULL, NULL);
642         return 0;
643 }
644 ]])], [
645         AC_DEFINE([HAVE_NCPU_SYSCTL], [1],
646                 [Define to 1 if the number of available CPU cores can be
647                 detected with sysctl().])
648         AC_MSG_RESULT([sysctl])
649 ], [
650         AC_MSG_RESULT([unknown])
651 ])])
652
653
654 ###############################################################################
655 # If using GCC, set some additional CFLAGS:
656 ###############################################################################
657
658 Wno_uninitialized=no
659
660 if test "x$GCC" = xyes ; then
661         echo
662         echo "GCC extensions:"
663         gl_VISIBILITY
664         if test -n "$CFLAG_VISIBILITY" ; then
665                 CFLAGS="$CFLAG_VISIBILITY $CFLAGS"
666         fi
667
668         # -Wno-uninitialized is needed with -Werror with SHA256 code
669         # to omit a bogus warning.
670         AC_MSG_CHECKING([if $CC accepts -Wno-uninitialized])
671         OLD_CFLAGS="$CFLAGS"
672         CFLAGS="$CFLAGS -Wno-uninitialized"
673         AC_COMPILE_IFELSE([void foo(void) { }], [Wno_uninitialized=yes])
674         CFLAGS="$OLD_CFLAGS"
675         AC_MSG_RESULT([$Wno_uninitialized])
676
677         # Enable as much warnings as possible. These commented warnings won't
678         # work for this package though:
679         #   * -Wunreachable-code breaks several assert(0) cases, which are
680         #     backed up with "return LZMA_PROG_ERROR".
681         #   * -Wcast-qual would break various things where we need a non-const
682         #     pointer although we don't modify anything through it.
683         #   * -Wcast-align breaks optimized CRC32 and CRC64 implementation
684         #     on some architectures (not on x86), where this warning is bogus,
685         #     because we take care of correct alignment.
686         #   * -Winline, -Wdisabled-optimization, -Wunsafe-loop-optimizations
687         #     don't seem so useful here; at least the last one gives some
688         #     warnings which are not bugs.
689         #
690         # The flags are in reverse order below so they end up in "beautiful"
691         # order on the actual command line.
692         for NEW_FLAG in \
693                         -Wredundant-decls \
694                         -Wmissing-noreturn \
695                         -Wmissing-declarations \
696                         -Wmissing-prototypes \
697                         -Wold-style-definition \
698                         -Wstrict-prototypes \
699                         -Waggregate-return \
700                         -Wlogical-op \
701                         -Wwrite-strings \
702                         -Wbad-function-cast \
703                         -Wpointer-arith \
704                         -Wshadow \
705                         -Wundef \
706                         -Wfloat-equal \
707                         -Wstrict-aliasing \
708                         -Wmissing-include-dirs \
709                         -Winit-self \
710                         -Wformat=2 \
711                         -Wextra \
712                         -Wall
713         do
714                 AC_MSG_CHECKING([if $CC accepts $NEW_FLAG])
715                 OLD_CFLAGS="$CFLAGS"
716                 CFLAGS="$NEW_FLAG $CFLAGS"
717                 AC_COMPILE_IFELSE([void foo(void) { }], [
718                         AC_MSG_RESULT([yes])
719                 ], [
720                         CFLAGS="$OLD_CFLAGS"
721                         AC_MSG_RESULT([no])
722                 ])
723         done
724
725         AC_ARG_ENABLE([werror],
726                 AC_HELP_STRING([--enable-werror], [Enable -Werror to abort
727                         compilation on all compiler warnings.]),
728                 [], [enable_werror=no])
729         if test "x$enable_werror" = "xyes"; then
730                 CFLAGS="-Werror $CFLAGS"
731         fi
732 fi
733
734 AM_CONDITIONAL([COND_WNO_UNINITIALIZED], test "x$Wno_uninitialized" = "xyes")
735
736
737 ###############################################################################
738 # Create the makefiles and config.h
739 ###############################################################################
740
741 echo
742
743 # Don't build the lib directory at all if we don't need any replacement
744 # functions.
745 AM_CONDITIONAL([COND_GNULIB], test -n "$LIBOBJS")
746
747 AC_CONFIG_FILES([
748         Doxyfile
749         Makefile
750         po/Makefile.in
751         lib/Makefile
752         src/Makefile
753         src/liblzma/liblzma.pc
754         src/liblzma/Makefile
755         src/liblzma/api/Makefile
756         src/liblzma/common/Makefile
757         src/liblzma/check/Makefile
758         src/liblzma/rangecoder/Makefile
759         src/liblzma/lz/Makefile
760         src/liblzma/lzma/Makefile
761         src/liblzma/subblock/Makefile
762         src/liblzma/delta/Makefile
763         src/liblzma/simple/Makefile
764         src/xz/Makefile
765         src/xzdec/Makefile
766         src/scripts/Makefile
767         tests/Makefile
768         debug/Makefile
769 ])
770
771 AC_OUTPUT