maint: allow per-directory CFLAGS settings with non-recursive make
[platform/upstream/coreutils.git] / configure.ac
1 # -*- autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 # Copyright (C) 1991-2012 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.64])
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.11.2 no-dist-gzip dist-xz color-tests parallel-tests
36                   subdir-objects])
37 AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
38
39 dnl POSIXCHECK is worthwhile for maintainers, but adds several seconds
40 dnl (more than 10% execution time) to ./configure, with no benefit for
41 dnl most users.  Using it to look for bugs requires:
42 dnl   GNULIB_POSIXCHECK=1 autoreconf -f
43 dnl   ./configure
44 dnl   make
45 dnl   make -C src clean
46 dnl   make CFLAGS=-DGNULIB_POSIXCHECK=1
47 dnl FIXME: Once we figure out how to avoid false positives, we should
48 dnl have 'make my-distcheck' in dist-check.mk exercise this.
49 m4_syscmd([test "${GNULIB_POSIXCHECK+set}" = set])
50 m4_if(m4_sysval, [0], [], [dnl
51 gl_ASSERT_NO_GNULIB_POSIXCHECK])
52
53 AC_PROG_CC_STDC
54 AM_PROG_CC_C_O
55 AC_PROG_CPP
56 AC_PROG_GCC_TRADITIONAL
57 AC_PROG_RANLIB
58 AC_PROG_LN_S
59 gl_EARLY
60 gl_INIT
61 coreutils_MACROS
62
63 # The test suite needs to know if we have a working perl.
64 # FIXME: this is suboptimal.  Ideally, we would be able to call gl_PERL
65 # with an ACTION-IF-NOT-FOUND argument ...
66 cu_have_perl=yes
67 case $PERL in *"/missing ") cu_have_perl=no;; esac
68 AM_CONDITIONAL([HAVE_PERL], [test $cu_have_perl = yes])
69
70 AC_ARG_ENABLE([gcc-warnings],
71   [AS_HELP_STRING([--enable-gcc-warnings],
72      [turn on many GCC warnings (for developers; best with GNU make)])],
73   [case $enableval in
74      yes|no) ;;
75      *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
76    esac
77    gl_gcc_warnings=$enableval],
78   [if test -d "$srcdir"/.git; then
79      gl_gcc_warnings=yes
80    else
81      gl_gcc_warnings=no
82    fi]
83 )
84
85 # gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
86 # ------------------------------------------------
87 # If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
88 # Otherwise, run RUN-IF-NOT-FOUND.
89 AC_DEFUN([gl_GCC_VERSION_IFELSE],
90   [AC_PREPROC_IFELSE(
91     [AC_LANG_PROGRAM(
92       [[
93 #if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
94 /* ok */
95 #else
96 # error "your version of gcc is older than $1.$2"
97 #endif
98       ]]),
99     ], [$3], [$4])
100   ]
101 )
102
103 if test "$gl_gcc_warnings" = yes; then
104   gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
105   AC_SUBST([WERROR_CFLAGS])
106
107   nw=
108   # This, $nw, is the list of warnings we disable.
109   nw="$nw -Wdeclaration-after-statement" # too useful to forbid
110   nw="$nw -Waggregate-return"       # anachronistic
111   nw="$nw -Wlong-long"              # C90 is anachronistic (lib/gethrxtime.h)
112   nw="$nw -Wc++-compat"             # We don't care about C++ compilers
113   nw="$nw -Wundef"                  # Warns on '#if GNULIB_FOO' etc in gnulib
114   nw="$nw -Wtraditional"            # Warns on #elif which we use often
115   nw="$nw -Wcast-qual"              # Too many warnings for now
116   nw="$nw -Wconversion"             # Too many warnings for now
117   nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
118   nw="$nw -Wsign-conversion"        # Too many warnings for now
119   nw="$nw -Wtraditional-conversion" # Too many warnings for now
120   nw="$nw -Wunreachable-code"       # Too many warnings for now
121   nw="$nw -Wpadded"                 # Our structs are not padded
122   nw="$nw -Wredundant-decls"        # openat.h declares e.g., mkdirat
123   nw="$nw -Wlogical-op"             # any use of fwrite provokes this
124   nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
125   nw="$nw -Wvla"                    # warnings in gettext.h
126   nw="$nw -Wnested-externs"         # use of XARGMATCH/verify_function__
127   nw="$nw -Wswitch-enum"            # Too many warnings for now
128   nw="$nw -Wswitch-default"         # Too many warnings for now
129   nw="$nw -Wstack-protector"        # not worth working around
130   # things I might fix soon:
131   nw="$nw -Wfloat-equal"            # sort.c, seq.c
132   nw="$nw -Wmissing-format-attribute" # copy.c
133   nw="$nw -Wunsafe-loop-optimizations" # a few src/*.c
134   nw="$nw -Winline"                 # system.h's readdir_ignoring_dot_and_dotdot
135   nw="$nw -Wsuggest-attribute=format" # warns about copy.c and factor.c
136
137   # Using -Wstrict-overflow is a pain, but the alternative is worse.
138   # For an example, see the code that provoked this report:
139   # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33498
140   # Code like that still infloops with gcc-4.6.0 and -O2.  Scary indeed.
141
142   gl_MANYWARN_ALL_GCC([ws])
143   gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
144   for w in $ws; do
145     gl_WARN_ADD([$w])
146   done
147   gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
148   gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
149   gl_WARN_ADD([-Wsuggest-attribute=const])
150   gl_WARN_ADD([-Wsuggest-attribute=noreturn])
151   gl_WARN_ADD([-Wno-format-nonliteral])
152
153   # Enable this warning only with gcc-4.7 and newer.  With 4.6.2 20111027,
154   # it suggests test.c's advance function may be pure, even though it
155   # increments a global variable.  Oops.
156   # Normally we'd write code to test for the precise failure, but that
157   # requires a relatively large input to make gcc exhibit the failure.
158   gl_GCC_VERSION_IFELSE([4], [7], [gl_WARN_ADD([-Wsuggest-attribute=pure])])
159
160   # In spite of excluding -Wlogical-op above, it is enabled, as of
161   # gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
162   gl_WARN_ADD([-Wno-logical-op])
163
164   gl_WARN_ADD([-fdiagnostics-show-option])
165   gl_WARN_ADD([-funit-at-a-time])
166
167   AC_SUBST([WARN_CFLAGS])
168
169   AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
170   AH_VERBATIM([FORTIFY_SOURCE],
171   [/* Enable compile-time and run-time bounds-checking, and some warnings,
172       without upsetting glibc 2.15+. */
173    #if defined __OPTIMIZE__ && __OPTIMIZE__
174    # define _FORTIFY_SOURCE 2
175    #endif
176   ])
177   AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
178
179   # We use a slightly smaller set of warning options for lib/.
180   # Remove the following and save the result in GNULIB_WARN_CFLAGS.
181   nw=
182   nw="$nw -Wstrict-overflow"
183   nw="$nw -Wuninitialized"
184   nw="$nw -Wunused-macros"
185   nw="$nw -Wmissing-prototypes"
186   nw="$nw -Wold-style-definition"
187   # FIXME: it may be easy to remove this, since it affects only one file:
188   # the snprintf call at ftoastr.c:132.
189   nw="$nw -Wdouble-promotion"
190   gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
191   AC_SUBST([GNULIB_WARN_CFLAGS])
192
193   # For gnulib-tests, the set is slightly smaller still.
194   nw=
195   nw="$nw -Wstrict-prototypes"
196   # It's not worth being this picky about test programs.
197   nw="$nw -Wsuggest-attribute=const"
198   nw="$nw -Wsuggest-attribute=pure"
199   gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
200                          [$GNULIB_WARN_CFLAGS], [$nw])
201   AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
202 fi
203
204 AC_FUNC_FORK
205
206 optional_bin_progs=
207 AC_CHECK_FUNCS([chroot],
208         gl_ADD_PROG([optional_bin_progs], [chroot]))
209 AC_CHECK_FUNCS([gethostid],
210         gl_ADD_PROG([optional_bin_progs], [hostid]))
211
212 gl_WINSIZE_IN_PTEM
213
214 AC_MSG_CHECKING([whether localtime caches TZ])
215 AC_CACHE_VAL([utils_cv_localtime_cache],
216 [if test x$ac_cv_func_tzset = xyes; then
217 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <time.h>
218 #if STDC_HEADERS
219 # include <stdlib.h>
220 #endif
221 extern char **environ;
222 void unset_TZ (void)
223 {
224   char **from, **to;
225   for (to = from = environ; (*to = *from); from++)
226     if (! (to[0][0] == 'T' && to[0][1] == 'Z' && to[0][2] == '='))
227       to++;
228 }
229 int main()
230 {
231   time_t now = time ((time_t *) 0);
232   int hour_GMT0, hour_unset;
233   if (putenv ("TZ=GMT0") != 0)
234     return 1;
235   hour_GMT0 = localtime (&now)->tm_hour;
236   unset_TZ ();
237   hour_unset = localtime (&now)->tm_hour;
238   if (putenv ("TZ=PST8") != 0)
239     return 1;
240   if (localtime (&now)->tm_hour == hour_GMT0)
241     return 1;
242   unset_TZ ();
243   if (localtime (&now)->tm_hour != hour_unset)
244     return 1;
245   return 0;
246 }]])],
247 [utils_cv_localtime_cache=no],
248 [utils_cv_localtime_cache=yes],
249 [# If we have tzset, assume the worst when cross-compiling.
250 utils_cv_localtime_cache=yes])
251 else
252         # If we lack tzset, report that localtime does not cache TZ,
253         # since we can't invalidate the cache if we don't have tzset.
254         utils_cv_localtime_cache=no
255 fi])dnl
256 AC_MSG_RESULT([$utils_cv_localtime_cache])
257 if test $utils_cv_localtime_cache = yes; then
258   AC_DEFINE([LOCALTIME_CACHE], [1], [FIXME])
259 fi
260
261 # SCO-ODT-3.0 is reported to need -los to link programs using initgroups
262 AC_CHECK_FUNCS([initgroups])
263 if test $ac_cv_func_initgroups = no; then
264   AC_CHECK_LIB([os], [initgroups])
265 fi
266
267 AC_CHECK_FUNCS([syslog])
268 if test $ac_cv_func_syslog = no; then
269   # syslog is not in the default libraries.  See if it's in some other.
270   for lib in bsd socket inet; do
271     AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG], [1], [FIXME])
272       LIBS="$LIBS -l$lib"; break])
273   done
274 fi
275
276 AC_CACHE_CHECK([for 3-argument setpriority function],
277   [utils_cv_func_setpriority],
278   [AC_LINK_IFELSE(
279     [AC_LANG_PROGRAM(
280        [[#include <sys/time.h>
281          #include <sys/resource.h>
282        ]],
283        [[setpriority (0, 0, 0);]])],
284     [utils_cv_func_setpriority=yes],
285     [utils_cv_func_setpriority=no])])
286 if test $utils_cv_func_setpriority = no; then
287   AC_CHECK_FUNCS([nice])
288 fi
289 case $utils_cv_func_setpriority,$ac_cv_func_nice in
290 *yes*)
291   gl_ADD_PROG([optional_bin_progs], [nice])
292 esac
293
294 AC_DEFUN([coreutils_DUMMY_1],
295 [
296   AC_REQUIRE([gl_READUTMP])
297   if test $ac_cv_header_utmp_h = yes || test $ac_cv_header_utmpx_h = yes; then
298     gl_ADD_PROG([optional_bin_progs], [who])
299     gl_ADD_PROG([optional_bin_progs], [users])
300     gl_ADD_PROG([optional_bin_progs], [pinky])
301   fi
302 ])
303 coreutils_DUMMY_1
304
305 AC_MSG_CHECKING([ut_host in struct utmp])
306 AC_CACHE_VAL([su_cv_func_ut_host_in_utmp],
307 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
308 #include <utmp.h>]], [[struct utmp ut; return !sizeof ut.ut_host;]])],
309   [su_cv_func_ut_host_in_utmp=yes],
310   [su_cv_func_ut_host_in_utmp=no])])
311 AC_MSG_RESULT([$su_cv_func_ut_host_in_utmp])
312 if test $su_cv_func_ut_host_in_utmp = yes; then
313   have_ut_host=1
314   AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
315 fi
316
317 if test -z "$have_ut_host"; then
318   AC_MSG_CHECKING([ut_host in struct utmpx])
319   AC_CACHE_VAL([su_cv_func_ut_host_in_utmpx],
320   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
321 #include <utmpx.h>]], [[struct utmpx ut; return !sizeof ut.ut_host;]])],
322     [su_cv_func_ut_host_in_utmpx=yes],
323     [su_cv_func_ut_host_in_utmpx=no])])
324   AC_MSG_RESULT([$su_cv_func_ut_host_in_utmpx])
325   if test $su_cv_func_ut_host_in_utmpx = yes; then
326     AC_DEFINE([HAVE_UTMPX_H], [1], [FIXME])
327     AC_DEFINE([HAVE_UT_HOST], [1], [FIXME])
328   fi
329 fi
330
331 GNULIB_BOOT_TIME([gl_ADD_PROG([optional_bin_progs], [uptime])])
332
333 AC_SYS_POSIX_TERMIOS()
334 gl_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL
335
336 if test $ac_cv_sys_posix_termios = yes; then
337   gl_ADD_PROG([optional_bin_progs], [stty])
338
339   AC_MSG_CHECKING([whether termios.h needs _XOPEN_SOURCE])
340   AC_CACHE_VAL([su_cv_sys_termios_needs_xopen_source],
341   [AC_EGREP_CPP([yes], [#include <termios.h>
342 #ifdef IUCLC
343 yes
344 #endif], su_cv_sys_termios_needs_xopen_source=no,
345    AC_EGREP_CPP([yes], [#define _XOPEN_SOURCE
346 #include <termios.h>
347 #ifdef IUCLC
348 yes
349 #endif], su_cv_sys_termios_needs_xopen_source=yes,
350    su_cv_sys_termios_needs_xopen_source=no))])
351   AC_MSG_RESULT([$su_cv_sys_termios_needs_xopen_source])
352   test $su_cv_sys_termios_needs_xopen_source = yes &&
353     AC_DEFINE([TERMIOS_NEEDS_XOPEN_SOURCE], [1], [FIXME])
354
355   AC_MSG_CHECKING([c_line in struct termios])
356   AC_CACHE_VAL([su_cv_sys_c_line_in_termios],
357   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#if TERMIOS_NEEDS_XOPEN_SOURCE
358 #define _XOPEN_SOURCE
359 #endif
360 #include <sys/types.h>
361 #include <termios.h>]], [[struct termios t; return !sizeof t.c_line;]])],
362     [su_cv_sys_c_line_in_termios=yes],
363     [su_cv_sys_c_line_in_termios=no])])
364   AC_MSG_RESULT([$su_cv_sys_c_line_in_termios])
365   test $su_cv_sys_c_line_in_termios = yes \
366     && AC_DEFINE([HAVE_C_LINE], [1], [FIXME])
367 fi
368
369 # FIXME: note that this macro appears above, too.
370 # I'm leaving it here for now.  This whole thing needs to be modernized...
371 gl_WINSIZE_IN_PTEM
372
373 gl_HEADER_TIOCGWINSZ_IN_TERMIOS_H
374
375 if test $gl_cv_sys_tiocgwinsz_needs_termios_h = no && \
376    test $gl_cv_sys_tiocgwinsz_needs_sys_ioctl_h = no; then
377   AC_MSG_CHECKING([TIOCGWINSZ in sys/pty.h])
378   AC_CACHE_VAL([su_cv_sys_tiocgwinsz_in_sys_pty_h],
379   [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
380 #ifdef WINSIZE_IN_PTEM
381 # include <sys/stream.h>
382 # include <sys/ptem.h>
383 #endif
384 #include <sys/ioctl.h>
385 #include <sys/tty.h>
386 #include <sys/pty.h>]], [[int x = TIOCGWINSZ;]])],
387     [su_cv_sys_tiocgwinsz_in_sys_pty_h=yes],
388     [su_cv_sys_tiocgwinsz_in_sys_pty_h=no])])
389   AC_MSG_RESULT([$su_cv_sys_tiocgwinsz_in_sys_pty_h])
390
391   test $su_cv_sys_tiocgwinsz_in_sys_pty_h = yes \
392       && AC_DEFINE([GWINSZ_IN_SYS_PTY], [1],
393                    [Define if your system defines TIOCGWINSZ in sys/pty.h.])
394 fi
395
396 # For src/kill.c.
397 AC_CHECK_DECLS([strsignal, sys_siglist, _sys_siglist, __sys_siglist], , ,
398   [AC_INCLUDES_DEFAULT
399 #include <signal.h>])
400
401 cu_GMP
402
403 # Build df only if there's a point to it.
404 if test $gl_cv_list_mounted_fs = yes && test $gl_cv_fs_space = yes; then
405   gl_ADD_PROG([optional_bin_progs], [df])
406 fi
407
408 # Limit stdbuf to ELF systems with GCC
409 AC_MSG_CHECKING([whether this is an ELF system])
410 AC_EGREP_CPP([yes], [#if __ELF__
411 yes
412 #endif], [elf_sys=yes], [elf_sys=no])
413 AC_MSG_RESULT([$elf_sys])
414 if test "$elf_sys" = "yes" && \
415    test "$GCC" = "yes"; then
416   gl_ADD_PROG([optional_bin_progs], [stdbuf])
417 fi
418
419 ############################################################################
420
421 dnl Autogenerated by the 'gen-lists-of-programs.sh' auxiliary script.
422 dnl Issue proper calls to the macros gl_INCLUDE_EXCLUDE_PROG and
423 dnl gl_ADD_PROG (updating $optional_bin_progs), and generate the list
424 dnl of coreutils programs to be built only upon explicit user request,
425 dnl saving that list in the $no_install_progs_default shell variable.
426 m4_include([m4/cu-progs.m4])
427
428 # Now that we know which programs will actually be built, determine
429 # which optional helper progs should be compiled.
430 case " $optional_bin_progs " in
431   *' stdbuf '*) pkglibexec_PROGRAMS='src/libstdbuf.so';;
432   *) pkglibexec_PROGRAMS='';;
433 esac
434
435 man1_MANS=`
436   for p in $optional_bin_progs; do
437     # Change "ginstall.1" to "install.1".
438     test $p = ginstall && p=install
439     # Ignore the "[" program, since writing a portable make rule to
440     # generate its manpage is not practical.
441     dnl Use the autoconf-provided quadrigraph to represent "[",
442     dnl otherwise we will incur in dreadful quoting issues.
443     test x$p = x'@<:@' && continue
444     echo "man/$p.1"
445   done`
446
447 # Not installed by "make install", but must be built when creating
448 # a distribution tarball.
449 EXTRA_MANS=`for p in $no_install_progs_default; do echo man/$p.1; done`
450
451 # The programs built and installed by "make && make install".
452 # Since this is AC_SUBST'd, Automake won't be able to perform rewrite
453 # with $(EXEEXT) appending on it, so we have to do it ourselves -- in
454 # this case, only for $(bin_PROGRAMS).
455 bin_PROGRAMS=`
456   for p in $optional_bin_progs; do echo src/"$p"'$(EXEEXT)'; done`
457
458 # Normalize whitespace.
459 man1_MANS=`echo $man1_MANS`
460 EXTRA_MANS=`echo $EXTRA_MANS`
461 bin_PROGRAMS=`echo $bin_PROGRAMS`
462 pkglibexec_PROGS=`echo $pkglibexec_PROGRAMS`
463
464 AC_SUBST([bin_PROGRAMS])        AM_SUBST_NOTMAKE([bin_PROGRAMS])
465 AC_SUBST([pkglibexec_PROGRAMS]) AM_SUBST_NOTMAKE([pkglibexec_PROGRAMS])
466 AC_SUBST([man1_MANS])           AM_SUBST_NOTMAKE([man1_MANS])
467 AC_SUBST([EXTRA_MANS])          AM_SUBST_NOTMAKE([EXTRA_MANS])
468
469 AC_SUBST([built_programs], [$optional_bin_progs])
470
471 AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
472
473 ############################################################################
474
475 # As long as "grep 'PRI[diouxX]' po/*.pot" reports matches in
476 # translatable strings, we must use need-formatstring-macros here.
477 AM_GNU_GETTEXT([external], [need-formatstring-macros])
478 AM_GNU_GETTEXT_VERSION([0.18.1])
479
480 # For a test of uniq: it uses the $LOCALE_FR envvar.
481 gt_LOCALE_FR
482
483 AC_CONFIG_FILES(
484   Makefile
485   lib/Makefile
486   po/Makefile.in
487   gnulib-tests/Makefile
488   )
489 AC_OUTPUT