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