1#                                               -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
4AC_PREREQ(2.50)
5AC_INIT(src/barnyard2.c)
6AM_CONFIG_HEADER(config.h)
7AM_INIT_AUTOMAKE(barnyard2,1.13)
8AC_CONFIG_MACRO_DIR([m4])
9
10LT_INIT
11
12NO_OPTIMIZE="no"
13ADD_WERROR="no"
14
15# Test for -Werror and sed it out for now since some of the auto tests,
16# for example AC_CHECK_LIB, will fail because of
17# warning: conflicting types for built-in function <func>
18if eval "echo $CFLAGS | grep -e -Werror"; then
19    CFLAGS=`echo $CFLAGS | sed -e "s/-Werror//g"`
20    ADD_WERROR="yes"
21fi
22
23# Disable annoying practice of recursively re-running the autotools
24AM_MAINTAINER_MODE
25AC_PROG_CC_STDC
26AC_PROG_CC
27AC_PROG_LIBTOOL
28AC_C_BIGENDIAN
29
30#AC_CANONICAL_HOST
31linux="no"
32sunos4="no"
33
34case "$host" in
35  *-openbsd2.6|*-openbsd2.5|*-openbsd2.4|*-openbsd2.3*)
36    AC_DEFINE([OPENBSD],[1],[Define if OpenBSD])
37    AC_DEFINE([BROKEN_SIOCGIFMTU],[1],[Define if BROKEN_SIOCGIFMTU])
38
39    ;;
40  *-openbsd*)
41    AC_DEFINE([OPENBSD],[1],[Define if OpenBSD < 2.3])
42
43    ;;
44  *-sgi-irix5*)
45    AC_DEFINE([IRIX],[1],[Define if Irix 5])
46    no_libsocket="yes"
47    no_libnsl="yes"
48    if test -z "$GCC"; then
49      sgi_cc="yes"
50    fi
51    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
52    extra_incl="-I/usr/local/include"
53    ;;
54  *-sgi-irix6*)
55    AC_DEFINE([IRIX],[1],[Define if Irix 6])
56    no_libsocket="yes"
57    no_libnsl="yes"
58    if test -z "$GCC"; then
59      sgi_cc="yes"
60    fi
61    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
62    extra_incl="-I/usr/local/include"
63    ;;
64  *-solaris*)
65    AC_DEFINE([SOLARIS],[1],[Define if Solaris])
66    CPPFLAGS="${CPPFLAGS} -DBSD_COMP -D_REENTRANT"
67    ;;
68  *-sunos*)
69    AC_DEFINE([SUNOS],[1],[Define if SunOS])
70    sunos4="yes"
71    ;;
72  *-linux*)
73    linux="yes"
74    AC_DEFINE([LINUX],[1],[Define if Linux])
75    # libpcap doesn't even LOOK at the timeout you give it under Linux
76    AC_DEFINE([PCAP_TIMEOUT_IGNORED],[1],[Define if pcap timeout is ignored])
77    AC_SUBST(extra_incl)
78    extra_incl="-I/usr/include/pcap"
79    ;;
80  *-hpux10*|*-hpux11*)
81    AC_DEFINE([HPUX],[1],[Define if HP-UX 10 or 11])
82    AC_DEFINE([WORDS_BIGENDIAN],[1],[Define if words are big endian])
83    AC_SUBST(extra_incl)
84    extra_incl="-I/usr/local/include"
85    ;;
86
87  *-freebsd*)
88    AC_DEFINE([FREEBSD],[1],[Define if FreeBSD])
89
90    ;;
91  *-bsdi*)
92    AC_DEFINE([BSDI],[1],[Define if BSDi])
93    ;;
94  *-aix*)
95    AC_DEFINE([AIX],[1],[Define if AIX])
96    ;;
97  *-osf4*)
98    AC_DEFINE([OSF1],[1],[Define if OSF-4])
99    ;;
100  *-osf5.1*)
101    AC_DEFINE([OSF1],[1],[Define if OSF-5.1])
102    ;;
103  *-tru64*)
104    AC_DEFINE([OSF1],[1],[Define if Tru64])
105    ;;
106# it is actually <platform>-apple-darwin1.2 or <platform>-apple-rhapsody5.x but lets stick with this for the moment
107  *-apple*)
108    AC_DEFINE([MACOS],[1],[Define if MacOS])
109    AC_DEFINE([BROKEN_SIOCGIFMTU],[1],[Define if broken SIOCGIFMTU])
110    LDFLAGS="${LDFLAGS} -L/sw/lib"
111    extra_incl="-I/sw/include"
112    ;;
113  *-cygwin*)
114   AC_DEFINE([CYGWIN],[1],[Define if CYGWIN])
115    ;;
116esac
117
118# This is really meant for Solaris Sparc v9 where it has 32bit and 64bit
119# capability but builds 32bit by default
120AC_ARG_ENABLE(64bit-gcc,
121[  --enable-64bit-gcc       Try to compile 64bit (only tested on Sparc Solaris 9 and 10).],
122       enable_64bit_gcc="$enableval", enable_64bit_gcc="no")
123if test "x$enable_64bit_gcc" = "xyes"; then
124    CFLAGS="$CFLAGS -m64"
125fi
126
127# AC_PROG_YACC defaults to "yacc" when not found
128# this check defaults to "none"
129AC_CHECK_PROGS(YACC,bison yacc,none)
130# AC_PROG_YACC includes the -y arg if bison is found
131if test "x$YACC" = "xbison"; then
132    YACC="$YACC -y"
133fi
134
135# AC_PROG_LEX defaults to ":" when not found
136# this check defaults to "none"
137# We're using flex specific options so we don't support lex
138AC_CHECK_PROGS(LEX,flex,none)
139
140#
141
142dnl checking headers
143AC_CHECK_HEADERS([strings.h string.h stdlib.h unistd.h sys/sockio.h paths.h inttypes.h wchar.h math.h])
144AC_CHECK_LIB([m],[floor])
145AC_CHECK_LIB([m],[ceil])
146
147dnl make sure we've got all our libraries
148if test -z "$no_libnsl"; then
149AC_CHECK_LIB(nsl, inet_ntoa)
150fi
151
152if test -z "$no_libsocket"; then
153AC_CHECK_LIB(socket, socket)
154fi
155
156# SunOS4 has several things `broken'
157if test  "$sunos4" != "no"; then
158AC_CHECK_FUNCS(vsnprintf,, LIBS="$LIBS -ldb")
159AC_CHECK_FUNCS(strtoul,, LIBS="$LIBS -l44bsd")
160fi
161
162# some funky macro to be backwards compatible with earlier autoconfs
163# in current they have AC_CHECK_DECLS
164
165AC_DEFUN([SN_CHECK_DECL],[
166AC_MSG_CHECKING([whether $1 must be declared])
167AC_CACHE_VAL(sn_cv_decl_needed_$1,
168[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
169#include <stdio.h>
170#ifdef HAVE_STRING_H
171#include <string.h>
172#endif
173#ifdef HAVE_STRINGS_H
174#include <strings.h>
175#endif
176#ifdef HAVE_STDLIB_H
177#include <stdlib.h>
178#endif
179#ifdef HAVE_UNISTD_H
180#include <unistd.h>
181#endif
182#include <sys/types.h>
183#include <sys/socket.h>
184#include <syslog.h>
185]], [[char *(*pfn); pfn = (char *(*)) $1;]])],[eval "sn_cv_decl_needed_$1=no"],[eval "sn_cv_decl_needed_$1=yes"]) ])
186
187if eval "test \"`echo '$sn_cv_decl_needed_'$1`\" != no"; then
188 AC_MSG_RESULT(yes)
189 ifelse([$2], , :, [$2])
190else
191 AC_MSG_RESULT(no)
192 ifelse([$3], , ,[$3])
193fi
194])dnl
195
196AC_DEFUN([SN_CHECK_DECLS],
197[for sn_decl in $1
198do
199sn_def_decl=`echo $sn_decl | tr [a-z] [A-Z]`
200SN_CHECK_DECL($sn_decl,
201[
202AC_DEFINE_UNQUOTED(NEED_DECL_$sn_def_decl, 1,
203                  [you have this cuz autoheader is dumb])
204$2], $3)dnl
205done
206])
207
208# some stuff for declarations which were missed on sunos4 platform too.
209#
210# add `#undef NEED_DECL_FUNCTIONAME to acconfig.h` because autoheader
211# fails to work properly with custom macroses.
212# you will see also #undef for each SN_CHECK_DECLS macros invocation
213# because autoheader doesn't execute shell script commands.
214# it is possible to make loops using m4 but the code would look even
215# more confusing..
216SN_CHECK_DECLS(printf fprintf syslog puts fputs fputc fopen  \
217           fclose fwrite fflush getopt bzero bcopy memset strtol  \
218           strcasecmp strncasecmp strerror perror socket sendto   \
219           vsnprintf snprintf strtoul)
220
221AC_CHECK_FUNCS([snprintf strlcpy strlcat strerror vswprintf wprintf])
222
223AC_CHECK_SIZEOF([char])
224AC_CHECK_SIZEOF([short])
225AC_CHECK_SIZEOF([int])
226AC_CHECK_SIZEOF([long int])
227AC_CHECK_SIZEOF([long long int])
228AC_CHECK_SIZEOF([unsigned int])
229AC_CHECK_SIZEOF([unsigned long int])
230AC_CHECK_SIZEOF([unsigned long long int])
231
232# Check for int types
233AC_CHECK_TYPES([u_int8_t,u_int16_t,u_int32_t,u_int64_t,uint8_t,uint16_t,uint32_t,uint64_t])
234AC_CHECK_TYPES([int8_t,int16_t,int32_t,int64_t])
235
236# In case INADDR_NONE is not defined (like on Solaris)
237have_inaddr_none="no"
238AC_MSG_CHECKING([for INADDR_NONE])
239AC_RUN_IFELSE(
240[AC_LANG_PROGRAM(
241[[
242#include <sys/types.h>
243#include <netinet/in.h>
244#include <arpa/inet.h>
245]],
246[[
247	if (inet_addr("10,5,2") == INADDR_NONE);
248    return 0;
249]])],
250[have_inaddr_none="yes"],
251[have_inaddr_none="no"])
252AC_MSG_RESULT($have_inaddr_none)
253if test "x$have_inaddr_none" = "xno"; then
254	AC_DEFINE([INADDR_NONE],[-1],[For INADDR_NONE definition])
255fi
256
257AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
258#include <stdio.h>
259]], [[const char *foo; foo = sys_errlist[0];]])],[AC_DEFINE(ERRLIST_PREDEFINED,1,Define if errlist is predefined)],[])
260
261AC_MSG_CHECKING(for __FUNCTION__)
262AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
263#include <stdio.h>
264]], [[printf ("%s", __FUNCTION__);]])],[sn_cv_have___FUNCTION__=yes],[sn_cv__have___FUNCTION__=no])
265if test "x$sn_cv_have___FUNCTION__" = "xyes"; then
266   AC_MSG_RESULT(yes)
267   AC_DEFINE([HAVE___FUNCTION__],[1],[Define if the compiler understands __FUNCTION__.])
268else
269   AC_MSG_RESULT(no)
270   AC_MSG_CHECKING(for __func__)
271   AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
272#include <stdio.h>
273]], [[printf ("%s", __func__);]])],[sn_cv_have___func__=yes],[sn_cv__have___func__=no])
274   if test "x$sn_cv_have___func__" = "xyes"; then
275      AC_MSG_RESULT(yes)
276      AC_DEFINE([HAVE___func__],[1],[Define if the compiler understands __func__.])
277      AC_DEFINE([__FUNCTION__],[__func__],[Define __FUNCTION__ as required.])
278   else
279      AC_MSG_RESULT(no)
280      AC_DEFINE([__FUNCTION__],["mystery function"])
281   fi
282fi
283
284AC_ARG_WITH(libpcap_includes,
285	[  --with-libpcap-includes=DIR    libpcap include directory],
286	[with_libpcap_includes="$withval"],[with_libpcap_includes="no"])
287
288AC_ARG_WITH(libpcap_libraries,
289	[  --with-libpcap-libraries=DIR   libpcap library directory],
290	[with_libpcap_libraries="$withval"],[with_libpcap_libraries="no"])
291
292
293if test "x$with_libpcap_includes" != "xno"; then
294   CPPFLAGS="${CPPFLAGS} -I${with_libpcap_includes}"
295fi
296
297if test "x$with_libpcap_libraries" != "xno"; then
298   LDFLAGS="${LDFLAGS}  -L${with_libpcap_libraries}"
299fi
300
301# --with-libpfring-* options
302AC_ARG_WITH(libpfring_includes,
303       [  --with-libpfring-includes=DIR  libpfring include directory],
304       [with_libpfring_includes="$withval"],[with_libpfring_includes="no"])
305
306AC_ARG_WITH(libpfring_libraries,
307       [  --with-libpfring-libraries=DIR libpfring library directory],
308       [with_libpfring_libraries="$withval"],[with_libpfring_libraries="no"])
309
310if test "x$with_libpfring_includes" != "xno"; then
311   CPPFLAGS="${CPPFLAGS} -I${with_libpfring_includes}"
312fi
313
314if test "x$with_libpfring_libraries" != "xno"; then
315   LDFLAGS="${LDFLAGS} -L${with_libpfring_libraries}"
316fi
317
318
319PCAP_HEADERS=""
320# Test for pcap headers
321
322AC_CHECK_HEADERS(pcap.h,,PCAP_HEADERS="no")
323
324if test "x$PCAP_HEADERS" = "xno"; then
325
326    if test "x$CYGWIN" = "x1" ; then
327
328
329    echo
330    echo "   ERROR: You will need to get Winpcap headers in your path"
331    echo "   Downlad from http://www.winpcap.org, uncompress it and copy"
332    echo "   */Include/* to your include path (/usr/include)"
333    echo "   or use the --with-libpcap-headers* options, if you have it installed"
334    echo "   in unusual place."
335    echo
336
337    exit 1
338
339    else
340
341    echo
342    echo "   ERROR!  Libpcap headers (pcap.h)"
343    echo "   not found, go get it from http://www.tcpdump.org"
344    echo "   or use the --with-libpcap-headers=* options, if you have it installed"
345    echo "   in unusual place."
346    echo
347
348    exit 1
349
350
351    fi
352
353fi
354
355
356LPCAP=""
357
358if test "x$with_libpcap_libraries" != "xyes"; then
359     if test "x$CYGWIN" = "x1"; then
360      	 AC_CHECK_LIB(wpcap, pcap_datalink,, LPCAP="no")
361      else
362         AC_CHECK_LIB(pcap, pcap_datalink,, LPCAP="no")
363      fi
364fi
365
366
367# If the normal AC_CHECK_LIB for pcap fails then check to see if we are
368# using a pfring-enabled pcap.
369if test "x$LPCAP" = "xno"; then
370  PFRING_H=""
371  AC_CHECK_HEADERS(pfring.h,, PFRING_H="no")
372
373# It is important to have the AC_CHECK_LIB for the pfring library BEFORE
374# the one for pfring-enabled pcap. When the Makefile is created, all the
375# libraries used during linking are added to the LIBS variable in the
376# Makefile in the opposite orded that their AC_CHECK_LIB macros appear
377# in configure.in. Durring linking, the pfring library (-lpfring) MUST come
378# _after_ the libpcap library (-lpcap) or linking will fail.
379  PFRING_L=""
380  AC_CHECK_LIB(pfring, pfring_open,, PFRING_L="no")
381
382  LPFRING_PCAP=""
383  AC_CHECK_LIB(pcap, pfring_open,, LPFRING_PCAP="no",-lpfring)
384fi
385
386# If both the AC_CHECK_LIB for normal pcap and pfring-enabled pcap fail then exit.
387if test "x$LPCAP" = "xno"; then
388  if test "x$LPFRING_PCAP" = "xno"; then
389
390         if test "x$CYGWIN" = "1" ; then
391
392    echo
393    echo "   Warning: You will need to get Winpcap, install libraries and headers in your path "
394    echo "   to compile barnyard2 with the output plugin LogTcpdump"
395    echo "   Downlad from http://www.winpcap.org, uncompress it and copy */Lib/* to your lib path (/lib)"
396    echo "   and */Include/* to your include path (/usr/include)"
397    echo "   or use the --with-libpcap-* options, if you have it installed"
398    echo "   in unusual place."
399    echo
400
401    else
402
403    echo
404    echo "   Warning: you will need Libpcap library/headers (libpcap.a (or .so)/pcap.h) in your path"
405    echo "   to compile barnyard2 with the output plugin LogTcpdump"
406    echo "   You can download source from  from http://www.tcpdump.org"
407    echo "   or use the --with-libpcap-* options, if you have it installed"
408    echo "   in unusual place."
409    echo
410
411
412    fi
413
414  fi
415fi
416
417AC_DEFUN([FAIL_MESSAGE],[
418   echo
419   echo
420   echo "**********************************************"
421   echo "  ERROR: unable to find" $1
422   echo "  checked in the following places"
423   for i in `echo $2`; do
424     echo "        $i"
425   done
426   echo "**********************************************"
427   echo
428   exit 1
429])
430
431# any sparc platform has to have this one defined.
432AC_MSG_CHECKING(for sparc)
433if eval "echo $host_cpu|grep -i sparc >/dev/null"; then
434    AC_DEFINE([WORDS_MUSTALIGN],[1],[Define if words must align])
435    AC_MSG_RESULT(yes)
436
437    # gcc, sparc and optimization not so good
438    if test -n "$GCC"; then
439        NO_OPTIMIZE="yes"
440    fi
441else
442    AC_MSG_RESULT(no)
443fi
444
445# check for sparc %time register
446if eval "echo $host_cpu|grep -i sparc >/dev/null"; then
447    OLD_CFLAGS="$CFLAGS"
448    CFLAGS="$CFLAGS -mcpu=v9 "
449    AC_MSG_CHECKING([for sparc %time register])
450    AC_RUN_IFELSE(
451    [AC_LANG_PROGRAM(
452    [[]],
453    [[
454        int val;
455        __asm__ __volatile__("rd %%tick, %0" : "=r"(val));
456    ]])],
457    [sparcv9="yes"],
458    [sparcv9="no"])
459    AC_MSG_RESULT($sparcv9)
460    if test "x$sparcv9" = "xyes"; then
461        AC_DEFINE([SPARCV9],[1],[For sparc v9 with %time register])
462    else
463        CFLAGS="$OLD_CFLAGS"
464    fi
465fi
466
467AC_ARG_ENABLE(ipv6,
468[  --enable-ipv6            Enable IPv6 support],
469       enable_ipv6="$enableval", enable_ipv6="no")
470if test "x$enable_ipv6" = "xyes"; then
471    CPPFLAGS="$CPPFLAGS -DSUP_IP6"
472fi
473AM_CONDITIONAL(HAVE_SUP_IP6, test "x$enable_ipv6" = "xyes")
474
475AC_ARG_ENABLE(gre,
476[  --enable-gre             Enable GRE and IP in IP encapsulation support],
477       enable_gre="$enableval", enable_gre="no")
478if test "x$enable_gre" = "xyes"; then
479    CPPFLAGS="$CPPFLAGS -DGRE"
480fi
481
482AC_ARG_ENABLE(mpls,
483[  --enable-mpls             Enable MPLS support],
484       enable_mpls="$enableval", enable_mpls="no")
485if test "x$enable_mpls" = "xyes"; then
486    CPPFLAGS="$CPPFLAGS -DMPLS"
487fi
488
489AC_ARG_ENABLE(prelude,
490[  --enable-prelude         Enable Prelude Hybrid IDS support],
491       enable_prelude="$enableval", enable_prelude="no")
492if test "x$enable_prelude" = "xyes"; then
493    AM_PATH_LIBPRELUDE(0.9.6, use_prelude="yes", use_prelude="no")
494    if test "$use_prelude" = "yes"; then
495        LDFLAGS="${LDFLAGS} ${LIBPRELUDE_LDFLAGS}"
496        LIBS="$LIBS ${LIBPRELUDE_LIBS}"
497        CFLAGS="$CFLAGS ${LIBPRELUDE_PTHREAD_CFLAGS}"
498        AC_DEFINE([HAVE_LIBPRELUDE],[1],[Define whether Prelude support is enabled])
499    fi
500fi
501
502AC_ARG_ENABLE(debug,
503[  --enable-debug           Enable debugging options (bugreports and developers only)],
504       enable_debug="$enableval", enable_debug="no")
505if test "x$enable_debug" = "xyes"; then
506    NO_OPTIMIZE="yes"
507    CPPFLAGS="$CPPFLAGS -DDEBUG"
508
509    # in case user override doesn't include -g
510    if echo $CFLAGS | grep -qve -g ; then
511        CFLAGS="$CFLAGS -g"
512    fi
513fi
514
515AC_ARG_WITH(mysql,
516    [  --with-mysql=DIR               Support for MySQL],
517    [ with_mysql="$withval"],
518    [ with_mysql="no" ])
519
520AC_ARG_WITH(mysql_includes,
521	[  --with-mysql-includes=DIR      MySQL include directory],
522	[with_mysql_includes="$withval"; with_mysql="yes"],[with_mysql_includes="no"])
523
524AC_ARG_WITH(mysql_libraries,
525	[  --with-mysql-libraries=DIR     MySQL library directory],
526	[with_mysql_libraries="$withval"; with_mysql="yes"],[with_mysql_libraries="no"])
527
528default_directory="/usr /usr/local"
529if test "x$with_mysql" != "xno"; then
530  if test "x$with_mysql" = "xyes"; then
531    if test "x$with_mysql_includes" != "xno"; then
532        mysql_inc_directory="$with_mysql_includes";
533    else
534        mysql_inc_directory="$default_directory";
535    fi
536    if test "x$with_mysql_libraries" != "xno"; then
537        mysql_lib_directory="$with_mysql_libraries";
538    else
539        mysql_lib_directory="$default_directory";
540    fi
541    mysql_fail="yes"
542  elif test -d "$withval"; then
543    AC_MSG_WARN(Providing a directory for the --with-mysql option)
544    AC_MSG_WARN(will be deprecated in the future in favour of)
545    AC_MSG_WARN(--with-mysql-libraries and --with-mysql-includes)
546    AC_MSG_WARN(options to address issues with non-standard)
547    AC_MSG_WARN(installations and 64bit platforms.)
548    mysql_inc_directory="$withval"
549    mysql_lib_directory="$withval"
550    mysql_fail="yes"
551  elif test "x$with_mysql" = "x"; then
552    mysql_inc_directory="$default_directory"
553    mysql_lib_directory="$default_directory"
554    mysql_fail="yes"
555  fi
556
557  AC_MSG_CHECKING(for mysql)
558
559  for i in $mysql_inc_directory; do
560      if test -r "$i/mysql.h"; then
561        MYSQL_INC_DIR="$i"
562      elif test -r "$i/include/mysql.h"; then
563        MYSQL_INC_DIR="$i/include"
564      elif test -r "$i/include/mysql/mysql.h"; then
565        MYSQL_INC_DIR="$i/include/mysql"
566      elif test -r "$i/mysql/mysql.h"; then
567        MYSQL_INC_DIR="$i/mysql"
568      elif test -r "$i/mysql/include/mysql.h"; then
569        MYSQL_INC_DIR="$i/mysql/include"
570      fi
571  done
572
573  for i in $mysql_lib_directory; do
574      if test -z "$MYSQL_LIB_DIR"; then
575        str="$i/libmysqlclient.*"
576        for j in `echo $str`; do
577          if test -r $j; then
578            MYSQL_LIB_DIR=$i
579            break 2
580          fi
581        done
582      fi
583      if test -z "$MYSQL_LIB_DIR"; then
584        str="$i/lib/libmysqlclient.*"
585        for j in `echo $str`; do
586          if test -r "$j"; then
587            MYSQL_LIB_DIR="$i/lib"
588            break 2
589          fi
590        done
591      fi
592      if test -z "$MYSQL_LIB_DIR"; then
593        str="$i/mysql/libmysqlclient.*"
594        for j in `echo $str`; do
595          if test -r "$j"; then
596            MYSQL_LIB_DIR="$i/mysql"
597            break 2
598          fi
599        done
600      fi
601      if test -z "$MYSQL_LIB_DIR"; then
602        str="$i/mysql/lib/libmysqlclient.*"
603        for j in `echo $str`; do
604          if test -r "$j"; then
605            MYSQL_LIB_DIR="$i/mysql/lib"
606            break 2
607          fi
608        done
609      fi
610      if test -z "$MYSQL_LIB_DIR"; then
611        str="$i/lib/mysql/libmysqlclient.*"
612        for j in `echo $str`; do
613          if test -r "$j"; then
614            MYSQL_LIB_DIR="$i/lib/mysql"
615            break 2
616          fi
617        done
618      fi
619  done
620
621  if test -z "$MYSQL_INC_DIR"; then
622    if test "x$mysql_fail" != "xno"; then
623      tmp=""
624      for i in $mysql_inc_directory; do
625        tmp="$tmp $i $i/include $i/include/mysql $i/mysql $i/mysql/include"
626      done
627      FAIL_MESSAGE("mysql headers (mysql.h)", $tmp)
628    else
629      AC_MSG_RESULT(no)
630    fi
631  else
632
633    if test -z "$MYSQL_LIB_DIR"; then
634      if test "x$mysql_fail" != "xno"; then
635        tmp=""
636        for i in $mysql_lib_directory; do
637          tmp="$tmp $i $i/lib $i/mysql $i/mysql/lib $i/lib/mysql"
638        done
639        FAIL_MESSAGE("mysqlclient library (libmysqlclient.*)", $tmp)
640      else
641        AC_MSG_RESULT(no)
642      fi
643    else
644      AC_MSG_RESULT(yes)
645      LDFLAGS="${LDFLAGS} -L${MYSQL_LIB_DIR}"
646      CPPFLAGS="${CPPFLAGS} -I${MYSQL_INC_DIR} -DENABLE_MYSQL"
647      AC_CHECK_LIB(z, compress)
648      LIBS="-lmysqlclient ${LIBS}"
649    fi
650  fi
651
652  AC_MSG_CHECKING([for mysql default client reconnect])
653
654  AC_RUN_IFELSE(
655  [AC_LANG_PROGRAM(
656  [[
657  #include <mysql.h>
658  ]],
659  [[
660      if (mysql_get_client_version() < 50003)
661          return 1;
662  ]])],
663  [mysql_default_reconnect="no"],
664  [mysql_default_reconnect="yes"])
665
666  AC_MSG_RESULT($mysql_default_reconnect)
667
668  if test "x$mysql_default_reconnect" = "xno"; then
669      AC_MSG_CHECKING([for mysql reconnect option])
670
671      AC_RUN_IFELSE(
672      [AC_LANG_PROGRAM(
673      [[
674      #include <mysql.h>
675      ]],
676      [[
677          if (mysql_get_client_version() < 50013)
678              return 1;
679      ]])],
680      [mysql_has_reconnect="yes"],
681      [mysql_has_reconnect="no"])
682
683      AC_MSG_RESULT($mysql_has_reconnect)
684
685      if test "x$mysql_has_reconnect" = "xyes"; then
686          AC_DEFINE([MYSQL_HAS_OPT_RECONNECT],[1],[For MySQL versions 5.0.13 and greater])
687
688          AC_MSG_CHECKING([for mysql setting of reconnect option before connect bug])
689
690          AC_RUN_IFELSE(
691          [AC_LANG_PROGRAM(
692          [[
693          #include <mysql.h>
694          ]],
695          [[
696              if (mysql_get_client_version() < 50019)
697                  return 1;
698          ]])],
699          [mysql_has_reconnect_bug="no"],
700          [mysql_has_reconnect_bug="yes"])
701
702          AC_MSG_RESULT($mysql_has_reconnect_bug)
703
704          if test "x$mysql_has_reconnect_bug" = "xyes"; then
705              AC_DEFINE([MYSQL_HAS_OPT_RECONNECT_BUG],[1],[For MySQL versions 5.0.13 to 5.0.18])
706          fi
707      fi
708  fi
709fi
710
711AC_ARG_ENABLE(mysql-ssl-support,
712[  --enable-mysql-ssl-support           Enable support for mysql SSL connections (experimental)],
713       enable_mysql_ssl_support="$enableval", enable_debug="no")
714if test "x$enable_mysql_ssl_support" = "xyes"; then
715    CPPFLAGS="$CPPFLAGS -DMYSQL_SSL_SUPPORT"
716
717    # in case user override doesn't include -g
718#    if echo $CFLAGS | grep -qve -g ; then
719#        CFLAGS="$CFLAGS -g"
720#    fi
721fi
722
723AC_ARG_WITH(odbc,
724    [  --with-odbc=DIR                Support for ODBC],
725    [ with_odbc="$withval" ],
726    [ with_odbc="no" ])
727
728if test "x$with_odbc" != "xno"; then
729  if test "x$with_odbc" = "xyes"; then
730    odbc_directory="$default_directory"
731    odbc_fail="yes"
732  elif test -d $withval; then
733    odbc_directory="$withval $default_directory";
734    odbc_fail="yes"
735  elif test "x$with_odbc" = "x"; then
736    odbc_directory="$default_directory"
737    odbc_fail="no"
738  fi
739
740  AC_MSG_CHECKING("for odbc")
741
742  for i in $odbc_directory; do
743    if test -r "$i/include/sql.h"; then
744    if test -r "$i/include/sqlext.h"; then
745    if test -r "$i/include/sqltypes.h"; then
746      ODBC_DIR="$i"
747      ODBC_INC_DIR="$i/include"
748    fi fi fi
749  done
750
751  if test -z "$ODBC_DIR"; then
752    if test "x$odbc_fail" != "xno"; then
753      tmp=""
754      for i in $odbc_directory; do
755        tmp="$tmp $i/include"
756      done
757      FAIL_MESSAGE("odbc headers (sql.h sqlext.h sqltypes.h)", $tmp)
758    else
759      AC_MSG_RESULT(no)
760    fi
761  else
762
763    str="$ODBC_DIR/lib/libodbc.*"
764    for j in `echo $str`; do
765      if test -r "$j"; then
766        ODBC_LIB_DIR="$ODBC_DIR/lib"
767        ODBC_LIB="odbc"
768      fi
769    done
770
771dnl    if test -z "$ODBC_LIB_DIR"; then
772dnl      str="$ODBC_DIR/lib/libiodbc.*"
773dnl      for j in `echo $str`; do
774dnl        if test -r $j; then
775dnl          ODBC_LIB_DIR="$ODBC_DIR/lib"
776dnl          ODBC_LIB="iodbc"
777dnl        fi
778dnl      done
779dnl    fi
780
781    if test -z "$ODBC_LIB_DIR"; then
782      if test "x$odbc_fail" != "xno"; then
783        FAIL_MESSAGE("odbc library (libodbc)", "$ODBC_DIR/lib")
784      else
785        AC_MSG_RESULT(no)
786      fi
787    else
788      AC_MSG_RESULT(yes)
789      LDFLAGS="${LDFLAGS} -L${ODBC_LIB_DIR}"
790      CPPFLAGS="${CPPFLAGS} -I${ODBC_INC_DIR} -DENABLE_ODBC"
791      LIBS="${LIBS} -l$ODBC_LIB"
792    fi
793  fi
794fi
795
796AC_ARG_WITH(postgresql,
797    [  --with-postgresql=DIR          Support for PostgreSQL],
798    [ with_postgresql="$withval" ],
799    [ with_postgresql="no" ])
800
801AC_ARG_WITH(pgsql_includes,
802    [  --with-pgsql-includes=DIR      PostgreSQL include directory],
803    [with_pgsql_includes="$withval" ],
804    [with_pgsql_includes="no" ])
805
806if test "x$with_postgresql" != "xno"; then
807  if test "x$with_postgresql" = "xyes"; then
808    postgresql_directory="$default_directory /usr/local/pgsql /usr/pgsql /usr/local"
809    postgresql_fail="yes"
810  elif test -d $withval; then
811    postgresql_directory="$withval $default_directory /usr/local/pgsql /usr/pgsql"
812    postgresql_fail="yes"
813  elif test "$with_postgresql" = ""; then
814    postgresql_directory="$default_directory /usr/local/pgsql /usr/pgsql"
815    postgresql_fail="no"
816  fi
817
818
819    AC_MSG_CHECKING([for postgresql])
820
821  if test "x$with_pgsql_includes" != "xno"; then
822    for i in $with_pgsql_includes $postgresql_directory; do
823      if test -r "$i/libpq-fe.h"; then
824        POSTGRESQL_INC_DIR="$i"
825      elif test -r "$i/include/pgsql/libpq-fe.h"; then
826        POSTGRESQL_INC_DIR="$i/include/pgsql"
827      elif test -r "$i/include/libpq-fe.h"; then
828        POSTGRESQL_INC_DIR="$i/include"
829      elif test -r "$i/include/postgresql/libpq-fe.h"; then
830        POSTGRESQL_INC_DIR="$i/include/postgresql"
831      fi
832    done
833  fi
834
835  if test -z "$POSTGRESQL_INC_DIR"; then
836    for i in $postgresql_directory; do
837      if test -r "$i/include/pgsql/libpq-fe.h"; then
838        POSTGRESQL_DIR="$i"
839        POSTGRESQL_INC_DIR="$i/include/pgsql"
840      elif test -r "$i/include/libpq-fe.h"; then
841        POSTGRESQL_DIR="$i"
842        POSTGRESQL_INC_DIR="$i/include"
843      elif test -r "$i/include/postgresql/libpq-fe.h"; then
844        POSTGRESQL_DIR="$i"
845        POSTGRESQL_INC_DIR="$i/include/postgresql"
846      fi
847    done
848  fi
849
850  if test -z "$POSTGRESQL_INC_DIR"; then
851    if test "x$postgresql_fail" != "xno"; then
852      tmp=""
853      if test "x$with_pgsql_includes" != "xno"; then
854        tmp="$tmp $with_pgsql_includes"
855      fi
856      for i in $postgresql_directory; do
857        tmp="$tmp $i/include $i/include/pgsql"
858      done
859      FAIL_MESSAGE("postgresql header file (libpq-fe.h)", $tmp)
860    else
861      AC_MSG_RESULT(no)
862    fi
863  fi
864
865
866  if test -z "$POSTGRESQL_DIR"; then
867    for dir in $postgresql_directory; do
868       for i in "lib" "lib/pgsql"; do
869         str="$dir/$i/libpq.*"
870         for j in `echo $str`; do
871           if test -r $j; then
872  	     POSTGRESQL_LIB_DIR="$dir/$i"
873             break 2
874           fi
875         done
876       done
877   done
878  else
879   POSTGRESQL_LIB_DIR="$POSTGRESQL_DIR/lib"
880  fi
881
882  if test -z "$POSTGRESQL_LIB_DIR"; then
883     if test "$postgresql_fail" != "no"; then
884       FAIL_MESSAGE("postgresql library libpq",
885       "$POSTGRESQL_DIR/lib $POSTGRESQL_DIR/lib/pgsql")
886     else
887       AC_MSG_RESULT(no);
888     fi
889  else
890     AC_MSG_RESULT(yes)
891     LDFLAGS="${LDFLAGS} -L${POSTGRESQL_LIB_DIR}"
892     CPPFLAGS="${CPPFLAGS} -I${POSTGRESQL_INC_DIR} -DENABLE_POSTGRESQL"
893     AC_CHECK_LIB(pq, PQexec,, PQLIB="no")
894     if test "x$PQLIB" != "xno"; then
895        LIBS="${LIBS} -lpq"
896     else
897        echo
898        echo "   ERROR!  libpq (postgresql) not found!"
899        echo
900        exit 1
901     fi
902  fi
903
904AC_CHECK_FUNC([PQping], [AC_DEFINE([HAVE_PQPING], [1],
905			[Define if PQping exists.])])
906
907fi
908
909AC_ARG_WITH(oracle,
910    [  --with-oracle=DIR              Support for Oracle],
911    [ with_oracle="$withval" ],
912    [ with_oracle="no" ])
913
914if test "x$with_oracle" != "xno"; then
915  if test "x$with_oracle" = "xyes"; then
916    oracle_directory="$default_directory ${ORACLE_HOME}"
917    oracle_fail="yes"
918  elif test -d $withval; then
919    oracle_directory="$withval $default_directory ${ORACLE_HOME}"
920    oracle_fail="yes"
921  elif test "x$with_oracle" = "x"; then
922    oracle_directory="$default_directory ${ORACLE_HOME}"
923    oracle_fail="no"
924  fi
925
926  AC_MSG_CHECKING(for oracle)
927
928  for i in $oracle_directory; do
929    if test -r "$i/rdbms/demo/oci.h"; then
930      ORACLE_DIR="$i"
931    fi
932  done
933
934  if test -z "$ORACLE_DIR"; then
935    if test "x$oracle_fail" != "xno"; then
936      tmp=""
937      for i in $oracle_directory; do
938        tmp="$tmp $i/rdbms/demo"
939      done
940      FAIL_MESSAGE("OCI header file (oci.h)", $tmp)
941    else
942      AC_MSG_RESULT(no)
943    fi
944  else
945    for i in "rdbms/demo" "rdbms/public" "network/public"; do
946      ORACLE_CPP_FLAGS="$ORACLE_CPP_FLAGS -I$ORACLE_DIR/$i"
947    done
948    ORACLE_LIB_DIR="$ORACLE_DIR/lib"
949    AC_MSG_RESULT(yes)
950
951    LDFLAGS="${LDFLAGS} -L${ORACLE_LIB_DIR}"
952    CPPFLAGS="${CPPFLAGS} ${ORACLE_CPP_FLAGS} -DENABLE_ORACLE"
953
954    ORACLE_LIBS="-lclntsh"
955    if test -r "$ORACLE_LIB_DIR/libwtc9.so"; then
956      ORACLE_LIBS="${ORACLE_LIBS} -lwtc9"
957    elif test -r "$ORACLE_LIB_DIR/libwtc8.so"; then
958      ORACLE_LIBS="${ORACLE_LIBS} -lwtc8"
959    fi
960    LIBS="${LIBS} ${ORACLE_LIBS}"
961  fi
962fi
963
964AC_ARG_ENABLE(aruba,
965[  --enable-aruba           Enable Aruba output plugin],
966       enable_aruba="$enableval", enable_aruba="no")
967if test "x$enable_aruba" = "xyes"; then
968    CPPFLAGS="$CPPFLAGS -DARUBA"
969fi
970
971AC_ARG_ENABLE(bro,
972[  --enable-bro             Enable Bro output plugin],
973       enable_bro="$enableval", enable_bro="no")
974AC_ARG_WITH(broccoli,
975[  --with-broccoli=DIR            Prefix where libbroccoli is installed
976                                 for Bro output plugin support (optional)],
977    [ with_broccoli="$withval" ],
978    [ with_broccoli="no" ])
979if test "x$enable_bro" = "xyes"; then
980  if test -d $withval; then
981    broccoli_directory="$withval $default_directory";
982  else
983    broccoli_directory="$default_directory /usr/local/bro";
984  fi
985
986  AC_MSG_CHECKING(for broccoli)
987
988  for i in $broccoli_directory; do
989    if test -x "$i/bin/broccoli-config"; then
990      BROCCOLI_DIR="$i"
991    fi
992  done
993
994  if test -z "$BROCCOLI_DIR"; then
995    tmp=""
996    for i in $broccoli_directory; do
997      tmp="$tmp $i/include"
998    done
999    FAIL_MESSAGE("Broccoli header file (broccoli.h)", $tmp)
1000  fi
1001
1002  AC_MSG_RESULT(yes)
1003  LDFLAGS="${LDFLAGS} `${BROCCOLI_DIR}/bin/broccoli-config --libs`"
1004  CPPFLAGS="${CPPFLAGS} `${BROCCOLI_DIR}/bin/broccoli-config --cflags`"
1005  LIBS="${LIBS} -lbroccoli"
1006fi
1007
1008# Checking for Tcl support (required by spo_sguil)
1009AC_ARG_WITH(tcl,
1010    [  --with-tcl=DIR        support for Tcl],
1011    [ with_tcl="$withval"],
1012    [ with_tcl=no ])
1013
1014if test "$with_tcl" != "no"; then
1015    # prioritise manual definition of the Tcl library.
1016	if test -d "$with_tcl"; then
1017		tclpath="$with_tcl"
1018	else
1019		# let tclsh tell us where it was installed (prefer new Tcl versions).
1020		AC_CHECK_PROGS(TCLSH, tclsh8.4 tclsh8.3 tclsh8.2 tclsh8.1 tclsh8.0 tclsh)
1021	    if test "$TCLSH" != ""; then
1022			tclpath=`echo 'puts [[lindex $tcl_pkgPath 0]]' | $TCLSH`
1023		fi
1024	fi
1025
1026	# check, if tclConfig.sh can be found in tclsh's installation directory.
1027    if test ! -r $tclpath/tclConfig.sh; then
1028		AC_MSG_RESULT(
1029		[
1030	Can't find Tcl libraries.  Use --with-tcl to specify
1031        the directory containing tclConfig.sh on your system.
1032	Continuing build without Tcl support.])
1033    else
1034	# source tclsh's configuration file and tell the user about the version.
1035	. $tclpath/tclConfig.sh
1036	AC_MSG_CHECKING([for the tcl version number])
1037	AC_MSG_RESULT([$TCL_VERSION, patchlevel $TCL_PATCH_LEVEL])
1038        LIBS="$LIBS $TCL_LIBS $TCL_LIB_SPEC"
1039	TCL_INCLUDE="$TCL_PREFIX/include/tcl$TCL_VERSION"
1040	CPPFLAGS="$CPPFLAGS -I$TCL_INCLUDE -DENABLE_TCL";
1041    fi
1042fi
1043
1044#
1045# OUTPUT PLUGIN - ECHIDNA
1046
1047AC_ARG_ENABLE(plugin-echidna,
1048[  --enable-plugin-echidna           Enable echidna plugin (experimental)],
1049       enable_plugin_echidna="$enableval", enable_plugin_echidna="no")
1050if test "x$enable_plugin_echidna" = "xyes"; then
1051    AC_CHECK_LIB([crypto], [SHA256_Init], [], [AC_MSG_ERROR([SHA256_Init was not found in libcrypto])])
1052    AC_CHECK_LIB([curl], [curl_easy_setopt], [], [AC_MSG_ERROR([curl_easy_setopt was not found in libcurl])])
1053    AC_CHECK_LIB([websockets], [libwebsocket_create_context], [], [AC_MSG_ERROR([libwebsocket_create_context was not found in libwebsockets])])
1054    AC_CHECK_LIB([json], [json_tokener_parse], [], [AC_MSG_ERROR([json_tokener_parse was not found in libjson])])
1055
1056    CPPFLAGS="$CPPFLAGS -DENABLE_PLUGIN_ECHIDNA"
1057    LIBS="$LIBS -lwebsockets -ljson -lcurl -lcrypto"
1058fi
1059
1060
1061# let's make some fixes..
1062
1063CFLAGS=`echo $CFLAGS | sed -e 's/-I\/usr\/include //g'`
1064CPPFLAGS=`echo $CPPFLAGS | sed -e 's/-I\/usr\/include //g'`
1065
1066if test "x$GCC" = "xyes" ; then
1067    echo `$CC -v 2>&1` | grep "version 4" > /dev/null
1068    if test $? = 0 ; then
1069        CFLAGS="$CFLAGS -fno-strict-aliasing"
1070    fi
1071fi
1072
1073if test "x$linux" = "xyes"; then
1074    AC_MSG_CHECKING(for linuxthreads)
1075    tstr=`getconf GNU_LIBPTHREAD_VERSION 2>&1`
1076    if test $? = 0; then  # GNU_LIBPTHREAD_VERSION is a valid system variable
1077        echo $tstr | grep -i linuxthreads > /dev/null 2>&1
1078        if test $? = 0; then
1079            AC_DEFINE([HAVE_LINUXTHREADS],[1],[Define whether linuxthreads is being used])
1080            AC_MSG_RESULT(yes)
1081        else
1082            AC_MSG_RESULT(no)
1083        fi
1084    else
1085        # Use libc.so to see if linuxthreads is being used
1086        $( ldd `which --skip-alias ls` | grep libc.so | awk '{print $3}' ) | grep -i linuxthreads > /dev/null 2>&1
1087        if test $? = 0; then
1088            AC_DEFINE([HAVE_LINUXTHREADS],[1],[Define whether linuxthreads is being used])
1089            AC_MSG_RESULT(yes)
1090        else
1091            AC_MSG_RESULT(no)
1092        fi
1093    fi
1094fi
1095
1096# Set to no optimization regardless of what user or autostuff set
1097if test "x$NO_OPTIMIZE" = "xyes"; then
1098    CFLAGS=`echo $CFLAGS | sed -e "s/-O./-O0/"`
1099
1100    # in case user override doesn't include -O
1101    if echo $CFLAGS | grep -qve -O0 ; then
1102        CFLAGS="$CFLAGS -O0"
1103    fi
1104fi
1105
1106if test "x$ADD_WERROR" = "xyes"; then
1107    CFLAGS="$CFLAGS -Werror"
1108fi
1109
1110if test -n "$GCC"; then
1111    CFLAGS="$CFLAGS -Wall"
1112fi
1113
1114echo $CFLAGS > cflags.out
1115echo $CPPFLAGS > cppflags.out
1116
1117INCLUDES='-I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/src/sfutil $(extra_incl) -I$(top_srcdir)/src/output-plugins -I$(top_srcdir)/src/input-plugins'
1118
1119AC_SUBST(INCLUDES)
1120
1121AC_PROG_INSTALL
1122AC_CONFIG_FILES([ \
1123Makefile \
1124src/Makefile \
1125src/sfutil/Makefile \
1126src/input-plugins/Makefile \
1127src/output-plugins/Makefile \
1128etc/Makefile \
1129doc/Makefile \
1130rpm/Makefile \
1131schemas/Makefile \
1132m4/Makefile])
1133AC_OUTPUT
1134
1135if test "x$mysql_has_reconnect" = "xno"; then
1136cat <<EOF
1137
1138********************************************************************************
1139 MySQL version warning
1140
1141 The MySQL client version you are using does not by default reconnect to the
1142 server if the connection is lost and does not have the option to configure
1143 this for the client.  Barnyard2, for security reasons, erases the connection
1144 password from memory, so it cannot explicity reconnect at runtime.  Please
1145 update your version of MySQL to 5.0.13 or greater or you risk connections
1146 timing out because of inactivity resulting in the inablilty of Barnyard2 to write
1147 alerts to the database.  If you can't upgrade, try setting the 'wait-timeout'
1148 configuration parameter to the maximum value possible in the @<:@mysqld@:>@
1149 section of my.cnf, e.g. wait-timeout=31536000.  This should give you a good
1150 year of inactivity before the server terminates the connection ... if your
1151 network is this clean, you probably don't need to use Barnyard2.
1152
1153********************************************************************************
1154
1155EOF
1156fi
1157