1AC_PREREQ(2.59)
2AC_INIT(srtp, 1.4.2, mcgrew@cisco.com)
3AC_CONFIG_AUX_DIR(build)
4AM_INIT_AUTOMAKE
5
6CFLAGS="$CFLAGS $CONFIGURE_CFLAGS"
7CXXFLAGS="$CXXFLAGS $CONFIGURE_CXXFLAGS"
8LDFLAGS="$LDFLAGS $CONFIGURE_LDFLAGS"
9
10#Set default language
11AC_LANG_C
12# Checks for programs.
13AC_PROG_CC
14AC_PROG_AWK
15AC_PROG_MAKE_SET
16AC_PROG_INSTALL
17AC_PROG_LIBTOOL
18AX_COMPILER_VENDOR
19
20# Optimization
21AC_ARG_ENABLE(optimization,
22[AC_HELP_STRING([--enable-optimization],[Set if you want us to add max optimising compiler flags])],[enable_optimizer="$enableval"],[enable_optimizer="no"])
23
24if test "${enable_optimizer}" = "yes" ; then
25        AC_DEFINE([OPTIMZER],[],[Enable Optimization.])
26        AX_CC_MAXOPT
27fi
28
29#  Enable debugging
30AC_ARG_ENABLE(debug,
31[AC_HELP_STRING([--enable-debug],[build with debug information])],[enable_debug="$enable_debug"],[enable_debug="yes"])
32
33if test "${enable_debug}" = "yes"; then
34        AC_DEFINE([DEBUG],[],[Enable extra debugging.])
35        AX_CFLAGS_WARN_ALL_ANSI
36fi
37
38
39AM_CONDITIONAL([WANT_DEBUG],[test "${enable_debug}" = "yes"])
40
41IN_LINE=inline
42
43case "$host" in
44                *-solaris2*)
45                        if test "x${ax_cv_c_compiler_vendor}"  = "xsun" ; then
46                                SOLINK="-Bdynamic -dy -G"
47                                new_AM_CFLAGS="-KPIC -DPIC"
48                                new_AM_LDFLAGS="-R${prefix}/lib"
49                                FUNC_DEF=__func__
50                                IN_LINE=""
51                        elif test "x${ax_cv_c_compiler_vendor}" = "xgnu" ; then
52                                SOLINK="-Bdynamic -dy -G"
53                                new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
54                                new_AM_LDFLAGS=""
55                                IN_LINE=inline
56                        fi
57                ;;
58                *-darwin*)
59                        if test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
60                                SOLINK="-dynamic -bundle -force-flat-namespace"
61                                new_AM_CFLAGS="-DMACOSX"
62                                new_AM_LDFLAGS=""
63                        fi
64                ;;
65                x86_64-*-linux-gnu)
66                        if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
67                                SOLINK="-Bdynamic -dy -G"
68                                new_AM_CFLAGS="-KPIC -DPIC"
69                                new_AM_LDFLAGS="-R${prefix}/lib"
70                                FUNC_DEF=__func__
71                        elif test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
72                               SOLINK="-shared -Xlinker -x"
73                                new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
74                                new_AM_LDFLAGS=""
75                        fi
76                ;;
77                i*6-*-linux-gnu)
78                        if test "x${ax_cv_c_compiler_vendor}" = "xsun" ; then
79                                SOLINK="-Bdynamic -dy -G"
80                                new_AM_CFLAGS="-KPIC -DPIC"
81                                new_AM_LDFLAGS="-R${prefix}/lib"
82                                FUNC_DEF=__func__
83                        elif test "x${ax_cv_c_compiler_vendor}"="xgnu" ; then
84                                SOLINK="-shared -Xlinker -x"
85                                new_AM_CFLAGS="-fpic -Wall -O4 -fexpensive-optimizations -funroll-loops"
86                                new_AM_LDFLAGS=""
87                        fi
88                ;;
89		i*6*-*-freebsd*)
90                        SOLINK="-shared -Xlinker -x"
91                        new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
92                        new_AM_LDFLAGS=""
93		;;
94		x86_64-*-freebsd*|amd64-*-freebsd*)
95                        SOLINK="-shared -Xlinker -x"
96                        new_AM_CFLAGS="-fPIC -Wall -O4 -fexpensive-optimizations -funroll-loops"
97                        new_AM_LDFLAGS=""
98		;;
99esac
100
101#  Enable 64 bit build
102AC_ARG_ENABLE(64,
103[AC_HELP_STRING([--enable-64],[build with 64 bit support])],[enable_64="$enable_64"],[enable_64="no"])
104
105if test "x${ax_cv_c_compiler_vendor}"  =  "xsun" ; then
106    if test "${enable_64}" = "yes"; then
107        new_AM_CFLAGS="$new_AM_CFLAGS -m64"
108    fi
109fi
110
111AC_SUBST(new_AM_CFLAGS)
112AC_SUBST(new_AM_LDFLAGS)
113AC_SUBST(SOLINK)
114if test "x$FUNC_DEF" != "x"; then
115   AC_DEFINE_UNQUOTED([__FUNCTION__],[$FUNC_DEF],[define it the right way ;)])
116fi
117AC_DEFINE_UNQUOTED([inline],[$IN_LINE],[sunpro is bad at inline])
118
119
120AC_ARG_ENABLE(kernel-linux,
121  [AS_HELP_STRING([--enable-kernel-linux],
122		  [build library to run in Linux kernel context])],
123  [], enable_kernel_linux=no)
124AC_MSG_CHECKING(whether to build for Linux kernel context)
125if test "$enable_kernel_linux" = "yes"; then
126   AC_DEFINE(SRTP_KERNEL, 1,
127	[Define to compile for kernel contexts.])
128   AC_DEFINE(SRTP_KERNEL_LINUX, 1,
129	[Define to compile for Linux kernel context.])
130fi
131AC_MSG_RESULT($enable_kernel_linux)
132
133dnl Check for /dev/urandom
134AC_CHECK_FILE(/dev/urandom, DEV_URANDOM=/dev/urandom,
135   [AC_CHECK_FILE(/dev/random, DEV_URANDOM=/dev/random)])
136
137dnl Checks for header files.
138AC_HEADER_STDC
139AC_CHECK_HEADERS(stdlib.h)
140AC_CHECK_HEADERS(unistd.h)
141AC_CHECK_HEADERS(stdint.h)
142AC_CHECK_HEADERS(sys/uio.h)
143AC_CHECK_HEADERS(inttypes.h)
144AC_CHECK_HEADERS(sys/types.h)
145AC_CHECK_HEADERS(machine/types.h)
146AC_CHECK_HEADERS(sys/int_types.h)
147
148AC_LINK_IFELSE([AC_LANG_PROGRAM([[
149#include <inttypes.h>
150#include <byteswap.h>
151]],[[
152uint64_t y = 0x1122334455667788LL;
153bswap_64(y);
154]])],byteswap_cv_bswap_64_usable=yes,byteswap_cv_bswap_64_usable=no)
155
156if test "x${byteswap_cv_bswap_64_usable}" = "xyes" ; then
157AC_DEFINE([HAVE_BYTESWAP_H],1,[define if you have a usable bswap_64 in byteswap.h])
158fi
159
160dnl socket() and friends
161AC_CHECK_HEADERS(sys/socket.h netinet/in.h arpa/inet.h)
162AC_CHECK_HEADERS(windows.h, [AC_CHECK_HEADERS(winsock2.h)])
163
164AC_CHECK_HEADERS(syslog.h)
165
166AC_CHECK_TYPES([int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,uint64_t])
167AC_CHECK_SIZEOF(unsigned long)
168AC_CHECK_SIZEOF(unsigned long long)
169
170dnl Checks for typedefs, structures, and compiler characteristics.
171AC_C_CONST
172AC_C_INLINE
173AC_TYPE_SIZE_T
174
175dnl Checks for library functions.
176AC_CHECK_FUNCS(socket inet_aton usleep sigaction)
177
178dnl Find socket function if not found yet.
179if test "x$ac_cv_func_socket" = "xno"; then
180  AC_CHECK_LIB(socket, socket)
181  AC_MSG_CHECKING([for socket in -lwsock32])
182  SAVELIBS="$LIBS"
183  LIBS="$LIBS -lwsock32"
184  AC_TRY_LINK([
185#include <winsock2.h>
186],[
187socket(0, 0, 0);
188],
189    ac_cv_func_socket=yes
190    AC_MSG_RESULT(yes),
191    LIBS="$SAVELIBS"
192    AC_MSG_RESULT(no))
193fi
194
195dnl Check the byte order
196AC_C_BIGENDIAN
197
198
199dnl check host_cpu type, set defines appropriately
200case $host_cpu in
201     i*86 | x86_64 )
202	AC_DEFINE(CPU_CISC, 1,
203	   [Define if building for a CISC machine (e.g. Intel).])
204	# Do not enable use of asm for MACOSX
205        if test "x$new_AM_CFLAGS" != "x-DMACOSX"; then
206	  AC_DEFINE(HAVE_X86, 1,
207	   [Define to use X86 inlined assembly code])
208	fi
209	;;
210	* )
211	# CPU_RISC is only supported for big endian machines.
212	if test "$ac_cv_c_bigendian" = "yes"; then
213	   AC_DEFINE(CPU_RISC, 1,
214	    [Define if building for a RISC machine (assume slow byte access).])
215	else
216	   AC_DEFINE(CPU_CISC, 1)
217	fi
218	;;
219esac
220
221dnl Check if we're on a Windows platform.
222case $host_os in
223  *cygwin*|*mingw* )
224	      EXE=.exe;;
225         * )  EXE="";;
226esac
227
228AC_SUBST(EXE)   # define executable suffix; this is needed for `make clean'
229
230AC_MSG_CHECKING(whether to compile in debugging)
231AC_ARG_ENABLE(debug,
232  [AS_HELP_STRING([--disable-debug],
233		  [do not compile in dynamic debugging system])],
234  [], enable_debug=yes)
235if test "$enable_debug" = "yes"; then
236   AC_DEFINE(ENABLE_DEBUGGING, 1,
237      [Define to compile in dynamic debugging system.])
238fi
239AC_MSG_RESULT($enable_debug)
240
241AC_MSG_CHECKING(whether to use ISMAcryp code)
242AC_ARG_ENABLE(generic-aesicm,
243  [AS_HELP_STRING([--enable-generic-aesicm],
244		  [compile in changes for ISMAcryp])],
245  [], enable_generic_aesicm=no)
246if test "$enable_generic_aesicm" = "yes"; then
247   AC_DEFINE(GENERIC_AESICM, 1, [Define this to use ISMAcryp code.])
248fi
249AC_MSG_RESULT($enable_generic_aesicm)
250
251AC_MSG_CHECKING(whether to leverage OpenSSL crypto)
252AC_ARG_ENABLE(openssl,
253  [AS_HELP_STRING([--enable-openssl],
254		  [compile in OpenSSL crypto engine])],
255  [], enable_openssl=no)
256if test "$enable_openssl" = "yes"; then
257   echo $enable_openssl
258   LDFLAGS="$LDFLAGS $(pkg-config --libs openssl)";
259   CFLAGS="$CFLAGS $(pkg-config --cflags openssl)";
260
261   AC_CHECK_LIB([crypto], [EVP_EncryptInit], [],
262             [AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
263   AC_CHECK_LIB([crypto], [EVP_aes_128_ctr], [],
264             [AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
265   AC_CHECK_LIB([crypto], [EVP_aes_128_gcm], [],
266             [AC_MSG_FAILURE([can't find openssl >1.0.1 crypto lib])])
267   AC_DEFINE(OPENSSL, 1, [Define this to use OpenSSL crypto.])
268   AES_ICM_OBJS="crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o"
269   HMAC_OBJS=crypto/hash/hmac_ossl.o
270   USE_OPENSSL=1
271   AC_SUBST(USE_OPENSSL)
272else
273   echo $enable_openssl
274   AES_ICM_OBJS="crypto/cipher/aes_icm.o crypto/cipher/aes.o crypto/cipher/aes_cbc.o"
275   AC_MSG_CHECKING(which random device to use)
276   if test "$enable_kernel_linux" = "yes"; then
277      AC_MSG_RESULT([Linux kernel builtin])
278   else
279      if test -n "$DEV_URANDOM"; then
280         AC_DEFINE_UNQUOTED(DEV_URANDOM, "$DEV_URANDOM",[Path to random device])
281         AC_MSG_RESULT([$DEV_URANDOM])
282      else
283         AC_MSG_RESULT([standard rand() function...])
284      fi
285   fi
286   HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
287fi
288AM_CONDITIONAL([ENABLE_OPENSSL],[test "${enable_openssl}" = "yes"])
289
290AC_SUBST(AES_ICM_OBJS)
291AC_SUBST(HMAC_OBJS)
292AC_MSG_RESULT($enable_openssl)
293
294AC_MSG_CHECKING(whether to use syslog for error reporting)
295AC_ARG_ENABLE(syslog,
296  [AS_HELP_STRING([--enable-syslog], [use syslog for error reporting])],
297  [], enable_syslog=no)
298if test "$enable_syslog" = "yes"; then
299   AC_DEFINE(USE_SYSLOG, 1, [Define to use syslog logging.])
300fi
301AC_MSG_RESULT($enable_syslog)
302
303AC_MSG_CHECKING(whether to use stdout for error reporting)
304AC_ARG_ENABLE(stdout,
305  [AS_HELP_STRING([--disable-stdout], [don't use stdout for error reporting])],
306  [], enable_stdout=yes)
307if test "$enable_stdout" = "yes"; then
308   AC_DEFINE(ERR_REPORTING_STDOUT, 1, [Define to use logging to stdout.])
309fi
310AC_MSG_RESULT($enable_stdout)
311
312AC_MSG_CHECKING(whether to use /dev/console for error reporting)
313AC_ARG_ENABLE(console,
314  [AS_HELP_STRING([--enable-console], [use /dev/console for error reporting])],
315  [], enable_console=no)
316if test "$enable_console" = "yes"; then
317   AC_DEFINE(USE_ERR_REPORTING_FILE, 1, [Write errors to this file])
318   AC_DEFINE(ERR_REPORTING_FILE, "/dev/console", [Report errors to this file.])
319fi
320AC_MSG_RESULT($enable_console)
321
322AC_MSG_CHECKING(whether to use GDOI key management)
323AC_ARG_ENABLE(gdoi,
324  [AS_HELP_STRING([--enable-gdoi], [enable GDOI key management])],
325  [], enable_gdoi=no)
326if test "$enable_gdoi" = "yes"; then
327   AC_DEFINE(SRTP_GDOI, 1, [Define to use GDOI.])
328   GDOI_OBJS=gdoi/srtp+gdoi.o
329   AC_SUBST(GDOI_OBJS)
330fi
331AC_MSG_RESULT($enable_gdoi)
332AM_CONDITIONAL([GDOI],[test "SRTP_GDOI" = "1"])
333
334AC_CONFIG_HEADERS(crypto/include/config.h:config_in.h)
335
336AC_OUTPUT(Makefile crypto/Makefile doc/Makefile test/Makefile libsrtp2.pc)
337
338# This is needed when building outside the source dir.
339AS_MKDIR_P(crypto/cipher)
340AS_MKDIR_P(crypto/hash)
341AS_MKDIR_P(crypto/kernel)
342AS_MKDIR_P(crypto/math)
343AS_MKDIR_P(crypto/replay)
344AS_MKDIR_P(crypto/test)
345AS_MKDIR_P(doc)
346AS_MKDIR_P(srtp)
347AS_MKDIR_P(tables)
348AS_MKDIR_P(test)
349