1
2# configure.ac script for md5deep/hashdeep family of programs.
3#
4
5AC_PREREQ(2.57)
6AC_INIT([MD5DEEP],[4.4],[research@jessekornblum.com])
7AC_CONFIG_FILES([Makefile src/Makefile man/Makefile tests/Makefile tests/testfiles/Makefile ])
8AM_INIT_AUTOMAKE
9AC_CONFIG_HEADERS([config.h])
10AC_DEFINE([_FILE_OFFSET_BITS],64,[Make sure we are using 64-bit offsets])
11
12AC_PROG_CC
13AC_PROG_CXX
14AC_PROG_INSTALL
15
16################################################################
17# http://osdir.com/ml/gnu.mingw.devel/2003-09/msg00040.html
18# Note: Windows 95 WINVER=0x400
19# Windows 98 WINVER=0x400  _WIN32_WINDOWS=0x0410
20# Windows Me WINVER=0x400  _WIN32_WINDOWS=0x0490
21# Windows NT 4.0 WINVER=0x0400  _WIN32_WINNT=0x0400
22# Windows NT 4.0 SP3 WINVER=0x0400 _WIN32_WINNT=0x0403
23# Windows 2000 WINVER=0x500 _WIN32_WINNT=0x0500
24# Windows XP WINVER=0x501 _WIN32_WINNT=0x0501
25# Windows Server 2003 WINVER=0x502 _WIN32_WINNT=0x0502
26
27# mingw32 includes  i686-w64-mingw32 and  x86_64-w64-mingw32
28
29mingw="no"
30case $host in
31  *-*-*linux*-*)
32     AC_DEFINE([__LINUX__],1,[Linux operating system functions])
33     ;;
34
35  *-*-mingw32*)
36     LIBS="-lws2_32 -lgdi32 -lpthread $LIBS"  # previously had -liberty
37     CPPFLAGS="-DUNICODE -D_UNICODE -D__MSVCRT_VERSION__=0x0601 -DWINVER=0x0500 -D_WIN32_WINNT=0x0500 -DHAVE_STRUCT_TIMESPEC $CPPFLAGS"
38     CXXFLAGS="$CXXFLAGS -Wno-format "  # compiler mingw-4.3.0 is broken on I64u formats
39     CXXFLAGS="$CXXFLAGS --static"
40     AC_DEFINE([MINGW],1,[We are cross-compiling with MINGW])
41     mingw="yes"
42     ;;
43esac
44
45
46# Bring additional directories where things might be found into our
47# search path. I don't know why autoconf doesn't do this by default
48if test x"${mingw}" == "xno" ; then
49  for spfx in /usr/local /opt/local /sw ; do
50    echo checking ${spfx}/include
51    if test -d ${spfx}/include; then
52        CPPFLAGS="-I${spfx}/include $CPPFLAGS"
53        LDFLAGS="-L${spfx}/lib $LDFLAGS"
54    fi
55  done
56fi
57#
58#
59################################################################
60
61AC_GNU_SOURCE
62AC_CANONICAL_HOST
63
64################################################################
65### I am a glutten for punishment and this is security-critical software
66# Check GCC
67WARNINGS_TO_TEST="-MD -D_FORTIFY_SOURCE=2 -Wpointer-arith -Wmissing-declarations -Wmissing-prototypes \
68    -Wshadow -Wwrite-strings -Wcast-align -Waggregate-return \
69    -Wbad-function-cast -Wcast-qual -Wundef -Wredundant-decls -Wdisabled-optimization \
70    -Wfloat-equal -Wmissing-format-attribute -Wmultichar -Wc++-compat -Wmissing-noreturn  -funit-at-a-time"
71
72if test $mingw = "no" ; then
73  # add the warnings we don't want to do on mingw
74  $WARNINGS_TO_TEST="$WARNINGS_TO_TEST -Wall -Wstrict-prototypes  -Weffc++"
75fi
76
77for option in $WARNINGS_TO_TEST
78do
79  SAVE_CFLAGS="$CFLAGS"
80  CFLAGS="$CFLAGS $option"
81  AC_MSG_CHECKING([whether gcc understands $option])
82  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
83      [has_option=yes],
84      [has_option=no; CFLAGS="$SAVE_CFLAGS"])
85  AC_MSG_RESULT($has_option)
86  unset has_option
87  unset SAVE_CFLAGS
88done
89unset option
90
91
92# Check G++
93# We don't use these warnings:
94# -Waggregate-return -- aggregate returns are GOOD; they simplify code design
95# We can use these warnings after ZLIB gets upgraded:
96# -Wundef  --- causes problems with zlib
97# -Wcast-qual
98# -Wmissing-format-attribute  - can't get this one right
99AC_LANG_PUSH(C++)
100WARNINGS_TO_TEST="-Wall -MD -D_FORTIFY_SOURCE=2 -Wpointer-arith \
101    -Wshadow -Wwrite-strings -Wcast-align  \
102    -Wredundant-decls -Wdisabled-optimization \
103    -Wfloat-equal -Wmultichar -Wmissing-noreturn \
104    -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo  -funit-at-a-time"
105
106if test $mingw = "no" ; then
107  # add the warnings we don't want to do on mingw
108  $WARNINGS_TO_TEST="$WARNINGS_TO_TEST  -Weffc++"
109fi
110
111for option in $WARNINGS_TO_TEST
112do
113  SAVE_CXXFLAGS="$CXXFLAGS"
114  CXXFLAGS="$CXXFLAGS $option"
115  AC_MSG_CHECKING([whether g++ understands $option])
116  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
117      [has_option=yes],
118      [has_option=no; CXXFLAGS="$SAVE_CXXFLAGS"])
119  AC_MSG_RESULT($has_option)
120  unset has_option
121  unset SAVE_CXXFLAGS
122done
123unset option
124AC_LANG_POP()
125#
126################################################################
127
128
129# Determine UTC date offset
130CPPFLAGS="$CPPFLAGS -DUTC_OFFSET=`date +%z`"
131
132# Checks for header files.
133AC_HEADER_DIRENT
134AC_HEADER_STDC
135AC_CHECK_HEADERS([libgen.h fcntl.h limits.h inttypes.h malloc.h stdint.h stdlib.h string.h \
136			   sys/cdefs.h sys/types.h sys/ioctl.h sys/mmap.h sys/mman.h sys/param.h \
137			   sys/resource.h wchar.h unistd.h sys/stat.h sys/disk.h\
138			   CommonCrypto/CommonDigest.h
139			   ])
140
141# Definition of MAP_FILE is missing e.g. on Solaris
142AC_CHECK_DECLS([MAP_FILE])
143
144# These functions not available everywhere
145AC_CHECK_FUNCS([_gmtime64_s _gmtime64 gmtime_r mmap usleep mkstemp vasprintf getrusage getprogname isxdigit])
146
147# This is for Apple's new CommonCrypto (which is FIPS validated)
148AC_CHECK_FUNCS([CC_MD5_Init CC_SHA1_Init CC_SHA256_Init])
149
150# These includes are required on FreeBSD
151AC_CHECK_HEADERS([sys/mount.h],[],[],
152[#ifdef HAVE_SYS_TYPES_H
153 # include <sys/types.h>
154 #endif
155 #ifdef HAVE_SYS_PARAM_H
156 # include <sys/param.h>
157 #endif])
158
159# http://www.gnu.org/s/hello/manual/autoconf/Particular-Headers.html
160#
161# If a program may include both time.h and sys/time.h, define
162# TIME_WITH_SYS_TIME. On some ancient systems, sys/time.h included
163# time.h, but time.h was not protected against multiple inclusion, so
164# programs could not explicitly include both files. This macro is
165# useful in programs that use, for example, struct timeval as well as
166# struct tm. It is best used in conjunction with HAVE_SYS_TIME_H,
167# which can be checked for using AC_CHECK_HEADERS([sys/time.h]).
168
169AC_CHECK_HEADERS([time.h sys/time.h])
170AC_HEADER_TIME
171
172
173################################################################
174# DFXML support
175AC_CHECK_HEADERS([sys/cdefs.h sys/resource.h pwd.h sys/utsname.h])
176AC_CHECK_FUNCS([localtime_r getuid gethostname getwpuid getrusage])
177
178# There are still users on big-endian operating systems out there!
179AC_C_BIGENDIAN
180
181# Checks for typedefs, structures, and compiler characteristics.
182AC_C_CONST
183AC_TYPE_OFF_T
184AC_TYPE_SIZE_T
185AC_CHECK_MEMBERS([struct stat.st_blksize])
186
187# Checks for library functions.
188AC_FUNC_CLOSEDIR_VOID
189AC_FUNC_FSEEKO
190AC_SYS_LARGEFILE
191AC_PROG_GCC_TRADITIONAL
192AC_FUNC_LSTAT
193AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
194AC_FUNC_MEMCMP
195AC_FUNC_STAT
196AC_FUNC_VPRINTF
197
198# More permutations of fseek/ftell lossage
199AC_CHECK_FUNCS([fseeko64 ftello64])
200
201# See if program_invocation_name is defined on this system
202AC_TRY_COMPILE([#include <errno.h>],
203			[const char *progname = program_invocation_name;],
204			extern_program_invocation_name=yes,
205			extern_program_invocation_name=no)
206if test x"${extern_program_invocation_name}" = x"yes"; then
207  AC_MSG_NOTICE([extern program_invocation_name in errno.h])
208  AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME,1,[define to 1 if program_invocation_name is available])
209fi
210
211
212################################################################
213# PTHREAD support
214# With special nods to compiling under mingw
215
216if test  x"$mingw" = x"yes";  then
217  AC_MSG_NOTICE([Checking for pthreads under mingw])
218  AC_DEFINE([HAVE_STRUCT_TIMESPEC],1,[Required for mingw])
219  CFLAGS="$CFLAGS -mthreads "
220  CPPFLAGS="-DPTW32_STATIC_LIB $CPPFLAGS"
221  CXXFLAGS="$CXXFLAGS -mthreads "
222  AC_DEFINE(HAVE_PTHREAD,1,[Defined to POSIX threads for mingw])
223else
224  m4_include([m4/ax_pthread.m4])
225  AX_PTHREAD([
226    echo Using settings from [AX_PTHREAD] macro
227    LIBS="$PTHREAD_LIBS $LIBS"
228    CFLAGS="  $PTHREAD_CFLAGS $CFLAGS"
229    CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS "
230    CPPFLAGS="$PTHREAD_CFLAGS $CPPFLAGS "
231    CC="$PTHREAD_CC"
232    AC_DEFINE(HAVE_PTHREAD,1,[Defined to POSIX threads for mingw])
233  ],[AC_MSG_NOTICE([pthreads not found by ax_pthread macro])])
234fi
235
236AC_CHECK_HEADERS([pthread.h])
237AC_CHECK_LIB([pthreadGC2],[pthread_create])
238
239# On mingw, be sure to use the static version and be sure we are using mthread option
240# (which should be a no-op on later version of G++ anyway)
241
242AC_CHECK_FUNCS([pthread_win32_process_attach_np pthread_win32_process_detach_np pthread_win32_thread_attach_np pthread_win32_thread_detach_np])
243# end PTHREAD SUPPORT
244################################################################
245
246# This allows us to easily disable optimizations for debugging
247AC_ARG_WITH([noopt], AC_HELP_STRING([--with-noopt],[Drop -O C flags]))
248if test x"${AFF_NOOPT}" != "x" ; then
249   with_noopt="yes";
250fi
251
252if test "${with_noopt}" = "yes" ; then
253  AC_MSG_NOTICE([XXXXXXXX DROPPING OPTIMIZATION FLAGS XXXXXXXX])
254  CFLAGS=`echo "$CFLAGS" | sed s/-O[[0-9]]// | sed s/-fast//`             # note the double quoting!
255  CXXFLAGS=`echo "$CXXFLAGS" | sed s/-O[[0-9]]// | sed s/-fast//`
256fi
257
258AC_OUTPUT
259
260echo ============================
261echo $0 finished at `date`
262echo PACKAGE_NAME:     $PACKAGE_NAME
263echo PACKAGE_VERSION:  $PACKAGE_VERSION
264echo CC:               $CC
265echo CXX:              $CXX
266echo CPPFLAGS:         $CPPFLAGS
267echo CFLAGS:           $CFLAGS
268echo CXXFLAGS:         $CXXFLAGS
269echo LIBS:             $LIBS
270echo LDFLAGS:          $LDFLAGS
271