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