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