Imported Upstream version 4.2.2
[platform/upstream/sed.git] / configure.ac
1 dnl Process this file with -*- autoconf -*- to produce a configure script.
2 AC_INIT([GNU sed], 4.2.2, bug-sed@gnu.org, sed)
3 AC_CONFIG_AUX_DIR(build-aux)
4 AC_CONFIG_SRCDIR([sed/sed.c])
5 AM_CONFIG_HEADER(config.h:config_h.in)
6 AC_PREREQ(2.60)
7 AM_INIT_AUTOMAKE
8
9 SED_FEATURE_VERSION=4.2.2
10 AC_DEFINE_UNQUOTED(SED_FEATURE_VERSION, "$SED_FEATURE_VERSION",
11   [Define to the version of GNU sed whose features are supported by this sed.])
12 AC_SUBST(SED_FEATURE_VERSION)
13
14 COPYRIGHT_YEAR=2012
15 AC_SUBST(COPYRIGHT_YEAR)
16
17 AC_PROG_CC
18 gl_EARLY
19 gl_INIT
20 gl_DISABLE_THREADS
21 AC_CACHE_CHECK([whether "rt" can be used with fopen], [sed_cv_fopen_rt], [
22 AC_TRY_RUN([
23 #include <stdio.h>
24 #include <errno.h>
25
26 int main()
27 {
28   FILE *fp;
29   int result;
30   errno = 0;
31   fp = fopen ("conftest.c", "rt");
32   if (fp) fclose (fp);
33   return fp ? 0 : 1;
34 }], [sed_cv_fopen_rt=yes],
35     [sed_cv_fopen_rt=no],
36     [case $host in
37        *cygwin* | *mingw*) sed_cv_fopen_rt=yes ;;
38        *) sed_cv_fopen_rt='assuming no' ;;
39      esac])])
40 if test "$sed_cv_fopen_rt" = yes; then
41   AC_DEFINE([HAVE_FOPEN_RT], [1],
42             [Defined if "rt" can be used as a mode to fopen.])
43 fi
44
45 AC_CACHE_CHECK([whether -lcP is needed], [sed_cv_libcp_needed], [
46 AC_TRY_RUN([
47 #include <stdio.h>
48 #include <errno.h>
49
50 int main()
51 {
52   FILE *fp;
53   int result;
54   errno = 0;
55   fp = fopen ("conftest.c", "r");
56   if (!fp) return 0;       /* error, assume not needed */
57   result = fflush (fp) == EOF && errno == 0;
58   fclose (fp);
59   return result;
60 }], [sed_cv_libcp_needed=no],
61     [sed_cv_libcp_needed=yes],
62     [sed_cv_libcp_needed="assuming no"])
63 ])
64 if test "$sed_cv_libcp_needed" = yes; then
65   LIBS="-lcP $LIBS"
66 fi
67
68 AC_CHECK_HEADERS_ONCE(locale.h errno.h wchar.h wctype.h mcheck.h,
69                       [], [], [AC_INCLUDES_DEFAULT])
70 AC_C_CONST
71 AC_TYPE_SIZE_T
72
73 AM_GNU_GETTEXT_VERSION(0.17)
74 AM_GNU_GETTEXT([external])
75
76 AC_CHECK_FUNCS_ONCE(isatty isascii memcpy strchr strtoul lstat readlink
77                     popen pathconf fchown fchmod setlocale)
78
79 # Check whether we are able to follow symlinks
80 if test "$ac_cv_func_lstat:$ac_cv_func_readlink" = yes:yes; then
81    AC_DEFINE(ENABLE_FOLLOW_SYMLINKS, ,[Follow symlinks when processing in place])
82 fi
83
84 AC_ARG_ENABLE(i18n,
85 [  --disable-i18n          disable internationalization (default=enabled)], ,
86 enable_i18n=yes)
87 if test "x$enable_i18n" = xno; then
88   ac_cv_func_wcscoll=no
89 fi
90
91 AC_ARG_ENABLE(regex-tests, 
92 [  --enable-regex-tests    enable regex matcher regression tests (default=yes)],
93 [if test "x$with_included_regex" = xno; then
94   enable_regex_tests=no
95 fi],
96 enable_regex_tests=$with_included_regex)
97
98 AM_CONDITIONAL(TEST_REGEX, test "x$enable_regex_tests" = xyes)
99 if test "x$enable_regex_tests" = xyes; then
100   AC_DEFINE_UNQUOTED(_REGEX_RE_COMP, 1,
101     [Include BSD functions in regex, used by the testsuite])
102 fi
103
104 # Determine whether we should run UTF-8 tests by checking if cyrillic
105 # letters are case-folded properly.  The test for UTF-8 locales (both
106 # in general and specifically for a Russian one) is a bit weak, but it
107 # should match exactly what is done in the testsuite.  In fact, sed's
108 # logic is portable (though testing it requires care) so it is enough to
109 # have a couple of platforms where these tests pass.  Right now, only
110 # Windows and HP/UX do not support the tests.
111 AC_MSG_CHECKING([whether UTF-8 case folding tests should pass])
112 AC_TRY_RUN([
113 #include <locale.h>
114 #include <string.h>
115 #include <stdlib.h>
116 #include <wchar.h>
117 #ifdef HAVE_WCTYPE_H
118 #include <wctype.h>
119 #endif
120
121 int test(void)
122 {
123   char in[] = "\xD0\xB4";
124   char good[] = "\xD0\x94";
125   char out[10];
126   wchar_t in_wc, good_wc;
127   if (mbtowc (&in_wc, in, 3) == -1)
128     return 0;
129   if (mbtowc (&good_wc, good, 3) == -1)
130     return 0;
131   if (towupper (in_wc) != good_wc)
132     return 0;
133   if (wctomb (out, good_wc) != 2)
134     return 0;
135   if (memcmp (out, good, 2))
136     return 0;
137   return 1;
138 }
139
140 int main()
141 {
142   char *old;
143   int len;
144
145   /* Try hardcoding a Russian UTF-8 locale.  If the name "ru_RU.UTF-8"
146      is invalid, use setlocale again just to get the current locale.  */
147   old = setlocale (LC_CTYPE, "ru_RU.UTF-8");
148   if (old)
149     {
150       if (test())
151         exit (0);
152     }
153   else
154     old = setlocale (LC_CTYPE, "C");
155
156   /* Maybe cyrillic case folding is implemented for all UTF-8 locales.
157      If the current locale is not UTF-8, the test will be skipped.  */
158   len = strlen (old);
159   if ((len > 6 && !strcmp (old + len - 6, ".UTF-8"))
160       || (len > 6 && !strcmp (old + len - 6, ".utf-8"))
161       || (len > 5 && !strcmp (old + len - 5, ".UTF8"))
162       || (len > 5 && !strcmp (old + len - 5, ".utf8")))
163
164     /* ok */
165     ;
166   else
167     exit (1);
168
169   /* Run the test in the detected UTF-8 locale.  */
170   setlocale (LC_CTYPE, old);
171   exit (!test ());
172 }
173 ], [AC_MSG_RESULT([yes]); XFAIL_TESTS=],
174    [AC_MSG_RESULT([no]); XFAIL_TESTS='utf8-1 utf8-2 utf8-3 utf8-4'],
175    [AC_MSG_RESULT([don't care (cross compiling)]); XFAIL_TESTS=])
176
177 # Under MinGW, the bsd.sh test fails because of the EOF character (^Z).
178 case $host in
179   *mingw*) XFAIL_TESTS="$XFAIL_TESTS bsd" ;;
180   *) ;;
181 esac
182 AC_SUBST([XFAIL_TESTS])
183
184 AC_CONFIG_FILES([testsuite/version.good:testsuite/version.gin])
185 AC_CONFIG_FILES([Makefile doc/Makefile \
186 lib/Makefile sed/Makefile testsuite/Makefile \
187 po/Makefile.in])
188 AC_OUTPUT