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