maint: Document how to best to enable gcc warnings for developers
[platform/upstream/coreutils.git] / configure.ac
1 # -*- autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 # Copyright (C) 1991, 1993-2009 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 dnl Written by Jim Meyering.
20
21 AC_PREREQ([2.61])
22
23 # Make inter-release version strings look like, e.g., v6.9-219-g58ddd, which
24 # indicates that it is built from the 219th delta (in _some_ repository)
25 # following the v6.9 tag, and that 58ddd is a prefix of the commit SHA1.
26 AC_INIT([GNU coreutils],
27         m4_esyscmd([build-aux/git-version-gen .tarball-version]),
28         [bug-coreutils@gnu.org])
29
30 AC_CONFIG_SRCDIR([src/ls.c])
31
32 AC_CONFIG_AUX_DIR([build-aux])
33 AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
34
35 AM_INIT_AUTOMAKE([1.10a dist-xz])
36
37 AC_PROG_CC_STDC
38 AM_PROG_CC_C_O
39 AC_PROG_CPP
40 AC_PROG_GCC_TRADITIONAL
41 AC_PROG_RANLIB
42 AC_PROG_LN_S
43 gl_EARLY
44 gl_INIT
45 coreutils_MACROS
46
47 AC_ARG_ENABLE([gcc-warnings],
48   [AS_HELP_STRING([--enable-gcc-warnings],
49                   [turn on lots of GCC warnings (for developers)])],
50   [case $enableval in
51      yes|no) ;;
52      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
53    esac
54    gl_gcc_warnings=$enableval],
55   [gl_gcc_warnings=no]
56 )
57
58 if test "$gl_gcc_warnings" = yes; then
59   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
60   AC_SUBST([WERROR_CFLAGS])
61
62   # Add many warnings, except some...
63   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
64   nw="$nw -Waggregate-return"       # anachronistic
65   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
66   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
67   nw="$nw -Wtraditional"            # Warns on #elif which we use often
68   nw="$nw -Wcast-qual"              # Too many warnings for now
69   nw="$nw -Wconversion"             # Too many warnings for now
70   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
71   nw="$nw -Wsign-conversion"        # Too many warnings for now
72   nw="$nw -Wtraditional-conversion" # Too many warnings for now
73   nw="$nw -Wunreachable-code"       # Too many warnings for now
74   nw="$nw -Wpadded"                 # Our structs are not padded
75   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
76   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
77   nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
78   nw="$nw -Wvla"                    # warnings in gettext.h
79   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
80   nw="$nw -Wswitch-enum"            # Too many warnings for now
81   nw="$nw -Wswitch-default"         # Too many warnings for now
82   # things I might fix soon:
83   nw="$nw -Wfloat-equal"            # sort.c, seq.c
84   nw="$nw -Wmissing-format-attribute" # copy.c
85   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
86   nw="$nw -Winline"                 # system.h's readdir_ignoring_dot_and_dotdot
87   nw="$nw -Wstrict-overflow"        # expr.c, pr.c, tr.c, factor.c
88   # ?? -Wstrict-overflow
89
90   gl_MANYWARN_ALL_GCC([ws])
91   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
92   for w in $ws; do
93     gl_WARN_ADD([$w])
94   done
95   gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one
96   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
97   gl_WARN_ADD([-Wno-pointer-sign])     # Too many warnings for now
98   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
99   gl_WARN_ADD([-fdiagnostics-show-option])
100
101   AC_SUBST([WARN_CFLAGS])
102
103   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
104   AC_DEFINE([_FORTIFY_SOURCE], [2],
105     [enable compile-time and run-time bounds-checking, and some warnings])
106   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
107 fi
108
109 AC_FUNC_FORK
110
111 optional_bin_progs=
112 AC_CHECK_FUNCS([uname],
113         gl_ADD_PROG([optional_bin_progs], [uname]))
114 AC_CHECK_FUNCS([chroot],
115         gl_ADD_PROG([optional_bin_progs], [chroot]))
116 AC_CHECK_FUNCS([gethostid],
117         gl_ADD_PROG([optional_bin_progs], [hostid]))
118
119 gl_WINSIZE_IN_PTEM
120
121 AC_MSG_CHECKING([whether localtime caches TZ])
122 AC_CACHE_VAL([utils_cv_localtime_cache],
123 [if test x$ac_cv_func_tzset = xyes; then
124 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <time.h>
125 #if STDC_HEADERS
126 # include <stdlib.h>
127 #endif
128 extern char **environ;
129 void unset_TZ (void)
130 {
131   char **from, **to;
132   for (to = from = environ; (*to = *from); from++)
133     if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '='))
134       to++;
135 }
136 int main()
137 {
138   time_t now = time ((time_t *) 0);
139   int hour_GMT0, hour_unset;
140   if (putenv ("TZ=GMT0") != 0)
141     exit (1);
142   hour_GMT0 = localtime (&now)->tm_hour;
143   unset_TZ ();
144   hour_unset = localtime (&now)->tm_hour;
145   if (putenv ("TZ=PST8") != 0)
146     exit (1);
147   if (localtime (&now)->tm_hour == hour_GMT0)
148     exit (1);
149   unset_TZ ();
150   if (localtime (&now)->tm_hour != hour_unset)
151     exit (1);
152   exit (0);
153 }]])],
154 [utils_cv_localtime_cache=no],
155 [utils_cv_localtime_cache=yes],
156 [# If we have tzset, assume the worst when cross-compiling.
157 utils_cv_localtime_cache=yes])
158 else
159         # If we lack tzset, report that localtime does not cache TZ,
160         # since we can't invalidate the cache if we don't have tzset.
161         utils_cv_localtime_cache=no
162 fi])dnl
163 AC_MSG_RESULT([$utils_cv_localtime_cache])
164 if test $utils_cv_localtime_cache = yes; then
165   AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
166 fi
167
168 # SCO-ODT-3.0 is reported to need -los to link programs using initgroups
169 AC_CHECK_FUNCS([initgroups])
170 if test $ac_cv_func_initgroups = no; then
171   AC_CHECK_LIB([os], [initgroups])
172 fi
173
174 AC_CHECK_FUNCS([syslog])
175 if test $ac_cv_func_syslog = no; then
176   # syslog is not in the default libraries.  See if it's in some other.
177   for lib in bsd socket inet; do
178     AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG], [1], [FIXME])
179       LIBS="$LIBS -l$lib"; break])
180   done
181 fi
182
183 AC_CACHE_CHECK([for 3-argument setpriority function],
184   [utils_cv_func_setpriority],
185   [AC_LINK_IFELSE(
186     [AC_LANG_PROGRAM(
187        [[#include <sys/time.h>
188          #include <sys/resource.h>
189        ]],
190        [[setpriority (0, 0, 0);]])],
191     [utils_cv_func_setpriority=yes],
192     [utils_cv_func_setpriority=no])])
193 if test $utils_cv_func_setpriority = no; then
194   AC_CHECK_FUNCS([nice])
195 fi
196 case $utils_cv_func_setpriority,$ac_cv_func_nice in
197 *yes*)
198   gl_ADD_PROG([optional_bin_progs], [nice])
199 esac
200
201 AC_DEFUN([coreutils_DUMMY_1],
202 [
203   AC_REQUIRE([gl_READUTMP])
204   if test $ac_cv_header_utmp_h = yes || test $ac_cv_header_utmpx_h = yes; then
205     gl_ADD_PROG([optional_bin_progs], [who])
206     gl_ADD_PROG([optional_bin_progs], [users])
207     gl_ADD_PROG([optional_bin_progs], [pinky])
208   fi
209 ])
210 coreutils_DUMMY_1
211
212 AC_MSG_CHECKING([ut_host in struct utmp])
213 AC_CACHE_VAL([su_cv_func_ut_host_in_utmp],
214 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
215 #include <utmp.h>]], [[struct utmp ut; return !sizeof ut.ut_host;]])],
216   [su_cv_func_ut_host_in_utmp=yes],
217   [su_cv_func_ut_host_in_utmp=no])])
218 AC_MSG_RESULT([$su_cv_func_ut_host_in_utmp])
219 if test $su_cv_func_ut_host_in_utmp = yes; then
220   have_ut_host=1
221   AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
222 fi
223
224 if test -z "$have_ut_host"; then
225   AC_MSG_CHECKING([ut_host in struct utmpx])
226   AC_CACHE_VAL([su_cv_func_ut_host_in_utmpx],
227   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
228 #include <utmpx.h>]], [[struct utmpx ut; return !sizeof ut.ut_host;]])],
229     [su_cv_func_ut_host_in_utmpx=yes],
230     [su_cv_func_ut_host_in_utmpx=no])])
231   AC_MSG_RESULT([$su_cv_func_ut_host_in_utmpx])
232   if test $su_cv_func_ut_host_in_utmpx = yes; then
233     AC_DEFINE([HAVE_UTMPX_H], [1], [FIXME])
234     AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
235   fi
236 fi
237
238 GNULIB_BOOT_TIME([gl_ADD_PROG([optional_bin_progs], [uptime])])
239
240 AC_SYS_POSIX_TERMIOS()
241 gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
242
243 if test $ac_cv_sys_posix_termios = yes; then
244   gl_ADD_PROG([optional_bin_progs], [stty])
245
246   AC_MSG_CHECKING([whether termios.h needs _XOPEN_SOURCE])
247   AC_CACHE_VAL([su_cv_sys_termios_needs_xopen_source],
248   [AC_EGREP_CPP([yes], [#include <termios.h>
249 #ifdef IUCLC
250 yes
251 #endif], su_cv_sys_termios_needs_xopen_source=no,
252    AC_EGREP_CPP([yes], [#define _XOPEN_SOURCE
253 #include <termios.h>
254 #ifdef IUCLC
255 yes
256 #endif], su_cv_sys_termios_needs_xopen_source=yes,
257    su_cv_sys_termios_needs_xopen_source=no))])
258   AC_MSG_RESULT([$su_cv_sys_termios_needs_xopen_source])
259   test $su_cv_sys_termios_needs_xopen_source = yes &&
260     AC_DEFINE([TERMIOS_NEEDS_XOPEN_SOURCE], [1], [FIXME])
261
262   AC_MSG_CHECKING([c_line in struct termios])
263   AC_CACHE_VAL([su_cv_sys_c_line_in_termios],
264   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#if TERMIOS_NEEDS_XOPEN_SOURCE
265 #define _XOPEN_SOURCE
266 #endif
267 #include <sys/types.h>
268 #include <termios.h>]], [[struct termios t; return !sizeof t.c_line;]])],
269     [su_cv_sys_c_line_in_termios=yes],
270     [su_cv_sys_c_line_in_termios=no])])
271   AC_MSG_RESULT([$su_cv_sys_c_line_in_termios])
272   test $su_cv_sys_c_line_in_termios = yes \
273     && AC_DEFINE([HAVE_C_LINE], [1], [FIXME])
274 fi
275
276 # FIXME: note that this macro appears above, too.
277 # I'm leaving it here for now.  This whole thing needs to be modernized...
278 gl_WINSIZE_IN_PTEM
279
280 gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H
281
282 if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
283    test $gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h = no; then
284   AC_MSG_CHECKING([TIOCGWINSZ in sys/pty.h])
285   AC_CACHE_VAL([su_cv_sys_tiocgwinsz_in_sys_pty_h],
286   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
287 #ifdef WINSIZE_IN_PTEM
288 # include <sys/stream.h>
289 # include <sys/ptem.h>
290 #endif
291 #include <sys/ioctl.h>
292 #include <sys/tty.h>
293 #include <sys/pty.h>]], [[int x = TIOCGWINSZ;]])],
294     [su_cv_sys_tiocgwinsz_in_sys_pty_h=yes],
295     [su_cv_sys_tiocgwinsz_in_sys_pty_h=no])])
296   AC_MSG_RESULT([$su_cv_sys_tiocgwinsz_in_sys_pty_h])
297
298   test $su_cv_sys_tiocgwinsz_in_sys_pty_h = yes \
299       && AC_DEFINE([GWINSZ_IN_SYS_PTY], [1],
300                    [Define if your system defines TIOCGWINSZ in sys/pty.h.])
301 fi
302
303 # For src/kill.c.
304 AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
305   [AC_INCLUDES_DEFAULT
306 #include <signal.h>])
307
308 cu_LIB_CHECK
309 cu_GMP
310
311 # Build df only if there's a point to it.
312 if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
313   gl_ADD_PROG([optional_bin_progs], [df])
314 fi
315
316 ############################################################################
317 mk="$srcdir/src/Makefile.am"
318 # Extract all literal names from the definition of $(EXTRA_PROGRAMS)
319 # in $mk but don't expand the variable references.
320 # Append each literal name to $optional_bin_progs.
321 v=EXTRA_PROGRAMS
322 for gl_i in `sed -n '/^'$v' =/,/[[^\]]$/p' $mk \
323     | sed 's/^  *//;/^\$.*/d;/^'$v' =/d' \
324     | tr -s '\\015\\012\\\\' '   '`; do
325   gl_ADD_PROG([optional_bin_progs], $gl_i)
326 done
327
328 # As above, extract literal names from the definition of $(no_install__progs)
329 # in $mk but don't expand the variable references.
330 v=no_install__progs
331 t=`sed -n '/^'$v' =/,/[[^\]]$/p' $mk \
332     | sed 's/^  *//;/^\$.*/d;/^'$v' =/d' \
333     | tr -s '\\015\\012\\\\' '   '`
334 # Remove any trailing space.
335 no_install_progs_default=`echo "$t"|sed 's/ $//'`
336
337 # Unfortunately, due to the way autoconf's AS_HELP_STRING works, the list
338 # of default-not-installed programs, "arch hostname su", must appear in two
339 # places: in this file below, and in $mk.  Using "$no_install_progs_default"
340 # below cannot work.  And we can't substitute the names into $mk because
341 # automake needs the literals, too.
342 # The compromise is to ensure that the space-separated list extracted
343 # above matches the literal 2nd argument below.
344 c="$srcdir/configure.ac"
345 re='^g''l_INCLUDE_EXCLUDE_PROG(.* [\[\(.*\)\]])'
346 t=`sed -n '/'"$re"'/{s/'"$re"'/\1/;s/,/ /gp
347 }' $c`
348 case $t in
349   $no_install_progs_default) ;;
350   *) AC_MSG_ERROR([[internal error: g'l_INCLUDE_EXCLUDE_PROG's 2nd arg, $t,
351                    does not match the list of default-not-installed programs
352                    ($no_install_progs_default) also recorded in $mk]],
353                    1) ;;
354 esac
355
356 # Given the name of a variable containing a space-separated list of
357 # install-by-default programs and the actual list do-not-install-by-default
358 # programs, modify the former variable to reflect any "do-install" and
359 # "don't-install" requests.
360 # I.e., add any program name specified via --enable-install-program=..., and
361 # remove any program name specified via --enable-no-install-program=...
362 # Note how the second argument below is a literal, with "," separators.
363 # That is required due to the way the macro works, and since the
364 # corresponding ./configure option argument is comma-separated on input.
365 gl_INCLUDE_EXCLUDE_PROG([optional_bin_progs], [arch,hostname,su])
366
367 # Set INSTALL_SU if su installation has been requested via
368 # --enable-install-program=su.
369 AC_SUBST([INSTALL_SU])
370 case " $optional_bin_progs " in
371   *' su '*) INSTALL_SU=yes ;;
372   *)        INSTALL_SU=no ;;
373 esac
374
375 MAN=`echo "$optional_bin_progs "|sed 's/ /.1 /g;s/ $//'|tr -d '\\015\\012'`
376
377 # Change ginstall.1 to "install.h" in $MAN.
378 MAN=`for m in $MAN; do test $m = ginstall.1 && m=install.1; echo $m; done \
379   | tr '\015\012' '  '; echo`
380
381 # Remove [.1, since writing a portable rule for it in man/Makefile.am
382 # is not practical.  The sed LHS below uses the autoconf quadrigraph
383 # representing '['.
384 MAN=`echo "$MAN"|sed 's/\@<:@\.1//'`
385
386 OPTIONAL_BIN_PROGS=`echo "$optional_bin_progs "|sed 's/ /\$(EXEEXT) /g;s/ $//'`
387 AC_SUBST([OPTIONAL_BIN_PROGS])
388 NO_INSTALL_PROGS_DEFAULT=$no_install_progs_default
389 AC_SUBST([NO_INSTALL_PROGS_DEFAULT])
390
391 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
392
393 # Arrange to rerun configure whenever the file, src/Makefile.am,
394 # containing the list of program names changes.
395 CONFIG_STATUS_DEPENDENCIES='$(top_srcdir)/src/Makefile.am'
396 AC_SUBST([CONFIG_STATUS_DEPENDENCIES])
397 ############################################################################
398
399 AM_GNU_GETTEXT([external], [need-formatstring-macros])
400 AM_GNU_GETTEXT_VERSION([0.15])
401
402 # For a test of uniq: it uses the $LOCALE_FR envvar.
403 gt_LOCALE_FR
404
405 AC_CONFIG_FILES(
406   Makefile
407   doc/Makefile
408   lib/Makefile
409   man/Makefile
410   po/Makefile.in
411   src/Makefile
412   tests/Makefile
413   gnulib-tests/Makefile
414   )
415 AC_OUTPUT