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