* Oops. Fix a problem running submakes like $(MAKE) $(MFLAGS).
[make.git] / acinclude.m4
blob3f4f9ad647cd4d5d8c0be6a4ec416d62eafa01a2
1 dnl acinclude.m4 -- Extra macros needed for GNU make.
2 dnl
3 dnl Automake will incorporate this into its generated aclocal.m4.
5 dnl ---------------------------------------------------------------------------
6 dnl Got this from the lynx 2.8 distribution.
7 dnl by T.E.Dickey <dickey@clark.net>
8 dnl and Jim Spath <jspath@mail.bcpl.lib.md.us>
9 dnl and Philippe De Muyter <phdm@macqel.be>
10 dnl
11 dnl Created: 1997/1/28
12 dnl Updated: 1997/12/23
13 dnl ---------------------------------------------------------------------------
14 dnl After checking for functions in the default $LIBS, make a further check
15 dnl for the functions that are netlib-related (these aren't always in the
16 dnl libc, etc., and have to be handled specially because there are conflicting
17 dnl and broken implementations.
18 dnl Common library requirements (in order):
19 dnl     -lresolv -lsocket -lnsl
20 dnl     -lnsl -lsocket
21 dnl     -lsocket
22 dnl     -lbsd
23 AC_DEFUN([CF_NETLIBS],[
24 cf_test_netlibs=no
25 AC_MSG_CHECKING(for network libraries)
26 AC_CACHE_VAL(cf_cv_netlibs,[
27 AC_MSG_RESULT(working...)
28 cf_cv_netlibs=""
29 cf_test_netlibs=yes
30 AC_CHECK_FUNCS(gethostname,,[
31         CF_RECHECK_FUNC(gethostname,nsl,cf_cv_netlibs,[
32                 CF_RECHECK_FUNC(gethostname,socket,cf_cv_netlibs)])])
34 # FIXME:  sequent needs this library (i.e., -lsocket -linet -lnsl), but
35 # I don't know the entrypoints - 97/7/22 TD
36 AC_CHECK_LIB(inet,main,cf_cv_netlibs="-linet $cf_cv_netlibs")
38 if test "$ac_cv_func_lsocket" != no ; then
39 AC_CHECK_FUNCS(socket,,[
40         CF_RECHECK_FUNC(socket,socket,cf_cv_netlibs,[
41                 CF_RECHECK_FUNC(socket,bsd,cf_cv_netlibs)])])
44 AC_CHECK_FUNCS(gethostbyname,,[
45         CF_RECHECK_FUNC(gethostbyname,nsl,cf_cv_netlibs)])
47 AC_CHECK_FUNCS(strcasecmp,,[
48         CF_RECHECK_FUNC(strcasecmp,resolv,cf_cv_netlibs)])
50 LIBS="$LIBS $cf_cv_netlibs"
51 test $cf_test_netlibs = no && echo "$cf_cv_netlibs" >&AC_FD_MSG
52 ])dnl
53 dnl ---------------------------------------------------------------------------
54 dnl Re-check on a function to see if we can pick it up by adding a library.
55 dnl     $1 = function to check
56 dnl     $2 = library to check in
57 dnl     $3 = environment to update (e.g., $LIBS)
58 dnl     $4 = what to do if this fails
59 dnl
60 dnl This uses 'unset' if the shell happens to support it, but leaves the
61 dnl configuration variable set to 'unknown' if not.  This is a little better
62 dnl than the normal autoconf test, which gives misleading results if a test
63 dnl for the function is made (e.g., with AC_CHECK_FUNC) after this macro is
64 dnl used (autoconf does not distinguish between a null token and one that is
65 dnl set to 'no').
66 AC_DEFUN([CF_RECHECK_FUNC],[
67 AC_CHECK_LIB($2,$1,[
68         CF_UPPER(cf_tr_func,$1)
69         AC_DEFINE_UNQUOTED(HAVE_$cf_tr_func)
70         ac_cv_func_$1=yes
71         $3="-l$2 [$]$3"],[
72         ac_cv_func_$1=unknown
73         unset ac_cv_func_$1 2>/dev/null
74         $4],
75         [[$]$3])
76 ])dnl
77 dnl ---------------------------------------------------------------------------
78 dnl Make an uppercase version of a variable
79 dnl $1=uppercase($2)
80 AC_DEFUN([CF_UPPER],
82 changequote(,)dnl
83 $1=`echo $2 | tr '[a-z]' '[A-Z]'`
84 changequote([,])dnl
85 ])dnl
87 dnl ---------------------------------------------------------------------------
88 dnl Got this from the GNU tar 1.13.11 distribution
89 dnl by Paul Eggert <eggert@twinsun.com>
90 dnl ---------------------------------------------------------------------------
92 dnl By default, many hosts won't let programs access large files;
93 dnl one must use special compiler options to get large-file access to work.
94 dnl For more details about this brain damage please see:
95 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
97 dnl Written by Paul Eggert <eggert@twinsun.com>.
99 dnl Internal subroutine of AC_SYS_LARGEFILE.
100 dnl AC_SYS_LARGEFILE_FLAGS(FLAGSNAME)
101 AC_DEFUN(AC_SYS_LARGEFILE_FLAGS,
102   [AC_CACHE_CHECK([for $1 value to request large file support],
103      ac_cv_sys_largefile_$1,
104      [ac_cv_sys_largefile_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
105         ac_cv_sys_largefile_$1=no
106         ifelse($1, CFLAGS,
107           [case "$host_os" in
108            # HP-UX 10.20 requires -D__STDC_EXT__ with gcc 2.95.1.
109 changequote(, )dnl
110            hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
111 changequote([, ])dnl
112              if test "$GCC" = yes; then
113                ac_cv_sys_largefile_CFLAGS=-D__STDC_EXT__
114              fi
115              ;;
116            # IRIX 6.2 and later require cc -n32.
117 changequote(, )dnl
118            irix6.[2-9]* | irix6.1[0-9]* | irix[7-9].* | irix[1-9][0-9]*)
119 changequote([, ])dnl
120              if test "$GCC" != yes; then
121                ac_cv_sys_largefile_CFLAGS=-n32
122              fi
123            esac
124            if test "$ac_cv_sys_largefile_CFLAGS" != no; then
125              ac_save_CC="$CC"
126              CC="$CC $ac_cv_sys_largefile_CFLAGS"
127              AC_TRY_LINK(, , , ac_cv_sys_largefile_CFLAGS=no)
128              CC="$ac_save_CC"
129            fi])
130       }])])
132 dnl Internal subroutine of AC_SYS_LARGEFILE.
133 dnl AC_SYS_LARGEFILE_SPACE_APPEND(VAR, VAL)
134 AC_DEFUN(AC_SYS_LARGEFILE_SPACE_APPEND,
135   [case $2 in
136    no) ;;
137    ?*)
138      case "[$]$1" in
139      '') $1=$2 ;;
140      *) $1=[$]$1' '$2 ;;
141      esac ;;
142    esac])
144 dnl Internal subroutine of AC_SYS_LARGEFILE.
145 dnl AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
146 AC_DEFUN(AC_SYS_LARGEFILE_MACRO_VALUE,
147   [AC_CACHE_CHECK([for $1], $2,
148      [$2=no
149 changequote(, )dnl
150       $4
151       for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
152         case "$ac_flag" in
153         -D$1)
154           $2=1 ;;
155         -D$1=*)
156           $2=`expr " $ac_flag" : '[^=]*=\(.*\)'` ;;
157         esac
158       done
159 changequote([, ])dnl
160       ])
161    if test "[$]$2" != no; then
162      AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
163    fi])
165 AC_DEFUN(AC_SYS_LARGEFILE,
166   [AC_REQUIRE([AC_CANONICAL_HOST])
167    AC_ARG_ENABLE(largefile,
168      [  --disable-largefile     omit support for large files])
169    if test "$enable_largefile" != no; then
170      AC_CHECK_TOOL(GETCONF, getconf)
171      AC_SYS_LARGEFILE_FLAGS(CFLAGS)
172      AC_SYS_LARGEFILE_FLAGS(LDFLAGS)
173      AC_SYS_LARGEFILE_FLAGS(LIBS)
175      for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
176        case "$ac_flag" in
177        no) ;;
178        -D_FILE_OFFSET_BITS=*) ;;
179        -D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
180        -D_LARGE_FILES | -D_LARGE_FILES=*) ;;
181        -D?* | -I?*)
182          AC_SYS_LARGEFILE_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
183        *)
184          AC_SYS_LARGEFILE_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
185        esac
186      done
187      AC_SYS_LARGEFILE_SPACE_APPEND(LDFLAGS, "$ac_cv_sys_largefile_LDFLAGS")
188      AC_SYS_LARGEFILE_SPACE_APPEND(LIBS, "$ac_cv_sys_largefile_LIBS")
189      AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS,
190        ac_cv_sys_file_offset_bits,
191        [Number of bits in a file offset, on hosts where this is settable.],
192        [case "$host_os" in
193         # HP-UX 10.20 and later
194         hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
195           ac_cv_sys_file_offset_bits=64 ;;
196         esac])
197      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE,
198        ac_cv_sys_largefile_source,
199        [Define to make fseeko etc. visible, on some hosts.],
200        [case "$host_os" in
201         # HP-UX 10.20 and later
202         hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
203           ac_cv_sys_largefile_source=1 ;;
204         esac])
205      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES,
206        ac_cv_sys_large_files,
207        [Define for large files, on AIX-style hosts.],
208        [case "$host_os" in
209         # AIX 4.2 and later
210         aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)
211           ac_cv_sys_large_files=1 ;;
212         esac])
213    fi
214   ])
217 dnl ---------------------------------------------------------------------------
218 dnl From Paul Eggert <eggert@twinsun.com>
220 dnl Define HAVE_INTTYPES_H if <inttypes.h> exists,
221 dnl doesn't clash with <sys/types.h>, and declares uintmax_t.
223 AC_DEFUN(jm_AC_HEADER_INTTYPES_H,
225   if test x = y; then
226     dnl This code is deliberately never run via ./configure.
227     dnl FIXME: this is a gross hack to make autoheader put an entry
228     dnl for `HAVE_INTTYPES_H' in config.h.in.
229     AC_CHECK_FUNCS(INTTYPES_H)
230   fi
231   AC_CACHE_CHECK([for inttypes.h], jm_ac_cv_header_inttypes_h,
232   [AC_TRY_COMPILE(
233     [#include <sys/types.h>
234 #include <inttypes.h>],
235     [uintmax_t i = (uintmax_t) -1;],
236     jm_ac_cv_header_inttypes_h=yes,
237     jm_ac_cv_header_inttypes_h=no)])
238   if test $jm_ac_cv_header_inttypes_h = yes; then
239     ac_kludge=HAVE_INTTYPES_H
240     AC_DEFINE_UNQUOTED($ac_kludge)
241   fi
245 dnl ---------------------------------------------------------------------------
246 dnl From Paul Eggert <eggert@twinsun.com>
248 AC_DEFUN(AC_STRUCT_ST_MTIM_NSEC,
249  [AC_CACHE_CHECK([for nanoseconds member of struct stat.st_mtim],
250    ac_cv_struct_st_mtim_nsec,
251    [ac_save_CPPFLAGS="$CPPFLAGS"
252     ac_cv_struct_st_mtim_nsec=no
253     # tv_nsec -- the usual case
254     # _tv_nsec -- Solaris 2.6, if
255     #   (defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1
256     #    && !defined __EXTENSIONS__)
257     # st__tim.tv_nsec -- UnixWare 2.1.2
258     for ac_val in tv_nsec _tv_nsec st__tim.tv_nsec; do
259       CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val"
260       AC_TRY_COMPILE([#include <sys/types.h>
261 #include <sys/stat.h>], [struct stat s; s.st_mtim.ST_MTIM_NSEC;],
262         [ac_cv_struct_st_mtim_nsec=$ac_val; break])
263     done
264     CPPFLAGS="$ac_save_CPPFLAGS"])
266   if test $ac_cv_struct_st_mtim_nsec != no; then
267     AC_DEFINE_UNQUOTED(ST_MTIM_NSEC, $ac_cv_struct_st_mtim_nsec)
268   fi
272 dnl ---------------------------------------------------------------------------
273 dnl From Paul Eggert <eggert@twinsun.com>
275 dnl Define uintmax_t to `unsigned long' or `unsigned long long'
276 dnl if <inttypes.h> does not exist.
278 AC_DEFUN(jm_AC_TYPE_UINTMAX_T,
280   AC_REQUIRE([jm_AC_HEADER_INTTYPES_H])
281   if test $jm_ac_cv_header_inttypes_h = no; then
282     AC_CACHE_CHECK([for unsigned long long], ac_cv_type_unsigned_long_long,
283     [AC_TRY_LINK([unsigned long long ull = 1; int i = 63;],
284       [unsigned long long ullmax = (unsigned long long) -1;
285        return ull << i | ull >> i | ullmax / ull | ullmax % ull;],
286       ac_cv_type_unsigned_long_long=yes,
287       ac_cv_type_unsigned_long_long=no)])
288     if test $ac_cv_type_unsigned_long_long = yes; then
289       AC_DEFINE(uintmax_t, unsigned long long)
290     else
291       AC_DEFINE(uintmax_t, unsigned long)
292     fi
293   fi
297 dnl ---------------------------------------------------------------------------
298 dnl From Steve Robbins <steve@nyongwa.montreal.qc.ca>
300 dnl From a proposed change made on the autoconf list on 2 Feb 1999
301 dnl http://sourceware.cygnus.com/ml/autoconf/1999-02/msg00001.html
302 dnl Patch for AIX 3.2 by Lars Hecking <lhecking@nmrc.ucc.ie> on 17 May 1999
304 AC_DEFUN(AC_FUNC_SELECT,
305 [AC_CHECK_FUNCS(select)
306 if test "$ac_cv_func_select" = yes; then
307   AC_CHECK_HEADERS(unistd.h sys/types.h sys/time.h sys/select.h sys/socket.h)
308   AC_MSG_CHECKING([argument types of select()])
309   AC_CACHE_VAL(ac_cv_type_fd_set_size_t,dnl
310     [AC_CACHE_VAL(ac_cv_type_fd_set,dnl
311       [for ac_cv_type_fd_set in 'fd_set' 'int' 'void'; do
312         for ac_cv_type_fd_set_size_t in 'int' 'size_t' 'unsigned long' 'unsigned'; do
313           for ac_type_timeval in 'struct timeval' 'const struct timeval'; do
314             AC_TRY_COMPILE(dnl
315 [#ifdef HAVE_SYS_TIME_H
316 #include <sys/time.h>
317 #endif
318 #ifdef HAVE_SYS_TYPES_H
319 #include <sys/types.h>
320 #endif
321 #ifdef HAVE_UNISTD_H
322 #include <unistd.h>
323 #endif
324 #ifdef HAVE_SYS_SELECT_H
325 #include <sys/select.h>
326 #endif
327 #ifdef HAVE_SYS_SOCKET_H
328 #include <sys/socket.h>
329 #endif],
330 [#ifdef __STDC__
331 extern select ($ac_cv_type_fd_set_size_t,
332  $ac_cv_type_fd_set *,  $ac_cv_type_fd_set *, $ac_cv_type_fd_set *,
333  $ac_type_timeval *);
334 #else
335 extern select ();
336   $ac_cv_type_fd_set_size_t s;
337   $ac_cv_type_fd_set *p;
338   $ac_type_timeval *t;
339 #endif],
340 [ac_found=yes ; break 3],ac_found=no)
341           done
342         done
343       done
344     ])dnl AC_CACHE_VAL
345   ])dnl AC_CACHE_VAL
346   if test "$ac_found" = no; then
347     AC_MSG_ERROR([can't determine argument types])
348   fi
350   AC_MSG_RESULT([select($ac_cv_type_fd_set_size_t,$ac_cv_type_fd_set *,...)])
351   AC_DEFINE_UNQUOTED(fd_set_size_t, $ac_cv_type_fd_set_size_t)
352   ac_cast=
353   if test "$ac_cv_type_fd_set" != fd_set; then
354     # Arguments 2-4 are not fd_set.  Some weirdo systems use fd_set type for
355     # FD_SET macros, but insist that you cast the argument to select.  I don't
356     # understand why that might be, but it means we cannot define fd_set.
357     AC_EGREP_CPP(dnl
358 changequote(<<,>>)dnl
359 <<(^|[^a-zA-Z_0-9])fd_set[^a-zA-Z_0-9]>>dnl
360 changequote([,]),dnl
361 [#ifdef HAVE_SYS_TIME_H
362 #include <sys/time.h>
363 #endif
364 #ifdef HAVE_SYS_TYPES_H
365 #include <sys/types.h>
366 #endif
367 #ifdef HAVE_UNISTD_H
368 #include <unistd.h>
369 #endif
370 #ifdef HAVE_SYS_SELECT_H
371 #include <sys/select.h>
372 #endif
373 #ifdef HAVE_SYS_SOCKET_H
374 #include <sys/socket.h>
375 #endif],dnl
376     # We found fd_set type in a header, need special cast
377     ac_cast="($ac_cv_type_fd_set *)",dnl
378     # No fd_set type; it is safe to define it
379     AC_DEFINE_UNQUOTED(fd_set,$ac_cv_type_fd_set))
380   fi
381   AC_DEFINE_UNQUOTED(SELECT_FD_SET_CAST,$ac_cast)
386 # The following is taken from automake 1.4,
387 # except that it prefers the compiler option -Ae to "-Aa -D_HPUX_SOURCE"
388 # because only the former supports 64-bit integral types on HP-UX 10.20.
390 ## ----------------------------------------- ##
391 ## ANSIfy the C compiler whenever possible.  ##
392 ## From Franc,ois Pinard                     ##
393 ## ----------------------------------------- ##
395 # serial 2
397 # @defmac AC_PROG_CC_STDC
398 # @maindex PROG_CC_STDC
399 # @ovindex CC
400 # If the C compiler in not in ANSI C mode by default, try to add an option
401 # to output variable @code{CC} to make it so.  This macro tries various
402 # options that select ANSI C on some system or another.  It considers the
403 # compiler to be in ANSI C mode if it handles function prototypes correctly.
405 # If you use this macro, you should check after calling it whether the C
406 # compiler has been set to accept ANSI C; if not, the shell variable
407 # @code{am_cv_prog_cc_stdc} is set to @samp{no}.  If you wrote your source
408 # code in ANSI C, you can make an un-ANSIfied copy of it by using the
409 # program @code{ansi2knr}, which comes with Ghostscript.
410 # @end defmac
412 AC_DEFUN(AM_PROG_CC_STDC,
413 [AC_REQUIRE([AC_PROG_CC])
414 AC_BEFORE([$0], [AC_C_INLINE])
415 AC_BEFORE([$0], [AC_C_CONST])
416 dnl Force this before AC_PROG_CPP.  Some cpp's, eg on HPUX, require
417 dnl a magic option to avoid problems with ANSI preprocessor commands
418 dnl like #elif.
419 dnl FIXME: can't do this because then AC_AIX won't work due to a
420 dnl circular dependency.
421 dnl AC_BEFORE([$0], [AC_PROG_CPP])
422 AC_MSG_CHECKING(for ${CC-cc} option to accept ANSI C)
423 AC_CACHE_VAL(am_cv_prog_cc_stdc,
424 [am_cv_prog_cc_stdc=no
425 ac_save_CC="$CC"
426 # Don't try gcc -ansi; that turns off useful extensions and
427 # breaks some systems' header files.
428 # AIX                   -qlanglvl=ansi
429 # Ultrix and OSF/1      -std1
430 # HP-UX                 -Aa -D_HPUX_SOURCE
431 # SVR4                  -Xc -D__EXTENSIONS__
432 for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
434   CC="$ac_save_CC $ac_arg"
435   AC_TRY_COMPILE(
436 [#include <stdarg.h>
437 #include <stdio.h>
438 #include <sys/types.h>
439 #include <sys/stat.h>
440 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
441 struct buf { int x; };
442 FILE * (*rcsopen) (struct buf *, struct stat *, int);
443 static char *e (p, i)
444      char **p;
445      int i;
447   return p[i];
449 static char *f (char * (*g) (char **, int), char **p, ...)
451   char *s;
452   va_list v;
453   va_start (v,p);
454   s = g (p, va_arg (v,int));
455   va_end (v);
456   return s;
458 int test (int i, double x);
459 struct s1 {int (*f) (int a);};
460 struct s2 {int (*f) (double a);};
461 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
462 int argc;
463 char **argv;
464 ], [
465 return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
467 [am_cv_prog_cc_stdc="$ac_arg"; break])
468 done
469 CC="$ac_save_CC"
471 if test -z "$am_cv_prog_cc_stdc"; then
472   AC_MSG_RESULT([none needed])
473 else
474   AC_MSG_RESULT($am_cv_prog_cc_stdc)
476 case "x$am_cv_prog_cc_stdc" in
477   x|xno) ;;
478   *) CC="$CC $am_cv_prog_cc_stdc" ;;
479 esac