Fix bugs exposed by hikari's update to configure.in.
[ircu2.10.12-pk.git] / acinclude.m4
1 dnl
2 dnl Macro: unet_PIPE_CFLAGS
3 dnl
4 dnl   If the compiler understands -pipe, add it to CFLAGS if not already
5 dnl   there.
6 dnl
7 AC_DEFUN(unet_PIPE_CFLAGS,
8 [AC_MSG_CHECKING([if the compiler understands -pipe])
9 unet_cv_pipe_flags="$ac_cv_prog_gcc"
10 if test "$ac_cv_prog_gcc" = no; then
11   OLDCFLAGS="$CFLAGS"
12   CFLAGS="$CFLAGS -pipe"
13   AC_TRY_COMPILE(,,unet_cv_pipe_flags=yes,)
14   CFLAGS="$OLDCFLAGS"
15 fi
16 AC_MSG_RESULT($unet_cv_pipe_flags)
17 if test "$unet_cv_pipe_flags" = yes ; then
18   x=`echo $CFLAGS | grep 'pipe' 2>/dev/null`
19   if test "$x" = "" ; then
20     CFLAGS="$CFLAGS -pipe"
21   fi
22 fi
23 ])
24
25 dnl
26 dnl Macro: unet_NONBLOCKING
27 dnl
28 dnl   Check whether we have posix, bsd or sysv non-blocking sockets and
29 dnl   define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV.
30 dnl
31 AC_DEFUN(unet_NONBLOCKING,
32 [dnl Do we have posix, bsd or sysv non-blocking stuff ?
33 AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix,
34 [AC_TRY_RUN([#include <sys/types.h>
35 #include <sys/socket.h>
36 #include <fcntl.h>
37 #include <sys/ioctl.h>
38 #include <sys/file.h>
39 #include <signal.h>
40 $ac_cv_type_signal alarmed() { exit(1); }
41 int main(void)
42 {
43   char b[12];
44   struct sockaddr x;
45   size_t l = sizeof(x);
46   int f = socket(AF_INET, SOCK_DGRAM, 0);
47   if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
48   {
49     signal(SIGALRM, alarmed);
50     alarm(2);
51     recvfrom(f, b, 12, 0, &x, &l);
52     alarm(0);
53     exit(0);
54   }
55   exit(1);
56 }], unet_cv_sys_nonblocking_posix=yes, unet_cv_sys_nonblocking_posix=no)])
57 if test $unet_cv_sys_nonblocking_posix = yes; then
58   AC_DEFINE([NBLOCK_POSIX],,[Define if you have POSIX non-blocking sockets.])
59 else
60 AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd,
61 [AC_TRY_RUN([#include <sys/types.h>
62 #include <sys/socket.h>
63 #include <fcntl.h>
64 #include <sys/ioctl.h>
65 #include <sys/file.h>
66 #include <signal.h>
67 $ac_cv_type_signal alarmed() { exit(1); }
68 int main(void)
69 {
70   char b[12];
71   struct sockaddr x;
72   size_t l = sizeof(x);
73   int f = socket(AF_INET, SOCK_DGRAM, 0);
74   if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
75   {
76     signal(SIGALRM, alarmed);
77     alarm(2);
78     recvfrom(f, b, 12, 0, &x, &l);
79     alarm(0);
80     exit(0);
81   }
82   exit(1);
83 }], unet_cv_sys_nonblocking_bsd=yes, unet_cv_sys_nonblocking_bsd=no)])
84 if test $unet_cv_sys_nonblocking_bsd = yes; then
85   AC_DEFINE([NBLOCK_BSD],,[Define if you have BSD non-blocking sockets.])
86 else
87   AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
88 fi
89 fi])
90
91 dnl
92 dnl Macro: unet_SIGNALS
93 dnl
94 dnl   Check if we have posix signals, reliable bsd signals or
95 dnl   unreliable sysv signals and define respectively POSIX_SIGNALS,
96 dnl   BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS.
97 dnl
98 AC_DEFUN(unet_SIGNALS,
99 [dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ?
100 AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix,
101 [AC_TRY_COMPILE([#include <signal.h>],
102 [sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L)],
103 unet_cv_sys_signal_posix=yes, unet_cv_sys_signal_posix=no)])
104 if test $unet_cv_sys_signal_posix = yes; then
105   AC_DEFINE([POSIX_SIGNALS],,[Define if you have POSIX signals.])
106 else
107 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
108 [AC_TRY_RUN([#include <signal.h>
109 int calls = 0;
110 $ac_cv_type_signal handler()
111 {
112   if (calls) return;
113   calls++;
114   kill(getpid(), SIGTERM);
115   sleep(1);
116 }
117 int main(void)
118 {
119   signal(SIGTERM, handler);
120   kill(getpid(), SIGTERM);
121   exit (0);
122 }], unet_cv_sys_signal_bsd=yes, unet_cv_sys_signal_bsd=no)])
123 if test $unet_cv_sys_signal_bsd = yes; then
124   AC_DEFINE([BSD_RELIABLE_SIGNALS],,[Define if you have (reliable) BSD signals.])
125 else
126   AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.])
127 fi
128 fi])
129
130 dnl
131 dnl Macro: unet_CHECK_TYPE_SIZES
132 dnl
133 dnl Check the size of several types and define a valid int16_t and int32_t.
134 dnl
135 AC_DEFUN(unet_CHECK_TYPE_SIZES,
136 [dnl Check type sizes
137 AC_CHECK_SIZEOF(short)
138 AC_CHECK_SIZEOF(int)
139 AC_CHECK_SIZEOF(long)
140 AC_CHECK_SIZEOF(void *)
141 if test "$ac_cv_sizeof_int" = 2 ; then
142   AC_CHECK_TYPE(int16_t, int)
143   AC_CHECK_TYPE(uint16_t, unsigned int)
144 elif test "$ac_cv_sizeof_short" = 2 ; then
145   AC_CHECK_TYPE(int16_t, short)
146   AC_CHECK_TYPE(uint16_t, unsigned short)
147 else
148   AC_MSG_ERROR([Cannot find a type with size of 16 bits])
149 fi
150 if test "$ac_cv_sizeof_int" = 4 ; then
151   AC_CHECK_TYPE(int32_t, int)
152   AC_CHECK_TYPE(uint32_t, unsigned int)
153 elif test "$ac_cv_sizeof_short" = 4 ; then
154   AC_CHECK_TYPE(int32_t, short)
155   AC_CHECK_TYPE(uint32_t, unsigned short)
156 elif test "$ac_cv_sizeof_long" = 4 ; then
157   AC_CHECK_TYPE(int32_t, long)
158   AC_CHECK_TYPE(uint32_t, unsigned long)
159 else
160   AC_MSG_ERROR([Cannot find a type with size of 32 bits])
161 fi])
162
163 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
164 dnl Domain.
165 dnl
166 dnl This test is for network applications that need socket() and
167 dnl gethostbyname() -ish functions.  Under Solaris, those applications need to
168 dnl link with "-lsocket -lnsl".  Under IRIX, they should *not* link with
169 dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
170 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
171 dnl IRIX).
172 dnl 
173 dnl Unfortunately, many application developers are not aware of this, and
174 dnl mistakenly write tests that cause -lsocket to be used under IRIX.  It is
175 dnl also easy to write tests that cause -lnsl to be used under operating
176 dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
177 dnl uses -lnsl for TLI.
178 dnl 
179 dnl This test exists so that every application developer does not test this in
180 dnl a different, and subtly broken fashion.
181 dnl 
182 dnl It has been argued that this test should be broken up into two seperate
183 dnl tests, one for the resolver libraries, and one for the libraries necessary
184 dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
185 dnl allowing the autoconf user to use them independantly potentially results in
186 dnl unfortunate ordering dependancies -- as such, such component macros would
187 dnl have to carefully use indirection and be aware if the other components were
188 dnl executed. Since other autoconf macros do not go to this trouble, and almost
189 dnl no applications use sockets without the resolver, this complexity has not
190 dnl been implemented.
191 dnl
192 dnl The check for libresolv is in case you are attempting to link statically
193 dnl and happen to have a libresolv.a lying around (and no libnsl.a).
194 dnl
195 AC_DEFUN(AC_LIBRARY_NET, [
196    # Most operating systems have gethostbyname() in the default searched
197    # libraries (i.e. libc):
198    AC_CHECK_FUNC(gethostbyname, ,
199      # Some OSes (eg. Solaris) place it in libnsl:
200      AC_CHECK_LIB(nsl, gethostbyname, , 
201        # Some strange OSes (SINIX) have it in libsocket:
202        AC_CHECK_LIB(socket, gethostbyname, ,
203           # Unfortunately libsocket sometimes depends on libnsl.
204           # AC_CHECK_LIB's API is essentially broken so the following
205           # ugliness is necessary:
206           AC_CHECK_LIB(socket, gethostbyname,
207              LIBS="-lsocket -lnsl $LIBS",
208                AC_CHECK_LIB(resolv, gethostbyname),
209              -lnsl)
210        )
211      )
212    )
213   AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
214     AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
215   ])