1#                                 -*- Autoconf -*-
2# bulk_extractor configure.ac
3#
4# Process this file with autoconf to produce a configure script.
5# Order is largely irrevellant, although it must start with AC_INIT and end with AC_OUTPUT
6# See http://autotoolset.sourceforge.net/tutorial.html
7# and http://www.openismus.com/documents/linux/automake/automake.shtml
8# and http://www.bioinf.uni-freiburg.de/~mmann/HowTo/automake.html
9
10AC_PREREQ([2.69])
11AC_INIT([BULK_EXTRACTOR],[2.0.0-beta2],[bugs@digitalcorpora.org])
12AC_CONFIG_MACRO_DIR(m4)
13AC_CONFIG_AUX_DIR([build-aux])
14################################################################
15## Includes
16
17m4_include([m4/slg_mingw_support.m4])
18m4_include([m4/slg_searchdirs.m4])
19m4_include([src/be13_api/dfxml_cpp/src/dfxml_configure.m4])
20m4_include([src/be13_api/be13_configure.m4])
21
22#
23# NOTE 1 - plugins/Makefile is referenced so that the plugins Makefile is created.
24# However, plugins is not listed as a SUBDIR for Makefile.am in this directory.
25# That prevents the plugins from automatically being built each time.
26#
27# NOTE 2 - src_win/Makefile is not automatically generated. This is necessary
28# so that it can be run even after a 'make distclean' is done
29AC_CONFIG_FILES([Makefile
30                 doc/Makefile doc/latex_manuals/Makefile
31                 src/Makefile src/tests/Makefile
32                 man/Makefile
33                 python/Makefile
34                 specfiles/Makefile specfiles/bulk_extractor.spec.m4
35                 tests/Makefile ])
36
37AC_CONFIG_HEADERS([config.h])
38AM_INIT_AUTOMAKE
39AM_MAINTAINER_MODE
40AC_PREFIX_PROGRAM(bulk_extractor) dnl build for same location
41
42# Programs we will be using
43AC_PROG_CC
44AC_PROG_CXX
45AM_PROG_CC_C_O                    dnl allow per-produce flags
46AC_PROG_INSTALL
47AC_PROG_LEX([noyywrap])
48# LT_INIT([disable-shared])
49
50# Must use C++17 mode.
51
52m4_include([m4/ax_cxx_compile_stdcxx.m4])
53AC_LANG_PUSH(C++)
54AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
55AC_LANG_POP()
56
57# Turn on all warnings
58m4_include([src/be13_api/m4/slg_gcc_all_warnings.m4])
59
60# These are needed for bulk_extractor. They are not needed for tcpflow
61AC_DEFINE([BULK_EXTRACTOR],1,[We are compiling bulk_extractor])
62
63if test x"$LEX" == x ; then
64  AC_MSG_ERROR([flex not required.])
65fi
66
67if test `basename "$LEX"` != flex; then
68  AC_MSG_ERROR([gnu flex is required.])
69fi
70
71## Determine if we can use flex -R
72if eval "echo %% | $LEX -R -t > /dev/null 2>&1"
73then
74  AC_MSG_NOTICE([$LEX supports -R])
75else
76  AC_MSG_ERROR([$LEX does not support -R.  Please get a modern version of gnu flex])
77fi
78
79
80
81################################################################
82## rar support
83AC_ARG_ENABLE([rar],
84              AS_HELP_STRING([--disable-rar], [Disable RAR decompression]),
85              [],
86	      [AC_DEFINE(USE_RAR, 1, [Use RAR decompression]) rar="yes"])
87AM_CONDITIONAL([RAR_ENABLED], [test "yes" = "$rar"])
88
89
90################################################################
91## lightgrep enabled
92AC_ARG_ENABLE([lightgrep],
93              AS_HELP_STRING([--enable-lightgrep], [enable LIGHTGREP]),
94	      [AC_DEFINE(USE_LIGHTGREP, 1, [Use LIGHTGREP]) lightgrep="yes"],
95              [])
96AM_CONDITIONAL([LIGHTGREP_ENABLED], [test "yes" = "$lightgrep"])
97AC_ARG_ENABLE([flexscanners],
98              AS_HELP_STRING([--disable-flexscanners], [disable FLEX-based scanners]),
99              [],
100              [AC_DEFINE(USE_FLEXSCANNERS, 1, [Use FLEX-based scanners]) flexscanners='yes'])
101AM_CONDITIONAL([FLEXSCANNERS_ENABLED], [test "yes" = "$flexscanners"])
102
103
104################################################################
105## mcheck support
106## enable memory analysis support for detecting memory leaks
107## and detecting multiply deallocated memory resources
108## see http://en.wikipedia.org/wiki/Mtrace
109## here is the basic workflow:
110##   1. example usage and recompile: "./configure --enable-mcheck"
111##   2. export the environment variable for the output file,
112##        e.g. "export MALLOC_TRACE=~/malloc_outfile.txt"
113##   3. improve readability of malloc_outfile.txt using mtrace,
114##        e.g. "mtrace /usr/local/bin/bulk_extractor ~/malloc_outfile.txt
115AC_ARG_ENABLE([mcheck],
116              [AS_HELP_STRING([--enable-mcheck],
117                            [enable memory analysis support for detecting memory leaks
118                             and detecting multiply deallocated memory resources])],
119              [AC_DEFINE(HAVE_MCHECK, 1,
120                [define the output file using global variable MALLOC_TRACE,
121                 for example "MALLOC_TRACE=./mcheck.out; export MALLOC_TRACE".
122                 Then post-process unreadable file mcheck.out using the mtrace command line tool,
123                 for example "mtrace /usr/local/bin/bulk_extractor mcheck.out".
124                 Unfortunately, only addresses with written code are looked up,
125                 in otherwords, use of malloc is looked up, but use of new is not.])]
126                 )
127
128
129# Specific include files and functions for bulk-extractor
130# Autoupdate added the next two lines to ensure that your configure
131# script's behavior did not change.  They are probably safe to remove.
132# AC_CHECK_INCLUDES_DEFAULT
133# AC_PROG_EGREP
134
135AC_TYPE_INT64_T
136AC_SYS_LARGEFILE
137AC_SYS_POSIX_TERMIOS
138
139## Check for headers used by bulk Extractor
140AC_CHECK_HEADERS([dlfcn.h fcntl.h inttypes.h libgen.h limits.h mmap.h pwd.h signal.h stdint.h sys/cdefs.h curses.h sys/disk.h sys/fcntl.h sys/ioctl.h sys/mman.h sys/mmap.h sys/mount.h sys/param.h sys/socket.h sys/stat.h sys/types.h sys/time.h sys/resource.h sys/sysctl.h sys/vmmeter.h term.h time.h unistd.h windows.h CoreServices/CoreServices.h mach-o/dyld.h])
141AC_CHECK_FUNCS([getuid getpwuid gethostname getrusage gmtime_r getprogname isxdigit ishexnumber le64toh localtime_r _lseeki64 inet_ntop ioctl isatty pread64 pread printf mmap munmap MD5 mkstemp mktemp sleep SleepEx strptime usleep vasprintf _NSGetExecutablePath])
142AC_CHECK_FUNCS([CreateProcess LoadLibrary IncrementAtomic InterlockedIncrement])
143
144## v2.0 uses termcap! So modern
145AC_CHECK_LIB([termcap], [tgetstr])
146
147## dlopen is now itself in a different library
148## Explicitly check for dlopen library before checking for dlopen
149##       -ldl (see http://stackoverflow.com/questions/956640/linux-c-error-undefined-reference-to-dlopen)
150AC_CHECK_LIB([dl],[dlopen])
151AC_CHECK_FUNCS([dlopen dlopen_preflight])
152
153# Test for sin_len
154AC_CHECK_HEADERS([arpa/inet.h netinet/in.h wsipx.h])
155AC_CHECK_HEADERS([netinet/ip.h], [], [],
156[[
157#include <sys/types.h>
158#ifdef HAVE_NETINET_IN_H
159#include <netinet/in.h>
160#endif
161]])
162
163AC_CHECK_MEMBERS([struct winsize.ws_col], [], [], [[#include <sys/ioctl.h>]])
164
165AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
166		[AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr.sin_len?])],
167		[],
168		[
169#include <sys/types.h>
170#include <arpa/inet.h>
171#ifdef HAVE_NETINET_IN_H
172#include <netinet/in.h>
173#endif
174		])
175
176#
177# ZLIB is required:
178# Note you cannot put comments in the AC_MSG_ERROR for some reason
179# Must be before ewf
180AC_CHECK_LIB([z],[uncompress],,
181	AC_MSG_ERROR([zlib libraries not installed; try installing zlib-devel zlib-dev zlib-devel zlib1g-dev or libz-dev]))
182
183## EXPAT is required for reading the dfxml file for restrarting.
184AC_CHECK_HEADERS([expat.h])
185AC_CHECK_LIB([expat],[XML_ParserCreate])
186
187################################################################
188## Lightgrep support
189##
190AC_CHECK_LIB([stdc++],[main])
191
192if test x"$lightgrep" == x"yes"; then
193  m4_ifndef([PKG_CHECK_MODULES],
194            [AC_MSG_ERROR([pkg-config autoconf macros are missing; try installing pkgconfig])])
195
196  if test x"$mingw" == x"yes" ; then
197    # get static flags when cross-compiling with mingw
198    PKG_CONFIG="$PKG_CONFIG --static"
199  else
200    # pkg-config doesn't look in /usr/local/lib on some systems
201    if test x"$PKG_CONFIG_PATH" != x; then
202      export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
203    else
204      export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
205    fi
206  fi
207
208  m4_ifdef([PKG_CHECK_MODULES],
209           [PKG_CHECK_MODULES([lightgrep], [lightgrep])])
210
211  AC_DEFINE([HAVE_LIBLIGHTGREP], 1, [Define to 1 if you have liblightgrep.])
212
213  CPPFLAGS="$CPPFLAGS $lightgrep_CFLAGS"
214  LIBS="$LIBS `$PKG_CONFIG --libs-only-l lightgrep`"
215  LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs-only-L --libs-only-other lightgrep`"
216fi
217
218################################################################
219## LIBEWF support
220
221AC_ARG_ENABLE([libewf],
222    [AS_HELP_STRING([--disable-libewf], [disable libewf support])],
223    [libewf=no],
224    [libewf=yes])
225AC_MSG_NOTICE([libewf is $libewf])
226if test x"$libewf" == x"yes" ; then
227  AC_CHECK_HEADER([libewf.h],
228	[AC_DEFINE(HAVE_LIBEWF_H,1,[Do we have libewf.h?])]
229	[AC_CHECK_LIB([ewf],[libewf_get_version],,
230		[AC_MSG_WARN([libewf not found; no E01 support])]
231		[libewf=no])],
232	[AC_MSG_WARN([libewf.h not found; no E01 support])]
233	[libewf=no])
234  AC_CHECK_FUNCS([libewf_handle_get_utf8_header_value_notes libewf_error_backtrace_fprint libewf_handle_close libewf_handle_free libewf_handle_read_buffer_at_offset libewf_handle_read_random])
235fi
236AC_MSG_NOTICE([libewf is now $libewf])
237
238
239################################################################
240## exiv2 support
241## now that exif is in place, exiv2 is an optional scanner.
242## On mingw we also need libiconv
243## We should probably test to make sure that exiv2 works too
244
245AC_ARG_ENABLE([exiv2],[AS_HELP_STRING([--enable-exiv2=true to check for exiv2; warning: exiv2 crashes])],
246   exiv2=yes,
247   exiv2=no)
248if test "${exiv2}" == yes ; then
249  AC_CHECK_LIB([iconv],[libiconv_open])
250  if test "${mingw}" == yes ; then
251    AC_MSG_WARN([exiv2 requires use of the DLL which must be present])
252    if test `uname -s` = "Linux" ; then
253      AC_MSG_WARN([exiv2 is not working properly with mingw and Linux cross-compiling; disabled])
254    exiv2=no
255    fi
256  fi
257fi
258if test x"$exiv2" == x"yes" ; then
259  AC_LANG_PUSH(C++)
260  AC_CHECK_HEADERS([exiv2/image.hpp exiv2/exif.hpp exiv2/error.hpp])
261    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
262         #include <exiv2/image.hpp>
263    	 #include <exiv2/exif.hpp>
264         #include <exiv2/error.hpp>
265         ]],
266         [[Exiv2::ImageFactory::open(0,0);]])],
267         [exiv2=yes],
268         [exiv2=no])
269    if test "${exiv2}" = yes; then
270      AC_DEFINE(HAVE_EXIV2,1,[define 1 if EXIV2 exists and works])
271      echo Using EXIV2
272      if test "${mingw}" = no ; then
273        LIBS="$LIBS -lexiv2"
274      else
275        LIBS="$LIBS -lexiv2.dll"	# static version does not work on mingw
276      fi
277      dnl see if we have the error feature
278      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
279            #include <exiv2/image.hpp>
280    	    #include <exiv2/exif.hpp>
281            #include <exiv2/error.hpp>
282            ]],
283            [[Exiv2::LogMsg::setLevel(Exiv2::LogMsg::mute);]],
284  	    [AC_DEFINE(HAVE_EXIV2__LOGMSG__SETLEVEL,1,[define 1 if EXIV2 exists and works])])])
285    fi
286  AC_LANG_POP()
287fi
288
289m4_include([m4/slg_check_gcc_diagnostics.m4])
290
291## If compiling on mingw, add another -lgdi32 to be safe
292## This is required becuase some libraries reference functions in gdi32 and, for whatever reason,
293## the linker is not smart enough to re-check the library
294##
295## Also add -municode per https://stackoverflow.com/questions/58324230/undefined-reference-to-winmain-c-mingw
296## but only for be_test
297if test "${mingw}" == yes ; then
298  AC_MSG_NOTICE([adding libraries for mingw])
299  LIBS="$LIBS -lgdi32"
300else
301  CFLAGS="$CFLAGS -fPIC"
302  CXXFLAGS="$CXXFLAGS -fPIC"
303fi
304
305m4_include([src/be13_api/m4/slg_address_sanitizer.m4])
306m4_include([src/be13_api/m4/slg_noopt.m4])
307
308################################################################
309## Check on two annoying warnings
310
311# https://stackoverflow.com/questions/47160617/more-robust-ac-compile-ifelse-feature-testing
312# MY_COMPILE_CLEAN_IFELSE(PROGRAM, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
313# ---------------------------------------------------------------
314# Try to compile PROGRAM.
315AC_DEFUN([MY_COMPILE_CLEAN_IFELSE],
316[AC_REQUIRE([AC_PROG_EGREP])
317AC_COMPILE_IFELSE([$1],[retval=0
318if $EGREP -i -c -E 'fatal|error|unrecognized|not found|not exist' conftest.err >/dev/null; then retval=1; fi
319],[retval=1])
320AS_IF([test $retval = 0],[$2],[$3])])
321
322
323AC_MSG_NOTICE([*************************************])
324AC_MSG_NOTICE([*************************************])
325AC_MSG_NOTICE([  PACKAGE_NAME:     $PACKAGE_NAME])
326AC_MSG_NOTICE([  PACKAGE_VERSION:  $PACKAGE_VERSION])
327AC_MSG_NOTICE([  CC:               $CC])
328AC_MSG_NOTICE([  CXX:              $CXX])
329AC_MSG_NOTICE([  CPPFLAGS:         $CPPFLAGS])
330AC_MSG_NOTICE([  CFLAGS:           $CFLAGS])
331AC_MSG_NOTICE([  CXXFLAGS:         $CXXFLAGS])
332AC_MSG_NOTICE([  LIBS:             $LIBS])
333AC_MSG_NOTICE([  LDFLAGS:          $LDFLAGS])
334
335#
336# Generate special warnings
337#
338
339if test x"${libewf}" != "xyes" ; then
340  AC_MSG_WARN([libewf-devel must be installed for E01 support.])
341fi
342
343AC_OUTPUT
344
345## Finally, record the values of CFLAGS, CPPFLAGS, and CXXFLAGS for DFXML
346echo "#define CPPFLAGS \"$CPPFLAGS\"" >> config.h
347echo "#define CFLAGS   \"$CFLAGS\""   >> config.h
348echo "#define CXXFLAGS \"$CXXFLAGS\"" >> config.h
349echo "#define LIBS     \"$LIBS\""     >> config.h
350echo "#define LDFLAGS  \"$LDFLAGS\""  >> config.h
351if test x"$GIT_COMMIT" != "x" ; then
352  echo "#define GIT_COMMIT  \"$GIT_COMMIT\""  >> config.h
353fi
354