Incorporate AM_LC_MESSAGES, AM_PATH_PROG_WITH_TEST as AM_GLIB_* to avoid
[platform/upstream/glib.git] / m4macros / glib-gettext.m4
1 # Macro to add for using GNU gettext.
2 # Ulrich Drepper <drepper@cygnus.com>, 1995, 1996
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 AC_DEFUN([AM_GLIB_LC_MESSAGES],
21   [if test $ac_cv_header_locale_h = yes; then
22     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
23       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
24        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
25     if test $am_cv_val_LC_MESSAGES = yes; then
26       AC_DEFINE(HAVE_LC_MESSAGES, 1,
27         [Define if your <locale.h> file defines LC_MESSAGES.])
28     fi
29   fi])
30
31 dnl AM_GLIB_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
32 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
33 AC_DEFUN([AM_GLIB_PATH_PROG_WITH_TEST],
34 [# Extract the first word of "$2", so it can be a program name with args.
35 set dummy $2; ac_word=[$]2
36 AC_MSG_CHECKING([for $ac_word])
37 AC_CACHE_VAL(ac_cv_path_$1,
38 [case "[$]$1" in
39   /*)
40   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
41   ;;
42   *)
43   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
44   for ac_dir in ifelse([$5], , $PATH, [$5]); do
45     test -z "$ac_dir" && ac_dir=.
46     if test -f $ac_dir/$ac_word; then
47       if [$3]; then
48         ac_cv_path_$1="$ac_dir/$ac_word"
49         break
50       fi
51     fi
52   done
53   IFS="$ac_save_ifs"
54 dnl If no 4th arg is given, leave the cache variable unset,
55 dnl so AC_PATH_PROGS will keep looking.
56 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
57 ])dnl
58   ;;
59 esac])dnl
60 $1="$ac_cv_path_$1"
61 if test ifelse([$4], , [-n "[$]$1"], ["[$]$1" != "$4"]); then
62   AC_MSG_RESULT([$]$1)
63 else
64   AC_MSG_RESULT(no)
65 fi
66 AC_SUBST($1)dnl
67 ])
68
69 # serial 5
70
71 AC_DEFUN(AM_GLIB_WITH_NLS,
72   dnl NLS is obligatory
73   [USE_NLS=yes
74     AC_SUBST(USE_NLS)
75
76     dnl Figure out what method
77     nls_cv_force_use_gnu_gettext="no"
78
79     nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
80     if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
81       dnl User does not insist on using GNU NLS library.  Figure out what
82       dnl to use.  If gettext or catgets are available (in this order) we
83       dnl use this.  Else we have to fall back to GNU NLS library.
84       dnl catgets is only used if permitted by option --with-catgets.
85       nls_cv_header_intl=
86       nls_cv_header_libgt=
87       CATOBJEXT=NONE
88
89       AC_CHECK_HEADER(libintl.h,
90         [AC_CACHE_CHECK([for dgettext in libc], gt_cv_func_dgettext_libc,
91           [AC_TRY_LINK([#include <libintl.h>], [return (int) dgettext ("","")],
92             gt_cv_func_dgettext_libc=yes, gt_cv_func_dgettext_libc=no)])
93
94           if test "$gt_cv_func_dgettext_libc" != "yes"; then
95             AC_CHECK_LIB(intl, bindtextdomain,
96               [AC_CACHE_CHECK([for dgettext in libintl],
97                 gt_cv_func_dgettext_libintl,
98                 [AC_CHECK_LIB(intl, dgettext,
99                   gt_cv_func_dgettext_libintl=yes,
100                   gt_cv_func_dgettext_libintl=no)],
101                 gt_cv_func_dgettext_libintl=no)])
102           fi
103
104           if test "$gt_cv_func_dgettext_libintl" = "yes"; then
105             LIBS="$LIBS -lintl";
106           fi
107
108           if test "$gt_cv_func_dgettext_libc" = "yes" \
109             || test "$gt_cv_func_dgettext_libintl" = "yes"; then
110             AC_DEFINE(HAVE_GETTEXT,1,
111               [Define if the GNU gettext() function is already present or preinstalled.])
112             AM_GLIB_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
113               [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
114             if test "$MSGFMT" != "no"; then
115               AC_CHECK_FUNCS(dcgettext)
116               AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
117               AM_GLIB_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
118                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
119               AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
120                              return _nl_msg_cat_cntr],
121                 [CATOBJEXT=.gmo
122                  DATADIRNAME=share],
123                 [CATOBJEXT=.mo
124                  DATADIRNAME=lib])
125               INSTOBJEXT=.mo
126             fi
127           fi
128
129           # Added by Martin Baulig 12/15/98 for libc5 systems
130           if test "$gt_cv_func_dgettext_libc" != "yes" \
131             && test "$gt_cv_func_dgettext_libintl" = "yes"; then
132             INTLLIBS=-lintl
133             LIBS=`echo $LIBS | sed -e 's/-lintl//'`
134           fi
135       ])
136
137       if test "$CATOBJEXT" = "NONE"; then
138         dnl Neither gettext nor catgets in included in the C library.
139         dnl Fall back on GNU gettext library.
140         nls_cv_use_gnu_gettext=yes
141       fi
142     fi
143
144     if test "$nls_cv_use_gnu_gettext" != "yes"; then
145       AC_DEFINE(ENABLE_NLS, 1,
146         [always defined to indicate that i18n is enabled])
147     else
148       dnl Unset this variable since we use the non-zero value as a flag.
149       CATOBJEXT=
150     fi
151
152     dnl Test whether we really found GNU xgettext.
153     if test "$XGETTEXT" != ":"; then
154       dnl If it is no GNU xgettext we define it as : so that the
155       dnl Makefiles still can work.
156       if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
157         : ;
158       else
159         AC_MSG_RESULT(
160           [found xgettext program is not GNU xgettext; ignore it])
161         XGETTEXT=":"
162       fi
163     fi
164
165     # We need to process the po/ directory.
166     POSUB=po
167
168     AC_OUTPUT_COMMANDS(
169       [case "$CONFIG_FILES" in *po/Makefile.in*)
170         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
171       esac])
172
173     dnl These rules are solely for the distribution goal.  While doing this
174     dnl we only have to keep exactly one list of the available catalogs
175     dnl in configure.in.
176     for lang in $ALL_LINGUAS; do
177       GMOFILES="$GMOFILES $lang.gmo"
178       POFILES="$POFILES $lang.po"
179     done
180
181     dnl Make all variables we use known to autoconf.
182     AC_SUBST(CATALOGS)
183     AC_SUBST(CATOBJEXT)
184     AC_SUBST(DATADIRNAME)
185     AC_SUBST(GMOFILES)
186     AC_SUBST(INSTOBJEXT)
187     AC_SUBST(INTLDEPS)
188     AC_SUBST(INTLLIBS)
189     AC_SUBST(INTLOBJS)
190     AC_SUBST(POFILES)
191     AC_SUBST(POSUB)
192   ])
193
194 AC_DEFUN(AM_GLIB_GNU_GETTEXT,
195   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
196    AC_REQUIRE([AC_PROG_CC])dnl
197    AC_REQUIRE([AC_PROG_RANLIB])dnl
198    AC_REQUIRE([AC_HEADER_STDC])dnl
199    AC_REQUIRE([AC_C_CONST])dnl
200    AC_REQUIRE([AC_C_INLINE])dnl
201    AC_REQUIRE([AC_TYPE_OFF_T])dnl
202    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
203    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
204    AC_REQUIRE([AC_FUNC_MMAP])dnl
205
206    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
207 unistd.h sys/param.h])
208    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
209 strdup __argz_count __argz_stringify __argz_next])
210
211    AM_GLIB_LC_MESSAGES
212    AM_GLIB_WITH_NLS
213
214    if test "x$CATOBJEXT" != "x"; then
215      if test "x$ALL_LINGUAS" = "x"; then
216        LINGUAS=
217      else
218        AC_MSG_CHECKING(for catalogs to be installed)
219        NEW_LINGUAS=
220        for lang in ${LINGUAS=$ALL_LINGUAS}; do
221          case "$ALL_LINGUAS" in
222           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
223          esac
224        done
225        LINGUAS=$NEW_LINGUAS
226        AC_MSG_RESULT($LINGUAS)
227      fi
228
229      dnl Construct list of names of catalog files to be constructed.
230      if test -n "$LINGUAS"; then
231        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
232      fi
233    fi
234
235    dnl Determine which catalog format we have (if any is needed)
236    dnl For now we know about two different formats:
237    dnl   Linux libc-5 and the normal X/Open format
238    test -d po || mkdir po
239    if test "$CATOBJEXT" = ".cat"; then
240      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
241
242      dnl Transform the SED scripts while copying because some dumb SEDs
243      dnl cannot handle comments.
244      sed -e '/^#/d' $srcdir/po/$msgformat-msg.sed > po/po2msg.sed
245    fi
246
247    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
248    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
249    dnl Try to locate is.
250    MKINSTALLDIRS=
251    if test -n "$ac_aux_dir"; then
252      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
253    fi
254    if test -z "$MKINSTALLDIRS"; then
255      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
256    fi
257    AC_SUBST(MKINSTALLDIRS)
258
259    dnl Generate list of files to be processed by xgettext which will
260    dnl be included in po/Makefile.
261    test -d po || mkdir po
262    if test "x$srcdir" != "x."; then
263      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
264        posrcprefix="$srcdir/"
265      else
266        posrcprefix="../$srcdir/"
267      fi
268    else
269      posrcprefix="../"
270    fi
271    rm -f po/POTFILES
272    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
273         < $srcdir/po/POTFILES.in > po/POTFILES
274   ])
275