Bump version for development.
[libpwmd.git] / m4 / gettext.m4
blob16f9db187947991d295132f310e0bfee5a690ff2
1 # gettext.m4 serial 78 (gettext-0.22.4)
2 dnl Copyright (C) 1995-2014, 2016, 2018-2023 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6 dnl
7 dnl This file can be used in projects which are not available under
8 dnl the GNU General Public License or the GNU Lesser General Public
9 dnl License but which still want to provide support for the GNU gettext
10 dnl functionality.
11 dnl Please note that the actual code of the GNU gettext library is covered
12 dnl by the GNU Lesser General Public License, and the rest of the GNU
13 dnl gettext package is covered by the GNU General Public License.
14 dnl They are *not* in the public domain.
16 dnl Authors:
17 dnl   Ulrich Drepper <drepper@cygnus.com>, 1995-2000.
18 dnl   Bruno Haible <haible@clisp.cons.org>, 2000-2006, 2008-2010.
20 dnl Macro to add for using GNU gettext.
22 dnl Usage: AM_GNU_GETTEXT([INTLSYMBOL], [NEEDSYMBOL], [INTLDIR]).
23 dnl INTLSYMBOL must be one of 'external', 'use-libtool', 'here'.
24 dnl    INTLSYMBOL should be 'external' for packages other than GNU gettext.
25 dnl    It should be 'use-libtool' for the packages 'gettext-runtime' and
26 dnl    'gettext-tools'.
27 dnl    It should be 'here' for the package 'gettext-runtime/intl'.
28 dnl    If INTLSYMBOL is 'here', then a libtool library
29 dnl    $(top_builddir)/libintl.la will be created (shared and/or static,
30 dnl    depending on --{enable,disable}-{shared,static} and on the presence of
31 dnl    AM-DISABLE-SHARED).
32 dnl If NEEDSYMBOL is specified and is 'need-ngettext', then GNU gettext
33 dnl    implementations (in libc or libintl) without the ngettext() function
34 dnl    will be ignored.  If NEEDSYMBOL is specified and is
35 dnl    'need-formatstring-macros', then GNU gettext implementations that don't
36 dnl    support the ISO C 99 <inttypes.h> formatstring macros will be ignored.
37 dnl INTLDIR is used to find the intl libraries.  If empty,
38 dnl    the value '$(top_builddir)/intl/' is used.
39 dnl
40 dnl The result of the configuration is one of three cases:
41 dnl 1) GNU gettext, as included in the intl subdirectory, will be compiled
42 dnl    and used.
43 dnl    Catalog format: GNU --> install in $(datadir)
44 dnl    Catalog extension: .mo after installation, .gmo in source tree
45 dnl 2) GNU gettext has been found in the system's C library.
46 dnl    Catalog format: GNU --> install in $(datadir)
47 dnl    Catalog extension: .mo after installation, .gmo in source tree
48 dnl 3) No internationalization, always use English msgid.
49 dnl    Catalog format: none
50 dnl    Catalog extension: none
51 dnl If INTLSYMBOL is 'external', only cases 2 and 3 can occur.
52 dnl The use of .gmo is historical (it was needed to avoid overwriting the
53 dnl GNU format catalogs when building on a platform with an X/Open gettext),
54 dnl but we keep it in order not to force irrelevant filename changes on the
55 dnl maintainers.
56 dnl
57 AC_DEFUN([AM_GNU_GETTEXT],
59   dnl Argument checking.
60   m4_if([$1], [], , [m4_if([$1], [external], , [m4_if([$1], [use-libtool], , [m4_if([$1], [here], ,
61     [errprint([ERROR: invalid first argument to AM_GNU_GETTEXT
62 ])])])])])
63   m4_if(m4_if([$1], [], [old])[]m4_if([$1], [no-libtool], [old]), [old],
64     [errprint([ERROR: Use of AM_GNU_GETTEXT without [external] argument is no longer supported.
65 ])])
66   m4_if([$2], [], , [m4_if([$2], [need-ngettext], , [m4_if([$2], [need-formatstring-macros], ,
67     [errprint([ERROR: invalid second argument to AM_GNU_GETTEXT
68 ])])])])
69   define([gt_building_libintl_in_same_build_tree],
70     m4_if([$1], [use-libtool], [yes], [m4_if([$1], [here], [yes], [no])]))
71   gt_NEEDS_INIT
72   AM_GNU_GETTEXT_NEED([$2])
74   AC_REQUIRE([AM_PO_SUBDIRS])dnl
76   dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
77   AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
78   AC_REQUIRE([AC_LIB_RPATH])
80   dnl Sometimes libintl requires libiconv, so first search for libiconv.
81   dnl Ideally we would do this search only after the
82   dnl      if test "$USE_NLS" = "yes"; then
83   dnl        if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
84   dnl tests. But if configure.ac invokes AM_ICONV after AM_GNU_GETTEXT
85   dnl the configure script would need to contain the same shell code
86   dnl again, outside any 'if'. There are two solutions:
87   dnl - Invoke AM_ICONV_LINKFLAGS_BODY here, outside any 'if'.
88   dnl - Control the expansions in more detail using AC_PROVIDE_IFELSE.
89   dnl Since AC_PROVIDE_IFELSE is not documented, we avoid it.
90   m4_if(gt_building_libintl_in_same_build_tree, yes, , [
91     AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
92   ])
94   dnl Sometimes, on Mac OS X, libintl requires linking with CoreFoundation.
95   gt_INTL_MACOSX
97   dnl Set USE_NLS.
98   AC_REQUIRE([AM_NLS])
100   m4_if(gt_building_libintl_in_same_build_tree, yes, [
101     USE_INCLUDED_LIBINTL=no
102   ])
103   LIBINTL=
104   LTLIBINTL=
105   POSUB=
107   dnl Add a version number to the cache macros.
108   case " $gt_needs " in
109     *" need-formatstring-macros "*) gt_api_version=3 ;;
110     *" need-ngettext "*) gt_api_version=2 ;;
111     *) gt_api_version=1 ;;
112   esac
113   gt_func_gnugettext_libc="gt_cv_func_gnugettext${gt_api_version}_libc"
114   gt_func_gnugettext_libintl="gt_cv_func_gnugettext${gt_api_version}_libintl"
116   dnl If we use NLS figure out what method
117   if test "$USE_NLS" = "yes"; then
118     gt_use_preinstalled_gnugettext=no
119     m4_if(gt_building_libintl_in_same_build_tree, yes, [
120       AC_MSG_CHECKING([whether included gettext is requested])
121       AC_ARG_WITH([included-gettext],
122         [  --with-included-gettext use the GNU gettext library included here],
123         nls_cv_force_use_gnu_gettext=$withval,
124         nls_cv_force_use_gnu_gettext=no)
125       AC_MSG_RESULT([$nls_cv_force_use_gnu_gettext])
127       nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
128       if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
129     ])
130         dnl User does not insist on using GNU NLS library.  Figure out what
131         dnl to use.  If GNU gettext is available we use this.  Else we have
132         dnl to fall back to GNU NLS library.
134         if test $gt_api_version -ge 3; then
135           gt_revision_test_code='
136 #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
137 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 0 : -1)
138 #endif
139 changequote(,)dnl
140 typedef int array [2 * (__GNU_GETTEXT_SUPPORTED_REVISION(0) >= 1) - 1];
141 changequote([,])dnl
143         else
144           gt_revision_test_code=
145         fi
146         if test $gt_api_version -ge 2; then
147           gt_expression_test_code=' + * ngettext ("", "", 0)'
148         else
149           gt_expression_test_code=
150         fi
152         AC_CACHE_CHECK([for GNU gettext in libc], [$gt_func_gnugettext_libc],
153          [AC_LINK_IFELSE(
154             [AC_LANG_PROGRAM(
155                [[
156 #include <libintl.h>
157 #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
158 extern int _nl_msg_cat_cntr;
159 extern int *_nl_domain_bindings;
160 #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_domain_bindings)
161 #else
162 #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
163 #endif
164 $gt_revision_test_code
165                ]],
166                [[
167 bindtextdomain ("", "");
168 return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
169                ]])],
170             [eval "$gt_func_gnugettext_libc=yes"],
171             [eval "$gt_func_gnugettext_libc=no"])])
173         if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" != "yes"; }; then
174           dnl Sometimes libintl requires libiconv, so first search for libiconv.
175           m4_if(gt_building_libintl_in_same_build_tree, yes, , [
176             AM_ICONV_LINK
177           ])
178           dnl Search for libintl and define LIBINTL, LTLIBINTL and INCINTL
179           dnl accordingly. Don't use AC_LIB_LINKFLAGS_BODY([intl],[iconv])
180           dnl because that would add "-liconv" to LIBINTL and LTLIBINTL
181           dnl even if libiconv doesn't exist.
182           AC_LIB_LINKFLAGS_BODY([intl])
183           AC_CACHE_CHECK([for GNU gettext in libintl],
184             [$gt_func_gnugettext_libintl],
185            [gt_save_CPPFLAGS="$CPPFLAGS"
186             CPPFLAGS="$CPPFLAGS $INCINTL"
187             gt_save_LIBS="$LIBS"
188             LIBS="$LIBS $LIBINTL"
189             dnl Now see whether libintl exists and does not depend on libiconv.
190             AC_LINK_IFELSE(
191               [AC_LANG_PROGRAM(
192                  [[
193 #include <libintl.h>
194 #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
195 extern int _nl_msg_cat_cntr;
196 extern
197 #ifdef __cplusplus
199 #endif
200 const char *_nl_expand_alias (const char *);
201 #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
202 #else
203 #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
204 #endif
205 $gt_revision_test_code
206                  ]],
207                  [[
208 bindtextdomain ("", "");
209 return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
210                  ]])],
211               [eval "$gt_func_gnugettext_libintl=yes"],
212               [eval "$gt_func_gnugettext_libintl=no"])
213             dnl Now see whether libintl exists and depends on libiconv or other
214             dnl OS dependent libraries, specifically on macOS and AIX.
215             gt_LIBINTL_EXTRA="$INTL_MACOSX_LIBS"
216             AC_REQUIRE([AC_CANONICAL_HOST])
217             case "$host_os" in
218               aix*) gt_LIBINTL_EXTRA="-lpthread" ;;
219             esac
220             if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" != yes; } \
221                && { test -n "$LIBICONV" || test -n "$gt_LIBINTL_EXTRA"; }; then
222               LIBS="$LIBS $LIBICONV $gt_LIBINTL_EXTRA"
223               AC_LINK_IFELSE(
224                 [AC_LANG_PROGRAM(
225                    [[
226 #include <libintl.h>
227 #ifndef __GNU_GETTEXT_SUPPORTED_REVISION
228 extern int _nl_msg_cat_cntr;
229 extern
230 #ifdef __cplusplus
232 #endif
233 const char *_nl_expand_alias (const char *);
234 #define __GNU_GETTEXT_SYMBOL_EXPRESSION (_nl_msg_cat_cntr + *_nl_expand_alias (""))
235 #else
236 #define __GNU_GETTEXT_SYMBOL_EXPRESSION 0
237 #endif
238 $gt_revision_test_code
239                    ]],
240                    [[
241 bindtextdomain ("", "");
242 return * gettext ("")$gt_expression_test_code + __GNU_GETTEXT_SYMBOL_EXPRESSION
243                    ]])],
244                 [LIBINTL="$LIBINTL $LIBICONV $gt_LIBINTL_EXTRA"
245                  LTLIBINTL="$LTLIBINTL $LTLIBICONV $gt_LIBINTL_EXTRA"
246                  eval "$gt_func_gnugettext_libintl=yes"
247                 ])
248             fi
249             CPPFLAGS="$gt_save_CPPFLAGS"
250             LIBS="$gt_save_LIBS"])
251         fi
253         dnl If an already present or preinstalled GNU gettext() is found,
254         dnl use it.  But if this macro is used in GNU gettext, and GNU
255         dnl gettext is already preinstalled in libintl, we update this
256         dnl libintl.  (Cf. the install rule in intl/Makefile.in.)
257         if { eval "gt_val=\$$gt_func_gnugettext_libc"; test "$gt_val" = "yes"; } \
258            || { { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; } \
259                 && test "$PACKAGE" != gettext-runtime \
260                 && test "$PACKAGE" != gettext-tools \
261                 && test "$PACKAGE" != libintl; }; then
262           gt_use_preinstalled_gnugettext=yes
263         else
264           dnl Reset the values set by searching for libintl.
265           LIBINTL=
266           LTLIBINTL=
267           INCINTL=
268         fi
270     m4_if(gt_building_libintl_in_same_build_tree, yes, [
271         if test "$gt_use_preinstalled_gnugettext" != "yes"; then
272           dnl GNU gettext is not found in the C library.
273           dnl Fall back on included GNU gettext library.
274           nls_cv_use_gnu_gettext=yes
275         fi
276       fi
278       if test "$nls_cv_use_gnu_gettext" = "yes"; then
279         dnl Mark actions used to generate GNU NLS library.
280         USE_INCLUDED_LIBINTL=yes
281         LIBINTL="m4_if([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LIBICONV $LIBTHREAD"
282         LTLIBINTL="m4_if([$3],[],\${top_builddir}/intl,[$3])/libintl.la $LTLIBICONV $LTLIBTHREAD"
283         LIBS=`echo " $LIBS " | sed -e 's/ -lintl / /' -e 's/^ //' -e 's/ $//'`
284       fi
286       CATOBJEXT=
287       if test "$gt_use_preinstalled_gnugettext" = "yes" \
288          || test "$nls_cv_use_gnu_gettext" = "yes"; then
289         dnl Mark actions to use GNU gettext tools.
290         CATOBJEXT=.gmo
291       fi
292     ])
294     if test -n "$INTL_MACOSX_LIBS"; then
295       if test "$gt_use_preinstalled_gnugettext" = "yes" \
296          || test "$nls_cv_use_gnu_gettext" = "yes"; then
297         dnl Some extra flags are needed during linking.
298         LIBINTL="$LIBINTL $INTL_MACOSX_LIBS"
299         LTLIBINTL="$LTLIBINTL $INTL_MACOSX_LIBS"
300       fi
301     fi
303     if test "$gt_use_preinstalled_gnugettext" = "yes" \
304        || test "$nls_cv_use_gnu_gettext" = "yes"; then
305       AC_DEFINE([ENABLE_NLS], [1],
306         [Define to 1 if translation of program messages to the user's native language
307    is requested.])
308     else
309       USE_NLS=no
310     fi
311   fi
313   AC_MSG_CHECKING([whether to use NLS])
314   AC_MSG_RESULT([$USE_NLS])
315   if test "$USE_NLS" = "yes"; then
316     AC_MSG_CHECKING([where the gettext function comes from])
317     if test "$gt_use_preinstalled_gnugettext" = "yes"; then
318       if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
319         gt_source="external libintl"
320       else
321         gt_source="libc"
322       fi
323     else
324       gt_source="included intl directory"
325     fi
326     AC_MSG_RESULT([$gt_source])
327   fi
329   if test "$USE_NLS" = "yes"; then
331     if test "$gt_use_preinstalled_gnugettext" = "yes"; then
332       if { eval "gt_val=\$$gt_func_gnugettext_libintl"; test "$gt_val" = "yes"; }; then
333         AC_MSG_CHECKING([how to link with libintl])
334         AC_MSG_RESULT([$LIBINTL])
335         AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCINTL])
336       fi
338       dnl For backward compatibility. Some packages may be using this.
339       AC_DEFINE([HAVE_GETTEXT], [1],
340        [Define if the GNU gettext() function is already present or preinstalled.])
341       AC_DEFINE([HAVE_DCGETTEXT], [1],
342        [Define if the GNU dcgettext() function is already present or preinstalled.])
343     fi
345     dnl We need to process the po/ directory.
346     POSUB=po
347   fi
349   m4_if(gt_building_libintl_in_same_build_tree, yes, [
350     dnl Make all variables we use known to autoconf.
351     AC_SUBST([USE_INCLUDED_LIBINTL])
352     AC_SUBST([CATOBJEXT])
353   ])
355   m4_if(gt_building_libintl_in_same_build_tree, yes, [], [
356     dnl For backward compatibility. Some Makefiles may be using this.
357     INTLLIBS="$LIBINTL"
358     AC_SUBST([INTLLIBS])
359   ])
361   dnl Make all documented variables known to autoconf.
362   AC_SUBST([LIBINTL])
363   AC_SUBST([LTLIBINTL])
364   AC_SUBST([POSUB])
366   dnl Define localedir_c and localedir_c_make.
367   dnl Find the final value of localedir.
368   gt_save_prefix="${prefix}"
369   gt_save_datarootdir="${datarootdir}"
370   gt_save_localedir="${localedir}"
371   dnl Unfortunately, prefix gets only finally determined at the end of
372   dnl configure.
373   if test "X$prefix" = "XNONE"; then
374     prefix="$ac_default_prefix"
375   fi
376   eval datarootdir="$datarootdir"
377   eval localedir="$localedir"
378   gl_BUILD_TO_HOST([localedir])
379   localedir="${gt_save_localedir}"
380   datarootdir="${gt_save_datarootdir}"
381   prefix="${gt_save_prefix}"
385 dnl gt_NEEDS_INIT ensures that the gt_needs variable is initialized.
386 m4_define([gt_NEEDS_INIT],
388   m4_divert_text([DEFAULTS], [gt_needs=])
389   m4_define([gt_NEEDS_INIT], [])
393 dnl Usage: AM_GNU_GETTEXT_NEED([NEEDSYMBOL])
394 AC_DEFUN([AM_GNU_GETTEXT_NEED],
396   m4_divert_text([INIT_PREPARE], [gt_needs="$gt_needs $1"])
400 dnl Usage: AM_GNU_GETTEXT_VERSION([gettext-version])
401 AC_DEFUN([AM_GNU_GETTEXT_VERSION], [])
404 dnl Usage: AM_GNU_GETTEXT_REQUIRE_VERSION([gettext-version])
405 AC_DEFUN([AM_GNU_GETTEXT_REQUIRE_VERSION], [])