1# Copyright (C) 1993-2020 Free Software Foundation, Inc.
2
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16dnl Process this file with -*- autoconf -*- to produce a configure script.
17AC_INIT([GNU sed],
18        m4_esyscmd([build-aux/git-version-gen .tarball-version]),
19        [bug-sed@gnu.org])
20AC_CONFIG_AUX_DIR(build-aux)
21AC_CONFIG_SRCDIR([sed/sed.c])
22AM_CONFIG_HEADER(config.h:config_h.in)
23AC_PREREQ([2.64])
24AM_INIT_AUTOMAKE([1.11.1 dist-xz color-tests parallel-tests
25                  subdir-objects])
26AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
27AC_CONFIG_MACRO_DIR([m4])
28
29AC_PROG_CC_STDC
30AM_PROG_CC_C_O
31gl_EARLY
32gl_INIT
33gl_DISABLE_THREADS
34
35# Ensure VLAs are not used.
36# Note -Wvla is implicitly added by gl_MANYWARN_ALL_GCC
37AC_DEFINE([GNULIB_NO_VLA], [1], [Define to 1 to disable use of VLAs])
38
39# The test suite needs to know if we have a working perl.
40# FIXME: this is suboptimal.  Ideally, we would be able to call gl_PERL
41# with an ACTION-IF-NOT-FOUND argument ...
42cu_have_perl=yes
43case $PERL in *"/missing "*) cu_have_perl=no;; esac
44AM_CONDITIONAL([HAVE_PERL], [test $cu_have_perl = yes])
45
46# gl_GCC_VERSION_IFELSE([major], [minor], [run-if-found], [run-if-not-found])
47# ------------------------------------------------
48# If $CPP is gcc-MAJOR.MINOR or newer, then run RUN-IF-FOUND.
49# Otherwise, run RUN-IF-NOT-FOUND.
50AC_DEFUN([gl_GCC_VERSION_IFELSE],
51  [AC_PREPROC_IFELSE(
52    [AC_LANG_PROGRAM(
53      [[
54#if ($1) < __GNUC__ || (($1) == __GNUC__ && ($2) <= __GNUC_MINOR__)
55/* ok */
56#else
57# error "your version of gcc is older than $1.$2"
58#endif
59      ]]),
60    ], [$3], [$4])
61  ]
62)
63
64AC_CACHE_CHECK([whether "rt" can be used with fopen], [sed_cv_fopen_rt], [
65AC_TRY_RUN([
66#include <stdio.h>
67#include <errno.h>
68
69int main()
70{
71  FILE *fp;
72  int result;
73  errno = 0;
74  fp = fopen ("conftest.c", "rt");
75  if (fp) fclose (fp);
76  return fp ? 0 : 1;
77}], [sed_cv_fopen_rt=yes],
78    [sed_cv_fopen_rt=no],
79    [case $host in
80       *cygwin* | *mingw*) sed_cv_fopen_rt=yes ;;
81       *) sed_cv_fopen_rt='assuming no' ;;
82     esac])])
83if test "$sed_cv_fopen_rt" = yes; then
84  AC_DEFINE([HAVE_FOPEN_RT], [1],
85            [Defined if "rt" can be used as a mode to fopen.])
86fi
87
88AC_CACHE_CHECK([whether -lcP is needed], [sed_cv_libcp_needed], [
89AC_TRY_RUN([
90#include <stdio.h>
91#include <errno.h>
92
93int main()
94{
95  FILE *fp;
96  int result;
97  errno = 0;
98  fp = fopen ("conftest.c", "r");
99  if (!fp) return 0;	   /* error, assume not needed */
100  result = fflush (fp) == EOF && errno == 0;
101  fclose (fp);
102  return result;
103}], [sed_cv_libcp_needed=no],
104    [sed_cv_libcp_needed=yes],
105    [sed_cv_libcp_needed="assuming no"])
106])
107if test "$sed_cv_libcp_needed" = yes; then
108  LIBS="-lcP $LIBS"
109fi
110
111AC_CHECK_HEADERS_ONCE(locale.h errno.h wchar.h wctype.h mcheck.h,
112                      [], [], [AC_INCLUDES_DEFAULT])
113AC_C_CONST
114AC_TYPE_SIZE_T
115
116AM_GNU_GETTEXT_VERSION([0.19.2])
117AM_GNU_GETTEXT([external])
118
119AC_CHECK_FUNCS_ONCE(isatty isascii memcpy strchr strtoul lstat readlink
120                    popen pathconf fchown fchmod setlocale)
121
122# Check whether we are able to follow symlinks
123if test "$ac_cv_func_lstat:$ac_cv_func_readlink" = yes:yes; then
124   AC_DEFINE([ENABLE_FOLLOW_SYMLINKS], ,
125             [Follow symlinks when processing in place])
126fi
127AM_CONDITIONAL([TEST_SYMLINKS],
128          [test "$ac_cv_func_lstat:$ac_cv_func_readlink" = yes:yes])
129
130AC_ARG_ENABLE(i18n,
131[  --disable-i18n          disable internationalization (default=enabled)], ,
132enable_i18n=yes)
133if test "x$enable_i18n" = xno; then
134  ac_cv_func_wcscoll=no
135fi
136
137
138# Determine whether we should run UTF-8 tests by checking if cyrillic
139# letters are case-folded properly.  The test for UTF-8 locales (both
140# in general and specifically for a Russian one) is a bit weak, but it
141# should match exactly what is done in the testsuite.  In fact, sed's
142# logic is portable (though testing it requires care) so it is enough to
143# have a couple of platforms where these tests pass.  Right now, only
144# Windows and HP/UX do not support the tests.
145AC_MSG_CHECKING([whether UTF-8 case folding tests should pass])
146AC_TRY_RUN([
147#include <locale.h>
148#include <string.h>
149#include <stdlib.h>
150#include <wchar.h>
151#ifdef HAVE_WCTYPE_H
152#include <wctype.h>
153#endif
154
155int test(void)
156{
157  char in[] = "\xD0\xB4";
158  char good[] = "\xD0\x94";
159  char out[10];
160  wchar_t in_wc, good_wc;
161  if (mbtowc (&in_wc, in, 3) == -1)
162    return 0;
163  if (mbtowc (&good_wc, good, 3) == -1)
164    return 0;
165  if (towupper (in_wc) != good_wc)
166    return 0;
167  if (wctomb (out, good_wc) != 2)
168    return 0;
169  if (memcmp (out, good, 2))
170    return 0;
171  return 1;
172}
173
174int main()
175{
176  char *old;
177  int len;
178
179  /* Try hardcoding a Russian UTF-8 locale.  If the name "ru_RU.UTF-8"
180     is invalid, use setlocale again just to get the current locale.  */
181  old = setlocale (LC_CTYPE, "ru_RU.UTF-8");
182  if (old)
183    {
184      if (test())
185        exit (0);
186    }
187  else
188    old = setlocale (LC_CTYPE, "C");
189
190  /* Maybe cyrillic case folding is implemented for all UTF-8 locales.
191     If the current locale is not UTF-8, the test will be skipped.  */
192  len = strlen (old);
193  if ((len > 6 && !strcmp (old + len - 6, ".UTF-8"))
194      || (len > 6 && !strcmp (old + len - 6, ".utf-8"))
195      || (len > 5 && !strcmp (old + len - 5, ".UTF8"))
196      || (len > 5 && !strcmp (old + len - 5, ".utf8")))
197
198    /* ok */
199    ;
200  else
201    exit (1);
202
203  /* Run the test in the detected UTF-8 locale.  */
204  setlocale (LC_CTYPE, old);
205  exit (!test ());
206}
207], [AC_MSG_RESULT([yes]); XFAIL_TESTS=],
208   [AC_MSG_RESULT([no]); XFAIL_TESTS='testsuite/utf8-1 testsuite/utf8-2 \
209                                      testsuite/utf8-3 testsuite/utf8-4'],
210   [AC_MSG_RESULT([don't care (cross compiling)]); XFAIL_TESTS=])
211
212# Under MinGW, the bsd.sh test fails because of the EOF character (^Z).
213case $host in
214  *mingw*) XFAIL_TESTS="$XFAIL_TESTS bsd" ;;
215  *) ;;
216esac
217AC_SUBST([XFAIL_TESTS])
218
219AC_ARG_ENABLE([gcc-warnings],
220  [AS_HELP_STRING([--enable-gcc-warnings],
221     [turn on many GCC warnings (for developers; best with GNU make)])],
222  [case $enableval in
223     yes|no) ;;
224     *)      AC_MSG_ERROR([bad value $enableval for gcc-warnings option]) ;;
225   esac
226   gl_gcc_warnings=$enableval],
227  [
228   # GCC provides fine-grained control over diagnostics which
229   # is used in gnulib for example to suppress warnings from
230   # certain sections of code.  So if this is available and
231   # we're running from a git repo, then auto enable the warnings.
232   gl_gcc_warnings=no
233   gl_GCC_VERSION_IFELSE([4], [6],
234                         [test -d "$srcdir"/.git \
235                          && ! test -f "$srcdir"/.tarball-version \
236                          && gl_gcc_warnings=yes])]
237)
238
239if test "$gl_gcc_warnings" = yes; then
240  gl_WARN_ADD([-Werror], [WERROR_CFLAGS])
241  AC_SUBST([WERROR_CFLAGS])
242
243  nw=
244  # This, $nw, is the list of warnings we disable.
245  nw="$nw -Wdeclaration-after-statement" # too useful to forbid
246  nw="$nw -Wsystem-headers"         # Don't let system headers trigger warnings
247  nw="$nw -Wsign-conversion"        # Too many warnings for now
248  nw="$nw -Wformat-nonliteral"      # who.c and pinky.c strftime uses
249  nw="$nw -Wswitch-default"         # Too many warnings for now
250
251  gl_MANYWARN_ALL_GCC([ws])
252  gl_MANYWARN_COMPLEMENT([ws], [$ws], [$nw])
253  for w in $ws; do
254    gl_WARN_ADD([$w])
255  done
256  gl_WARN_ADD([-Wno-sign-compare])     # Too many warnings for now
257
258  # clang is unduly picky about some things.
259  AC_CACHE_CHECK([whether the compiler is clang], [utils_cv_clang],
260    [AC_COMPILE_IFELSE(
261       [AC_LANG_PROGRAM([[
262            #ifndef __clang__
263              #error "not clang"
264            #endif
265          ]])],
266       [utils_cv_clang=yes],
267       [utils_cv_clang=no])])
268  if test $utils_cv_clang = yes; then
269    gl_WARN_ADD([-Wno-format-extra-args])
270    gl_WARN_ADD([-Wno-tautological-constant-out-of-range-compare])
271  fi
272
273  gl_WARN_ADD([-fdiagnostics-show-option])
274  gl_WARN_ADD([-funit-at-a-time])
275
276  AC_SUBST([WARN_CFLAGS])
277
278  AC_DEFINE([lint], [1], [Define to 1 if the compiler is checking for lint.])
279  AH_VERBATIM([FORTIFY_SOURCE],
280  [/* Enable compile-time and run-time bounds-checking, and some warnings,
281      without upsetting glibc 2.15+. */
282   #if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
283   # define _FORTIFY_SOURCE 2
284   #endif
285  ])
286  AC_DEFINE([GNULIB_PORTCHECK], [1], [enable some gnulib portability checks])
287
288  # For gnulib-tests, the set is slightly smaller still.
289  nw=
290  gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
291                         [$WARN_CFLAGS], [$nw])
292  AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
293fi
294
295AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes])
296
297# Perl is needed for help2man
298AC_PATH_PROG([PERL], [perl])
299
300# building from tarball?
301built_from_tarball=no
302test -f "$srcdir"/.tarball-version && \
303  ! test -d "$srcdir/.git" && \
304  built_from_tarball=yes
305
306# Can the man page be built?
307# Perl needed for help2man, executing sed needed for 'sed --help'
308can_rebuild_man_page=no
309test -n "$PERL" && \
310  test "$cross_compiling" != yes && \
311  can_rebuild_man_page=yes
312
313# Build the man page when
314# building from git and rebuilding is possible.
315AM_CONDITIONAL([BUILD_MAN_PAGE],
316 [test "$built_from_tarball" = no && \
317    test "$can_rebuild_man_page" = yes])
318
319# Create a stub man page instead of failing when
320# building from git and rebuilding is not possible.
321AM_CONDITIONAL([BUILD_DUMMY_MAN_PAGE],
322 [test "$built_from_tarball" = no && \
323    test "$can_rebuild_man_page" = no])
324
325
326# This is needed when building outside the source dir
327# with --disable-dependency-tracking, see https://bugs.gnu.org/25371
328AS_MKDIR_P([lib])
329AS_MKDIR_P([sed])
330AS_MKDIR_P([doc])
331AS_MKDIR_P([testsuite])
332
333AC_CONFIG_FILES([
334  Makefile
335  po/Makefile.in
336  gnulib-tests/Makefile
337])
338AC_OUTPUT
339