checkin of 0.3.0
[pspp-builds.git] / acinclude.m4
1 dnl --------------------------------------------------------- ##
2 dnl The following definitions are from gettext-0.10.27.       ##
3 dnl --------------------------------------------------------- ##
4
5 # Macro to add for using GNU gettext.
6 # Ulrich Drepper <drepper@cygnus.com>, 1995.
7
8 # serial 2
9
10 AC_DEFUN(AM_WITH_NLS,
11   [AC_MSG_CHECKING([whether NLS is requested])
12     dnl Default is enabled NLS
13     AC_ARG_ENABLE(nls,
14       [  --disable-nls           do not use Native Language Support],
15       USE_NLS=$enableval, USE_NLS=yes)
16     AC_MSG_RESULT($USE_NLS)
17     AC_SUBST(USE_NLS)
18
19     USE_INCLUDED_LIBINTL=no
20
21     dnl If we use NLS figure out what method
22     if test "$USE_NLS" = "yes"; then
23       AC_DEFINE(ENABLE_NLS)
24       AC_MSG_CHECKING([whether included gettext is requested])
25       AC_ARG_WITH(included-gettext,
26         [  --with-included-gettext use the GNU gettext library included here],
27         nls_cv_force_use_gnu_gettext=$withval,
28         nls_cv_force_use_gnu_gettext=no)
29       AC_MSG_RESULT($nls_cv_force_use_gnu_gettext)
30
31       nls_cv_use_gnu_gettext="$nls_cv_force_use_gnu_gettext"
32       if test "$nls_cv_force_use_gnu_gettext" != "yes"; then
33         dnl User does not insist on using GNU NLS library.  Figure out what
34         dnl to use.  If gettext or catgets are available (in this order) we
35         dnl use this.  Else we have to fall back to GNU NLS library.
36         dnl catgets is only used if permitted by option --with-catgets.
37         nls_cv_header_intl=
38         nls_cv_header_libgt=
39         CATOBJEXT=NONE
40
41         AC_CHECK_HEADER(libintl.h,
42           [AC_CACHE_CHECK([for gettext in libc], gt_cv_func_gettext_libc,
43             [AC_TRY_LINK([#include <libintl.h>], [return (int) gettext ("")],
44                gt_cv_func_gettext_libc=yes, gt_cv_func_gettext_libc=no)])
45
46            if test "$gt_cv_func_gettext_libc" != "yes"; then
47              AC_CHECK_LIB(intl, bindtextdomain,
48                [AC_CACHE_CHECK([for gettext in libintl],
49                  gt_cv_func_gettext_libintl,
50                  [AC_TRY_LINK([], [return (int) gettext ("")],
51                  gt_cv_func_gettext_libintl=yes,
52                  gt_cv_func_gettext_libintl=no)])])
53            fi
54
55            if test "$gt_cv_func_gettext_libc" = "yes" \
56               || test "$gt_cv_func_gettext_libintl" = "yes"; then
57               AC_DEFINE(HAVE_GETTEXT)
58               AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
59                 [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)dnl
60               if test "$MSGFMT" != "no"; then
61                 AC_CHECK_FUNCS(dcgettext)
62                 AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
63                 AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
64                   [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
65                 AC_TRY_LINK(, [extern int _nl_msg_cat_cntr;
66                                return _nl_msg_cat_cntr],
67                   [CATOBJEXT=.gmo
68                    DATADIRNAME=share],
69                   [CATOBJEXT=.mo
70                    DATADIRNAME=lib])
71                 INSTOBJEXT=.mo
72               fi
73             fi
74         ])
75
76         if test "$CATOBJEXT" = "NONE"; then
77           AC_MSG_CHECKING([whether catgets can be used])
78           AC_ARG_WITH(catgets,
79             [  --with-catgets          use catgets functions if available],
80             nls_cv_use_catgets=$withval, nls_cv_use_catgets=no)
81           AC_MSG_RESULT($nls_cv_use_catgets)
82
83           if test "$nls_cv_use_catgets" = "yes"; then
84             dnl No gettext in C library.  Try catgets next.
85             AC_CHECK_LIB(i, main)
86             AC_CHECK_FUNC(catgets,
87               [AC_DEFINE(HAVE_CATGETS)
88                INTLOBJS="\$(CATOBJS)"
89                AC_PATH_PROG(GENCAT, gencat, no)dnl
90                if test "$GENCAT" != "no"; then
91                  AC_PATH_PROG(GMSGFMT, gmsgfmt, no)
92                  if test "$GMSGFMT" = "no"; then
93                    AM_PATH_PROG_WITH_TEST(GMSGFMT, msgfmt,
94                     [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], no)
95                  fi
96                  AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
97                    [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
98                  USE_INCLUDED_LIBINTL=yes
99                  CATOBJEXT=.cat
100                  INSTOBJEXT=.cat
101                  DATADIRNAME=lib
102                  INTLDEPS="../intl/libintl.a"
103                  INTLLIBS=$INTLDEPS
104                  LIBS=`echo $LIBS | sed -e 's/-lintl//'`
105                  nls_cv_header_intl=intl/libintl.h
106                  nls_cv_header_libgt=intl/libgettext.h
107                fi])
108           fi
109         fi
110
111         if test "$CATOBJEXT" = "NONE"; then
112           dnl Neither gettext nor catgets in included in the C library.
113           dnl Fall back on GNU gettext library.
114           nls_cv_use_gnu_gettext=yes
115         fi
116       fi
117
118       if test "$nls_cv_use_gnu_gettext" = "yes"; then
119         dnl Mark actions used to generate GNU NLS library.
120         INTLOBJS="\$(GETTOBJS)"
121         AM_PATH_PROG_WITH_TEST(MSGFMT, msgfmt,
122           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep 'dv '`"], msgfmt)
123         AC_PATH_PROG(GMSGFMT, gmsgfmt, $MSGFMT)
124         AM_PATH_PROG_WITH_TEST(XGETTEXT, xgettext,
125           [test -z "`$ac_dir/$ac_word -h 2>&1 | grep '(HELP)'`"], :)
126         AC_SUBST(MSGFMT)
127         USE_INCLUDED_LIBINTL=yes
128         CATOBJEXT=.gmo
129         INSTOBJEXT=.mo
130         DATADIRNAME=share
131         INTLDEPS="../intl/libintl.a"
132         INTLLIBS=$INTLDEPS
133         LIBS=`echo $LIBS | sed -e 's/-lintl//'`
134         nls_cv_header_intl=intl/libintl.h
135         nls_cv_header_libgt=intl/libgettext.h
136       fi
137
138       dnl Test whether we really found GNU xgettext.
139       if test "$XGETTEXT" != ":"; then
140         dnl If it is no GNU xgettext we define it as : so that the
141         dnl Makefiles still can work.
142         if $XGETTEXT --omit-header /dev/null 2> /dev/null; then
143           : ;
144         else
145           AC_MSG_RESULT(
146             [found xgettext programs is not GNU xgettext; ignore it])
147           XGETTEXT=":"
148         fi
149       fi
150
151       # We need to process the po/ directory.
152       POSUB=po
153     else
154       DATADIRNAME=share
155       nls_cv_header_intl=intl/libintl.h
156       nls_cv_header_libgt=intl/libgettext.h
157     fi
158
159     # If this is used in GNU gettext we have to set USE_NLS to `yes'
160     # because some of the sources are only built for this goal.
161     if test "$PACKAGE" = gettext; then
162       USE_NLS=yes
163       USE_INCLUDED_LIBINTL=yes
164     fi
165
166     dnl These rules are solely for the distribution goal.  While doing this
167     dnl we only have to keep exactly one list of the available catalogs
168     dnl in configure.in.
169     for lang in $ALL_LINGUAS; do
170       GMOFILES="$GMOFILES $lang.gmo"
171       POFILES="$POFILES $lang.po"
172     done
173
174     dnl Make all variables we use known to autoconf.
175     AC_SUBST(USE_INCLUDED_LIBINTL)
176     AC_SUBST(CATALOGS)
177     AC_SUBST(CATOBJEXT)
178     AC_SUBST(DATADIRNAME)
179     AC_SUBST(GMOFILES)
180     AC_SUBST(INSTOBJEXT)
181     AC_SUBST(INTLDEPS)
182     AC_SUBST(INTLLIBS)
183     AC_SUBST(INTLOBJS)
184     AC_SUBST(POFILES)
185     AC_SUBST(POSUB)
186   ])
187
188 AC_DEFUN(AM_GNU_GETTEXT,
189   [AC_REQUIRE([AC_PROG_MAKE_SET])dnl
190    AC_REQUIRE([AC_PROG_CC])dnl
191    AC_REQUIRE([AC_ISC_POSIX])dnl
192    AC_REQUIRE([AC_HEADER_STDC])dnl
193    AC_REQUIRE([AC_C_CONST])dnl
194    AC_REQUIRE([AC_C_INLINE])dnl
195    AC_REQUIRE([AC_TYPE_OFF_T])dnl
196    AC_REQUIRE([AC_TYPE_SIZE_T])dnl
197    AC_REQUIRE([AC_FUNC_ALLOCA])dnl
198    AC_REQUIRE([AC_FUNC_MMAP])dnl
199
200    AC_CHECK_HEADERS([argz.h limits.h locale.h nl_types.h malloc.h string.h \
201 unistd.h values.h])
202    AC_CHECK_FUNCS([getcwd munmap putenv setenv setlocale strchr strcasecmp \
203 __argz_count __argz_stringify __argz_next])
204
205    if test "${ac_cv_func_stpcpy+set}" != "set"; then
206      AC_CHECK_FUNCS(stpcpy)
207    fi
208    if test "${ac_cv_func_stpcpy}" = "yes"; then
209      AC_DEFINE(HAVE_STPCPY)
210    fi
211
212    AM_LC_MESSAGES
213    AM_WITH_NLS
214
215    if test "x$CATOBJEXT" != "x"; then
216      if test "x$ALL_LINGUAS" = "x"; then
217        LINGUAS=
218      else
219        AC_MSG_CHECKING(for catalogs to be installed)
220        NEW_LINGUAS=
221        for lang in ${LINGUAS=$ALL_LINGUAS}; do
222          case "$ALL_LINGUAS" in
223           *$lang*) NEW_LINGUAS="$NEW_LINGUAS $lang" ;;
224          esac
225        done
226        LINGUAS=$NEW_LINGUAS
227        AC_MSG_RESULT($LINGUAS)
228      fi
229
230      dnl Construct list of names of catalog files to be constructed.
231      if test -n "$LINGUAS"; then
232        for lang in $LINGUAS; do CATALOGS="$CATALOGS $lang$CATOBJEXT"; done
233      fi
234    fi
235
236    dnl Determine which catalog format we have (if any is needed)
237    dnl For now we know about two different formats:
238    dnl   Linux libc-5 and the normal X/Open format
239    test -d intl || mkdir intl
240    if test "$CATOBJEXT" = ".cat"; then
241      AC_CHECK_HEADER(linux/version.h, msgformat=linux, msgformat=xopen)
242
243      dnl Transform the SED scripts while copying because some dumb SEDs
244      dnl cannot handle comments.
245      sed -e '/^#/d' $srcdir/intl/$msgformat-msg.sed > intl/po2msg.sed
246    fi
247    dnl po2tbl.sed is always needed.
248    sed -e '/^#.*[^\\]$/d' -e '/^#$/d' \
249      $srcdir/intl/po2tbl.sed.in > intl/po2tbl.sed
250
251    dnl In the intl/Makefile.in we have a special dependency which makes
252    dnl only sense for gettext.  We comment this out for non-gettext
253    dnl packages.
254    if test "$PACKAGE" = "gettext"; then
255      GT_NO="#NO#"
256      GT_YES=
257    else
258      GT_NO=
259      GT_YES="#YES#"
260    fi
261    AC_SUBST(GT_NO)
262    AC_SUBST(GT_YES)
263
264    dnl If the AC_CONFIG_AUX_DIR macro for autoconf is used we possibly
265    dnl find the mkinstalldirs script in another subdir but ($top_srcdir).
266    dnl Try to locate is.
267    MKINSTALLDIRS=
268    if test $ac_aux_dir; then
269      MKINSTALLDIRS="$ac_aux_dir/mkinstalldirs"
270    fi
271    if test -z $MKINSTALLDIRS; then
272      MKINSTALLDIRS="\$(top_srcdir)/mkinstalldirs"
273    fi
274    AC_SUBST(MKINSTALLDIRS)
275
276    dnl Configure the intl/Makefile for shared libs.
277    if test "${enable_shared+set}" = set; then
278      l=l
279    else
280      l=
281    fi
282    AC_SUBST(l)
283
284    dnl Generate list of files to be processed by xgettext which will
285    dnl be included in po/Makefile.
286    test -d po || mkdir po
287    if test "x$srcdir" != "x."; then
288      if test "x`echo $srcdir | sed 's@/.*@@'`" = "x"; then
289        posrcprefix="$srcdir/"
290      else
291        posrcprefix="../$srcdir/"
292      fi
293    else
294      posrcprefix="../"
295    fi
296    sed -e "/^#/d" -e "/^\$/d" -e "s,.*, $posrcprefix& \\\\," -e "\$s/\(.*\) \\\\/\1/" \
297         < $srcdir/po/POTFILES.in > po/POTFILES
298   ])
299
300 # Search path for a program which passes the given test.
301 # Ulrich Drepper <drepper@cygnus.com>, 1996.
302
303 # serial 1
304
305 dnl AM_PATH_PROG_WITH_TEST(VARIABLE, PROG-TO-CHECK-FOR,
306 dnl   TEST-PERFORMED-ON-FOUND_PROGRAM [, VALUE-IF-NOT-FOUND [, PATH]])
307 AC_DEFUN(AM_PATH_PROG_WITH_TEST,
308 [# Extract the first word of "$2", so it can be a program name with args.
309 set dummy $2; ac_word=[$]2
310 AC_MSG_CHECKING([for $ac_word])
311 AC_CACHE_VAL(ac_cv_path_$1,
312 [case "[$]$1" in
313   /*)
314   ac_cv_path_$1="[$]$1" # Let the user override the test with a path.
315   ;;
316   *)
317   IFS="${IFS=   }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
318   for ac_dir in ifelse([$5], , $PATH, [$5]); do
319     test -z "$ac_dir" && ac_dir=.
320     if test -f $ac_dir/$ac_word; then
321       if [$3]; then
322         ac_cv_path_$1="$ac_dir/$ac_word"
323         break
324       fi
325     fi
326   done
327   IFS="$ac_save_ifs"
328 dnl If no 4th arg is given, leave the cache variable unset,
329 dnl so AC_PATH_PROGS will keep looking.
330 ifelse([$4], , , [  test -z "[$]ac_cv_path_$1" && ac_cv_path_$1="$4"
331 ])dnl
332   ;;
333 esac])dnl
334 $1="$ac_cv_path_$1"
335 if test -n "[$]$1"; then
336   AC_MSG_RESULT([$]$1)
337 else
338   AC_MSG_RESULT(no)
339 fi
340 AC_SUBST($1)dnl
341 ])
342
343 # Check whether LC_MESSAGES is available in <locale.h>.
344 # Ulrich Drepper <drepper@cygnus.com>, 1995.
345
346 # serial 1
347
348 AC_DEFUN(AM_LC_MESSAGES,
349   [if test $ac_cv_header_locale_h = yes; then
350     AC_CACHE_CHECK([for LC_MESSAGES], am_cv_val_LC_MESSAGES,
351       [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
352        am_cv_val_LC_MESSAGES=yes, am_cv_val_LC_MESSAGES=no)])
353     if test $am_cv_val_LC_MESSAGES = yes; then
354       AC_DEFINE(HAVE_LC_MESSAGES)
355     fi
356   fi])
357
358 dnl Check longest integer in digits.
359
360 AC_DEFUN([BLP_INT_DIGITS],
361 [
362 AC_MSG_CHECKING(number of digits in LONG_MIN (incl. sign))
363 AC_CACHE_VAL(blp_int_digits,
364              [AC_TRY_RUN([#include <stdio.h>
365                           #include <limits.h>
366                           int
367                           main()
368                           {
369                             int len;
370                             char s[80];
371                             sprintf(s, "%ld", LONG_MAX);
372                             len = strlen(s);
373                             sprintf(s, "%ld", LONG_MIN);
374                             if(strlen(s)>len) len=strlen(s);
375                             sprintf(s, "%lu", ULONG_MAX);
376                             if(strlen(s)>len) len=strlen(s);
377                             exit(len);
378                           }
379                          ],
380                          eval "blp_int_digits=19",
381                          eval "blp_int_digits=$?"
382                          if test "$blp_int_digits" -lt 11; then
383                            blp_int_digits=11
384                          fi,
385                          eval "blp_int_digits=19")
386              ])
387 AC_DEFINE_UNQUOTED(INT_DIGITS, $blp_int_digits)
388 AC_MSG_RESULT($blp_int_digits)
389 ])dnl
390
391 dnl Check quality of this machine's sprintf implementation.
392
393 AC_DEFUN([BLP_IS_SPRINTF_GOOD],
394 [
395 AC_MSG_CHECKING(if sprintf returns a char count)
396 AC_CACHE_VAL(blp_is_sprintf_good,
397              [AC_TRY_RUN([#include <stdio.h>
398                           int 
399                           main()
400                           {
401                             char s[8];
402                             exit((int)sprintf(s, "abcdefg")!=7);
403                           }
404                          ], 
405                          eval "blp_is_sprintf_good=yes",
406                          eval "blp_is_sprintf_good=no",
407                          eval "blp_is_sprintf_good=no")
408              ])
409 if test "$blp_is_sprintf_good" = yes; then
410   AC_DEFINE(HAVE_GOOD_SPRINTF)
411   AC_MSG_RESULT(yes)
412 else
413   AC_MSG_RESULT(no)
414 fi
415 ])dnl
416
417 dnl Check for proper random number generator.
418
419 AC_DEFUN([BLP_RANDOM],
420 [
421 AC_MSG_CHECKING(random number generator)
422 AC_CACHE_VAL(blp_random_good, 
423   AC_TRY_COMPILE([#include <stdlib.h>], [int x=RAND_MAX;], 
424     blp_random_good=yes, blp_random_good=no))
425 if test "$blp_random_good" = yes; then
426   AC_DEFINE(HAVE_GOOD_RANDOM)
427   AC_MSG_RESULT(good)
428 else
429   AC_MSG_RESULT(bad)
430 fi
431 ])dnl
432
433 dnl aclocal.m4 ends here