1dnl @(#) $Id: aclocal.m4 990 2013-11-12 01:43:43Z leres $ (LBL)
2dnl
3dnl Copyright (c) 2008, 2009, 2010, 2011, 2013
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 the following conditions are met:
8dnl      * Redistributions of source code must retain the above copyright
9dnl        notice, this list of conditions and the following disclaimer.
10dnl      * Redistributions in binary form must reproduce the above copyright
11dnl        notice, this list of conditions and the following disclaimer in the
12dnl        documentation and/or other materials provided with the distribution.
13dnl      * Neither the name of the University nor the names of its contributors
14dnl        may be used to endorse or promote products derived from this software
15dnl        without specific prior written permission.
16dnl
17dnl  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18dnl  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19dnl  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20dnl  ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21dnl  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22dnl  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23dnl  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24dnl  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25dnl  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26dnl  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27dnl  SUCH DAMAGE.
28dnl
29dnl LBL autoconf macros
30dnl
31
32dnl
33dnl Determine which compiler we're using (cc or gcc)
34dnl If using gcc, determine the version number
35dnl If using cc, require that it support ansi prototypes
36dnl If using cc, explicitly specify /usr/local/include
37dnl
38dnl usage:
39dnl
40dnl	AC_LBL_C_INIT(copt, incls)
41dnl
42dnl results:
43dnl
44dnl	$1 (copt set)
45dnl	$2 (incls set)
46dnl	CC
47dnl	LDFLAGS set
48dnl
49AC_DEFUN(AC_LBL_C_INIT,
50    [AC_PREREQ(2.12)
51    AC_ARG_ENABLE([optimization],
52	[AS_HELP_STRING([--disable-optimization],
53	    [turn off gcc optimization])],
54	ac_cv_enable_optimization=${enableval})
55    AC_BEFORE([$0], [AC_PROG_CC])
56    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
57    AC_BEFORE([$0], [AC_LBL_DEVEL])
58    AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
59    AC_USE_SYSTEM_EXTENSIONS
60    AC_PROG_CC
61    AC_SYS_LARGEFILE
62    $1=""
63    if test "${ac_cv_enable_optimization}" = "no"; then
64	    CFLAGS="`echo ${CFLAGS} | sed -e 's/ -O[[0-3]]*//'`"
65    fi
66    $2=""
67    if test "${srcdir}" != "." ; then
68	    $2="-I\$\(srcdir\)"
69    fi
70    if test -z "$CC" ; then
71	    case "$target_os" in
72
73	    bsdi*)
74		    AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
75		    if test $SHLICC2 = yes ; then
76			    CC=shlicc2
77			    export CC
78		    fi
79		    ;;
80	    esac
81    fi
82    if test -z "$CC" -a "$with_gcc" = no ; then
83	    CC=cc
84	    export CC
85    fi
86    if test "$GCC" != yes ; then
87	    AC_MSG_CHECKING(that $CC handles ansi prototypes)
88	    AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes,
89		AC_TRY_COMPILE(
90		    [#include <sys/types.h>],
91		    [int frob(int, char *)],
92		    ac_cv_lbl_cc_ansi_prototypes=yes,
93		    ac_cv_lbl_cc_ansi_prototypes=no))
94	    AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes)
95	    if test $ac_cv_lbl_cc_ansi_prototypes = no ; then
96		    case "$target_os" in
97
98		    hpux*)
99			    AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
100			    savedcflags="$CFLAGS"
101			    CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
102			    AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa,
103				AC_TRY_COMPILE(
104				    [#include <sys/types.h>],
105				    [int frob(int, char *)],
106				    ac_cv_lbl_cc_hpux_cc_aa=yes,
107				    ac_cv_lbl_cc_hpux_cc_aa=no))
108			    AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa)
109			    if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then
110				    AC_MSG_ERROR(see the INSTALL doc for more info)
111			    fi
112			    CFLAGS="$savedcflags"
113			    $1="-Aa $$1"
114			    AC_DEFINE(_HPUX_SOURCE,,[HP-UX ansi compiler])
115			    ;;
116
117		    *)
118			    AC_MSG_ERROR(see the INSTALL doc for more info)
119			    ;;
120		    esac
121	    fi
122	    $2="$$2 -I/usr/local/include"
123	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
124
125	    case "$target_os" in
126
127	    irix*)
128		    $1="$$1 -xansi -signed -g3"
129		    ;;
130
131	    osf*)
132		    $1="$$1 -std1 -g3"
133		    ;;
134
135	    ultrix*)
136		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
137		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
138			AC_TRY_COMPILE(
139			    [#include <sys/types.h>],
140			    [struct a { int b; };
141			    void c(const struct a *)],
142			    ac_cv_lbl_cc_const_proto=yes,
143			    ac_cv_lbl_cc_const_proto=no))
144		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
145		    if test $ac_cv_lbl_cc_const_proto = no ; then
146			    AC_DEFINE(const,,[ultrix can't hack const])
147		    fi
148		    ;;
149	    esac
150    fi
151])
152
153AC_LBL_ENABLE_CHECK(brov6 activemapping expire-dfa-states)
154dnl
155dnl This allows us to check for bogus configure enable/disable
156dnl command line options
157dnl
158dnl usage:
159dnl
160dnl	AC_LBL_ENABLE_CHECK(opt ...)
161dnl
162AC_DEFUN(AC_LBL_ENABLE_CHECK,
163    [set |
164	sed -n -e 's/^enable_\([[^=]]*\)=[[^=]]*$/\1/p' |
165	while read var; do
166	    ok=0
167	    for o in $1; do
168		    if test "${o}" = "${var}" ; then
169			    ok=1
170			    break
171		    fi
172	    done
173	    if test ${ok} -eq 0 ; then
174		    # It's hard to kill configure script from subshell!
175		    AC_MSG_ERROR(unknown enable option: ${var})
176		    exit 1
177	    fi
178	done
179	if test $? -ne 0 ; then
180		exit 1
181	fi])
182
183dnl
184dnl Use pfopen.c if available and pfopen() not in standard libraries
185dnl Require libpcap
186dnl Look for libpcap in ..
187dnl Use the installed libpcap if there is no local version
188dnl
189dnl usage:
190dnl
191dnl	AC_LBL_LIBPCAP(pcapdep, incls)
192dnl
193dnl results:
194dnl
195dnl	$1 (pcapdep set)
196dnl	$2 (incls appended)
197dnl	LIBS
198dnl	LDFLAGS
199dnl	LBL_LIBS
200dnl
201AC_DEFUN(AC_LBL_LIBPCAP,
202    [AC_REQUIRE([AC_LBL_LIBRARY_NET])
203    dnl
204    dnl save a copy before locating libpcap.a
205    dnl
206    LBL_LIBS="$LIBS"
207    pfopen=/usr/examples/packetfilter/pfopen.c
208    if test -f $pfopen ; then
209	    AC_CHECK_FUNCS(pfopen)
210	    if test $ac_cv_func_pfopen = "no" ; then
211		    AC_MSG_RESULT(Using $pfopen)
212		    LIBS="$LIBS $pfopen"
213	    fi
214    fi
215    AC_MSG_CHECKING(for local pcap library)
216    libpcap=FAIL
217    lastdir=FAIL
218    places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
219	egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
220    for dir in $places ../libpcap libpcap ; do
221	    basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'`
222	    if test $lastdir = $basedir ; then
223		    dnl skip alphas when an actual release is present
224		    continue;
225	    fi
226	    lastdir=$dir
227	    if test -r $dir/pcap.c ; then
228		    libpcap=$dir/libpcap.a
229		    d=$dir
230		    dnl continue and select the last one that exists
231	    fi
232    done
233    if test "x$libpcap" = xFAIL ; then
234	    AC_MSG_RESULT(not found)
235	    AC_CHECK_LIB(pcap, pcap_open_live, libpcap="-lpcap")
236	    unset ac_cv_lib_pcap_pcap_open_live
237	    if test "x$libpcap" = xFAIL ; then
238		    CFLAGS="${CFLAGS} -I/usr/local/include"
239		    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
240		    AC_CHECK_LIB(pcap, pcap_open_live, libpcap="-lpcap")
241		    unset ac_cv_lib_pcap_pcap_open_live
242		    if test "x$libpcap" = xFAIL ; then
243			    AC_MSG_ERROR(see the INSTALL doc for more info)
244		    fi
245		    $2="$$2 -I/usr/local/include"
246	    fi
247	    LIBS="$LIBS -lpcap"
248    else
249	    $1=$libpcap
250	    $2="-I$d $$2"
251	    AC_MSG_RESULT($libpcap)
252    fi
253    if test "x$libpcap" != "x-lpcap" ; then
254	    LIBS="$libpcap $LIBS"
255    fi
256    case "$target_os" in
257
258    aix*)
259	    pseexe="/lib/pse.exp"
260	    AC_MSG_CHECKING(for $pseexe)
261	    if test -f $pseexe ; then
262		    AC_MSG_RESULT(yes)
263		    LIBS="$LIBS -I:$pseexe"
264	    fi
265	    ;;
266    esac])
267
268dnl
269dnl Define RETSIGTYPE and RETSIGVAL
270dnl
271dnl usage:
272dnl
273dnl	AC_LBL_TYPE_SIGNAL
274dnl
275dnl results:
276dnl
277dnl	RETSIGTYPE (defined)
278dnl	RETSIGVAL (defined)
279dnl
280AC_DEFUN(AC_LBL_TYPE_SIGNAL,
281    [AC_BEFORE([$0], [AC_LBL_LIBPCAP])
282    AC_TYPE_SIGNAL
283    if test "$ac_cv_type_signal" = void ; then
284	    AC_DEFINE(RETSIGVAL,,[signal function return value])
285    else
286	    AC_DEFINE(RETSIGVAL,(0))
287    fi
288    case "$target_os" in
289
290    irix*)
291	    AC_DEFINE(_BSD_SIGNALS,,[irix's BSD style signals])
292	    ;;
293
294    *)
295	    dnl prefer sigset() to sigaction()
296	    AC_CHECK_FUNCS(sigset)
297	    if test $ac_cv_func_sigset = yes ; then
298		    AC_DEFINE(signal,sigset,[use sigset() instead of signal()])
299	    else
300		    AC_CHECK_FUNCS(sigaction)
301	    fi
302	    ;;
303    esac])
304
305dnl
306dnl If using gcc, make sure we have ANSI ioctl definitions
307dnl
308dnl usage:
309dnl
310dnl	AC_LBL_FIXINCLUDES
311dnl
312AC_DEFUN(AC_LBL_FIXINCLUDES,
313    [if test "$GCC" = yes ; then
314	    AC_MSG_CHECKING(for ANSI ioctl definitions)
315	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
316		AC_TRY_COMPILE(
317		    [/*
318		     * This generates a "duplicate case value" when fixincludes
319		     * has not be run.
320		     */
321#		include <sys/types.h>
322#		include <sys/time.h>
323#		include <sys/ioctl.h>
324#		ifdef HAVE_SYS_IOCCOM_H
325#		include <sys/ioccom.h>
326#		endif],
327		    [switch (0) {
328		    case _IO('A', 1):;
329		    case _IO('B', 1):;
330		    }],
331		    ac_cv_lbl_gcc_fixincludes=yes,
332		    ac_cv_lbl_gcc_fixincludes=no))
333	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
334	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
335		    # Don't cache failure
336		    unset ac_cv_lbl_gcc_fixincludes
337		    AC_MSG_ERROR(see the INSTALL for more info)
338	    fi
339    fi])
340
341dnl
342dnl Check for flex, default to lex
343dnl Require flex 2.4 or higher
344dnl Check for bison, default to yacc
345dnl Default to lex/yacc if both flex and bison are not available
346dnl Define the yy prefix string if using flex and bison
347dnl
348dnl usage:
349dnl
350dnl	AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
351dnl
352dnl results:
353dnl
354dnl	$1 (lex set)
355dnl	$2 (yacc appended)
356dnl	$3 (optional flex and bison -P prefix)
357dnl
358AC_DEFUN(AC_LBL_LEX_AND_YACC,
359    [AC_ARG_WITH(flex, [  --without-flex          don't use flex])
360    AC_ARG_WITH(bison, [  --without-bison         don't use bison])
361    if test "$with_flex" = no ; then
362	    $1=lex
363    else
364	    AC_CHECK_PROGS($1, flex, lex)
365    fi
366    if test "$$1" = flex ; then
367	    # The -V flag was added in 2.4
368	    AC_MSG_CHECKING(for flex 2.4 or higher)
369	    AC_CACHE_VAL(ac_cv_lbl_flex_v24,
370		if flex -V >/dev/null 2>&1; then
371			ac_cv_lbl_flex_v24=yes
372		else
373			ac_cv_lbl_flex_v24=no
374		fi)
375	    AC_MSG_RESULT($ac_cv_lbl_flex_v24)
376	    if test $ac_cv_lbl_flex_v24 = no ; then
377		    s="2.4 or higher required"
378		    AC_MSG_WARN(ignoring obsolete flex executable ($s))
379		    $1=lex
380	    fi
381    fi
382    if test "$with_bison" = no ; then
383	    $2=yacc
384    else
385	    AC_CHECK_PROGS($2, bison, yacc)
386    fi
387    if test "$$2" = bison ; then
388	    $2="$$2 -y"
389    fi
390    if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
391	    AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
392	    $1=lex
393	    $2=yacc
394    fi
395    if test "$$1" = flex -a -n "$3" ; then
396	    $1="$$1 -P$3"
397	    $2="$$2 -p $3"
398    fi])
399
400dnl
401dnl Checks to see if union wait is used with WEXITSTATUS()
402dnl
403dnl usage:
404dnl
405dnl	AC_LBL_UNION_WAIT
406dnl
407dnl results:
408dnl
409dnl	DECLWAITSTATUS (defined)
410dnl
411AC_DEFUN(AC_LBL_UNION_WAIT,
412    [AC_MSG_CHECKING(if union wait is used)
413    AC_CACHE_VAL(ac_cv_lbl_union_wait,
414	AC_TRY_COMPILE([
415#	include <sys/types.h>
416#	include <sys/wait.h>],
417	    [int status;
418	    u_int i = WEXITSTATUS(status);
419	    u_int j = waitpid(0, &status, 0);],
420	    ac_cv_lbl_union_wait=no,
421	    ac_cv_lbl_union_wait=yes))
422    AC_MSG_RESULT($ac_cv_lbl_union_wait)
423    if test $ac_cv_lbl_union_wait = yes ; then
424	    AC_DEFINE(DECLWAITSTATUS,union wait)
425    else
426	    AC_DEFINE(DECLWAITSTATUS,int)
427    fi])
428
429dnl
430dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
431dnl
432dnl usage:
433dnl
434dnl	AC_LBL_SOCKADDR_SA_LEN
435dnl
436dnl results:
437dnl
438dnl	HAVE_SOCKADDR_SA_LEN (defined)
439dnl
440AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
441    [AC_CHECK_MEMBERS(struct sockaddr.sa_len,
442	AC_DEFINE(HAVE_SOCKADDR_SA_LEN),,[
443#	include <sys/types.h>
444#	include <sys/socket.h>])])
445
446dnl
447dnl Makes sure socklen_t is defined
448dnl
449dnl usage:
450dnl
451dnl	AC_LBL_SOCKLEN_T
452dnl
453dnl results:
454dnl
455dnl	socklen_t (defined if missing)
456dnl
457AC_DEFUN(AC_LBL_SOCKLEN_T,
458    [AC_MSG_CHECKING(for socklen_t in sys/socket.h using $CC)
459    AC_CACHE_VAL(ac_cv_lbl_socklen_t,
460	AC_TRY_COMPILE([
461#	include "confdefs.h"
462#	include <sys/types.h>
463#	include <sys/socket.h>
464#	if STDC_HEADERS
465#	include <stdlib.h>
466#	include <stddef.h>
467#	endif],
468	[socklen_t i],
469	ac_cv_lbl_socklen_t=yes,
470	ac_cv_lbl_socklen_t=no))
471    AC_MSG_RESULT($ac_cv_lbl_socklen_t)
472    if test $ac_cv_lbl_socklen_t = no ; then
473	    AC_DEFINE(socklen_t, int, [Define socklen_t if missing])
474    fi])
475
476dnl
477dnl Checks to see if the IFF_LOOPBACK exists as a define or enum
478dnl
479dnl   (stupidly some versions of linux use an enum...)
480dnl
481dnl usage:
482dnl
483dnl	AC_LBL_IFF_LOOPBACK
484dnl
485dnl results:
486dnl
487dnl	HAVE_IFF_LOOPBACK (defined)
488dnl
489AC_DEFUN(AC_LBL_IFF_LOOPBACK,
490    [AC_MSG_CHECKING(for IFF_LOOPBACK define/enum)
491    AC_CACHE_VAL(ac_cv_lbl_have_iff_loopback,
492	AC_TRY_COMPILE([
493#	include <sys/param.h>
494#	include <sys/file.h>
495#	include <sys/ioctl.h>
496#	include <sys/socket.h>
497#	ifdef HAVE_SYS_SOCKIO_H
498#	include <sys/sockio.h>
499#	endif
500#	include <sys/time.h>
501#	include <net/if.h>
502#	include <netinet/in.h>],
503	[int i = IFF_LOOPBACK],
504	ac_cv_lbl_have_iff_loopback=yes,
505	ac_cv_lbl_have_iff_loopback=no))
506    AC_MSG_RESULT($ac_cv_lbl_have_iff_loopback)
507    if test $ac_cv_lbl_have_iff_loopback = yes ; then
508	    AC_DEFINE(HAVE_IFF_LOOPBACK,, [Have IFF_LOOPBACK define/enum])
509    fi])
510
511dnl
512dnl Due to the stupid way it's implemented, AC_CHECK_TYPE is nearly useless.
513dnl
514dnl usage:
515dnl
516dnl	AC_LBL_CHECK_TYPE
517dnl
518dnl results:
519dnl
520dnl	int32_t (defined)
521dnl	u_int32_t (defined)
522dnl
523AC_DEFUN(AC_LBL_CHECK_TYPE,
524    [AC_MSG_CHECKING(for $1 using $CC)
525    AC_CACHE_VAL(ac_cv_lbl_have_$1,
526	AC_TRY_COMPILE([
527#	include "confdefs.h"
528#	include <sys/types.h>
529#	if STDC_HEADERS
530#	include <stdlib.h>
531#	include <stddef.h>
532#	endif],
533	[$1 i],
534	ac_cv_lbl_have_$1=yes,
535	ac_cv_lbl_have_$1=no))
536    AC_MSG_RESULT($ac_cv_lbl_have_$1)
537    if test $ac_cv_lbl_have_$1 = no ; then
538	    AC_DEFINE($1, $2, Define $1)
539    fi])
540
541dnl
542dnl Checks to see if unaligned memory accesses fail
543dnl
544dnl usage:
545dnl
546dnl	AC_LBL_UNALIGNED_ACCESS
547dnl
548dnl results:
549dnl
550dnl	LBL_ALIGN (DEFINED)
551dnl
552AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
553    [AC_MSG_CHECKING(if unaligned accesses fail)
554    AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
555	[case "$target_cpu" in
556
557	alpha|hp*|mips|sparc)
558		ac_cv_lbl_unaligned_fail=yes
559		;;
560
561	*)
562		cat >conftest.c <<EOF
563#		include <sys/types.h>
564#		include <sys/wait.h>
565#		include <stdio.h>
566		unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
567		main() {
568		unsigned int i;
569		pid_t pid;
570		int status;
571		/* avoid "core dumped" message */
572		pid = fork();
573		if (pid <  0)
574			exit(2);
575		if (pid > 0) {
576			/* parent */
577			pid = waitpid(pid, &status, 0);
578			if (pid < 0)
579				exit(3);
580			exit(!WIFEXITED(status));
581		}
582		/* child */
583		i = *(unsigned int *)&a[[1]];
584		printf("%d\n", i);
585		exit(0);
586		}
587EOF
588		${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
589		    conftest.c $LIBS >/dev/null 2>&1
590		if test ! -x conftest ; then
591			dnl failed to compile for some reason
592			ac_cv_lbl_unaligned_fail=yes
593		else
594			./conftest >conftest.out
595			if test ! -s conftest.out ; then
596				ac_cv_lbl_unaligned_fail=yes
597			else
598				ac_cv_lbl_unaligned_fail=no
599			fi
600		fi
601		rm -f conftest* core core.conftest
602		;;
603	esac])
604    AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
605    if test $ac_cv_lbl_unaligned_fail = yes ; then
606	    AC_DEFINE(LBL_ALIGN)
607    fi])
608
609dnl
610dnl add all warning option to CFLAGS
611dnl
612dnl usage:
613dnl
614dnl	AC_LBL_CHECK_WALL
615dnl
616dnl results:
617dnl
618dnl	CFLAGS (appended)
619dnl	ac_cv_lbl_gcc_vers
620dnl
621AC_DEFUN(AC_LBL_CHECK_WALL,
622    [ if test "$GCC" = yes ; then
623	    CFLAGS="${CFLAGS} -Wall -Wmissing-prototypes -Wstrict-prototypes"
624	    if [[ "`uname -s`" = "FreeBSD" ]]; then
625		    CFLAGS="${CFLAGS} -Werror"
626	    fi
627    fi])
628
629dnl
630dnl If --enable-debug:
631dnl
632dnl	If an os prototype include exists, symlink os-proto.h to it
633dnl	If gcc (or compatible) Compile with:
634dnl
635dnl		-Wall -Wmissing-prototypes -Wstrict-prototypes
636dnl
637dnl usage:
638dnl
639dnl	AC_LBL_DEVEL
640dnl
641dnl results:
642dnl
643dnl	$1 (appended)
644dnl	HAVE_OS_PROTO_H (defined)
645dnl	os-proto.h (symlinked)
646dnl
647AC_DEFUN(AC_LBL_DEVEL,[
648    AC_BEFORE([$0], [AC_LBL_LD_RUN_PATH])
649    AC_ARG_ENABLE([debug],
650	[AS_HELP_STRING([--enable-debug],
651	    [enable debugging @<:@default=no@:>@])],
652	ac_cv_enable_debug=${enableval})
653
654    rm -f os-proto.h
655    if test "${ac_cv_enable_debug}" = yes ; then
656	    AC_LBL_CHECK_WALL
657	    os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
658	    name="lbl/os-$os.h"
659	    if test -f $name ; then
660		    ln -s $name os-proto.h
661		    AC_DEFINE(HAVE_OS_PROTO_H,,[have os-proto.h])
662	    fi
663    fi])
664
665dnl
666dnl Improved version of AC_CHECK_LIB
667dnl
668dnl Thanks to John Hawkinson (jhawk@mit.edu)
669dnl
670dnl usage:
671dnl
672dnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
673dnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
674dnl
675dnl results:
676dnl
677dnl	LIBS
678dnl
679
680define(AC_LBL_CHECK_LIB,
681[AC_MSG_CHECKING([for $2 in -l$1])
682dnl Use a cache variable name containing both the library and function name,
683dnl because the test really is for library $1 defining function $2, not
684dnl just for library $1.  Separate tests with the same $1 and different $2's
685dnl may have different results.
686ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
687AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
688[ac_save_LIBS="$LIBS"
689LIBS="-l$1 $5 $LIBS"
690AC_TRY_LINK(dnl
691ifelse([$2], [main], , dnl Avoid conflicting decl of main.
692[/* Override any gcc2 internal prototype to avoid an error.  */
693]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
694extern "C"
695#endif
696])dnl
697[/* We use char because int might match the return type of a gcc2
698    builtin and then its argument prototype would still apply.  */
699char $2();
700]),
701	    [$2()],
702	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
703	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
704LIBS="$ac_save_LIBS"
705])dnl
706if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
707  AC_MSG_RESULT(yes)
708  ifelse([$3], ,
709[changequote(, )dnl
710  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
711    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
712changequote([, ])dnl
713  AC_DEFINE_UNQUOTED($ac_tr_lib)
714  LIBS="-l$1 $LIBS"
715], [$3])
716else
717  AC_MSG_RESULT(no)
718ifelse([$4], , , [$4
719])dnl
720fi
721])
722
723dnl
724dnl AC_LBL_LIBRARY_NET
725dnl
726dnl This test is for network applications that need socket() and
727dnl gethostbyname() -ish functions.  Under Solaris, those applications
728dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
729dnl with "-lnsl" but should *not* link with "-lsocket" because
730dnl libsocket.a breaks a number of things (for instance:
731dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
732dnl versions of IRIX).
733dnl
734dnl Unfortunately, many application developers are not aware of this,
735dnl and mistakenly write tests that cause -lsocket to be used under
736dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
737dnl under operating systems where neither are necessary (or useful),
738dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
739dnl
740dnl This test exists so that every application developer does not test
741dnl this in a different, and subtly broken fashion.
742
743dnl It has been argued that this test should be broken up into two
744dnl seperate tests, one for the resolver libraries, and one for the
745dnl libraries necessary for using Sockets API. Unfortunately, the two
746dnl are carefully intertwined and allowing the autoconf user to use
747dnl them independantly potentially results in unfortunate ordering
748dnl dependancies -- as such, such component macros would have to
749dnl carefully use indirection and be aware if the other components were
750dnl executed. Since other autoconf macros do not go to this trouble,
751dnl and almost no applications use sockets without the resolver, this
752dnl complexity has not been implemented.
753dnl
754dnl The check for libresolv is in case you are attempting to link
755dnl statically and happen to have a libresolv.a lying around (and no
756dnl libnsl.a).
757dnl
758AC_DEFUN(AC_LBL_LIBRARY_NET, [
759    dnl Most operating systems have gethostbyname() in the default searched
760    dnl libraries (i.e. libc):
761    AC_CHECK_FUNC([gethostbyname])
762    if test ${ac_cv_func_gethostbyname} = "no" ; then
763	dnl Some OSes (eg. Solaris) place it in libnsl:
764	AC_CHECK_LIB([nsl], [gethostbyname])
765	if test ${ac_cv_lib_nsl_gethostbyname} = "no" ; then
766	    dnl Some strange OSes [SINIX] have it in libsocket:
767	    AC_CHECK_LIB([socket], [gethostbyname])
768	    if test ${ac_cv_lib_socket_gethostbyname} = "no" ; then
769		dnl Unfortunately libsocket sometimes depends on libnsl.
770		dnl AC_CHECK_LIB's API is essentially broken so the
771		dnl following ugliness is necessary:
772		dnl (clear cache)
773		unset ac_cv_lib_socket_gethostbyname
774		AC_CHECK_LIB([socket], [gethostbyname],
775		    LIBS="-lsocket -lnsl $LIBS", , -nsl)
776		if test ${ac_cv_lib_socket_gethostbyname} = "no" ; then
777		    AC_CHECK_LIB([resolv], [gethostbyname])
778		fi
779	    fi
780	fi
781	AC_CHECK_FUNC([socket])
782	if test ${ac_cv_func_socket} = "no" ; then
783	    AC_CHECK_LIB([socket], [socket])
784	    if test ${ac_cv_lib_socket_socket} = "no" ; then
785		dnl (clear cache)
786		unset ac_cv_lib_socket_socket
787		AC_CHECK_LIB([socket], [socket], LIBS="-lsocket -lnsl $LIBS", ,
788		    -lnsl)
789	    fi
790	fi
791	dnl DLPI needs putmsg under HPUX so test for -lstr while we're at it
792	AC_CHECK_LIB(str, putmsg)
793    fi])
794
795dnl
796dnl AC_LBL_RUN_PATH
797dnl
798dnl Extracts -L directories from LIBS; if any are found they are
799dnl converted to a LD_RUN_PATH and put in V_ENVIRONMENT
800dnl
801dnl usage:
802dnl
803dnl	AC_LBL_RUN_PATH
804dnl
805dnl results:
806dnl
807dnl	V_ENVIRONMENT
808dnl
809AC_DEFUN(AC_LBL_LD_RUN_PATH, [
810	AC_MSG_CHECKING(LD_RUN_PATH)
811	AC_SUBST(V_ENVIRONMENT)
812	dnl
813	dnl Split out -L directories
814	dnl
815	ldirs=""
816	for x in ${LIBS}; do
817		case x${x} in
818
819		x-L*)
820			ldirs="${ldirs} ${x}"
821			;;
822
823		*)
824			;;
825		esac
826	done
827
828	dnl
829	dnl Build ld_run_path (put existing dirs first)
830	dnl
831	ld_run_path=""
832	if test -n "${ldirs}"; then
833		ld_run_path="`echo \"${ldirs}\" | sed -e 's,-L,,g' -e 's,^ *,,' -e 's, ,:,g'`"
834		if test -n "${LD_RUN_PATH}"; then
835			ld_run_path="${LD_RUN_PATH}:${ld_run_path}"
836		fi
837	elif test -n "${LD_RUN_PATH}"; then
838		ld_run_path="${LD_RUN_PATH}"
839	fi
840	dnl
841	dnl Build V_ENVIRONMENT
842	dnl
843	if test -n "${ld_run_path}"; then
844		V_ENVIRONMENT="LD_RUN_PATH=\"${ld_run_path}\""
845		AC_MSG_RESULT(${V_ENVIRONMENT})
846	else
847		AC_MSG_RESULT(empty)
848	fi])
849
850dnl
851dnl AC_LBL_BROCCOLI
852dnl
853dnl Include Broccoli support
854dnl
855dnl usage:
856dnl
857dnl	AC_LBL_BROCCOLI(copt, incls, [min-vers])
858dnl
859dnl results:
860dnl
861dnl	$1 (copt variable appended)
862dnl	$2 (incls variable appended)
863dnl	$3 minimum version (optional)
864dnl     HAVE_BROCCOLI defined
865dnl
866AC_DEFUN(AC_LBL_BROCCOLI, [
867    AC_BEFORE([$0], [AC_LBL_LD_RUN_PATH])
868    dnl
869    dnl configure flags
870    dnl
871    AC_ARG_WITH([broccoli],
872	[AS_HELP_STRING([--without-broccoli],
873	    [disable Broccoli support @<:@default=check@:>@])],
874	ac_cv_with_broccoli=${withval})
875    dnl
876    dnl Network application libraries
877    dnl
878    AC_LBL_LIBRARY_NET
879
880    AC_MSG_CHECKING(for broccoli)
881    if test "${ac_cv_with_broccoli}" = "" -o \
882	"${ac_cv_with_broccoli}" = yes ; then
883	    cflags=""
884	    libs=""
885	    dnl
886	    dnl Our entire path
887	    dnl
888	    dirs="`echo ${PATH} | sed -e 's/:/ /g'`"
889	    dnl
890	    dnl Add in default Bro install bin directory
891	    dnl
892	    dirs="${dirs} /usr/local/bro/bin"
893	    for d in ${dirs}; do
894		    if test -x ${d}/broccoli-config ; then
895			    broccoli_config_path="${d}/broccoli-config"
896			    cflags="`${broccoli_config_path} --cflags`"
897			    libs="`${broccoli_config_path} --libs`"
898			    break
899		    fi
900	    done
901	    if test -n "${cflags}" ; then
902		    ac_cv_have_broccoli=yes
903	    else
904		    ac_cv_have_broccoli=no
905	    fi
906	    AC_MSG_RESULT($ac_cv_have_broccoli)
907	    if test "${ac_cv_with_broccoli}" = yes -a \
908		${ac_cv_have_broccoli} = "no" ; then
909		    AC_MSG_ERROR(Broccoli explicitly enabled but not supported)
910	    fi
911    else
912	    AC_MSG_RESULT([disabled])
913    fi
914
915    dnl
916    dnl Optionally check for minimum Broccoli version
917    dnl
918    if test "$ac_cv_have_broccoli" = yes -a -n "$3"; then
919	    AC_MSG_CHECKING(Broccoli >= $3)
920	    BROCCOLI_VERSION="`${broccoli_config_path} --version`"
921	    AC_MSG_RESULT(${BROCCOLI_VERSION})
922
923	    AS_VERSION_COMPARE(${BROCCOLI_VERSION}, $3,
924		broccoli_ok="no", broccoli_ok="yes", broccoli_ok="yes")
925
926	    if test "${broccoli_ok}" != "yes"; then
927		    if test "${ac_cv_with_broccoli}" = yes; then
928			    AC_MSG_ERROR(Broccoli $3 or higher is required)
929		    fi
930		    AC_MSG_NOTICE(Broccoli support disabled)
931		    ac_cv_have_broccoli="no"
932	    fi
933	    v="1.5.0"
934	    AS_VERSION_COMPARE(${BROCCOLI_VERSION}, ${v},
935		lexer_ok="no", lexer_ok="no", lexer_ok="yes")
936	    if test "${lexer_ok}" != "yes"; then
937		    AC_MSG_WARN([Broccoli ${BROCCOLI_VERSION} has a ssl empty passphrase bug])
938		    AC_MSG_WARN([(See the INSTALL file for patching instructions)])
939	    fi
940    fi
941
942    dnl
943    dnl Broccoli ho!
944    dnl
945    if test "$ac_cv_have_broccoli" = yes ; then
946	    AC_DEFINE(HAVE_BROCCOLI)
947	    dnl
948	    dnl Split out -I directories
949	    dnl
950	    for x in ${cflags}; do
951		    case x${x} in
952
953		    x-I*)
954			    eval "$2=\"\$$2 ${x}\""
955			    ;;
956
957		    *)
958			    eval "$1=\"\$$1 ${x}\""
959			    ;;
960		    esac
961	    done
962
963	    dnl
964	    dnl Add in Broccoli libs
965	    dnl
966	    LIBS="$LIBS ${libs}"
967
968	    dnl
969	    dnl Look for the libs in DIR or DIR/lib
970	    dnl
971	    AC_ARG_WITH([openssl],
972		[AS_HELP_STRING([--with-openssl=DIR],
973		[Use OpenSSL installation in DIR])],
974		[eval "$2=\"-I${withval}/include \$$2\""
975		for x in ${withval}/lib ${withval}; do
976			if test -r ${x}/libssl.a; then
977				LIBS="-L${x} ${LIBS}"
978				break
979			fi
980		done])
981
982	    dnl
983	    dnl -lssl needs to come first on some systems!
984	    dnl
985	    AC_CHECK_LIB(ssl, OPENSSL_add_all_algorithms_conf,
986		[LIBS="${LIBS} -lssl -lcrypto"],,-lcrypto)
987	    dnl
988	    dnl We can SSL failures if we have bro_init()
989	    dnl
990	    AC_CHECK_FUNCS([bro_init])
991	    if test "x$ac_cv_func_bro_init" != xyes; then
992		AC_MSG_WARN(SSL failures will not be detected)
993	    fi
994    fi])
995
996dnl
997dnl usage:
998dnl
999dnl	AC_LBL_ELECTRICFENCE
1000dnl
1001dnl results:
1002dnl
1003dnl	LIBS updated
1004dnl
1005AC_DEFUN(AC_LBL_ELECTRICFENCE, [
1006    AC_ARG_ENABLE([electricfence],
1007	[AS_HELP_STRING([--enable-electricfence],
1008	    [disable electric fence support @<:@default=no@:>@])],
1009	ac_cv_enable_electricfence=${enableval})
1010
1011    if test "${ac_cv_enable_electricfence}" = yes ; then
1012	    AC_CHECK_LIB(efence, EF_Abort)
1013	    ac_save_LDFLAGS="$LDFLAGS"
1014	    if test $ac_cv_lib_efence_EF_Abort = no ; then
1015		    local_lib="-L/usr/local/lib"
1016		    AC_MSG_NOTICE([Retry with ${local_lib}])
1017		    LDFLAGS="${LDFLAGS} ${local_lib}"
1018		    dnl
1019		    dnl unset cache variable
1020		    dnl
1021		    unset ac_cv_lib_efence_EF_Abort
1022		    AC_CHECK_LIB(efence, EF_Abort)
1023
1024	    fi
1025	    if test $ac_cv_lib_efence_EF_Abort = no ; then
1026		    AC_MSG_ERROR(electricfence requested not available)
1027		    LDFLAGS="${ac_save_LDFLAGS}"
1028	    fi
1029    fi])
1030