1dnl @(#) $Header: aclocal.m4,v 1.32 96/07/23 22:55:48 leres Exp $ (LBL) 2dnl 3dnl Copyright (c) 1995, 1996 4dnl The Regents of the University of California. All rights reserved. 5dnl 6dnl Redistribution and use in source and binary forms, with or without 7dnl modification, are permitted provided that: (1) source code distributions 8dnl retain the above copyright notice and this paragraph in its entirety, (2) 9dnl distributions including binary code include the above copyright notice and 10dnl this paragraph in its entirety in the documentation or other materials 11dnl provided with the distribution, and (3) all advertising materials mentioning 12dnl features or use of this software display the following acknowledgement: 13dnl ``This product includes software developed by the University of California, 14dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 15dnl the University nor the names of its contributors may be used to endorse 16dnl or promote products derived from this software without specific prior 17dnl written permission. 18dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 19dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 20dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 21dnl 22dnl LBL autoconf macros 23dnl 24 25dnl 26dnl Determine which compiler we're using (cc or gcc) 27dnl If using gcc, determine the version number 28dnl If using cc, require that it support ansi prototypes 29dnl If using gcc, use -O2 (otherwise use -O) 30dnl If using cc, explicitly specify /usr/local/include 31dnl 32dnl usage: 33dnl 34dnl AC_LBL_C_INIT(copt, incls) 35dnl 36dnl results: 37dnl 38dnl $1 (copt set) 39dnl $2 (incls set) 40dnl CC 41dnl ac_cv_gcc_vers 42dnl 43AC_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 157dnl 158dnl Use pfopen.c if available and pfopen() not in standard libraries 159dnl Require libpcap 160dnl Look for libpcap in .. 161dnl Use the installed libpcap if there is no local version 162dnl 163dnl usage: 164dnl 165dnl AC_LBL_LIBPCAP(pcapdep, incls) 166dnl 167dnl results: 168dnl 169dnl $1 (pcapdep set) 170dnl $2 (incls appended) 171dnl LIBS 172dnl 173AC_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 206dnl 207dnl Define RETSIGTYPE and RETSIGVAL 208dnl 209dnl usage: 210dnl 211dnl AC_LBL_TYPE_SIGNAL 212dnl 213dnl results: 214dnl 215dnl RETSIGTYPE (defined) 216dnl RETSIGVAL (defined) 217dnl 218AC_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 239dnl 240dnl If using gcc, see if fixincludes should be run 241dnl 242dnl usage: 243dnl 244dnl AC_LBL_FIXINCLUDES 245dnl 246AC_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 275dnl 276dnl Check for flex, default to lex 277dnl Require flex 2.4 or higher 278dnl Check for bison, default to yacc 279dnl Default to lex/yacc if both flex and bison are not available 280dnl Define the yy prefix string if using flex and bison 281dnl 282dnl usage: 283dnl 284dnl AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix) 285dnl 286dnl results: 287dnl 288dnl $1 (lex set) 289dnl $2 (yacc appended) 290dnl $3 (optional flex and bison -P prefix) 291dnl 292AC_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 324dnl 325dnl Checks to see if union wait is used with WEXITSTATUS() 326dnl 327dnl usage: 328dnl 329dnl AC_LBL_UNION_WAIT 330dnl 331dnl results: 332dnl 333dnl DECLWAITSTATUS (defined) 334dnl 335AC_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 353dnl 354dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member 355dnl 356dnl usage: 357dnl 358dnl AC_LBL_SOCKADDR_SA_LEN 359dnl 360dnl results: 361dnl 362dnl HAVE_SOCKADDR_SA_LEN (defined) 363dnl 364AC_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 378dnl 379dnl Checks to see if -R is used 380dnl 381dnl usage: 382dnl 383dnl AC_LBL_HAVE_RUN_PATH 384dnl 385dnl results: 386dnl 387dnl ac_cv_have_run_path (yes or no) 388dnl 389AC_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 403dnl 404dnl Checks to see if unaligned memory accesses fail 405dnl 406dnl usage: 407dnl 408dnl AC_LBL_UNALIGNED_ACCESS 409dnl 410dnl results: 411dnl 412dnl LBL_ALIGN (DEFINED) 413dnl 414AC_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 } 449EOF 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 471dnl 472dnl If using gcc and the file .devel exists: 473dnl Compile with -g (if supported) and -Wall 474dnl If using gcc 2, do extra prototype checking 475dnl If an os prototype include exists, symlink os-proto.h to it 476dnl 477dnl usage: 478dnl 479dnl AC_LBL_DEVEL(copt) 480dnl 481dnl results: 482dnl 483dnl $1 (copt appended) 484dnl HAVE_OS_PROTO_H (defined) 485dnl os-proto.h (symlinked) 486dnl 487AC_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]) 506