2 dnl Macro: unet_PIPE_CFLAGS
4 dnl If the compiler understands -pipe, add it to CFLAGS if not already
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
12 CFLAGS="$CFLAGS -pipe"
13 AC_TRY_COMPILE(,,unet_cv_pipe_flags=yes,)
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"
26 dnl Macro: unet_CHECK_LIB_RESOLV
28 dnl Check for res_mkquery in -lresolv and add that to LIBS when needed.
30 AC_DEFUN(unet_CHECK_LIB_RESOLV,
31 [AC_CACHE_CHECK([for res_mkquery in -lresolv], unet_cv_lib_resolv,
32 [AC_TRY_LINK([struct rrec;
33 extern int res_mkquery(int, const char *, int, int, const char *,
34 int, struct rrec *, unsigned char *, int);],
43 res_mkquery(op,dname,class,type,data,datalen,newrr,buf,buflen)],
44 unet_cv_lib_resolv=no, [OLD_LIBS="$LIBS"
46 AC_TRY_LINK([extern char *_res;], [*_res=0],
47 unet_cv_lib_resolv=yes, unet_cv_lib_resolv=no)
49 if test $unet_cv_lib_resolv = yes; then
50 AC_DEFINE(HAVE_LIB_RESOLV)
55 dnl Macro: unet_NONBLOCKING
57 dnl Check whether we have posix, bsd or sysv non-blocking sockets and
58 dnl define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV.
60 AC_DEFUN(unet_NONBLOCKING,
61 [dnl Do we have posix, bsd or sysv non-blocking stuff ?
62 AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix,
63 [AC_TRY_RUN([#include <sys/types.h>
64 #include <sys/socket.h>
66 #include <sys/ioctl.h>
69 $ac_cv_type_signal alarmed() { exit(1); }
75 int f = socket(AF_INET, SOCK_DGRAM, 0);
76 if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
78 signal(SIGALRM, alarmed);
80 recvfrom(f, b, 12, 0, &x, &l);
85 }], unet_cv_sys_nonblocking_posix=yes, unet_cv_sys_nonblocking_posix=no)])
86 if test $unet_cv_sys_nonblocking_posix = yes; then
87 AC_DEFINE(NBLOCK_POSIX)
89 AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd,
90 [AC_TRY_RUN([#include <sys/types.h>
91 #include <sys/socket.h>
93 #include <sys/ioctl.h>
96 $ac_cv_type_signal alarmed() { exit(1); }
101 size_t l = sizeof(x);
102 int f = socket(AF_INET, SOCK_DGRAM, 0);
103 if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
105 signal(SIGALRM, alarmed);
107 recvfrom(f, b, 12, 0, &x, &l);
112 }], unet_cv_sys_nonblocking_bsd=yes, unet_cv_sys_nonblocking_bsd=no)])
113 if test $unet_cv_sys_nonblocking_bsd = yes; then
114 AC_DEFINE(NBLOCK_BSD)
116 AC_DEFINE(NBLOCK_SYSV)
121 dnl Macro: unet_SIGNALS
123 dnl Check if we have posix signals, reliable bsd signals or
124 dnl unreliable sysv signals and define respectively POSIX_SIGNALS,
125 dnl BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS.
127 AC_DEFUN(unet_SIGNALS,
128 [dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ?
129 AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix,
130 [AC_TRY_COMPILE([#include <signal.h>],
131 [sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L)],
132 unet_cv_sys_signal_posix=yes, unet_cv_sys_signal_posix=no)])
133 if test $unet_cv_sys_signal_posix = yes; then
134 AC_DEFINE(POSIX_SIGNALS)
136 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
137 [AC_TRY_RUN([#include <signal.h>
139 $ac_cv_type_signal handler()
143 kill(getpid(), SIGTERM);
148 signal(SIGTERM, handler);
149 kill(getpid(), SIGTERM);
151 }], unet_cv_sys_signal_bsd=yes, unet_cv_sys_signal_bsd=no)])
152 if test $unet_cv_sys_signal_bsd = yes; then
153 AC_DEFINE(BSD_RELIABLE_SIGNALS)
155 AC_DEFINE(SYSV_UNRELIABLE_SIGNALS)
160 dnl Macro: unet_DEFINE_SIZE_T_FMT
162 dnl Define SIZE_T_FMT to be "%u" or "%lu", whichever seems more appropriate.
164 AC_DEFUN(unet_DEFINE_SIZE_T_FMT,
165 [dnl Make educated guess :/, if size_t is a long or not
166 AC_CHECK_SIZEOF(size_t)dnl
167 AC_MSG_CHECKING(printf format of size_t)
168 if test "$ac_cv_sizeof_size_t" = 4 ; then
170 AC_DEFINE(SIZE_T_FMT, "%u")
173 AC_DEFINE(SIZE_T_FMT, "%lu")
177 dnl Macro: unet_DEFINE_TIME_T_FMT
179 dnl Try to figure out if time_t is an int or not, and if so define
180 dnl TIME_T_FMT to be "%u", otherwise define it to be "%lu".
181 dnl Likewise define STIME_T_FMT for the signed format.
183 AC_DEFUN(unet_DEFINE_TIME_T_FMT,
184 [dnl Make educated guess :/, if time_t is a long or not
185 AC_MSG_CHECKING(size of time_t)
186 AC_CACHE_VAL(unet_cv_sizeof_time_t,
187 [AC_TRY_RUN([#include <stdio.h>
188 #include <sys/types.h>
191 FILE *f=fopen("conftestval", "w");
193 fprintf(f, "%d\n", sizeof(time_t));
195 }], unet_cv_sizeof_time_t=`cat conftestval`,
196 unet_cv_sizeof_time_t=0, unet_cv_sizeof_time_t=0)])
197 if test "$unet_cv_sizeof_time_t" = 0 ; then
198 AC_MSG_RESULT(unknown)
199 AC_DEFINE(TIME_T_FMT, "%lu")
200 AC_DEFINE(STIME_T_FMT, "%ld")
202 AC_MSG_RESULT([$unet_cv_sizeof_time_t])
203 AC_MSG_CHECKING(printf format of time_t)
204 if test "$unet_cv_sizeof_time_t" = "$ac_cv_sizeof_long" ; then
206 AC_DEFINE(TIME_T_FMT, "%lu")
207 AC_DEFINE(STIME_T_FMT, "%ld")
210 AC_DEFINE(TIME_T_FMT, "%u")
211 AC_DEFINE(STIME_T_FMT, "%d")
216 dnl Macro: unet_CHECK_TYPE_SIZES
218 dnl Check the size of several types and define a valid int16_t and int32_t.
220 AC_DEFUN(unet_CHECK_TYPE_SIZES,
221 [dnl Check type sizes
222 AC_CHECK_SIZEOF(short)
224 AC_CHECK_SIZEOF(long)
225 if test "$ac_cv_sizeof_int" = 2 ; then
226 AC_CHECK_TYPE(int16_t, int)
227 AC_CHECK_TYPE(u_int16_t, unsigned int)
228 elif test "$ac_cv_sizeof_short" = 2 ; then
229 AC_CHECK_TYPE(int16_t, short)
230 AC_CHECK_TYPE(u_int16_t, unsigned short)
232 AC_MSG_ERROR([Cannot find a type with size of 16 bits])
234 if test "$ac_cv_sizeof_int" = 4 ; then
235 AC_CHECK_TYPE(int32_t, int)
236 AC_CHECK_TYPE(u_int32_t, unsigned int)
237 elif test "$ac_cv_sizeof_short" = 4 ; then
238 AC_CHECK_TYPE(int32_t, short)
239 AC_CHECK_TYPE(u_int32_t, unsigned short)
240 elif test "$ac_cv_sizeof_long" = 4 ; then
241 AC_CHECK_TYPE(int32_t, long)
242 AC_CHECK_TYPE(u_int32_t, unsigned long)
244 AC_MSG_ERROR([Cannot find a type with size of 32 bits])
248 dnl Macro: unet_FUNC_POLL_SYSCALL
250 dnl Try to figure out if we have a system call poll (not if it is emulated).
251 dnl Manical laughter...
253 AC_DEFUN(unet_FUNC_POLL_SYSCALL,
254 [AC_CHECK_HEADERS(poll.h)dnl
255 if test -z "$unet_cv_func_poll_syscall" ; then
256 AC_MSG_CHECKING([if poll is a system call (please wait)])
258 AC_MSG_CHECKING([if poll is a system call])
260 AC_CACHE_VAL(unet_cv_func_poll_syscall,
261 [unet_cv_func_poll_syscall=no
262 dnl No need to go through the trouble when we don't have poll.h:
264 if test "$ac_cv_header_poll_h" = yes; then
265 unet_dirs=`find /usr/include/sys -type f -name '*.h' -exec egrep '^#include <[^/]*/.*>' {} \; | sed -e 's/^.*<//' -e 's%/.*$%%' | sort | uniq`
266 for i in $unet_dirs ; do
267 if test "$unet_cv_func_poll_syscall" = no ; then
268 unet_files=`ls /usr/include/$i/*.h 2> /dev/null`
269 if test -n "$unet_files" ; then
270 for j in $unet_files ; do
271 if test "$unet_cv_func_poll_syscall" = no ; then
272 unet_line=`egrep '^#define[[:space:]]+[[:alnum:]_]*[Pp][Oo][Ll][Ll]' $j`
273 if test -n "$unet_line" ; then
274 unet_sig=`echo "$unet_line" | sed -e 's/poll/fork/g' -e 's/POLL/FORK/g' -e 's/[[:space:]]//g' -e 's%/\*.*\*/%%g' -e 's/[0-9]//g'`
275 unet_set=`for k in "$unet_sig" ; do echo $k; done | sed -e 's% %|%g'`
276 unet_match=`sed -e 's/[[:space:]]//g' -e 's%/\*.*\*/%%g' -e 's/[0-9]//g' $j | egrep "$unet_set"`
277 if test -n "$unet_match" ; then
278 unet_cv_func_poll_syscall=yes
289 AC_MSG_RESULT([$unet_cv_func_poll_syscall])