remove references to po2tbl
[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)
62             AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
63               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
64             if test "$MSGFMT" != "no"; then
65               AC_CHECK_FUNCS(dcgettext)
66               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
67               AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
68                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
69               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
70                              return _nl_msg_cat_cntr],
71                 [CATOBJEXT=.gmo
72                  DATADIRNAME=share],
73                 [CATOBJEXT=.mo
74                  DATADIRNAME=lib])
75               INSTOBJEXT=.mo
76             fi
77           fi
78
79           # Added by Martin Baulig 12/15/98 for libc5 systems
80           if test "$gt_cv_func_dgettext_libc" != "yes" \
81             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
82             INTLLIBS=-lintl
83             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
84           fi
85       ])
86
87       if test "$CATOBJEXT" = "NONE"; then
88         dnl Neither gettext nor catgets in included in the C library.
89         dnl Fall back on GNU gettext library.
90         nls_cv_use_gnu_gettext=yes
91       fi
92     fi
93
94     if test "$nls_cv_use_gnu_gettext" != "yes"; then
95       AC_DEFINE(ENABLE_NLS)
96     else
97       dnl Unset this variable since we use the non-zero value as a flag.
98       CATOBJEXT=
99     fi
100
101     dnl Test whether we really found GNU xgettext.
102     if test "$XGETTEXT" != ":"; then
103       dnl If it is no GNU xgettext we define it as : so that the
104       dnl Makefiles still can work.
105       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
106         : ;
107       else
108         AC_MSG_RESULT(
109           [found xgettext program is not GNU xgettext; ignore it])
110         XGETTEXT=":"
111       fi
112     fi
113
114     # We need to process the po/ directory.
115     POSUB=po
116
117     AC_OUTPUT_COMMANDS(
118       [case "$CONFIG_FILES" in *po/Makefile.in*)
119         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
120       esac])
121
122     dnl These rules are solely for the distribution goal.  While doing this
123     dnl we only have to keep exactly one list of the available catalogs
124     dnl in configure.in.
125     for lang in $ALL_LINGUAS; do
126       GMOFILES="$GMOFILES $lang.gmo"
127       POFILES="$POFILES $lang.po"
128     done
129
130     dnl Make all variables we use known to autoconf.
131     AC_SUBST(CATALOGS)
132     AC_SUBST(CATOBJEXT)
133     AC_SUBST(DATADIRNAME)
134     AC_SUBST(GMOFILES)
135     AC_SUBST(INSTOBJEXT)
136     AC_SUBST(INTLDEPS)
137     AC_SUBST(INTLLIBS)
138     AC_SUBST(INTLOBJS)
139     AC_SUBST(POFILES)
140     AC_SUBST(POSUB)
141   ])
142
143 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
144   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
145    AC_REQUIRE([AC_PROG_CC])dnl
146    AC_REQUIRE([AC_PROG_RANLIB])dnl
147    AC_REQUIRE([AC_HEADER_STDC])dnl
148    AC_REQUIRE([AC_C_CONST])dnl
149    AC_REQUIRE([AC_C_INLINE])dnl
150    AC_REQUIRE([AC_TYPE_OFF_T])dnl
151    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
152    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
153    AC_REQUIRE([AC_FUNC_MMAP])dnl
154
155    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
156 unistd.h sys/param.h])
157    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
158 strdup __argz_count __argz_stringify __argz_next])
159
160    AM_LC_MESSAGES
161    AM_GLIB_WITH_NLS
162
163    if test "x$CATOBJEXT" != "x"; then
164      if test "x$ALL_LINGUAS" = "x"; then
165        LINGUAS=
166      else
167        AC_MSG_CHECKING(for catalogs to be installed)
168        NEW_LINGUAS=
169        for lang in ${LINGUAS=$ALL_LINGUAS}; do
170          case "$ALL_LINGUAS" in
171           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
172          esac
173        done
174        LINGUAS=$NEW_LINGUAS
175        AC_MSG_RESULT($LINGUAS)
176      fi
177
178      dnl Construct list of names of catalog files to be constructed.
179      if test -n "$LINGUAS"; then
180        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
181      fi
182    fi
183
184    dnl Determine which catalog format we have (if any is needed)
185    dnl For now we know about two different formats:
186    dnl   Linux libc-5 and the normal X/Open format
187    test -d po || mkdir po
188    if test "$CATOBJEXT" = ".cat"; then
189      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
190
191      dnl Transform the SED scripts while copying because some dumb SEDs
192      dnl cannot handle comments.
193      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
194    fi
195
196    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
197    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
198    dnl Try to locate is.
199    MKINSTALLDIRS=
200    if test -n "$ac_aux_dir"; then
201      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
202    fi
203    if test -z "$MKINSTALLDIRS"; then
204      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
205    fi
206    AC_SUBST(MKINSTALLDIRS)
207
208    dnl Generate list of files to be processed by xgettext which will
209    dnl be included in po/Makefile.
210    test -d po || mkdir po
211    if test "x$srcdir" != "x."; then
212      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
213        posrcprefix="$srcdir/"
214      else
215        posrcprefix="../$srcdir/"
216      fi
217    else
218      posrcprefix="../"
219    fi
220    rm -f po/POTFILES
221    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
222         < $srcdir/po/POTFILES.in > po/POTFILES
223   ])
224