2119861ff0cec5e9fa2f6d2b1758b05029097337
[ircu2.10.12-pk.git] / config / 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_CHECK_LIB_RESOLV
27 dnl
28 dnl   Check for res_mkquery in -lresolv and add that to LIBS when needed.
29 dnl
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);],
35 [int op;
36 const char *dname;
37 int class, type;
38 const char *data;
39 int datalen;
40 struct rrec *newrr;
41 unsigned char *buf;
42 int buflen;
43 res_mkquery(op,dname,class,type,data,datalen,newrr,buf,buflen)],
44 unet_cv_lib_resolv=no, [OLD_LIBS="$LIBS"
45 LIBS="$LIBS -lresolv"
46 AC_TRY_LINK([extern char *_res;], [*_res=0],
47 unet_cv_lib_resolv=yes, unet_cv_lib_resolv=no)
48 LIBS="$OLD_LIBS"])])
49 if test $unet_cv_lib_resolv = yes; then
50   AC_DEFINE(HAVE_LIB_RESOLV)
51   LIBS="$LIBS -lresolv"
52 fi])
53
54 dnl
55 dnl Macro: unet_NONBLOCKING
56 dnl
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.
59 dnl
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>
65 #include <fcntl.h>
66 #include <sys/ioctl.h>
67 #include <sys/file.h>
68 #include <signal.h>
69 $ac_cv_type_signal alarmed() { exit(1); }
70 int main(void)
71 {
72   char b[12];
73   struct sockaddr x;
74   size_t l = sizeof(x);
75   int f = socket(AF_INET, SOCK_DGRAM, 0);
76   if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
77   {
78     signal(SIGALRM, alarmed);
79     alarm(2);
80     recvfrom(f, b, 12, 0, &x, &l);
81     alarm(0);
82     exit(0);
83   }
84   exit(1);
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)
88 else
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>
92 #include <fcntl.h>
93 #include <sys/ioctl.h>
94 #include <sys/file.h>
95 #include <signal.h>
96 $ac_cv_type_signal alarmed() { exit(1); }
97 int main(void)
98 {
99   char b[12];
100   struct sockaddr x;
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)))
104   {
105     signal(SIGALRM, alarmed);
106     alarm(2);
107     recvfrom(f, b, 12, 0, &x, &l);
108     alarm(0);
109     exit(0);
110   }
111   exit(1);
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)
115 else
116   AC_DEFINE(NBLOCK_SYSV)
117 fi
118 fi])
119
120 dnl
121 dnl Macro: unet_SIGNALS
122 dnl
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.
126 dnl
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)
135 else
136 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
137 [AC_TRY_RUN([#include <signal.h>
138 int calls = 0;
139 $ac_cv_type_signal handler()
140 {
141   if (calls) return;
142   calls++;
143   kill(getpid(), SIGTERM);
144   sleep(1);
145 }
146 int main(void)
147 {
148   signal(SIGTERM, handler);
149   kill(getpid(), SIGTERM);
150   exit (0);
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)
154 else
155   AC_DEFINE(SYSV_UNRELIABLE_SIGNALS)
156 fi
157 fi])
158
159 dnl
160 dnl Macro: unet_DEFINE_SIZE_T_FMT
161 dnl
162 dnl Define SIZE_T_FMT to be "%u" or "%lu", whichever seems more appropriate.
163 dnl
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
169   AC_MSG_RESULT("%u")
170   AC_DEFINE(SIZE_T_FMT, "%u")
171 else
172   AC_MSG_RESULT("%lu")
173   AC_DEFINE(SIZE_T_FMT, "%lu")
174 fi])
175
176 dnl
177 dnl Macro: unet_DEFINE_TIME_T_FMT
178 dnl
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.
182 dnl
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>
189 main()
190 {
191   FILE *f=fopen("conftestval", "w");
192   if (!f) exit(1);
193   fprintf(f, "%d\n", sizeof(time_t));
194   exit(0);
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")
201 else
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
205     AC_MSG_RESULT("%lu")
206     AC_DEFINE(TIME_T_FMT, "%lu")
207     AC_DEFINE(STIME_T_FMT, "%ld")
208   else
209     AC_MSG_RESULT("%u")
210     AC_DEFINE(TIME_T_FMT, "%u")
211     AC_DEFINE(STIME_T_FMT, "%d")
212   fi
213 fi])
214
215 dnl
216 dnl Macro: unet_CHECK_TYPE_SIZES
217 dnl
218 dnl Check the size of several types and define a valid int16_t and int32_t.
219 dnl
220 AC_DEFUN(unet_CHECK_TYPE_SIZES,
221 [dnl Check type sizes
222 AC_CHECK_SIZEOF(short)
223 AC_CHECK_SIZEOF(int)
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)
231 else
232   AC_MSG_ERROR([Cannot find a type with size of 16 bits])
233 fi
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)
243 else
244   AC_MSG_ERROR([Cannot find a type with size of 32 bits])
245 fi])
246
247 dnl
248 dnl Macro: unet_FUNC_POLL_SYSCALL
249 dnl
250 dnl Try to figure out if we have a system call poll (not if it is emulated).
251 dnl Manical laughter...
252 dnl
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)])
257 else
258   AC_MSG_CHECKING([if poll is a system call])
259 fi
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:
263 changequote(, )dnl
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
279               fi
280             fi
281           fi
282         done
283       fi
284     fi
285   done
286 fi
287 changequote([, ])dnl
288 ])
289 AC_MSG_RESULT([$unet_cv_func_poll_syscall])
290 ])