1 # Configure template for gzip.
3 # Copyright (C) 1999-2002, 2006-2007, 2009-2024 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)
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, see <https://www.gnu.org/licenses/>.
22 m4_esyscmd([build-aux/git-version-gen .tarball-version]),
25 AC_CONFIG_SRCDIR([gzip.c])
26 AC_CONFIG_AUX_DIR([build-aux])
27 AC_CONFIG_MACRO_DIR([m4])
28 AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
29 AM_INIT_AUTOMAKE([1.11 subdir-objects dist-xz dist-zip
30 color-tests parallel-tests])
31 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
33 dnl POSIXCHECK is worthwhile for maintainers, but adds several seconds
34 dnl (more than 10% execution time) to ./configure, with no benefit for
35 dnl most users. Using it to look for bugs requires:
36 dnl GNULIB_POSIXCHECK=1 autoreconf -f
40 dnl make CFLAGS=-DGNULIB_POSIXCHECK=1
41 dnl FIXME: Once we figure out how to avoid false positives, we should
42 dnl have 'make my-distcheck' in dist-check.mk exercise this.
43 m4_syscmd([test "${GNULIB_POSIXCHECK+set}" = set])
44 m4_if(m4_sysval, [0], [], [dnl
45 gl_ASSERT_NO_GNULIB_POSIXCHECK])
51 AC_CHECK_PROG([LESS], [less], [less])
52 AM_CONDITIONAL([LESS], [test "$LESS"])
53 AC_CHECK_TOOL([NM], [nm], [nm])
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 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
67 # ------------------------------------------------
68 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
69 # Otherwise, run RUN-IF-NOT-FOUND.
70 AC_DEFUN([gl_GCC_VERSION_IFELSE],
74 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
77 # error "your version of gcc is older than $1.$2"
84 AC_ARG_ENABLE([gcc-warnings],
85 [AS_HELP_STRING([--enable-gcc-warnings@<:@=TYPE@:>@],
86 [control generation of GCC warnings. The TYPE 'no' disables
87 warnings (default for non-developer builds); 'yes' generates
88 cheap warnings if available (default for developer builds);
89 'expensive' in addition generates expensive-to-compute warnings
93 *) AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
95 gl_gcc_warnings=$enableval],
97 # GCC provides fine-grained control over diagnostics which
98 # is used in gnulib for example to suppress warnings from
99 # certain sections of code. So if this is available and
100 # we're running from a git repo, then auto enable the warnings.
102 gl_GCC_VERSION_IFELSE([4], [6],
103 [test -d "$srcdir"/.git \
104 && ! test -f "$srcdir"/.tarball-version \
105 && gl_gcc_warnings=yes])]
108 AC_ARG_ENABLE([dfltcc],
109 [AS_HELP_STRING([--enable-dfltcc],
110 [use DEFLATE COMPRESSION CALL instruction on IBM Z])],
112 yes|no) gl_dfltcc=$enableval ;;
113 *) AC_MSG_ERROR([bad value $enableval for dfltcc option]) ;;
118 if test "$gl_gcc_warnings" = yes; then
119 gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
120 AC_SUBST([WERROR_CFLAGS])
123 AS_IF([test $gl_gcc_warnings != expensive],
124 [# -fanalyzer and related options slow GCC considerably.
125 ew="$ew -fanalyzer -Wno-analyzer-double-free -Wno-analyzer-malloc-leak"
126 ew="$ew -Wno-analyzer-null-dereference -Wno-analyzer-use-after-free"])
128 # This, $nw, is the list of warnings we disable.
130 nw="$nw -Wdeclaration-after-statement" # too useful to forbid
131 nw="$nw -Waggregate-return" # anachronistic
132 nw="$nw -Wlong-long" # C90 is anachronistic (lib/gethrxtime.h)
133 nw="$nw -Wc++-compat" # We don't care about C++ compilers
134 nw="$nw -Wundef" # Warns on '#if GNULIB_FOO' etc in gnulib
135 nw="$nw -Wtraditional" # Warns on #elif which we use often
136 nw="$nw -Wcast-qual" # Too many warnings for now
137 nw="$nw -Wconversion" # Too many warnings for now
138 nw="$nw -Wduplicated-branches" # Too many false alarms
139 nw="$nw -Wsystem-headers" # Don't let system headers trigger warnings
140 nw="$nw -Wsign-conversion" # Too many warnings for now
141 nw="$nw -Wtraditional-conversion" # Too many warnings for now
142 nw="$nw -Wpadded" # Our structs are not padded
143 nw="$nw -Wredundant-decls" # openat.h declares e.g., mkdirat
144 nw="$nw -Wlogical-op" # any use of fwrite provokes this
145 nw="$nw -Wformat-nonliteral" # who.c and pinky.c strftime uses
146 nw="$nw -Wnested-externs" # use of XARGMATCH/verify_function__
147 nw="$nw -Wswitch-enum" # Too many warnings for now
148 nw="$nw -Wswitch-default" # Too many warnings for now
149 nw="$nw -Wstack-protector" # not worth working around
150 # things I might fix soon:
151 nw="$nw -Wfloat-equal" # sort.c, seq.c
152 nw="$nw -Wmissing-format-attribute" # copy.c
153 nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
154 nw="$nw -Winline" # system.h's readdir_ignoring_dot_and_dotdot
156 # Warnings that gzip runs afoul of but coreutils does not.
157 nw="$nw -Wold-style-definition"
159 nw="$nw -Wstrict-overflow"
161 # Using -Wstrict-overflow is a pain, but the alternative is worse.
162 # For an example, see the code that provoked this report:
163 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
164 # Code like that still infloops with gcc-4.6.0 and -O2. Scary indeed.
166 gl_MANYWARN_ALL_GCC([ws])
167 gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
171 gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now
172 gl_WARN_ADD([-Wno-type-limits]) # false alarms if 32-bit long, 64-bit time_t
173 gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
174 gl_WARN_ADD([-Wsuggest-attribute=const])
175 gl_WARN_ADD([-Wsuggest-attribute=noreturn])
176 gl_WARN_ADD([-Wno-format-nonliteral])
178 # Enable this warning only with gcc-4.7 and newer. With 4.6.2 20111027,
179 # it suggests test.c's advance function may be pure, even though it
180 # increments a global variable. Oops.
181 # Normally we'd write code to test for the precise failure, but that
182 # requires a relatively large input to make gcc exhibit the failure.
183 gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
185 # In spite of excluding -Wlogical-op above, it is enabled, as of
186 # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
187 gl_WARN_ADD([-Wno-logical-op])
189 gl_WARN_ADD([-fdiagnostics-show-option])
190 gl_WARN_ADD([-funit-at-a-time])
192 AC_SUBST([WARN_CFLAGS])
194 AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
195 AH_VERBATIM([FORTIFY_SOURCE],
196 [/* Enable compile-time and run-time bounds-checking, and some warnings,
197 without upsetting glibc 2.15+. */
198 #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
199 # define _FORTIFY_SOURCE 2
202 AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
204 # We use a slightly smaller set of warning options for lib/.
205 # Remove the following and save the result in GNULIB_WARN_CFLAGS.
207 nw="$nw -Wstrict-overflow"
208 nw="$nw -Wformat-truncation=2"
209 nw="$nw -Wuninitialized"
210 nw="$nw -Wunused-macros"
211 nw="$nw -Wmissing-prototypes"
212 nw="$nw -Wold-style-definition"
213 gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
214 AC_SUBST([GNULIB_WARN_CFLAGS])
217 if test "$gl_dfltcc" = yes; then
218 AC_DEFINE([IBM_Z_DFLTCC], ,
219 [Use DEFLATE COMPRESSION CALL instruction on IBM Z machines.])
221 AM_CONDITIONAL([IBM_Z_DFLTCC], [test "$gl_dfltcc" = yes])
223 # cc -E produces incorrect asm files on SVR4, so postprocess it.
224 ASCPPPOST="sed '/^ *\\#/d; s,//.*,,; s/% /%/g; s/\\. /./g'"
225 AC_SUBST([ASCPPPOST])
227 AC_CACHE_CHECK([for underline in external names], [gzip_cv_underline],
228 [gzip_cv_underline=yes
230 [AC_LANG_PROGRAM([[int foo() {return 0;}]], [[]])],
231 [$NM conftest.$OBJEXT | grep _foo >/dev/null 2>&1 ||
232 gzip_cv_underline=no])])
234 if test $gzip_cv_underline = no; then
235 ASCPPFLAGS='-DNO_UNDERLINE'
237 AC_SUBST([ASCPPFLAGS])
240 # Try to assemble match.S.
241 # "gcc -E match.s" ignores -E, so we must use _match.S.
242 AC_CACHE_CHECK([for an assembler syntax supported by this package],
244 [gzip_cv_assembler=no
248 if cp $srcdir/lib/match.c _match.S &&
249 eval "$CPP $CPPFLAGS $ASCPPFLAGS _match.S > _match.i" &&
250 eval "$ASCPPPOST < _match.i > match_.s"; then
251 if test ! -s match_.s || grep error < match_.s > /dev/null; then
253 elif eval "$CC $CPPFLAGS $CFLAGS -c match_.s >/dev/null" &&
254 test -f match_.$OBJEXT; then
256 gzip_cv_assembler=yes
257 if echo 'void foo (void) {}' > conftest.c &&
258 eval "$CC $CPPFLAGS $CFLAGS -S conftest.c >/dev/null" &&
259 grep '\.note\.GNU-stack' conftest.s >/dev/null &&
260 eval "$CC $CPPFLAGS $CFLAGS -c -Wa,--noexecstack match_.s >/dev/null" &&
261 test -f match_.$OBJEXT; then
262 gzip_cv_assembler='yes, with -Wa,--noexecstack'
266 rm -f conftest* _match.i _match.S match_.s match_.$OBJEXT;;
268 if test "$gzip_cv_assembler" != no; then
270 [Define if an assembler version of longest_match is available.])
273 if test "$gzip_cv_assembler" = 'yes, with -Wa,--noexecstack'; then
274 ASFLAGS_config='-Wa,--noexecstack'
278 AC_SUBST([ASFLAGS_config])
280 GZIP_TRANSFORMED=` echo gzip | sed "$program_transform_name"`
281 ZDIFF_TRANSFORMED=`echo zdiff | sed "$program_transform_name"`
282 ZGREP_TRANSFORMED=`echo zgrep | sed "$program_transform_name"`
283 AC_SUBST([GZIP_TRANSFORMED])
284 AC_SUBST([ZDIFF_TRANSFORMED])
285 AC_SUBST([ZGREP_TRANSFORMED])
286 AM_CONDITIONAL([GZIP_IS_TRANSFORMED], [test "$GZIP_TRANSFORMED" != gzip])
287 AM_CONDITIONAL([ZDIFF_IS_TRANSFORMED], [test "$ZDIFF_TRANSFORMED" != zdiff])
288 AM_CONDITIONAL([ZGREP_IS_TRANSFORMED], [test "$ZGREP_TRANSFORMED" != zgrep])
291 AC_CHECK_HEADERS_ONCE(fcntl.h limits.h memory.h time.h sys/sdt.h)
292 AC_CHECK_FUNCS_ONCE([chown fchmod fchown lstat siginterrupt])
297 AC_CONFIG_FILES([Makefile doc/Makefile lib/Makefile tests/Makefile])