1dnl acinclude.m4 -- Extra macros needed for GNU make.
2dnl
3dnl Automake will incorporate this into its generated aclocal.m4.
4dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5dnl 2008, 2009, 2010 Free Software Foundation, Inc.
6dnl This file is part of GNU Make.
7dnl
8dnl GNU Make is free software; you can redistribute it and/or modify it under
9dnl the terms of the GNU General Public License as published by the Free
10dnl Software Foundation; either version 3 of the License, or (at your option)
11dnl any later version.
12dnl
13dnl GNU Make is distributed in the hope that it will be useful, but WITHOUT
14dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for.
16dnl more details.
17dnl
18dnl You should have received a copy of the GNU General Public License along
19dnl with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21dnl ---------------------------------------------------------------------------
22dnl Got this from the lynx 2.8 distribution.
23dnl by T.E.Dickey <dickey@clark.net>
24dnl and Jim Spath <jspath@mail.bcpl.lib.md.us>
25dnl and Philippe De Muyter <phdm@macqel.be>
26dnl
27dnl Created: 1997/1/28
28dnl Updated: 1997/12/23
29dnl ---------------------------------------------------------------------------
30dnl After checking for functions in the default $LIBS, make a further check
31dnl for the functions that are netlib-related (these aren't always in the
32dnl libc, etc., and have to be handled specially because there are conflicting
33dnl and broken implementations.
34dnl Common library requirements (in order):
35dnl	-lresolv -lsocket -lnsl
36dnl	-lnsl -lsocket
37dnl	-lsocket
38dnl	-lbsd
39AC_DEFUN([CF_NETLIBS],[
40cf_test_netlibs=no
41AC_MSG_CHECKING(for network libraries)
42AC_CACHE_VAL(cf_cv_netlibs,[
43AC_MSG_RESULT(working...)
44cf_cv_netlibs=""
45cf_test_netlibs=yes
46AC_CHECK_FUNCS(gethostname,,[
47	CF_RECHECK_FUNC(gethostname,nsl,cf_cv_netlibs,[
48		CF_RECHECK_FUNC(gethostname,socket,cf_cv_netlibs)])])
49#
50# FIXME:  sequent needs this library (i.e., -lsocket -linet -lnsl), but
51# I don't know the entrypoints - 97/7/22 TD
52AC_CHECK_LIB(inet,main,cf_cv_netlibs="-linet $cf_cv_netlibs")
53#
54if test "$ac_cv_func_lsocket" != no ; then
55AC_CHECK_FUNCS(socket,,[
56	CF_RECHECK_FUNC(socket,socket,cf_cv_netlibs,[
57		CF_RECHECK_FUNC(socket,bsd,cf_cv_netlibs)])])
58fi
59#
60AC_CHECK_FUNCS(gethostbyname,,[
61	CF_RECHECK_FUNC(gethostbyname,nsl,cf_cv_netlibs)])
62])
63LIBS="$LIBS $cf_cv_netlibs"
64test $cf_test_netlibs = no && echo "$cf_cv_netlibs" >&AC_FD_MSG
65])dnl
66dnl ---------------------------------------------------------------------------
67dnl Re-check on a function to see if we can pick it up by adding a library.
68dnl	$1 = function to check
69dnl	$2 = library to check in
70dnl	$3 = environment to update (e.g., $LIBS)
71dnl	$4 = what to do if this fails
72dnl
73dnl This uses 'unset' if the shell happens to support it, but leaves the
74dnl configuration variable set to 'unknown' if not.  This is a little better
75dnl than the normal autoconf test, which gives misleading results if a test
76dnl for the function is made (e.g., with AC_CHECK_FUNC) after this macro is
77dnl used (autoconf does not distinguish between a null token and one that is
78dnl set to 'no').
79AC_DEFUN([CF_RECHECK_FUNC],[
80AC_CHECK_LIB($2,$1,[
81	CF_UPPER(cf_tr_func,$1)
82	AC_DEFINE_UNQUOTED(HAVE_$cf_tr_func,1,[Define if you have function $1])
83	ac_cv_func_$1=yes
84	$3="-l$2 [$]$3"],[
85	ac_cv_func_$1=unknown
86	unset ac_cv_func_$1 2>/dev/null
87	$4],
88	[[$]$3])
89])dnl
90dnl ---------------------------------------------------------------------------
91dnl Make an uppercase version of a variable
92dnl $1=uppercase($2)
93AC_DEFUN([CF_UPPER],
94[
95changequote(,)dnl
96$1=`echo $2 | tr '[a-z]' '[A-Z]'`
97changequote([,])dnl
98])dnl
99
100
101dnl ---------------------------------------------------------------------------
102dnl From Paul Eggert <eggert@twinsun.com>
103
104AC_DEFUN([AC_STRUCT_ST_MTIM_NSEC],
105 [AC_CACHE_CHECK([for nanoseconds field of struct stat.st_mtim],
106   ac_cv_struct_st_mtim_nsec,
107   [ac_save_CPPFLAGS="$CPPFLAGS"
108    ac_cv_struct_st_mtim_nsec=no
109    # tv_nsec -- the usual case
110    # _tv_nsec -- Solaris 2.6, if
111    #	(defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1
112    #	 && !defined __EXTENSIONS__)
113    # st__tim.tv_nsec -- UnixWare 2.1.2
114    for ac_val in tv_nsec _tv_nsec st__tim.tv_nsec; do
115      CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val"
116      AC_TRY_COMPILE([#include <sys/types.h>
117#include <sys/stat.h>
118	], [struct stat s; s.st_mtim.ST_MTIM_NSEC;],
119        [ac_cv_struct_st_mtim_nsec=$ac_val; break])
120    done
121    CPPFLAGS="$ac_save_CPPFLAGS"
122   ])
123
124  if test $ac_cv_struct_st_mtim_nsec != no; then
125    AC_DEFINE_UNQUOTED([ST_MTIM_NSEC], [$ac_cv_struct_st_mtim_nsec],
126	[Define if struct stat contains a nanoseconds field])
127  fi
128 ]
129)
130