6c7c497f81a62c704eabc736e4cf90cd8c7afec9
[platform/upstream/gnome-common.git] / hack-macros / gnome.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 # serial 5
14
15 AC_DEFUN(AM_GNOME_WITH_NLS,
16   [AC_MSG_CHECKING([whether NLS is requested])
17     dnl Default is enabled NLS
18     AC_ARG_ENABLE(nls,
19       [  --disable-nls           do not use Native Language Support],
20       USE_NLS=$enableval, USE_NLS=yes)
21     AC_MSG_RESULT($USE_NLS)
22     AC_SUBST(USE_NLS)
23
24     USE_INCLUDED_LIBINTL=no
25
26     dnl If we use NLS figure out what method
27     if test "$USE_NLS" = "yes"; then
28       AC_DEFINE(ENABLE_NLS)
29 #      AC_MSG_CHECKING([whether included gettext is requested])
30 #      AC_ARG_WITH(included-gettext,
31 #        [  --with-included-gettext use the GNU gettext library included here],
32 #        nls_cv_force_use_gnu_gettext=$withval,
33 #        nls_cv_force_use_gnu_gettext=no)
34 #      AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
35       nls_cv_force_use_gnu_gettext="no"
36
37       nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
38       if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
39         dnl User does not insist on using GNU NLS library.  Figure out what
40         dnl to use.  If gettext or catgets are available (in this order) we
41         dnl use this.  Else we have to fall back to GNU NLS library.
42         dnl catgets is only used if permitted by option --with-catgets.
43         nls_cv_header_intl=
44         nls_cv_header_libgt=
45         CATOBJEXT=NONE
46
47         AC_CHECK_HEADER(libintl.h,
48           [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
49             [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
50                gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
51
52            if test "$gt_cv_func_gettext_libc" != "yes"; then
53              AC_CHECK_LIB(intl, bindtextdomain,
54                [AC_CACHE_CHECK([for gettext in libintl],
55                  gt_cv_func_gettext_libintl,
56                  [AC_CHECK_LIB(intl, gettext,
57                   gt_cv_func_gettext_libintl=yes,
58                   gt_cv_func_gettext_libintl=no)],
59                  gt_cv_func_gettext_libintl=no)])
60            fi
61
62            if test "$gt_cv_func_gettext_libc" = "yes" \
63               || test "$gt_cv_func_gettext_libintl" = "yes"; then
64               AC_DEFINE(HAVE_GETTEXT)
65               AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
66                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
67               if test "$MSGFMT" != "no"; then
68                 AC_CHECK_FUNCS(dcgettext)
69                 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
70                 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
71                   [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
72                 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
73                                return _nl_msg_cat_cntr],
74                   [CATOBJEXT=.gmo
75                    DATADIRNAME=share],
76                   [CATOBJEXT=.mo
77                    DATADIRNAME=lib])
78                 INSTOBJEXT=.mo
79               fi
80             fi
81
82             # Added by Martin Baulig 12/15/98 for libc5 systems
83             if test "$gt_cv_func_gettext_libc" != "yes" \
84                && test "$gt_cv_func_gettext_libintl" = "yes"; then
85                INTLLIBS=-lintl
86                LIBS=`echo $LIBS | sed -e 's/-lintl//'`
87             fi
88         ])
89
90         if test "$CATOBJEXT" = "NONE"; then
91           AC_MSG_CHECKING([whether catgets can be used])
92           AC_ARG_WITH(catgets,
93             [  --with-catgets          use catgets functions if available],
94             nls_cv_use_catgets=$withval, nls_cv_use_catgets=no)
95           AC_MSG_RESULT($nls_cv_use_catgets)
96
97           if test "$nls_cv_use_catgets" = "yes"; then
98             dnl No gettext in C library.  Try catgets next.
99             AC_CHECK_LIB(i, main)
100             AC_CHECK_FUNC(catgets,
101               [AC_DEFINE(HAVE_CATGETS)
102                INTLOBJS="\$(CATOBJS)"
103                AC_PATH_PROG(GENCAT, gencat, no)dnl
104 #              if test "$GENCAT" != "no"; then
105 #                AC_PATH_PROG(GMSGFMT, gmsgfmt, no)
106 #                if test "$GMSGFMT" = "no"; then
107 #                  AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt,
108 #                   [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)
109 #                fi
110 #                AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
111 #                  [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
112 #                USE_INCLUDED_LIBINTL=yes
113 #                CATOBJEXT=.cat
114 #                INSTOBJEXT=.cat
115 #                DATADIRNAME=lib
116 #                INTLDEPS='$(top_builddir)/intl/libintl.a'
117 #                INTLLIBS=$INTLDEPS
118 #                LIBS=`echo $LIBS | sed -e 's/-lintl//'`
119 #                nls_cv_header_intl=intl/libintl.h
120 #                nls_cv_header_libgt=intl/libgettext.h
121 #              fi
122             ])
123           fi
124         fi
125
126         if test "$CATOBJEXT" = "NONE"; then
127           dnl Neither gettext nor catgets in included in the C library.
128           dnl Fall back on GNU gettext library.
129           nls_cv_use_gnu_gettext=yes
130         fi
131       fi
132
133       if test "$nls_cv_use_gnu_gettext" != "yes"; then
134         AC_DEFINE(ENABLE_NLS)
135       else
136          # Unset this variable since we use the non-zero value as a flag.
137          CATOBJEXT=
138 #        dnl Mark actions used to generate GNU NLS library.
139 #        INTLOBJS="\$(GETTOBJS)"
140 #        AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
141 #         [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
142 #        AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
143 #        AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
144 #         [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
145 #        AC_SUBST(MSGFMT)
146 #       USE_INCLUDED_LIBINTL=yes
147 #        CATOBJEXT=.gmo
148 #        INSTOBJEXT=.mo
149 #        DATADIRNAME=share
150 #       INTLDEPS='$(top_builddir)/intl/libintl.a'
151 #       INTLLIBS=$INTLDEPS
152 #       LIBS=`echo $LIBS | sed -e 's/-lintl//'`
153 #        nls_cv_header_intl=intl/libintl.h
154 #        nls_cv_header_libgt=intl/libgettext.h
155       fi
156
157       dnl Test whether we really found GNU xgettext.
158       if test "$XGETTEXT" != ":"; then
159         dnl If it is no GNU xgettext we define it as : so that the
160         dnl Makefiles still can work.
161         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
162           : ;
163         else
164           AC_MSG_RESULT(
165             [found xgettext program is not GNU xgettext; ignore it])
166           XGETTEXT=":"
167         fi
168       fi
169
170       # We need to process the po/ directory.
171       POSUB=po
172     else
173       DATADIRNAME=share
174       nls_cv_header_intl=intl/libintl.h
175       nls_cv_header_libgt=intl/libgettext.h
176     fi
177     AC_LINK_FILES($nls_cv_header_libgt, $nls_cv_header_intl)
178     AC_OUTPUT_COMMANDS(
179      [case "$CONFIG_FILES" in *po/Makefile.in*)
180         sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile
181       esac])
182
183
184 #    # If this is used in GNU gettext we have to set USE_NLS to `yes'
185 #    # because some of the sources are only built for this goal.
186 #    if test "$PACKAGE" = gettext; then
187 #      USE_NLS=yes
188 #      USE_INCLUDED_LIBINTL=yes
189 #    fi
190
191     dnl These rules are solely for the distribution goal.  While doing this
192     dnl we only have to keep exactly one list of the available catalogs
193     dnl in configure.in.
194     for lang in $ALL_LINGUAS; do
195       GMOFILES="$GMOFILES $lang.gmo"
196       POFILES="$POFILES $lang.po"
197     done
198
199     dnl Make all variables we use known to autoconf.
200     AC_SUBST(USE_INCLUDED_LIBINTL)
201     AC_SUBST(CATALOGS)
202     AC_SUBST(CATOBJEXT)
203     AC_SUBST(DATADIRNAME)
204     AC_SUBST(GMOFILES)
205     AC_SUBST(INSTOBJEXT)
206     AC_SUBST(INTLDEPS)
207     AC_SUBST(INTLLIBS)
208     AC_SUBST(INTLOBJS)
209     AC_SUBST(POFILES)
210     AC_SUBST(POSUB)
211   ])
212
213 AC_DEFUN(AM_GNOME_GETTEXT,
214   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
215    AC_REQUIRE([AC_PROG_CC])dnl
216    AC_REQUIRE([AC_PROG_RANLIB])dnl
217    AC_REQUIRE([AC_ISC_POSIX])dnl
218    AC_REQUIRE([AC_HEADER_STDC])dnl
219    AC_REQUIRE([AC_C_CONST])dnl
220    AC_REQUIRE([AC_C_INLINE])dnl
221    AC_REQUIRE([AC_TYPE_OFF_T])dnl
222    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
223    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
224    AC_REQUIRE([AC_FUNC_MMAP])dnl
225
226    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
227 unistd.h sys/param.h])
228    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
229 strdup __argz_count __argz_stringify __argz_next])
230
231    if test "${ac_cv_func_stpcpy+set}" != "set"; then
232      AC_CHECK_FUNCS(stpcpy)
233    fi
234    if test "${ac_cv_func_stpcpy}" = "yes"; then
235      AC_DEFINE(HAVE_STPCPY)
236    fi
237
238    AM_LC_MESSAGES
239    AM_GNOME_WITH_NLS
240
241    if test "x$CATOBJEXT" != "x"; then
242      if test "x$ALL_LINGUAS" = "x"; then
243        LINGUAS=
244      else
245        AC_MSG_CHECKING(for catalogs to be installed)
246        NEW_LINGUAS=
247        if test "x$LINGUAS" = "x"; then
248            LINGUAS=$ALL_LINGUAS
249        fi
250        for lang in $LINGUAS; do
251          case "$ALL_LINGUAS" in
252           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
253          esac
254        done
255        LINGUAS=$NEW_LINGUAS
256        AC_MSG_RESULT($LINGUAS)
257      fi
258
259      dnl Construct list of names of catalog files to be constructed.
260      if test -n "$LINGUAS"; then
261        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
262      fi
263    fi
264
265    dnl The reference to <locale.h> in the installed <libintl.h> file
266    dnl must be resolved because we cannot expect the users of this
267    dnl to define HAVE_LOCALE_H.
268    if test $ac_cv_header_locale_h = yes; then
269      INCLUDE_LOCALE_H="#include <locale.h>"
270    else
271      INCLUDE_LOCALE_H="\
272 /* The system does not provide the header <locale.h>.  Take care yourself.  */"
273    fi
274    AC_SUBST(INCLUDE_LOCALE_H)
275
276    dnl Determine which catalog format we have (if any is needed)
277    dnl For now we know about two different formats:
278    dnl   Linux libc-5 and the normal X/Open format
279    test -d intl || mkdir intl
280    if test "$CATOBJEXT" = ".cat"; then
281      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
282
283      dnl Transform the SED scripts while copying because some dumb SEDs
284      dnl cannot handle comments.
285      sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
286    fi
287    dnl po2tbl.sed is always needed.
288    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
289      $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
290
291    dnl In the intl/Makefile.in we have a special dependency which makes
292    dnl only sense for gettext.  We comment this out for non-gettext
293    dnl packages.
294    if test "$PACKAGE" = "gettext"; then
295      GT_NO="#NO#"
296      GT_YES=
297    else
298      GT_NO=
299      GT_YES="#YES#"
300    fi
301    AC_SUBST(GT_NO)
302    AC_SUBST(GT_YES)
303
304    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
305    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
306    dnl Try to locate is.
307    MKINSTALLDIRS=
308    if test -n "$ac_aux_dir"; then
309      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
310    fi
311    if test -z "$MKINSTALLDIRS"; then
312      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
313    fi
314    AC_SUBST(MKINSTALLDIRS)
315
316    dnl *** For now the libtool support in intl/Makefile is not for real.
317    l=
318    AC_SUBST(l)
319
320    dnl Generate list of files to be processed by xgettext which will
321    dnl be included in po/Makefile.
322    test -d po || mkdir po
323    if test "x$srcdir" != "x."; then
324      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
325        posrcprefix="$srcdir/"
326      else
327        posrcprefix="../$srcdir/"
328      fi
329    else
330      posrcprefix="../"
331    fi
332    rm -f po/POTFILES
333    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
334         < $srcdir/po/POTFILES.in > po/POTFILES
335   ])
336
337
338 AC_DEFUN(AM_PATH_GNOME,
339 [dnl 
340 dnl Get the cflags and libraries from the gnome-config script
341 dnl
342 AC_ARG_WITH(gnome-prefix,[  --with-gnome-prefix=PFX   Prefix where GNOME is installed (optional)],
343             gnome_config_prefix="$withval", gnome_config_prefix="")
344 AC_ARG_WITH(gnome-exec-prefix,[  --with-gnome-exec-prefix=PFX Exec prefix where GNOME is installed (optional)],
345             gnome_config_exec_prefix="$withval", gnome_config_exec_prefix="")
346
347   if test x$gnome_config_exec_prefix != x ; then
348      gnome_config_args="$gnome_config_args --exec-prefix=$gnome_config_exec_prefix"
349      if test x${GNOME_CONFIG+set} != xset ; then
350         GNOME_CONFIG=$gnome_config_exec_prefix/bin/gnome-config
351      fi
352   fi
353   if test x$gnome_config_prefix != x ; then
354      gnome_config_args="$gnome_config_args --prefix=$gnome_config_prefix"
355      if test x${GNOME_CONFIG+set} != xset ; then
356         GNOME_CONFIG=$gnome_config_prefix/bin/gnome-config
357      fi
358   fi
359
360   AC_PATH_PROG(GNOME_CONFIG, gnome-config, no)
361   min_gnome_version=ifelse([$1], , 1.1.0, $1)
362
363   AC_MSG_CHECKING(for GNOME - version >= $min_gnome_version)
364   no_gnome=""
365   if test "$GNOME_CONFIG" = "no" ; then
366     no_gnome=yes
367   else
368     GNOME_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnome`"
369     GNOME_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnome`"
370     GNOMEUI_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnomeui`"
371     GNOMEUI_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnomeui`"
372
373     gnome_config_major_version=`$GNOME_CONFIG $gnome_config_args --version | \
374            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
375     gnome_config_minor_version=`$GNOME_CONFIG $gnome_config_args --version | \
376            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
377     gnome_config_micro_version=`$GNOME_CONFIG $gnome_config_args --version | \
378            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
379     needed_major_version=`echo $min_gnome_version | \
380            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\1/'`
381     needed_minor_version=`echo $min_gnome_version | \
382            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\2/'`
383     needed_micro_version=`echo $min_gnome_version | \
384            sed 's/[[^0-9]]*\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)/\3/'`
385
386     if test $gnome_config_major_version -lt $needed_major_version; then
387         ifelse([$3], , :, [$3])
388         no_gnome=yes
389     elif test $gnome_config_major_version = $needed_major_version; then
390         if test -n "$needed_minor_version" -a $gnome_config_minor_version -lt $needed_minor_version; then
391                 ifelse([$3], , :, [$3])
392                 no_gnome=yes
393         elif test -n "$needed_minor_version" -a $gnome_config_minor_version = $needed_minor_version; then
394                 if test -n "$needed_micro_version" -a $gnome_config_micro_version -lt $needed_micro_version; then
395                         ifelse([$3], , :, [$3])
396                         no_gnome=yes
397                 fi
398         fi
399     fi
400   fi
401   AC_SUBST(GNOME_CFLAGS)
402   AC_SUBST(GNOME_LIBS)
403   AC_SUBST(GNOMEUI_CFLAGS)
404   AC_SUBST(GNOMEUI_LIBS)
405
406   if test "x$no_gnome" = x ; then
407      AC_MSG_RESULT(yes)
408      ifelse([$2], , :, [$2])     
409   else
410      AC_MSG_RESULT(no)
411      if test "$GNOME_CONFIG" = "no" ; then
412        echo "*** The gnome-config script installed by GNOME could not be found"
413        echo "*** If GNOME was installed in PREFIX, make sure PREFIX/bin is in"
414        echo "*** your path, or set the GNOME_CONFIG environment variable to the"
415        echo "*** full path to gnome-config."
416      else
417         :
418      fi
419      GNOME_CFLAGS=""
420      GNOME_LIBS=""
421      ifelse([$3], , :, [$3])
422   fi
423
424   tmp_gnome_libdir=`$GNOME_CONFIG $gnome_config_args --libdir`
425   if test -n "$4"; then
426         AC_MSG_CHECKING([for additional GNOME modules])
427   fi
428   for module in $4 ""; do
429         gnome_m4_notfound=no
430         if test "$module" = zvt; then
431           ZVT_LIBS="`$GNOME_CONFIG $gnome_config_args --libs zvt`"
432           AC_SUBST(ZVT_LIBS)
433         elif test "$module" = gtk; then
434           GTK_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gtk`"
435           GTK_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gtk`"
436           AC_SUBST(GTK_CFLAGS)
437           AC_SUBST(GTK_LIBS)
438         elif test "$module" = "glib"; then
439           GLIB_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags glib`"
440           GLIB_LIBS="`$GNOME_CONFIG $gnome_config_args --libs glib`"
441           AC_SUBST(GLIB_CFLAGS)
442           AC_SUBST(GLIB_LIBS)
443         elif test "$module" = "oaf"; then
444           OAF_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags oaf`"
445           OAF_LIBS="`$GNOME_CONFIG $gnome_config_args --libs oaf`"
446           AC_SUBST(OAF_CFLAGS)
447           AC_SUBST(OAF_LIBS)
448         elif test "$module" = "gnorba"; then
449           GNORBA_CFLAGS="`$GNOME_CONFIG $gnome_config_args --cflags gnorba`"
450           GNORBA_LIBS="`$GNOME_CONFIG $gnome_config_args --libs gnorba`"
451           AC_SUBST(GNORBA_CFLAGS)
452           AC_SUBST(GNORBA_LIBS)
453         elif test -n "$module"; then
454           if $GNOME_CONFIG $gnome_config_args --cflags $module >/dev/null 2>&1; then
455                 tmp_bsnom=`echo $module | tr a-z A-Z`
456                 eval $tmp_bsnom'_CFLAGS'=\"`$GNOME_CONFIG $gnome_config_args --cflags $module`\"
457                 eval $tmp_bsnom'_LIBS'=\"`$GNOME_CONFIG $gnome_config_args --libs $module`\"
458           else
459                 AC_MSG_RESULT([*** $module library is not installed])
460                 ifelse([$3], , :, [$3])
461                 gnome_m4_notfound=yes
462           fi
463         fi
464         if test "$gnome_m4_notfound" = no; then
465           echo $ac_n " $module" 1>&6
466         fi
467   done
468   if test -n "$4"; then
469         AC_MSG_RESULT([])
470   fi
471 ])