tests: work even if non-GNU gzip is installed in /usr/local/bin
[debian/gzip] / configure.ac
1 # Configure template for gzip.
2
3 # Copyright (C) 1999-2002, 2006-2007, 2009-2013 Free Software Foundation, Inc.
4
5 # Copyright (C) 1992-1993 Jean-loup Gailly
6
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.
11
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.
16
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.
21
22 AC_PREREQ([2.60])
23 AC_INIT([gzip],
24         m4_esyscmd([build-aux/git-version-gen .tarball-version]),
25         [bug-gzip@gnu.org])
26
27 AC_CONFIG_SRCDIR(gzip.c)
28 AC_CONFIG_AUX_DIR(build-aux)
29 AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
30 AM_INIT_AUTOMAKE([1.11 dist-xz color-tests parallel-tests])
31 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
32
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
37 dnl   ./configure
38 dnl   make
39 dnl   make -C src clean
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])
46
47 AC_PROG_CC_STDC
48 AM_PROG_CC_C_O
49 AC_PROG_CPP
50 AC_PROG_GREP
51 AC_CHECK_TOOL([NM], [nm], [nm])
52 AC_PROG_LN_S
53 AC_PROG_RANLIB
54 AC_PROG_SHELL
55
56 gl_EARLY
57
58 gl_INIT
59
60 AC_ARG_ENABLE([gcc-warnings],
61   [AS_HELP_STRING([--enable-gcc-warnings],
62      [turn on many GCC warnings (for developers; best with GNU make)])],
63   [case $enableval in
64      yes|no) ;;
65      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
66    esac
67    gl_gcc_warnings=$enableval],
68   [if test -d "$srcdir"/.git; then
69      gl_gcc_warnings=yes
70    else
71      gl_gcc_warnings=no
72    fi]
73 )
74
75 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
76 # ------------------------------------------------
77 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
78 # Otherwise, run RUN-IF-NOT-FOUND.
79 AC_DEFUN([gl_GCC_VERSION_IFELSE],
80   [AC_PREPROC_IFELSE(
81     [AC_LANG_PROGRAM(
82       [[
83 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
84 /* ok */
85 #else
86 # error "your version of gcc is older than $1.$2"
87 #endif
88       ]]),
89     ], [$3], [$4])
90   ]
91 )
92
93 if test "$gl_gcc_warnings" = yes; then
94   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
95   AC_SUBST([WERROR_CFLAGS])
96
97   nw=
98   # This, $nw, is the list of warnings we disable.
99   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
100   nw="$nw -Waggregate-return"       # anachronistic
101   nw="$nw -Wlong-long"              # C90 is anachronistic (lib/gethrxtime.h)
102   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
103   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
104   nw="$nw -Wtraditional"            # Warns on #elif which we use often
105   nw="$nw -Wcast-qual"              # Too many warnings for now
106   nw="$nw -Wconversion"             # Too many warnings for now
107   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
108   nw="$nw -Wsign-conversion"        # Too many warnings for now
109   nw="$nw -Wtraditional-conversion" # Too many warnings for now
110   nw="$nw -Wunreachable-code"       # Too many warnings for now
111   nw="$nw -Wpadded"                 # Our structs are not padded
112   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
113   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
114   nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
115   nw="$nw -Wvla"                    # warnings in gettext.h
116   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
117   nw="$nw -Wswitch-enum"            # Too many warnings for now
118   nw="$nw -Wswitch-default"         # Too many warnings for now
119   nw="$nw -Wstack-protector"        # not worth working around
120   # things I might fix soon:
121   nw="$nw -Wfloat-equal"            # sort.c, seq.c
122   nw="$nw -Wmissing-format-attribute" # copy.c
123   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
124   nw="$nw -Winline"                 # system.h's readdir_ignoring_dot_and_dotdot
125
126   # Warnings that gzip runs afoul of but coreutils does not.
127   nw="$nw -Wold-style-definition"
128   nw="$nw -Wshadow"
129   nw="$nw -Wstrict-overflow"
130
131   # Using -Wstrict-overflow is a pain, but the alternative is worse.
132   # For an example, see the code that provoked this report:
133   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
134   # Code like that still infloops with gcc-4.6.0 and -O2.  Scary indeed.
135
136   gl_MANYWARN_ALL_GCC([ws])
137   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
138   for w in $ws; do
139     gl_WARN_ADD([$w])
140   done
141   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
142   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
143   gl_WARN_ADD([-Wsuggest-attribute=const])
144   gl_WARN_ADD([-Wsuggest-attribute=noreturn])
145   gl_WARN_ADD([-Wno-format-nonliteral])
146
147   # Enable this warning only with gcc-4.7 and newer.  With 4.6.2 20111027,
148   # it suggests test.c's advance function may be pure, even though it
149   # increments a global variable.  Oops.
150   # Normally we'd write code to test for the precise failure, but that
151   # requires a relatively large input to make gcc exhibit the failure.
152   gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
153
154   # In spite of excluding -Wlogical-op above, it is enabled, as of
155   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
156   gl_WARN_ADD([-Wno-logical-op])
157
158   gl_WARN_ADD([-fdiagnostics-show-option])
159   gl_WARN_ADD([-funit-at-a-time])
160
161   AC_SUBST([WARN_CFLAGS])
162
163   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
164   AH_VERBATIM([FORTIFY_SOURCE],
165   [/* Enable compile-time and run-time bounds-checking, and some warnings,
166       without upsetting glibc 2.15+. */
167    #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
168    # define _FORTIFY_SOURCE 2
169    #endif
170   ])
171   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
172
173   # We use a slightly smaller set of warning options for lib/.
174   # Remove the following and save the result in GNULIB_WARN_CFLAGS.
175   nw=
176   nw="$nw -Wstrict-overflow"
177   nw="$nw -Wuninitialized"
178   nw="$nw -Wunused-macros"
179   nw="$nw -Wmissing-prototypes"
180   nw="$nw -Wold-style-definition"
181   gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
182   AC_SUBST([GNULIB_WARN_CFLAGS])
183 fi
184
185 # cc -E produces incorrect asm files on SVR4, so postprocess it.
186 ASCPPPOST="sed '/^ *\\#/d; s,//.*,,; s/% /%/g; s/\\. /./g'"
187 AC_SUBST([ASCPPPOST])
188
189 AC_CACHE_CHECK([for underline in external names], [gzip_cv_underline],
190   [gzip_cv_underline=yes
191    AC_TRY_COMPILE([int foo() {return 0;}], [],
192      [$NM conftest.$OBJEXT | grep _foo >/dev/null 2>&1 ||
193         gzip_cv_underline=no])])
194 ASCPPFLAGS=
195 if test $gzip_cv_underline = no; then
196   ASCPPFLAGS='-DNO_UNDERLINE'
197 fi
198 AC_SUBST([ASCPPFLAGS])
199 AC_OBJEXT
200
201 # Try to assemble match.S.
202 # "gcc -E match.s" ignores -E, so we must use _match.S.
203 AC_CACHE_CHECK([for an assembler syntax supported by this package],
204   [gzip_cv_assembler],
205   [gzip_cv_assembler=no
206    case " $DEFS " in
207    *' NO_ASM '*) ;;
208    *)
209      if cp $srcdir/lib/match.c _match.S &&
210         eval "$CPP $CPPFLAGS $ASCPPFLAGS _match.S > _match.i" &&
211         eval "$ASCPPPOST < _match.i > match_.s"; then
212        if test ! -s match_.s || grep error < match_.s > /dev/null; then
213          :
214        elif eval "$CC $CPPFLAGS $CFLAGS -c match_.s >/dev/null" &&
215             test -f match_.$OBJEXT; then
216          rm -f match_.$OBJEXT
217          gzip_cv_assembler=yes
218          if echo 'void foo (void) {}' > conftest.c &&
219             eval "$CC $CPPFLAGS $CFLAGS -S conftest.c >/dev/null" &&
220             grep '\.note\.GNU-stack' conftest.s >/dev/null &&
221             eval "$CC $CPPFLAGS $CFLAGS -c -Wa,--noexecstack match_.s >/dev/null" &&
222             test -f match_.$OBJEXT; then
223            gzip_cv_assembler='yes, with -Wa,--noexecstack'
224          fi
225        fi
226      fi
227      rm -f conftest* _match.i _match.S match_.s match_.$OBJEXT;;
228    esac])
229 if test "$gzip_cv_assembler" != no; then
230   AC_DEFINE(ASMV, ,
231     [Define if an assembler version of longest_match is available.])
232   AC_LIBOBJ(match)
233 fi
234 if test "$gzip_cv_assembler" = 'yes, with -Wa,--noexecstack'; then
235   ASFLAGS_config='-Wa,--noexecstack'
236 else
237   ASFLAGS_config=
238 fi
239 AC_SUBST([ASFLAGS_config])
240
241 AC_ISC_POSIX
242 AC_C_CONST
243 AC_HEADER_STDC
244 AC_CHECK_HEADERS_ONCE(fcntl.h limits.h memory.h time.h)
245 AC_CHECK_FUNCS_ONCE([chown fchmod fchown lstat siginterrupt])
246 AC_HEADER_DIRENT
247 AC_TYPE_SIGNAL
248 AC_TYPE_SIZE_T
249 AC_TYPE_OFF_T
250
251 AC_CONFIG_FILES([Makefile doc/Makefile lib/Makefile tests/Makefile])
252 AC_OUTPUT