tac: do not let failed allocation cause immediate exit
[coreutils.git] / configure.ac
blob8241b55db83f5c71a557dc7d987595ca177eb67a
1 # -*- autoconf -*-
2 # Process this file with autoconf to produce a configure script.
4 # Copyright (C) 1991, 1993-2011 Free Software Foundation, Inc.
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.
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.
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/>.
19 dnl Written by Jim Meyering.
21 AC_PREREQ([2.64])
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])
30 AC_CONFIG_SRCDIR([src/ls.c])
32 AC_CONFIG_AUX_DIR([build-aux])
33 AC_CONFIG_HEADERS([lib/config.h:lib/config.hin])
35 AM_INIT_AUTOMAKE([1.11.1 no-dist-gzip dist-xz color-tests parallel-tests])
36 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
38 AC_PROG_CC_STDC
39 AM_PROG_CC_C_O
40 AC_PROG_CPP
41 AC_PROG_GCC_TRADITIONAL
42 AC_PROG_RANLIB
43 AC_PROG_LN_S
44 gl_EARLY
45 gl_INIT
46 coreutils_MACROS
48 AC_ARG_ENABLE([gcc-warnings],
49   [AS_HELP_STRING([--enable-gcc-warnings],
50                   [turn on lots of GCC warnings (for developers)])],
51   [case $enableval in
52      yes|no) ;;
53      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
54    esac
55    gl_gcc_warnings=$enableval],
56   [gl_gcc_warnings=no]
59 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
60 # ------------------------------------------------
61 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
62 # Otherwise, run RUN-IF-NOT-FOUND.
63 AC_DEFUN([gl_GCC_VERSION_IFELSE],
64   [AC_PREPROC_IFELSE(
65     [AC_LANG_PROGRAM(
66       [[
67 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
68 /* ok */
69 #else
70 # error "your version of gcc is older than $1.$2"
71 #endif
72       ]]),
73     ], [$3], [$4])
74   ]
77 if test "$gl_gcc_warnings" = yes; then
78   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
79   AC_SUBST([WERROR_CFLAGS])
81   nw=
82   # This, $nw, is the list of warnings we disable.
83   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
84   nw="$nw -Waggregate-return"       # anachronistic
85   nw="$nw -Wlong-long"              # C90 is anachronistic (lib/gethrxtime.h)
86   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
87   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
88   nw="$nw -Wtraditional"            # Warns on #elif which we use often
89   nw="$nw -Wcast-qual"              # Too many warnings for now
90   nw="$nw -Wconversion"             # Too many warnings for now
91   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
92   nw="$nw -Wsign-conversion"        # Too many warnings for now
93   nw="$nw -Wtraditional-conversion" # Too many warnings for now
94   nw="$nw -Wunreachable-code"       # Too many warnings for now
95   nw="$nw -Wpadded"                 # Our structs are not padded
96   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
97   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
98   nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
99   nw="$nw -Wvla"                    # warnings in gettext.h
100   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
101   nw="$nw -Wswitch-enum"            # Too many warnings for now
102   nw="$nw -Wswitch-default"         # Too many warnings for now
103   nw="$nw -Wstack-protector"        # not worth working around
104   # things I might fix soon:
105   nw="$nw -Wfloat-equal"            # sort.c, seq.c
106   nw="$nw -Wmissing-format-attribute" # copy.c
107   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
108   nw="$nw -Winline"                 # system.h's readdir_ignoring_dot_and_dotdot
110   # Using -Wstrict-overflow is a pain, but the alternative is worse.
111   # For an example, see the code that provoked this report:
112   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
113   # Code like that still infloops with gcc-4.6.0 and -O2.  Scary indeed.
115   gl_MANYWARN_ALL_GCC([ws])
116   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
117   for w in $ws; do
118     gl_WARN_ADD([$w])
119   done
120   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
121   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
122   gl_WARN_ADD([-Wsuggest-attribute=const])
123   gl_WARN_ADD([-Wsuggest-attribute=noreturn])
125   # Enable this warning only with gcc-4.7 and newer.  With 4.6.1 20110824,
126   # it suggests test.c's advance function may be pure, even though it
127   # increments a global variable.  Oops.
128   # Normally we'd write code to test for the precise failure, but that
129   # requires a relatively large input to make gcc exhibit the failure.
130   gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
132   # In spite of excluding -Wlogical-op above, it is enabled, as of
133   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
134   gl_WARN_ADD([-Wno-logical-op])
136   gl_WARN_ADD([-fdiagnostics-show-option])
137   gl_WARN_ADD([-funit-at-a-time])
139   AC_SUBST([WARN_CFLAGS])
141   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
142   AC_DEFINE([_FORTIFY_SOURCE], [2],
143     [enable compile-time and run-time bounds-checking, and some warnings])
144   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
146   # We use a slightly smaller set of warning options for lib/.
147   # Remove the following and save the result in GNULIB_WARN_CFLAGS.
148   nw=
149   nw="$nw -Wstrict-overflow"
150   nw="$nw -Wuninitialized"
151   nw="$nw -Wunused-macros"
152   nw="$nw -Wmissing-prototypes"
153   nw="$nw -Wold-style-definition"
154   # FIXME: remove/reenable the following two, once gnulib is adjusted.
155   nw="$nw -Wsuggest-attribute=const"
156   nw="$nw -Wsuggest-attribute=pure"
157   gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
158   AC_SUBST([GNULIB_WARN_CFLAGS])
160   # For gnulib-tests, the set is slightly smaller still.
161   nw=
162   nw="$nw -Wstrict-prototypes"
163   gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
164                          [$GNULIB_WARN_CFLAGS], [$nw])
165   AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
168 AC_FUNC_FORK
170 optional_bin_progs=
171 AC_CHECK_FUNCS([chroot],
172         gl_ADD_PROG([optional_bin_progs], [chroot]))
173 AC_CHECK_FUNCS([gethostid],
174         gl_ADD_PROG([optional_bin_progs], [hostid]))
176 gl_WINSIZE_IN_PTEM
178 AC_MSG_CHECKING([whether localtime caches TZ])
179 AC_CACHE_VAL([utils_cv_localtime_cache],
180 [if test x$ac_cv_func_tzset = xyes; then
181 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <time.h>
182 #if STDC_HEADERS
183 # include <stdlib.h>
184 #endif
185 extern char **environ;
186 void unset_TZ (void)
188   char **from, **to;
189   for (to = from = environ; (*to = *from); from++)
190     if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '='))
191       to++;
193 int main()
195   time_t now = time ((time_t *) 0);
196   int hour_GMT0, hour_unset;
197   if (putenv ("TZ=GMT0") != 0)
198     return 1;
199   hour_GMT0 = localtime (&now)->tm_hour;
200   unset_TZ ();
201   hour_unset = localtime (&now)->tm_hour;
202   if (putenv ("TZ=PST8") != 0)
203     return 1;
204   if (localtime (&now)->tm_hour == hour_GMT0)
205     return 1;
206   unset_TZ ();
207   if (localtime (&now)->tm_hour != hour_unset)
208     return 1;
209   return 0;
210 }]])],
211 [utils_cv_localtime_cache=no],
212 [utils_cv_localtime_cache=yes],
213 [# If we have tzset, assume the worst when cross-compiling.
214 utils_cv_localtime_cache=yes])
215 else
216         # If we lack tzset, report that localtime does not cache TZ,
217         # since we can't invalidate the cache if we don't have tzset.
218         utils_cv_localtime_cache=no
219 fi])dnl
220 AC_MSG_RESULT([$utils_cv_localtime_cache])
221 if test $utils_cv_localtime_cache = yes; then
222   AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
225 # SCO-ODT-3.0 is reported to need -los to link programs using initgroups
226 AC_CHECK_FUNCS([initgroups])
227 if test $ac_cv_func_initgroups = no; then
228   AC_CHECK_LIB([os], [initgroups])
231 AC_CHECK_FUNCS([syslog])
232 if test $ac_cv_func_syslog = no; then
233   # syslog is not in the default libraries.  See if it's in some other.
234   for lib in bsd socket inet; do
235     AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG], [1], [FIXME])
236       LIBS="$LIBS -l$lib"; break])
237   done
240 AC_CACHE_CHECK([for 3-argument setpriority function],
241   [utils_cv_func_setpriority],
242   [AC_LINK_IFELSE(
243     [AC_LANG_PROGRAM(
244        [[#include <sys/time.h>
245          #include <sys/resource.h>
246        ]],
247        [[setpriority (0, 0, 0);]])],
248     [utils_cv_func_setpriority=yes],
249     [utils_cv_func_setpriority=no])])
250 if test $utils_cv_func_setpriority = no; then
251   AC_CHECK_FUNCS([nice])
253 case $utils_cv_func_setpriority,$ac_cv_func_nice in
254 *yes*)
255   gl_ADD_PROG([optional_bin_progs], [nice])
256 esac
258 AC_DEFUN([coreutils_DUMMY_1],
260   AC_REQUIRE([gl_READUTMP])
261   if test $ac_cv_header_utmp_h = yes || test $ac_cv_header_utmpx_h = yes; then
262     gl_ADD_PROG([optional_bin_progs], [who])
263     gl_ADD_PROG([optional_bin_progs], [users])
264     gl_ADD_PROG([optional_bin_progs], [pinky])
265   fi
267 coreutils_DUMMY_1
269 AC_MSG_CHECKING([ut_host in struct utmp])
270 AC_CACHE_VAL([su_cv_func_ut_host_in_utmp],
271 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
272 #include <utmp.h>]], [[struct utmp ut; return !sizeof ut.ut_host;]])],
273   [su_cv_func_ut_host_in_utmp=yes],
274   [su_cv_func_ut_host_in_utmp=no])])
275 AC_MSG_RESULT([$su_cv_func_ut_host_in_utmp])
276 if test $su_cv_func_ut_host_in_utmp = yes; then
277   have_ut_host=1
278   AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
281 if test -z "$have_ut_host"; then
282   AC_MSG_CHECKING([ut_host in struct utmpx])
283   AC_CACHE_VAL([su_cv_func_ut_host_in_utmpx],
284   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
285 #include <utmpx.h>]], [[struct utmpx ut; return !sizeof ut.ut_host;]])],
286     [su_cv_func_ut_host_in_utmpx=yes],
287     [su_cv_func_ut_host_in_utmpx=no])])
288   AC_MSG_RESULT([$su_cv_func_ut_host_in_utmpx])
289   if test $su_cv_func_ut_host_in_utmpx = yes; then
290     AC_DEFINE([HAVE_UTMPX_H], [1], [FIXME])
291     AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
292   fi
295 GNULIB_BOOT_TIME([gl_ADD_PROG([optional_bin_progs], [uptime])])
297 AC_SYS_POSIX_TERMIOS()
298 gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
300 if test $ac_cv_sys_posix_termios = yes; then
301   gl_ADD_PROG([optional_bin_progs], [stty])
303   AC_MSG_CHECKING([whether termios.h needs _XOPEN_SOURCE])
304   AC_CACHE_VAL([su_cv_sys_termios_needs_xopen_source],
305   [AC_EGREP_CPP([yes], [#include <termios.h>
306 #ifdef IUCLC
308 #endif], su_cv_sys_termios_needs_xopen_source=no,
309    AC_EGREP_CPP([yes], [#define _XOPEN_SOURCE
310 #include <termios.h>
311 #ifdef IUCLC
313 #endif], su_cv_sys_termios_needs_xopen_source=yes,
314    su_cv_sys_termios_needs_xopen_source=no))])
315   AC_MSG_RESULT([$su_cv_sys_termios_needs_xopen_source])
316   test $su_cv_sys_termios_needs_xopen_source = yes &&
317     AC_DEFINE([TERMIOS_NEEDS_XOPEN_SOURCE], [1], [FIXME])
319   AC_MSG_CHECKING([c_line in struct termios])
320   AC_CACHE_VAL([su_cv_sys_c_line_in_termios],
321   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#if TERMIOS_NEEDS_XOPEN_SOURCE
322 #define _XOPEN_SOURCE
323 #endif
324 #include <sys/types.h>
325 #include <termios.h>]], [[struct termios t; return !sizeof t.c_line;]])],
326     [su_cv_sys_c_line_in_termios=yes],
327     [su_cv_sys_c_line_in_termios=no])])
328   AC_MSG_RESULT([$su_cv_sys_c_line_in_termios])
329   test $su_cv_sys_c_line_in_termios = yes \
330     && AC_DEFINE([HAVE_C_LINE], [1], [FIXME])
333 # FIXME: note that this macro appears above, too.
334 # I'm leaving it here for now.  This whole thing needs to be modernized...
335 gl_WINSIZE_IN_PTEM
337 gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H
339 if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
340    test $gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h = no; then
341   AC_MSG_CHECKING([TIOCGWINSZ in sys/pty.h])
342   AC_CACHE_VAL([su_cv_sys_tiocgwinsz_in_sys_pty_h],
343   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
344 #ifdef WINSIZE_IN_PTEM
345 # include <sys/stream.h>
346 # include <sys/ptem.h>
347 #endif
348 #include <sys/ioctl.h>
349 #include <sys/tty.h>
350 #include <sys/pty.h>]], [[int x = TIOCGWINSZ;]])],
351     [su_cv_sys_tiocgwinsz_in_sys_pty_h=yes],
352     [su_cv_sys_tiocgwinsz_in_sys_pty_h=no])])
353   AC_MSG_RESULT([$su_cv_sys_tiocgwinsz_in_sys_pty_h])
355   test $su_cv_sys_tiocgwinsz_in_sys_pty_h = yes \
356       && AC_DEFINE([GWINSZ_IN_SYS_PTY], [1],
357                    [Define if your system defines TIOCGWINSZ in sys/pty.h.])
360 # For src/kill.c.
361 AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
362   [AC_INCLUDES_DEFAULT
363 #include <signal.h>])
365 cu_LIB_CHECK
366 cu_GMP
368 # Build df only if there's a point to it.
369 if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
370   gl_ADD_PROG([optional_bin_progs], [df])
373 # Limit stdbuf to ELF systems with GCC
374 AC_MSG_CHECKING([whether this is an ELF system])
375 AC_EGREP_CPP([yes], [#if __ELF__
377 #endif], [elf_sys=yes], [elf_sys=no])
378 AC_MSG_RESULT([$elf_sys])
379 if test "$elf_sys" = "yes" && \
380    test "$GCC" = "yes"; then
381   gl_ADD_PROG([optional_bin_progs], [stdbuf])
384 ############################################################################
385 mk="$srcdir/src/Makefile.am"
386 # Extract all literal names from the definition of $(EXTRA_PROGRAMS)
387 # in $mk but don't expand the variable references.
388 # Append each literal name to $optional_bin_progs.
389 v=EXTRA_PROGRAMS
390 for gl_i in `sed -n '/^'$v' =/,/[[^\]]$/p' $mk \
391     | sed 's/^  *//;/^\$.*/d;/^'$v' =/d' \
392     | tr -s '\\015\\012\\\\' '   '`; do
393   gl_ADD_PROG([optional_bin_progs], $gl_i)
394 done
396 # As above, extract literal names from the definition of $(no_install__progs)
397 # in $mk but don't expand the variable references.
398 v=no_install__progs
399 t=`sed -n '/^'$v' =/,/[[^\]]$/p' $mk \
400     | sed 's/^  *//;/^\$.*/d;/^'$v' =/d' \
401     | tr -s '\\015\\012\\\\' '   '`
402 # Remove any trailing space.
403 no_install_progs_default=`echo "$t"|sed 's/ $//'`
405 # Unfortunately, due to the way autoconf's AS_HELP_STRING works, the list
406 # of default-not-installed programs, "arch hostname su", must appear in two
407 # places: in this file below, and in $mk.  Using "$no_install_progs_default"
408 # below cannot work.  And we can't substitute the names into $mk because
409 # automake needs the literals, too.
410 # The compromise is to ensure that the space-separated list extracted
411 # above matches the literal 2nd argument below.
412 c="$srcdir/configure.ac"
413 re='^g''l_INCLUDE_EXCLUDE_PROG(.* [\[\(.*\)\]])'
414 t=`sed -n '/'"$re"'/{s/'"$re"'/\1/;s/,/ /gp
415 }' $c`
416 case $t in
417   $no_install_progs_default) ;;
418   *) AC_MSG_ERROR([[internal error: g'l_INCLUDE_EXCLUDE_PROG's 2nd arg, $t,
419                    does not match the list of default-not-installed programs
420                    ($no_install_progs_default) also recorded in $mk]],
421                    1) ;;
422 esac
424 # Given the name of a variable containing a space-separated list of
425 # install-by-default programs and the actual list do-not-install-by-default
426 # programs, modify the former variable to reflect any "do-install" and
427 # "don't-install" requests.
428 # I.e., add any program name specified via --enable-install-program=..., and
429 # remove any program name specified via --enable-no-install-program=...
430 # Note how the second argument below is a literal, with "," separators.
431 # That is required due to the way the macro works, and since the
432 # corresponding ./configure option argument is comma-separated on input.
433 gl_INCLUDE_EXCLUDE_PROG([optional_bin_progs], [arch,hostname,su])
435 # Now that we know which programs will actually be built up, figure out
436 # which optional helper progs should be compiled.
437 optional_pkglib_progs=
438 case " $optional_bin_progs " in
439   *' stdbuf '*) gl_ADD_PROG([optional_pkglib_progs], [libstdbuf.so]) ;;
440 esac
442 # Set INSTALL_SU if su installation has been requested via
443 # --enable-install-program=su.
444 AC_SUBST([INSTALL_SU])
445 case " $optional_bin_progs " in
446   *' su '*) INSTALL_SU=yes ;;
447   *)        INSTALL_SU=no ;;
448 esac
450 MAN=`echo "$optional_bin_progs "|sed 's/ /.1 /g;s/ $//'|tr -d '\\015\\012'`
452 # Change "ginstall.1" to "install.1" in $MAN.
453 MAN=`for m in $MAN; do test $m = ginstall.1 && m=install.1; echo $m; done \
454   | tr '\015\012' '  '; echo`
456 # Remove [.1, since writing a portable rule for it in man/Makefile.am
457 # is not practical.  The sed LHS below uses the autoconf quadrigraph
458 # representing '['.
459 MAN=`echo "$MAN"|sed 's/\@<:@\.1//'`
461 OPTIONAL_BIN_PROGS=`echo "$optional_bin_progs "|sed 's/ /\$(EXEEXT) /g;s/ $//'`
462 AC_SUBST([OPTIONAL_BIN_PROGS])
463 OPTIONAL_PKGLIB_PROGS=`echo "$optional_pkglib_progs " | sed 's/ $//'`
464 AC_SUBST([OPTIONAL_PKGLIB_PROGS])
465 NO_INSTALL_PROGS_DEFAULT=$no_install_progs_default
466 AC_SUBST([NO_INSTALL_PROGS_DEFAULT])
468 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
470 # Arrange to rerun configure whenever the file, src/Makefile.am,
471 # containing the list of program names changes.
472 CONFIG_STATUS_DEPENDENCIES='$(top_srcdir)/src/Makefile.am'
473 AC_SUBST([CONFIG_STATUS_DEPENDENCIES])
474 ############################################################################
476 # As long as "grep 'PRI[diouxX]' po/*.pot" reports matches in
477 # translatable strings, we must use need-formatstring-macros here.
478 AM_GNU_GETTEXT([external], [need-formatstring-macros])
479 AM_GNU_GETTEXT_VERSION([0.18.1])
481 # For a test of uniq: it uses the $LOCALE_FR envvar.
482 gt_LOCALE_FR
484 AC_CONFIG_FILES(
485   Makefile
486   doc/Makefile
487   lib/Makefile
488   man/Makefile
489   po/Makefile.in
490   src/Makefile
491   tests/Makefile
492   gnulib-tests/Makefile
493   )
494 AC_OUTPUT