]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/libpcap/acsite.m4
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / libpcap / acsite.m4
1 dnl @(#) $Header: acsite.m4,v 1.41 96/11/29 15:30:40 leres Exp $ (LBL)
2 dnl
3 dnl Copyright (c) 1995, 1996
4 dnl     The Regents of the University of California.  All rights reserved.
5 dnl
6 dnl Redistribution and use in source and binary forms, with or without
7 dnl modification, are permitted provided that: (1) source code distributions
8 dnl retain the above copyright notice and this paragraph in its entirety, (2)
9 dnl distributions including binary code include the above copyright notice and
10 dnl this paragraph in its entirety in the documentation or other materials
11 dnl provided with the distribution, and (3) all advertising materials mentioning
12 dnl features or use of this software display the following acknowledgement:
13 dnl ``This product includes software developed by the University of California,
14 dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 dnl the University nor the names of its contributors may be used to endorse
16 dnl or promote products derived from this software without specific prior
17 dnl written permission.
18 dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 dnl
22 dnl LBL autoconf macros
23 dnl
24
25 dnl
26 dnl Determine which compiler we're using (cc or gcc)
27 dnl If using gcc, determine the version number
28 dnl If using cc, require that it support ansi prototypes
29 dnl If using gcc, use -O2 (otherwise use -O)
30 dnl If using cc, explicitly specify /usr/local/include
31 dnl
32 dnl usage:
33 dnl
34 dnl     AC_LBL_C_INIT(copt, incls)
35 dnl
36 dnl results:
37 dnl
38 dnl     $1 (copt set)
39 dnl     $2 (incls set)
40 dnl     CC
41 dnl     ac_cv_gcc_vers
42 dnl     LBL_CFLAGS
43 dnl
44 dnl XXX need to add test to make sure ac_prog_cc hasn't been called
45 AC_DEFUN(AC_LBL_C_INIT,
46     [AC_PREREQ(2.12)
47     $1=-O
48     $2=""
49     if test "${CFLAGS+set}" = set; then
50             LBL_CFLAGS="$CFLAGS"
51     fi
52     if test -z "$CC" ; then
53             case "$target_os" in
54
55             bsdi*)
56                     AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
57                     if test $SHLICC2 = yes ; then
58                             CC=shlicc2
59                             export CC
60                     fi
61                     ;;
62             esac
63     fi
64     AC_PROG_CC
65     if test $ac_cv_prog_gcc = yes ; then
66             if test "$SHLICC2" = yes ; then
67                     ac_cv_gcc_vers=2
68                     $1=-O2
69             else
70                     AC_MSG_CHECKING(gcc version)
71                     AC_CACHE_VAL(ac_cv_gcc_vers,
72                         ac_cv_gcc_vers=`$CC -v 2>&1 | \
73                             sed -n -e '$s/.* //' -e '$s/\..*//p'`)
74                     AC_MSG_RESULT($ac_cv_gcc_vers)
75                     if test $ac_cv_gcc_vers -gt 1 ; then
76                             $1=-O2
77                     fi
78             fi
79     else
80             AC_MSG_CHECKING(that $CC handles ansi prototypes)
81             AC_CACHE_VAL(ac_cv_cc_ansi_prototypes,
82                 AC_TRY_COMPILE(
83                     [#include <sys/types.h>],
84                     [int frob(int, char *)],
85                     ac_cv_cc_ansi_prototypes=yes,
86                     ac_cv_cc_ansi_prototypes=no))
87             AC_MSG_RESULT($ac_cv_cc_ansi_prototypes)
88             if test $ac_cv_cc_ansi_prototypes = no ; then
89                     case "$target_os" in
90
91                     hpux*)
92                             AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
93                             savedcflags="$CFLAGS"
94                             CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
95                             AC_CACHE_VAL(ac_cv_cc_hpux_cc_aa,
96                                 AC_TRY_COMPILE(
97                                     [#include <sys/types.h>],
98                                     [int frob(int, char *)],
99                                     ac_cv_cc_hpux_cc_aa=yes,
100                                     ac_cv_cc_hpux_cc_aa=no))
101                             AC_MSG_RESULT($ac_cv_cc_hpux_cc_aa)
102                             if test $ac_cv_cc_hpux_cc_aa = no ; then
103                                     AC_MSG_ERROR(see the INSTALL for more info)
104                             fi
105                             CFLAGS="$savedcflags"
106                             V_CCOPT="-Aa $V_CCOPT"
107                             AC_DEFINE(_HPUX_SOURCE)
108                             ;;
109
110                     *)
111                             AC_MSG_ERROR(see the INSTALL for more info)
112                             ;;
113                     esac
114             fi
115             $2=-I/usr/local/include
116
117             case "$target_os" in
118
119             irix*)
120                     V_CCOPT="$V_CCOPT -xansi -signed -g3"
121                     ;;
122
123             osf*)
124                     V_CCOPT="$V_CCOPT -g3"
125                     ;;
126
127             ultrix*)
128                     AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
129                     AC_CACHE_VAL(ac_cv_cc_const_proto,
130                         AC_TRY_COMPILE(
131                             [#include <sys/types.h>],
132                             [struct a { int b; };
133                             void c(const struct a *)],
134                             ac_cv_cc_const_proto=yes,
135                             ac_cv_cc_const_proto=no))
136                     AC_MSG_RESULT($ac_cv_cc_const_proto)
137                     if test $ac_cv_cc_const_proto = no ; then
138                             AC_DEFINE(const,)
139                     fi
140                     ;;
141             esac
142     fi
143 ])
144
145 dnl
146 dnl Use pfopen.c if available and pfopen() not in standard libraries
147 dnl Require libpcap
148 dnl Look for libpcap in ..
149 dnl Use the installed libpcap if there is no local version
150 dnl
151 dnl usage:
152 dnl
153 dnl     AC_LBL_LIBPCAP(pcapdep, incls)
154 dnl
155 dnl results:
156 dnl
157 dnl     $1 (pcapdep set)
158 dnl     $2 (incls appended)
159 dnl     LIBS
160 dnl
161 AC_DEFUN(AC_LBL_LIBPCAP,
162     [pfopen=/usr/examples/packetfilter/pfopen.c
163     if test -f $pfopen ; then
164             AC_CHECK_FUNCS(pfopen)
165             if test $ac_cv_func_pfopen = "no" ; then
166                     AC_MSG_RESULT(Using $pfopen)
167                     LIBS="$LIBS $pfopen"
168             fi
169     fi
170     AC_MSG_CHECKING(for local pcap library)
171     libpcap=FAIL
172     lastdir=FAIL
173     places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
174         egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
175     for dir in $places ../libpcap libpcap ; do
176             basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'`
177             if test $lastdir = $basedir ; then
178                     dnl skip alphas when an actual release is present
179                     continue;
180             fi
181             lastdir=$dir
182             if test -r $dir/pcap.c ; then
183                     libpcap=$dir/libpcap.a
184                     d=$dir
185                     dnl continue and select the last one that exists
186             fi
187     done
188     if test $libpcap = FAIL ; then
189             AC_MSG_RESULT(not found)
190             AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
191             if test $libpcap = FAIL ; then
192                     AC_MSG_ERROR(see the INSTALL doc for more info)
193             fi
194     else
195             $1=$libpcap
196             $2="-I$d $$2"
197             AC_MSG_RESULT($libpcap)
198     fi
199     LIBS="$libpcap $LIBS"])
200
201 dnl
202 dnl Define RETSIGTYPE and RETSIGVAL
203 dnl
204 dnl usage:
205 dnl
206 dnl     AC_LBL_TYPE_SIGNAL
207 dnl
208 dnl results:
209 dnl
210 dnl     RETSIGTYPE (defined)
211 dnl     RETSIGVAL (defined)
212 dnl
213 AC_DEFUN(AC_LBL_TYPE_SIGNAL,
214     [AC_TYPE_SIGNAL
215     if test "$ac_cv_type_signal" = void ; then
216             AC_DEFINE(RETSIGVAL,)
217     else
218             AC_DEFINE(RETSIGVAL,(0))
219     fi
220     case "$target_os" in
221
222     irix*)
223             AC_DEFINE(_BSD_SIGNALS)
224             ;;
225
226     *)
227             AC_CHECK_FUNCS(sigset)
228             if test $ac_cv_func_sigset = yes ; then
229                     AC_DEFINE(signal, sigset)
230             fi
231             ;;
232     esac])
233
234 dnl
235 dnl If using gcc, see if fixincludes should be run
236 dnl
237 dnl usage:
238 dnl
239 dnl     AC_LBL_FIXINCLUDES
240 dnl
241 AC_DEFUN(AC_LBL_FIXINCLUDES,
242     [if test $ac_cv_prog_gcc = yes ; then
243             AC_MSG_CHECKING(if fixincludes is needed)
244             AC_CACHE_VAL(ac_cv_gcc_fixincludes,
245                 AC_TRY_COMPILE(
246                     [/*
247                      * This generates a "duplicate case value" when fixincludes
248                      * has not be run.
249                      */
250 #               include <sys/types.h>
251 #               include <sys/time.h>
252 #               include <sys/ioctl.h>
253 #               ifdef HAVE_SYS_IOCCOM_H
254 #               include <sys/ioccom.h>
255 #               endif],
256                     [switch (0) {
257                     case _IO('A', 1):;
258                     case _IO('B', 1):;
259                     }],
260                     ac_cv_gcc_fixincludes=yes,
261                     ac_cv_gcc_fixincludes=no))
262             AC_MSG_RESULT($ac_cv_gcc_fixincludes)
263             if test $ac_cv_gcc_fixincludes = no ; then
264                     # Don't cache failure
265                     unset ac_cv_gcc_fixincludes
266                     AC_MSG_ERROR(see the INSTALL for more info)
267             fi
268     fi])
269
270 dnl
271 dnl Check for flex, default to lex
272 dnl Require flex 2.4 or higher
273 dnl Check for bison, default to yacc
274 dnl Default to lex/yacc if both flex and bison are not available
275 dnl Define the yy prefix string if using flex and bison
276 dnl
277 dnl usage:
278 dnl
279 dnl     AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
280 dnl
281 dnl results:
282 dnl
283 dnl     $1 (lex set)
284 dnl     $2 (yacc appended)
285 dnl     $3 (optional flex and bison -P prefix)
286 dnl
287 AC_DEFUN(AC_LBL_LEX_AND_YACC,
288     [AC_CHECK_PROGS($1, flex, lex)
289     if test "$$1" = flex ; then
290             # The -V flag was added in 2.4
291             AC_MSG_CHECKING(for flex 2.4 or higher)
292             AC_CACHE_VAL(ac_cv_flex_v24,
293                 if flex -V >/dev/null 2>&1; then
294                         ac_cv_flex_v24=yes
295                 else
296                         ac_cv_flex_v24=no
297                 fi)
298             AC_MSG_RESULT($ac_cv_flex_v24)
299             if test $ac_cv_flex_v24 = no ; then
300                     s="2.4 or higher required"
301                     AC_MSG_WARN(ignoring obsolete flex executable ($s))
302                     $1=lex
303             fi
304     fi
305     AC_CHECK_PROGS($2, bison, yacc)
306     if test "$$2" = bison ; then
307             $2="$$2 -y"
308     fi
309     if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
310             AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
311             $1=lex
312             $2=yacc
313     fi
314     if test "$$1" = flex -a -n "$3" ; then
315             $1="$$1 -P$3"
316             $2="$$2 -p $3"
317     fi])
318
319 dnl
320 dnl Checks to see if union wait is used with WEXITSTATUS()
321 dnl
322 dnl usage:
323 dnl
324 dnl     AC_LBL_UNION_WAIT
325 dnl
326 dnl results:
327 dnl
328 dnl     DECLWAITSTATUS (defined)
329 dnl
330 AC_DEFUN(AC_LBL_UNION_WAIT,
331     [AC_MSG_CHECKING(if union wait is used)
332     AC_CACHE_VAL(ac_cv_union_wait,
333         AC_TRY_COMPILE([
334 #       include <sys/types.h>
335 #       include <sys/wait.h>],
336             [int status;
337             u_int i = WEXITSTATUS(status);
338             u_int j = waitpid(0, &status, 0);],
339             ac_cv_union_wait=no,
340             ac_cv_union_wait=yes))
341     AC_MSG_RESULT($ac_cv_union_wait)
342     if test $ac_cv_union_wait = yes ; then
343             AC_DEFINE(DECLWAITSTATUS,union wait)
344     else
345             AC_DEFINE(DECLWAITSTATUS,int)
346     fi])
347
348 dnl
349 dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
350 dnl
351 dnl usage:
352 dnl
353 dnl     AC_LBL_SOCKADDR_SA_LEN
354 dnl
355 dnl results:
356 dnl
357 dnl     HAVE_SOCKADDR_SA_LEN (defined)
358 dnl
359 AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
360     [AC_MSG_CHECKING(if sockaddr struct has sa_len member)
361     AC_CACHE_VAL(ac_cv_sockaddr_has_sa_len,
362         AC_TRY_COMPILE([
363 #       include <sys/types.h>
364 #       include <sys/socket.h>],
365         [u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
366         ac_cv_sockaddr_has_sa_len=yes,
367         ac_cv_sockaddr_has_sa_len=no))
368     AC_MSG_RESULT($ac_cv_sockaddr_has_sa_len)
369     if test $ac_cv_sockaddr_has_sa_len = yes ; then
370             AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
371     fi])
372
373 dnl
374 dnl Checks to see if -R is used
375 dnl
376 dnl usage:
377 dnl
378 dnl     AC_LBL_HAVE_RUN_PATH
379 dnl
380 dnl results:
381 dnl
382 dnl     ac_cv_have_run_path (yes or no)
383 dnl
384 AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
385     [AC_MSG_CHECKING(for ${CC-cc} -R)
386     AC_CACHE_VAL(ac_cv_have_run_path,
387         [echo 'main(){}' > conftest.c
388         ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
389         if test ! -s conftest.out ; then
390                 ac_cv_have_run_path=yes
391         else
392                 ac_cv_have_run_path=no
393         fi
394         rm -f conftest*])
395     AC_MSG_RESULT($ac_cv_have_run_path)
396     ])
397
398 dnl
399 dnl Checks to see if unaligned memory accesses fail
400 dnl
401 dnl usage:
402 dnl
403 dnl     AC_LBL_UNALIGNED_ACCESS
404 dnl
405 dnl results:
406 dnl
407 dnl     LBL_ALIGN (DEFINED)
408 dnl
409 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
410     [AC_MSG_CHECKING(if unaligned accesses fail)
411     AC_CACHE_VAL(ac_cv_unaligned_fail,
412         [case "$target_cpu" in
413
414         alpha|hp*|mips|sparc)
415                 ac_cv_unaligned_fail=yes
416                 ;;
417
418         *)
419                 cat >conftest.c <<EOF
420 #               include <sys/types.h>
421 #               include <sys/wait.h>
422 #               include <stdio.h>
423                 unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
424                 main() {
425                 unsigned int i;
426                 pid_t pid;
427                 int status;
428                 /* avoid "core dumped" message */
429                 pid = fork();
430                 if (pid <  0)
431                         exit(2);
432                 if (pid > 0) {
433                         /* parent */
434                         pid = waitpid(pid, &status, 0);
435                         if (pid < 0)
436                                 exit(3);
437                         exit(!WIFEXITED(status));
438                 }
439                 /* child */
440                 i = *(unsigned int *)&a[[1]];
441                 printf("%d\n", i);
442                 exit(0);
443                 }
444 EOF
445                 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
446                     conftest.c $LIBS >/dev/null 2>&1
447                 if test ! -x conftest ; then
448                         dnl failed to compile for some reason
449                         ac_cv_unaligned_fail=yes
450                 else
451                         ./conftest >conftest.out
452                         if test ! -s conftest.out ; then
453                                 ac_cv_unaligned_fail=yes
454                         else
455                                 ac_cv_unaligned_fail=no
456                         fi
457                 fi
458                 rm -f conftest* core core.conftest
459                 ;;
460         esac])
461     AC_MSG_RESULT($ac_cv_unaligned_fail)
462     if test $ac_cv_unaligned_fail = yes ; then
463             AC_DEFINE(LBL_ALIGN)
464     fi])
465
466 dnl
467 dnl If using gcc and the file .devel exists:
468 dnl     Compile with -g (if supported) and -Wall
469 dnl     If using gcc 2, do extra prototype checking
470 dnl     If an os prototype include exists, symlink os-proto.h to it
471 dnl
472 dnl usage:
473 dnl
474 dnl     AC_LBL_DEVEL(copt)
475 dnl
476 dnl results:
477 dnl
478 dnl     $1 (copt appended)
479 dnl     HAVE_OS_PROTO_H (defined)
480 dnl     os-proto.h (symlinked)
481 dnl
482 AC_DEFUN(AC_LBL_DEVEL,
483     [rm -f os-proto.h
484     if test "${LBL_CFLAGS+set}" = set; then
485             $1="$$1 ${LBL_CFLAGS}"
486     fi
487     if test $ac_cv_prog_gcc = yes -a -f .devel ; then
488             if test "${LBL_CFLAGS+set}" != set; then
489                     if test "$ac_cv_prog_cc_g" = yes ; then
490                             $1="-g $$1"
491                     fi
492                     $1="$$1 -Wall"
493                     if test $ac_cv_gcc_vers -gt 1 ; then
494                             $1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
495                     fi
496             fi
497             os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
498             name="lbl/os-$os.h"
499             if test -f $name ; then
500                     ln -s $name os-proto.h
501                     AC_DEFINE(HAVE_OS_PROTO_H)
502             else
503                     AC_MSG_WARN(can't find $name)
504             fi
505     fi])