gzip: gzip -l now outputs accurate size
[gzip.git] / configure.ac
blob25de62c14292feadf931070496b7daf8b350caca
1 # Configure template for gzip.
3 # Copyright (C) 1999-2002, 2006-2007, 2009-2021 Free Software Foundation, Inc.
5 # Copyright (C) 1992-1993 Jean-loup Gailly
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # 02111-1307, USA.
22 AC_PREREQ([2.64])
23 AC_INIT([gzip],
24         m4_esyscmd([build-aux/git-version-gen .tarball-version]),
25         [bug-gzip@gnu.org])
27 AC_CONFIG_SRCDIR([gzip.c])
28 AC_CONFIG_AUX_DIR([build-aux])
29 AC_CONFIG_MACRO_DIR([m4])
30 AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
31 AM_INIT_AUTOMAKE([1.11 subdir-objects dist-xz dist-zip
32                   color-tests parallel-tests])
33 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
35 dnl POSIXCHECK is worthwhile for maintainers, but adds several seconds
36 dnl (more than 10% execution time) to ./configure, with no benefit for
37 dnl most users.  Using it to look for bugs requires:
38 dnl   GNULIB_POSIXCHECK=1 autoreconf -f
39 dnl   ./configure
40 dnl   make
41 dnl   make -C src clean
42 dnl   make CFLAGS=-DGNULIB_POSIXCHECK=1
43 dnl FIXME: Once we figure out how to avoid false positives, we should
44 dnl have 'make my-distcheck' in dist-check.mk exercise this.
45 m4_syscmd([test "${GNULIB_POSIXCHECK+set}" = set])
46 m4_if(m4_sysval, [0], [], [dnl
47 gl_ASSERT_NO_GNULIB_POSIXCHECK])
49 AC_PROG_CC
50 AM_PROG_CC_C_O
51 AC_PROG_CPP
52 AC_PROG_GREP
53 AC_CHECK_TOOL([NM], [nm], [nm])
54 AC_PROG_LN_S
55 AC_PROG_RANLIB
56 AC_PROG_SHELL
58 gl_EARLY
60 gl_INIT
62 # Ensure VLAs are not used.
63 # Note -Wvla is implicitly added by gl_MANYWARN_ALL_GCC
64 AC_DEFINE([GNULIB_NO_VLA], [1], [Define to 1 to disable use of VLAs])
66 AC_ARG_ENABLE([gcc-warnings],
67   [AS_HELP_STRING([--enable-gcc-warnings],
68      [turn on many GCC warnings (for developers; best with GNU make)])],
69   [case $enableval in
70      yes|no) ;;
71      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
72    esac
73    gl_gcc_warnings=$enableval],
74   [if test -d "$srcdir"/.git; then
75      gl_gcc_warnings=yes
76    else
77      gl_gcc_warnings=no
78    fi]
81 AC_ARG_ENABLE([dfltcc],
82   [AS_HELP_STRING([--enable-dfltcc],
83      [use DEFLATE COMPRESSION CALL instruction on IBM Z])],
84   [case $enableval in
85      yes|no) gl_dfltcc=$enableval ;;
86      *)      AC_MSG_ERROR([bad value $enableval for dfltcc option]) ;;
87    esac],
88   [gl_dfltcc=no]
91 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
92 # ------------------------------------------------
93 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
94 # Otherwise, run RUN-IF-NOT-FOUND.
95 AC_DEFUN([gl_GCC_VERSION_IFELSE],
96   [AC_PREPROC_IFELSE(
97     [AC_LANG_PROGRAM(
98       [[
99 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
100 /* ok */
101 #else
102 # error "your version of gcc is older than $1.$2"
103 #endif
104       ]]),
105     ], [$3], [$4])
106   ]
109 if test "$gl_gcc_warnings" = yes; then
110   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
111   AC_SUBST([WERROR_CFLAGS])
113   nw=
114   # This, $nw, is the list of warnings we disable.
115   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
116   nw="$nw -Waggregate-return"       # anachronistic
117   nw="$nw -Wlong-long"              # C90 is anachronistic (lib/gethrxtime.h)
118   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
119   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
120   nw="$nw -Wtraditional"            # Warns on #elif which we use often
121   nw="$nw -Wcast-qual"              # Too many warnings for now
122   nw="$nw -Wconversion"             # Too many warnings for now
123   nw="$nw -Wduplicated-branches"    # Too many false alarms
124   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
125   nw="$nw -Wsign-conversion"        # Too many warnings for now
126   nw="$nw -Wtraditional-conversion" # Too many warnings for now
127   nw="$nw -Wpadded"                 # Our structs are not padded
128   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
129   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
130   nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
131   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
132   nw="$nw -Wswitch-enum"            # Too many warnings for now
133   nw="$nw -Wswitch-default"         # Too many warnings for now
134   nw="$nw -Wstack-protector"        # not worth working around
135   # things I might fix soon:
136   nw="$nw -Wfloat-equal"            # sort.c, seq.c
137   nw="$nw -Wmissing-format-attribute" # copy.c
138   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
139   nw="$nw -Winline"                 # system.h's readdir_ignoring_dot_and_dotdot
141   # Warnings that gzip runs afoul of but coreutils does not.
142   nw="$nw -Wold-style-definition"
143   nw="$nw -Wshadow"
144   nw="$nw -Wstrict-overflow"
146   # Using -Wstrict-overflow is a pain, but the alternative is worse.
147   # For an example, see the code that provoked this report:
148   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
149   # Code like that still infloops with gcc-4.6.0 and -O2.  Scary indeed.
151   gl_MANYWARN_ALL_GCC([ws])
152   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
153   for w in $ws; do
154     gl_WARN_ADD([$w])
155   done
156   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
157   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
158   gl_WARN_ADD([-Wsuggest-attribute=const])
159   gl_WARN_ADD([-Wsuggest-attribute=noreturn])
160   gl_WARN_ADD([-Wno-format-nonliteral])
162   # Enable this warning only with gcc-4.7 and newer.  With 4.6.2 20111027,
163   # it suggests test.c's advance function may be pure, even though it
164   # increments a global variable.  Oops.
165   # Normally we'd write code to test for the precise failure, but that
166   # requires a relatively large input to make gcc exhibit the failure.
167   gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
169   # In spite of excluding -Wlogical-op above, it is enabled, as of
170   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
171   gl_WARN_ADD([-Wno-logical-op])
173   gl_WARN_ADD([-fdiagnostics-show-option])
174   gl_WARN_ADD([-funit-at-a-time])
176   AC_SUBST([WARN_CFLAGS])
178   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
179   AH_VERBATIM([FORTIFY_SOURCE],
180   [/* Enable compile-time and run-time bounds-checking, and some warnings,
181       without upsetting glibc 2.15+. */
182    #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
183    # define _FORTIFY_SOURCE 2
184    #endif
185   ])
186   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
188   # We use a slightly smaller set of warning options for lib/.
189   # Remove the following and save the result in GNULIB_WARN_CFLAGS.
190   nw=
191   nw="$nw -Wstrict-overflow"
192   nw="$nw -Wformat-truncation=2"
193   nw="$nw -Wuninitialized"
194   nw="$nw -Wunused-macros"
195   nw="$nw -Wmissing-prototypes"
196   nw="$nw -Wold-style-definition"
197   gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
198   AC_SUBST([GNULIB_WARN_CFLAGS])
201 if test "$gl_dfltcc" = yes; then
202   AC_DEFINE([IBM_Z_DFLTCC], ,
203     [Use DEFLATE COMPRESSION CALL instruction on IBM Z machines.])
205 AM_CONDITIONAL([IBM_Z_DFLTCC],  [test "$gl_dfltcc" = yes])
207 # cc -E produces incorrect asm files on SVR4, so postprocess it.
208 ASCPPPOST="sed '/^ *\\#/d; s,//.*,,; s/% /%/g; s/\\. /./g'"
209 AC_SUBST([ASCPPPOST])
211 AC_CACHE_CHECK([for underline in external names], [gzip_cv_underline],
212   [gzip_cv_underline=yes
213    AC_COMPILE_IFELSE(
214      [AC_LANG_PROGRAM([[int foo() {return 0;}]], [[]])],
215        [$NM conftest.$OBJEXT | grep _foo >/dev/null 2>&1 ||
216         gzip_cv_underline=no])])
217 ASCPPFLAGS=
218 if test $gzip_cv_underline = no; then
219   ASCPPFLAGS='-DNO_UNDERLINE'
221 AC_SUBST([ASCPPFLAGS])
222 AC_OBJEXT
224 # Try to assemble match.S.
225 # "gcc -E match.s" ignores -E, so we must use _match.S.
226 AC_CACHE_CHECK([for an assembler syntax supported by this package],
227   [gzip_cv_assembler],
228   [gzip_cv_assembler=no
229    case $DEFS in
230    *NO_ASM*) ;;
231    *)
232      if cp $srcdir/lib/match.c _match.S &&
233         eval "$CPP $CPPFLAGS $ASCPPFLAGS _match.S > _match.i" &&
234         eval "$ASCPPPOST < _match.i > match_.s"; then
235        if test ! -s match_.s || grep error < match_.s > /dev/null; then
236          :
237        elif eval "$CC $CPPFLAGS $CFLAGS -c match_.s >/dev/null" &&
238             test -f match_.$OBJEXT; then
239          rm -f match_.$OBJEXT
240          gzip_cv_assembler=yes
241          if echo 'void foo (void) {}' > conftest.c &&
242             eval "$CC $CPPFLAGS $CFLAGS -S conftest.c >/dev/null" &&
243             grep '\.note\.GNU-stack' conftest.s >/dev/null &&
244             eval "$CC $CPPFLAGS $CFLAGS -c -Wa,--noexecstack match_.s >/dev/null" &&
245             test -f match_.$OBJEXT; then
246            gzip_cv_assembler='yes, with -Wa,--noexecstack'
247          fi
248        fi
249      fi
250      rm -f conftest* _match.i _match.S match_.s match_.$OBJEXT;;
251    esac])
252 if test "$gzip_cv_assembler" != no; then
253   AC_DEFINE([ASMV], ,
254     [Define if an assembler version of longest_match is available.])
255   AC_LIBOBJ(match)
257 if test "$gzip_cv_assembler" = 'yes, with -Wa,--noexecstack'; then
258   ASFLAGS_config='-Wa,--noexecstack'
259 else
260   ASFLAGS_config=
262 AC_SUBST([ASFLAGS_config])
264 AC_C_CONST
265 AC_CHECK_HEADERS_ONCE(fcntl.h limits.h memory.h time.h sys/sdt.h)
266 AC_CHECK_FUNCS_ONCE([chown fchmod fchown lstat siginterrupt])
267 AC_HEADER_DIRENT
268 AC_TYPE_SIZE_T
269 AC_TYPE_OFF_T
271 AC_CONFIG_FILES([Makefile doc/Makefile lib/Makefile tests/Makefile])
272 AC_OUTPUT