]>
Commit | Line | Data |
---|---|---|
8c44d3ec AD |
1 | # Macro to add for using GNU gettext. |
2 | # Ulrich Drepper <drepper@cygnus.com>, 1995. | |
3 | # | |
4 | # This file can be copied and used freely without restrictions. It can | |
5 | # be used in projects which are not available under the GNU Public License | |
6 | # but which still want to provide support for the GNU gettext functionality. | |
7 | # Please note that the actual code is *not* freely available. | |
8 | ||
9 | # serial 109 | |
10 | ||
11 | AC_PREREQ(2.13) dnl Minimum Autoconf version required. | |
12 | ||
13 | AC_DEFUN(AM_WITH_NLS, | |
14 | [AC_MSG_CHECKING([whether NLS is requested]) | |
15 | dnl Default is enabled NLS | |
16 | AC_ARG_ENABLE(nls, | |
17 | [ --disable-nls do not use Native Language Support], | |
18 | USE_NLS=$enableval, USE_NLS=yes) | |
19 | AC_MSG_RESULT($USE_NLS) | |
20 | AC_SUBST(USE_NLS) | |
21 | ||
22 | USE_INCLUDED_LIBINTL=no | |
23 | ||
24 | dnl If we use NLS figure out what method | |
25 | if test "$USE_NLS" = "yes"; then | |
26 | AC_DEFINE(ENABLE_NLS, 1, [Define to 1 if NLS is requested.]) | |
27 | AC_MSG_CHECKING([whether included gettext is requested]) | |
28 | AC_ARG_WITH(included-gettext, | |
29 | [ --with-included-gettext use the GNU gettext library included here], | |
30 | nls_cv_force_use_gnu_gettext=$withval, | |
31 | nls_cv_force_use_gnu_gettext=no) | |
32 | AC_MSG_RESULT($nls_cv_force_use_gnu_gettext) | |
33 | ||
34 | nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext" | |
35 | if test "$nls_cv_force_use_gnu_gettext" != "yes"; then | |
36 | dnl User does not insist on using GNU NLS library. Figure out what | |
37 | dnl to use. If gettext or catgets are available (in this order) we | |
38 | dnl use this. Else we have to fall back to GNU NLS library. | |
39 | dnl catgets is only used if permitted by option --with-catgets. | |
40 | nls_cv_header_intl= | |
41 | nls_cv_header_libgt= | |
42 | CATOBJEXT=NONE | |
43 | ||
44 | AC_CHECK_HEADER(libintl.h, | |
45 | [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc, | |
46 | [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")], | |
47 | gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)]) | |
48 | ||
49 | if test "$gt_cv_func_gettext_libc" != "yes"; then | |
50 | AC_CHECK_LIB(intl, bindtextdomain, | |
51 | [AC_CHECK_LIB(intl, gettext)]) | |
52 | fi | |
53 | ||
54 | if test "$gt_cv_func_gettext_libc" = "yes" \ | |
55 | || test "$ac_cv_lib_intl_gettext" = "yes"; then | |
56 | AC_DEFINE(HAVE_GETTEXT, 1, | |
57 | [Define to 1 if you have gettext and don't want to use GNU gettext.]) | |
58 | AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, | |
59 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl | |
60 | if test "$MSGFMT" != "no"; then | |
61 | AC_CHECK_FUNCS(dcgettext) | |
62 | AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) | |
63 | AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, | |
64 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :) | |
65 | AC_TRY_LINK(, [extern int _nl_msg_cat_cntr; | |
66 | return _nl_msg_cat_cntr], | |
67 | [CATOBJEXT=.gmo | |
68 | DATADIRNAME=share], | |
69 | [CATOBJEXT=.mo | |
70 | DATADIRNAME=lib]) | |
71 | INSTOBJEXT=.mo | |
72 | fi | |
73 | fi | |
74 | ]) | |
75 | ||
76 | if test "$CATOBJEXT" = "NONE"; then | |
77 | AC_MSG_CHECKING([whether catgets can be used]) | |
78 | AC_ARG_WITH(catgets, | |
79 | [ --with-catgets use catgets functions if available], | |
80 | nls_cv_use_catgets=$withval, nls_cv_use_catgets=no) | |
81 | AC_MSG_RESULT($nls_cv_use_catgets) | |
82 | ||
83 | if test "$nls_cv_use_catgets" = "yes"; then | |
84 | dnl No gettext in C library. Try catgets next. | |
85 | AC_CHECK_LIB(i, main) | |
86 | AC_CHECK_FUNC(catgets, | |
87 | [AC_DEFINE(HAVE_CATGETS, 1, | |
88 | [Define as 1 if you have \`catgets' and don't want to use GNU gettext.]) | |
89 | INTLOBJS="\$(CATOBJS)" | |
90 | AC_PATH_PROG(GENCAT, gencat, no)dnl | |
91 | if test "$GENCAT" != "no"; then | |
92 | AC_PATH_PROG(GMSGFMT, gmsgfmt, no) | |
93 | if test "$GMSGFMT" = "no"; then | |
94 | AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt, | |
95 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no) | |
96 | fi | |
97 | AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, | |
98 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :) | |
99 | USE_INCLUDED_LIBINTL=yes | |
100 | CATOBJEXT=.cat | |
101 | INSTOBJEXT=.cat | |
102 | DATADIRNAME=lib | |
103 | INTLDEPS='$(top_builddir)/intl/libintl.a' | |
104 | INTLLIBS=$INTLDEPS | |
105 | LIBS=`echo $LIBS | sed -e 's/-lintl//'` | |
106 | nls_cv_header_intl=intl/libintl.h | |
107 | nls_cv_header_libgt=intl/libgettext.h | |
108 | fi]) | |
109 | fi | |
110 | fi | |
111 | ||
112 | if test "$CATOBJEXT" = "NONE"; then | |
113 | dnl Neither gettext nor catgets in included in the C library. | |
114 | dnl Fall back on GNU gettext library. | |
115 | nls_cv_use_gnu_gettext=yes | |
116 | fi | |
117 | fi | |
118 | ||
119 | if test "$nls_cv_use_gnu_gettext" = "yes"; then | |
120 | dnl Mark actions used to generate GNU NLS library. | |
121 | INTLOBJS="\$(GETTOBJS)" | |
122 | AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt, | |
123 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt) | |
124 | AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT) | |
125 | AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext, | |
126 | [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :) | |
127 | AC_SUBST(MSGFMT) | |
128 | USE_INCLUDED_LIBINTL=yes | |
129 | CATOBJEXT=.gmo | |
130 | INSTOBJEXT=.mo | |
131 | DATADIRNAME=share | |
132 | INTLDEPS='$(top_builddir)/intl/libintl.a' | |
133 | INTLLIBS=$INTLDEPS | |
134 | LIBS=`echo $LIBS | sed -e 's/-lintl//'` | |
135 | nls_cv_header_intl=intl/libintl.h | |
136 | nls_cv_header_libgt=intl/libgettext.h | |
137 | fi | |
138 | ||
139 | dnl Test whether we really found GNU xgettext. | |
140 | if test "$XGETTEXT" != ":"; then | |
141 | dnl If it is no GNU xgettext we define it as : so that the | |
142 | dnl Makefiles still can work. | |
143 | if $XGETTEXT --omit-header /dev/null 2> /dev/null; then | |
144 | : ; | |
145 | else | |
146 | AC_MSG_RESULT( | |
147 | [found xgettext program is not GNU xgettext; ignore it]) | |
148 | XGETTEXT=":" | |
149 | fi | |
150 | fi | |
151 | ||
152 | # We need to process the po/ directory. | |
153 | POSUB=po | |
154 | else | |
155 | DATADIRNAME=share | |
156 | nls_cv_header_intl=intl/libintl.h | |
157 | nls_cv_header_libgt=intl/libgettext.h | |
158 | fi | |
159 | if test -z "$nls_cv_header_intl"; then | |
160 | # Clean out junk possibly left behind by a previous configuration. | |
161 | rm -f intl/libintl.h | |
162 | fi | |
163 | AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl) | |
164 | AC_OUTPUT_COMMANDS( | |
165 | [case "$CONFIG_FILES" in *po/Makefile.in*) | |
166 | sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile | |
167 | esac]) | |
168 | ||
169 | ||
170 | # If this is used in GNU gettext we have to set USE_NLS to `yes' | |
171 | # because some of the sources are only built for this goal. | |
172 | if test "$PACKAGE" = gettext; then | |
173 | USE_NLS=yes | |
174 | USE_INCLUDED_LIBINTL=yes | |
175 | fi | |
176 | ||
177 | dnl These rules are solely for the distribution goal. While doing this | |
178 | dnl we only have to keep exactly one list of the available catalogs | |
179 | dnl in configure.in. | |
180 | for lang in $ALL_LINGUAS; do | |
181 | GMOFILES="$GMOFILES $lang.gmo" | |
182 | POFILES="$POFILES $lang.po" | |
183 | done | |
184 | ||
185 | dnl Make all variables we use known to autoconf. | |
186 | AC_SUBST(USE_INCLUDED_LIBINTL) | |
187 | AC_SUBST(CATALOGS) | |
188 | AC_SUBST(CATOBJEXT) | |
189 | AC_SUBST(DATADIRNAME) | |
190 | AC_SUBST(GMOFILES) | |
191 | AC_SUBST(INSTOBJEXT) | |
192 | AC_SUBST(INTLDEPS) | |
193 | AC_SUBST(INTLLIBS) | |
194 | AC_SUBST(INTLOBJS) | |
195 | AC_SUBST(POFILES) | |
196 | AC_SUBST(POSUB) | |
197 | ]) | |
198 | ||
199 | AC_DEFUN(AM_GNU_GETTEXT, | |
200 | [AC_REQUIRE([AC_PROG_MAKE_SET])dnl | |
201 | AC_REQUIRE([AC_PROG_CC])dnl | |
202 | AC_REQUIRE([AC_PROG_RANLIB])dnl | |
203 | AC_REQUIRE([AC_ISC_POSIX])dnl | |
204 | AC_REQUIRE([AC_HEADER_STDC])dnl | |
205 | AC_REQUIRE([AC_C_CONST])dnl | |
206 | AC_REQUIRE([AC_C_INLINE])dnl | |
207 | AC_REQUIRE([AC_TYPE_OFF_T])dnl | |
208 | AC_REQUIRE([AC_TYPE_SIZE_T])dnl | |
209 | AC_REQUIRE([AC_FUNC_ALLOCA])dnl | |
210 | AC_REQUIRE([AC_FUNC_MMAP])dnl | |
211 | ||
212 | AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \ | |
213 | unistd.h sys/param.h]) | |
214 | AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \ | |
215 | strdup __argz_count __argz_stringify __argz_next]) | |
216 | ||
217 | if test "${ac_cv_func_stpcpy+set}" != "set"; then | |
218 | AC_CHECK_FUNCS(stpcpy) | |
219 | fi | |
220 | if test "${ac_cv_func_stpcpy}" = "yes"; then | |
221 | AC_DEFINE(HAVE_STPCPY, 1, | |
222 | [Define to 1 if you have the \`stpcpy' function.]) | |
223 | fi | |
224 | ||
225 | AM_LC_MESSAGES | |
226 | AM_WITH_NLS | |
227 | ||
228 | if test "x$CATOBJEXT" != "x"; then | |
229 | if test "x$ALL_LINGUAS" = "x"; then | |
230 | LINGUAS= | |
231 | else | |
232 | AC_MSG_CHECKING(for catalogs to be installed) | |
233 | NEW_LINGUAS= | |
234 | for lang in ${LINGUAS=$ALL_LINGUAS}; do | |
235 | case "$ALL_LINGUAS" in | |
236 | *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;; | |
237 | esac | |
238 | done | |
239 | LINGUAS=$NEW_LINGUAS | |
240 | AC_MSG_RESULT($LINGUAS) | |
241 | fi | |
242 | ||
243 | dnl Construct list of names of catalog files to be constructed. | |
244 | if test -n "$LINGUAS"; then | |
245 | for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done | |
246 | fi | |
247 | fi | |
248 | ||
249 | dnl The reference to <locale.h> in the installed <libintl.h> file | |
250 | dnl must be resolved because we cannot expect the users of this | |
251 | dnl to define HAVE_LOCALE_H. | |
252 | if test $ac_cv_header_locale_h = yes; then | |
253 | INCLUDE_LOCALE_H="#include <locale.h>" | |
254 | else | |
255 | INCLUDE_LOCALE_H="\ | |
256 | /* The system does not provide the header <locale.h>. Take care yourself. */" | |
257 | fi | |
258 | AC_SUBST(INCLUDE_LOCALE_H) | |
259 | ||
260 | dnl Determine which catalog format we have (if any is needed) | |
261 | dnl For now we know about two different formats: | |
262 | dnl Linux libc-5 and the normal X/Open format | |
263 | test -d intl || mkdir intl | |
264 | if test "$CATOBJEXT" = ".cat"; then | |
265 | AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen) | |
266 | ||
267 | dnl Transform the SED scripts while copying because some dumb SEDs | |
268 | dnl cannot handle comments. | |
269 | sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed | |
270 | fi | |
271 | dnl po2tbl.sed is always needed. | |
272 | sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \ | |
273 | $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed | |
274 | ||
275 | dnl In the intl/Makefile.in we have a special dependency which makes | |
276 | dnl only sense for gettext. We comment this out for non-gettext | |
277 | dnl packages. | |
278 | if test "$PACKAGE" = "gettext"; then | |
279 | GT_NO="#NO#" | |
280 | GT_YES= | |
281 | else | |
282 | GT_NO= | |
283 | GT_YES="#YES#" | |
284 | fi | |
285 | AC_SUBST(GT_NO) | |
286 | AC_SUBST(GT_YES) | |
287 | ||
288 | dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly | |
289 | dnl find the mkinstalldirs script in another subdir but ($top_srcdir). | |
290 | dnl Try to locate is. | |
291 | MKINSTALLDIRS= | |
292 | if test -n "$ac_aux_dir"; then | |
293 | MKINSTALLDIRS="\$(top_srcdir)/$ac_aux_dir/mkinstalldirs" | |
294 | fi | |
295 | if test -z "$MKINSTALLDIRS"; then | |
296 | MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs" | |
297 | fi | |
298 | AC_SUBST(MKINSTALLDIRS) | |
299 | ||
300 | dnl *** For now the libtool support in intl/Makefile is not for real. | |
301 | l= | |
302 | AC_SUBST(l) | |
303 | ||
304 | dnl Generate list of files to be processed by xgettext which will | |
305 | dnl be included in po/Makefile. | |
306 | test -d po || mkdir po | |
307 | changequote(, )dnl | |
308 | case "$srcdir" in | |
309 | .) | |
310 | posrcprefix="../" ;; | |
311 | /* | [A-Za-z]:*) | |
312 | posrcprefix="$srcdir/" ;; | |
313 | *) | |
314 | posrcprefix="../$srcdir/" ;; | |
315 | esac | |
316 | changequote([, ])dnl | |
317 | rm -f po/POTFILES | |
318 | sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \ | |
319 | < $srcdir/po/POTFILES.in > po/POTFILES | |
320 | ]) |