add third argument to the AC_DEFINE calls, so users of the macro don't
[platform/upstream/glib.git] / m4macros / glib-gettext.m4
1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995.
3 #
4 # Modified to never use included libintl. 
5 # Owen Taylor <otaylor@redhat.com>, 12/15/1998
6 #
7 #
8 # This file can be copied and used freely without restrictions.  It can
9 # be used in projects which are not available under the GNU Public License
10 # but which still want to provide support for the GNU gettext functionality.
11 # Please note that the actual code is *not* freely available.
12 #
13 #
14 # If you make changes to this file, you MUST update the copy in
15 # acinclude.m4. [ aclocal dies on duplicate macros, so if
16 # we run 'aclocal -I macros/' then we'll run into problems
17 # once we've installed glib-gettext.m4 :-( ]
18 #
19
20 # serial 5
21
22 AC_DEFUN(AM_GLIB_WITH_NLS,
23   dnl NLS is obligatory
24   [USE_NLS=yes
25     AC_SUBST(USE_NLS)
26
27     dnl Figure out what method
28     nls_cv_force_use_gnu_gettext="no"
29
30     nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
31     if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
32       dnl User does not insist on using GNU NLS library.  Figure out what
33       dnl to use.  If gettext or catgets are available (in this order) we
34       dnl use this.  Else we have to fall back to GNU NLS library.
35       dnl catgets is only used if permitted by option --with-catgets.
36       nls_cv_header_intl=
37       nls_cv_header_libgt=
38       CATOBJEXT=NONE
39
40       AC_CHECK_HEADER(libintl.h,
41         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
42           [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
43             gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
44
45           if test "$gt_cv_func_dgettext_libc" != "yes"; then
46             AC_CHECK_LIB(intl, bindtextdomain,
47               [AC_CACHE_CHECK([for dgettext in libintl],
48                 gt_cv_func_dgettext_libintl,
49                 [AC_CHECK_LIB(intl, dgettext,
50                   gt_cv_func_dgettext_libintl=yes,
51                   gt_cv_func_dgettext_libintl=no)],
52                 gt_cv_func_dgettext_libintl=no)])
53           fi
54
55           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
56             LIBS="$LIBS -lintl";
57           fi
58
59           if test "$gt_cv_func_dgettext_libc" = "yes" \
60             || test "$gt_cv_func_dgettext_libintl" = "yes"; then
61             AC_DEFINE(HAVE_GETTEXT,1,
62               [Define if the GNU gettext() function is already present or preinstalled.])
63             AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
64               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
65             if test "$MSGFMT" != "no"; then
66               AC_CHECK_FUNCS(dcgettext)
67               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
68               AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
69                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
70               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
71                              return _nl_msg_cat_cntr],
72                 [CATOBJEXT=.gmo
73                  DATADIRNAME=share],
74                 [CATOBJEXT=.mo
75                  DATADIRNAME=lib])
76               INSTOBJEXT=.mo
77             fi
78           fi
79
80           # Added by Martin Baulig 12/15/98 for libc5 systems
81           if test "$gt_cv_func_dgettext_libc" != "yes" \
82             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
83             INTLLIBS=-lintl
84             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
85           fi
86       ])
87
88       if test "$CATOBJEXT" = "NONE"; then
89         dnl Neither gettext nor catgets in included in the C library.
90         dnl Fall back on GNU gettext library.
91         nls_cv_use_gnu_gettext=yes
92       fi
93     fi
94
95     if test "$nls_cv_use_gnu_gettext" != "yes"; then
96       AC_DEFINE(ENABLE_NLS, 1,
97         [always defined to indicate that i18n is enabled])
98     else
99       dnl Unset this variable since we use the non-zero value as a flag.
100       CATOBJEXT=
101     fi
102
103     dnl Test whether we really found GNU xgettext.
104     if test "$XGETTEXT" != ":"; then
105       dnl If it is no GNU xgettext we define it as : so that the
106       dnl Makefiles still can work.
107       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
108         : ;
109       else
110         AC_MSG_RESULT(
111           [found xgettext program is not GNU xgettext; ignore it])
112         XGETTEXT=":"
113       fi
114     fi
115
116     # We need to process the po/ directory.
117     POSUB=po
118
119     AC_OUTPUT_COMMANDS(
120       [case "$CONFIG_FILES" in *po/Makefile.in*)
121         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
122       esac])
123
124     dnl These rules are solely for the distribution goal.  While doing this
125     dnl we only have to keep exactly one list of the available catalogs
126     dnl in configure.in.
127     for lang in $ALL_LINGUAS; do
128       GMOFILES="$GMOFILES $lang.gmo"
129       POFILES="$POFILES $lang.po"
130     done
131
132     dnl Make all variables we use known to autoconf.
133     AC_SUBST(CATALOGS)
134     AC_SUBST(CATOBJEXT)
135     AC_SUBST(DATADIRNAME)
136     AC_SUBST(GMOFILES)
137     AC_SUBST(INSTOBJEXT)
138     AC_SUBST(INTLDEPS)
139     AC_SUBST(INTLLIBS)
140     AC_SUBST(INTLOBJS)
141     AC_SUBST(POFILES)
142     AC_SUBST(POSUB)
143   ])
144
145 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
146   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
147    AC_REQUIRE([AC_PROG_CC])dnl
148    AC_REQUIRE([AC_PROG_RANLIB])dnl
149    AC_REQUIRE([AC_HEADER_STDC])dnl
150    AC_REQUIRE([AC_C_CONST])dnl
151    AC_REQUIRE([AC_C_INLINE])dnl
152    AC_REQUIRE([AC_TYPE_OFF_T])dnl
153    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
154    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
155    AC_REQUIRE([AC_FUNC_MMAP])dnl
156
157    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
158 unistd.h sys/param.h])
159    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
160 strdup __argz_count __argz_stringify __argz_next])
161
162    AM_LC_MESSAGES
163    AM_GLIB_WITH_NLS
164
165    if test "x$CATOBJEXT" != "x"; then
166      if test "x$ALL_LINGUAS" = "x"; then
167        LINGUAS=
168      else
169        AC_MSG_CHECKING(for catalogs to be installed)
170        NEW_LINGUAS=
171        for lang in ${LINGUAS=$ALL_LINGUAS}; do
172          case "$ALL_LINGUAS" in
173           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
174          esac
175        done
176        LINGUAS=$NEW_LINGUAS
177        AC_MSG_RESULT($LINGUAS)
178      fi
179
180      dnl Construct list of names of catalog files to be constructed.
181      if test -n "$LINGUAS"; then
182        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
183      fi
184    fi
185
186    dnl Determine which catalog format we have (if any is needed)
187    dnl For now we know about two different formats:
188    dnl   Linux libc-5 and the normal X/Open format
189    test -d po || mkdir po
190    if test "$CATOBJEXT" = ".cat"; then
191      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
192
193      dnl Transform the SED scripts while copying because some dumb SEDs
194      dnl cannot handle comments.
195      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
196    fi
197
198    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
199    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
200    dnl Try to locate is.
201    MKINSTALLDIRS=
202    if test -n "$ac_aux_dir"; then
203      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
204    fi
205    if test -z "$MKINSTALLDIRS"; then
206      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
207    fi
208    AC_SUBST(MKINSTALLDIRS)
209
210    dnl Generate list of files to be processed by xgettext which will
211    dnl be included in po/Makefile.
212    test -d po || mkdir po
213    if test "x$srcdir" != "x."; then
214      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
215        posrcprefix="$srcdir/"
216      else
217        posrcprefix="../$srcdir/"
218      fi
219    else
220      posrcprefix="../"
221    fi
222    rm -f po/POTFILES
223    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
224         < $srcdir/po/POTFILES.in > po/POTFILES
225   ])
226