blob: f6f6d1e6853bd8add6ec1f024cb16e95ab2dbf4f [file] [log] [blame]
Cullen Jennings235513a2005-09-21 22:51:36 +00001dnl Process this file with autoconf to produce a configure script.
Pascal Bühler34acba62017-01-19 10:57:30 +01002AC_INIT([libsrtp2], [2.1.0-pre], [https://github.com/cisco/libsrtp/issues])
Cullen Jennings235513a2005-09-21 22:51:36 +00003
David McGrewb67061f2005-09-28 14:23:06 +00004dnl Must come before AC_PROG_CC
Idar Tollefsen0e790752017-01-26 10:59:03 +01005EMPTY_CFLAGS="no"
Idar Tollefsen27d857c2017-01-19 15:28:18 +01006if test "x$CFLAGS" = "x"; then
David McGrewb67061f2005-09-28 14:23:06 +00007 dnl Default value for CFLAGS if not specified.
Idar Tollefsen0e790752017-01-26 10:59:03 +01008 EMPTY_CFLAGS="yes"
David McGrewb67061f2005-09-28 14:23:06 +00009fi
10
Cullen Jennings235513a2005-09-21 22:51:36 +000011dnl Checks for programs.
Alexander Traud52c30db2016-06-16 17:24:18 +020012m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
Cullen Jennings235513a2005-09-21 22:51:36 +000013AC_PROG_RANLIB
14AC_PROG_CC
David McGrewb67061f2005-09-28 14:23:06 +000015AC_PROG_INSTALL
Idar Tollefsen0e790752017-01-26 10:59:03 +010016AC_PROG_SED
Cullen Jennings235513a2005-09-21 22:51:36 +000017
Marcus Sundbergfaf84ca2007-05-23 17:24:52 +000018dnl Check the byte order
19AC_C_BIGENDIAN
20
21AC_CANONICAL_HOST
22
23dnl check host_cpu type, set defines appropriately
24case $host_cpu in
Idar Tollefsen5fd11872017-01-19 15:25:12 +010025 i*86 | x86_64 )
Idar Tollefsen5e67d392017-01-20 13:03:52 +010026 AC_DEFINE([CPU_CISC], [1], [Define if building for a CISC machine (e.g. Intel).])
27 AC_DEFINE([HAVE_X86], [1], [Define to use X86 inlined assembly code])
Idar Tollefsen5fd11872017-01-19 15:25:12 +010028 ;;
29 * )
Idar Tollefsen5e67d392017-01-20 13:03:52 +010030 AC_DEFINE([CPU_RISC], [1], [Define if building for a RISC machine (assume slow byte access).])
Idar Tollefsen5fd11872017-01-19 15:25:12 +010031 ;;
32esac
Marcus Sundbergfaf84ca2007-05-23 17:24:52 +000033
34dnl Check if we are on a Windows platform.
35case $host_os in
Idar Tollefsen5fd11872017-01-19 15:25:12 +010036 *cygwin*|*mingw* )
37 EXE=.exe
Idar Tollefsen5fd11872017-01-19 15:25:12 +010038 ;;
39 * )
40 EXE=""
41 ;;
Marcus Sundbergfaf84ca2007-05-23 17:24:52 +000042esac
Idar Tollefsen5e67d392017-01-20 13:03:52 +010043AC_SUBST([EXE]) # define executable suffix; this is needed for `make clean'
Marcus Sundbergfaf84ca2007-05-23 17:24:52 +000044
Idar Tollefsen0e790752017-01-26 10:59:03 +010045dnl Checks for supported compiler flags.
46supported_cflags=""
47if test "$EMPTY_CFLAGS" = "no"; then
48 supported_cflags="$CFLAGS"
49fi
50
51dnl For accurate detection, we need warnings as errors.
52dnl I.e. Clang will issue a warning about unsupported flags.
53dnl For the compilation to fail, those warnings needs to be upgraded to errors.
54dnl This will be removed again once the tests are complete (see below).
55WERROR=""
56for w in -Werror -errwarn; do
57 if test "x$WERROR" = "x"; then
58 AC_MSG_CHECKING([whether the compiler supports $w])
59 save_cflags="$CFLAGS"
60 AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$w"], [CFLAGS="$CFLAGS $w"])
61 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
62 [WERROR="$w"
63 AC_MSG_RESULT([yes])],
64 [CFLAGS="$save_cflags"
65 AC_MSG_RESULT([no])])
66 fi
67done
68
69dnl Note that -fPIC is also added to LDFLAGS.
70AC_MSG_CHECKING([whether the compiler supports -fPIC])
71save_cflags="$CFLAGS"
72AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="-fPIC"], [CFLAGS="$CFLAGS -fPIC"])
73AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
74 [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="-fPIC"], [supported_cflags="$supported_cflags -fPIC"])
75 AS_IF([test "x$LDFLAGS" = "x"], [LDFLAGS="-fPIC"], [LDFLAGS="$LDFLAGS -fPIC"])
76 AC_MSG_RESULT([yes])],
77 [CFLAGS="$save_cflags"
78 AC_MSG_RESULT([no])])
79
80if test "$EMPTY_CFLAGS" = "yes"; then
81 for f in -Wall -pedantic; do
82 AC_MSG_CHECKING([whether the compiler supports $f])
83 save_cflags="$CFLAGS"
84 AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
85 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
86 [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
87 AC_MSG_RESULT([yes])],
88 [CFLAGS="$save_cflags"
89 AC_MSG_RESULT([no])])
90 done
91
92 OOPT=""
93 for f in -O4 -O3; do
94 if test "x$OOPT" = "x"; then
95 AC_MSG_CHECKING([whether the compiler supports $f])
96 save_cflags="$CFLAGS"
97 AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
98 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
99 [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
100 OOPT="$f"
101 AC_MSG_RESULT([yes])],
102 [CFLAGS="$save_cflags"
103 AC_MSG_RESULT([no])])
104 fi
105 done
106
107 for f in -fexpensive-optimizations -funroll-loops; do
108 AC_MSG_CHECKING([whether the compiler supports $f])
109 save_cflags="$CFLAGS"
110 AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
111 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
112 [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
113 AC_MSG_RESULT([yes])],
114 [CFLAGS="$save_cflags"
115 AC_MSG_RESULT([no])])
116 done
117fi
118
119dnl When turning off warnigns, we're expecting unrecognized command line option errors if they're not
120dnl supported. However, the -Wno-<warning> form isn't consulted unless a warning is triggered.
121dnl At least that's the case for GCC. So to check which warnings we can turn off, we dnl need to check
122dnl if they can be turned on, thereby forcing GCC to take the argument into account right away.
123for f in -Wno-language-extension-token; do
124 AC_MSG_CHECKING([whether the compiler supports $f])
125 save_cflags="$CFLAGS"
126 testf=$(echo "$f" | $SED 's|-Wno-\(.*\)|-W\1|g')
127 AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$testf"], [CFLAGS="$CFLAGS $testf"])
128 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
129 [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
130 AC_MSG_RESULT([yes])],
131 [CFLAGS="$save_cflags"
132 AC_MSG_RESULT([no])])
133done
134
135dnl Remowing -Werror again
136CFLAGS="$supported_cflags"
Cullen Jennings235513a2005-09-21 22:51:36 +0000137
138dnl Checks for header files.
139AC_HEADER_STDC
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100140AC_CHECK_HEADERS(
141 [unistd.h byteswap.h stdint.h sys/uio.h inttypes.h sys/types.h machine/types.h sys/int_types.h],
142 [], [], [AC_INCLUDES_DEFAULT])
Cullen Jennings235513a2005-09-21 22:51:36 +0000143
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000144dnl socket() and friends
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100145AC_CHECK_HEADERS([sys/socket.h netinet/in.h arpa/inet.h], [], [], [AC_INCLUDES_DEFAULT])
146AC_CHECK_HEADERS(
147 [windows.h],
148 [AC_CHECK_HEADERS([winsock2.h], [], [], [AC_INCLUDES_DEFAULT])],
149 [], [AC_INCLUDES_DEFAULT])
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000150
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100151AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, uint64_t])
152AC_CHECK_SIZEOF([unsigned long])
153AC_CHECK_SIZEOF([unsigned long long])
Cullen Jennings235513a2005-09-21 22:51:36 +0000154
155dnl Checks for typedefs, structures, and compiler characteristics.
156AC_C_CONST
157AC_C_INLINE
158AC_TYPE_SIZE_T
159
160dnl Checks for library functions.
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100161AC_CHECK_FUNCS([socket inet_aton usleep sigaction])
David McGrewb67061f2005-09-28 14:23:06 +0000162
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000163dnl Find socket function if not found yet.
164if test "x$ac_cv_func_socket" = "xno"; then
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100165 AC_CHECK_LIB([socket], [socket])
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000166 AC_MSG_CHECKING([for socket in -lwsock32])
167 SAVELIBS="$LIBS"
168 LIBS="$LIBS -lwsock32"
Alexander Traudd80ef6c2016-06-16 17:31:35 +0200169 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000170#include <winsock2.h>
Alexander Traudd80ef6c2016-06-16 17:31:35 +0200171]], [[
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000172socket(0, 0, 0);
Alexander Traudd80ef6c2016-06-16 17:31:35 +0200173]])],[ac_cv_func_socket=yes
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100174 AC_MSG_RESULT([yes])],[LIBS="$SAVELIBS"
175 AC_MSG_RESULT([no])])
Marcus Sundberg8046c3a2005-10-02 20:02:05 +0000176fi
Cullen Jennings235513a2005-09-21 22:51:36 +0000177
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100178AC_MSG_CHECKING([whether to enable debug logging in all modules])
179AC_ARG_ENABLE([debug-logging],
180 [AS_HELP_STRING([--enable-debug-logging], [Enable debug logging in all modules])],
Pascal Bühler88579e62017-01-30 21:05:37 +0100181 [], enable_debug_logging=no)
182if test "$enable_debug_logging" = "yes"; then
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100183 AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to enabled debug logging for all mudules.])
Cullen Jennings235513a2005-09-21 22:51:36 +0000184fi
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100185AC_MSG_RESULT([$enable_debug_logging])
Cullen Jennings235513a2005-09-21 22:51:36 +0000186
Michael Thomas (malinka)1d4460d2016-06-04 19:59:31 -0400187PKG_PROG_PKG_CONFIG
Idar Tollefsenf9c148d2017-02-09 11:10:04 +0100188AS_IF([test "x$PKG_CONFIG" != "x"], [PKG_CONFIG="$PKG_CONFIG --static"])
Michael Thomas (malinka)1d4460d2016-06-04 19:59:31 -0400189
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100190AC_MSG_CHECKING([whether to leverage OpenSSL crypto])
191AC_ARG_ENABLE([openssl],
192 [AS_HELP_STRING([--enable-openssl], [compile in OpenSSL crypto engine])],
193 [], [enable_openssl=no])
194AC_MSG_RESULT([$enable_openssl])
jfigusa14b5a02013-03-29 12:24:12 -0400195if test "$enable_openssl" = "yes"; then
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100196 AC_MSG_CHECKING([for user specified OpenSSL directory])
197 AC_ARG_WITH([openssl-dir],
jfigus038d2cf2015-05-11 14:10:11 -0400198 [AS_HELP_STRING([--with-openssl-dir], [Location of OpenSSL installation])],
Idar Tollefsen333fa842017-01-20 16:44:33 +0100199 [if test "x$PKG_CONFIG" != "x" && test -f $with_openssl_dir/lib/pkgconfig/libcrypto.pc; then
200 if test "x$PKG_CONFIG_PATH" = "x"; then
201 export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig"
202 else
203 export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig:$PKG_CONFIG_PATH"
204 fi
205 AC_MSG_RESULT([$with_openssl_dir])
206 elif test -d $with_openssl_dir/lib; then
207 CFLAGS="$CFLAGS -I$with_openssl_dir/include"
208 if test "x$LDFLAGS" = "x"; then
209 LDFLAGS="-L$with_openssl_dir/lib"
210 else
211 LDFLAGS="$LDFLAGS -L$with_openssl_dir/lib"
212 fi
213 AC_MSG_RESULT([$with_openssl_dir])
214 else
215 AC_MSG_RESULT([invalid])
216 AC_MSG_FAILURE([Invalid OpenSSL location: $with_openssl_dir])
217 fi],
218 [AC_MSG_RESULT([no])])
jfigus038d2cf2015-05-11 14:10:11 -0400219
Idar Tollefsen333fa842017-01-20 16:44:33 +0100220 if test "x$PKG_CONFIG" != "x"; then
Pascal Bühler6c949b62017-02-09 14:22:36 +0100221 PKG_CHECK_MODULES([crypto], [libcrypto >= 1.0.1],
Idar Tollefsen333fa842017-01-20 16:44:33 +0100222 [CFLAGS="$CFLAGS $crypto_CFLAGS"
223 LIBS="$crypto_LIBS $LIBS"])
224 else
225 AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_WARN([can't find libdl])])
226 AC_CHECK_LIB([z], [inflate], [], [AC_MSG_WARN([can't find libz])])
227 fi
Cullen Jenningse1de50f2013-05-22 12:27:28 -0600228
Idar Tollefsen333fa842017-01-20 16:44:33 +0100229 AC_SEARCH_LIBS([EVP_EncryptInit], [crypto],
Pascal Bühler6c949b62017-02-09 14:22:36 +0100230 [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
Idar Tollefsen333fa842017-01-20 16:44:33 +0100231 AC_SEARCH_LIBS([EVP_aes_128_ctr], [crypto],
Pascal Bühler6c949b62017-02-09 14:22:36 +0100232 [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
Idar Tollefsen333fa842017-01-20 16:44:33 +0100233 AC_SEARCH_LIBS([EVP_aes_128_gcm], [crypto],
Pascal Bühler6c949b62017-02-09 14:22:36 +0100234 [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
Idar Tollefsen333fa842017-01-20 16:44:33 +0100235
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100236 AC_DEFINE([OPENSSL], [1], [Define this to use OpenSSL crypto.])
jfigus7882dd92013-08-02 16:08:23 -0400237 AES_ICM_OBJS="crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o"
jfigus0d3a2682013-04-02 15:42:37 -0400238 HMAC_OBJS=crypto/hash/hmac_ossl.o
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100239 AC_SUBST([USE_OPENSSL], [1])
jfigus038d2cf2015-05-11 14:10:11 -0400240
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100241 AC_MSG_CHECKING([whether to leverage OpenSSL KDF algorithm])
242 AC_ARG_ENABLE([openssl-kdf],
jfigus038d2cf2015-05-11 14:10:11 -0400243 [AS_HELP_STRING([--enable-openssl-kdf], [Use OpenSSL KDF algorithm])],
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100244 [], [enable_openssl_kdf=no])
245 AC_MSG_RESULT([$enable_openssl_kdf])
jfigus038d2cf2015-05-11 14:10:11 -0400246 if test "$enable_openssl_kdf" = "yes"; then
Idar Tollefsen333fa842017-01-20 16:44:33 +0100247 AC_SEARCH_LIBS([kdf_srtp], [crypto],
248 [], [AC_MSG_FAILURE([can't find openssl KDF lib])])
249 AC_DEFINE([OPENSSL_KDF], [1], [Define this to use OpenSSL KDF for SRTP.])
jfigus038d2cf2015-05-11 14:10:11 -0400250 fi
jfigusa14b5a02013-03-29 12:24:12 -0400251else
jfigusa3127b82014-11-19 14:46:52 -0500252 AES_ICM_OBJS="crypto/cipher/aes_icm.o crypto/cipher/aes.o"
jfigus0d3a2682013-04-02 15:42:37 -0400253 HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
jfigusa14b5a02013-03-29 12:24:12 -0400254fi
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100255AC_SUBST([AES_ICM_OBJS])
256AC_SUBST([HMAC_OBJS])
jfigusa14b5a02013-03-29 12:24:12 -0400257
Bernardo Torres79e38ae2014-10-10 05:29:36 -0300258dnl Checking for PCAP
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100259AC_CHECK_LIB([pcap], [pcap_create],
260 [LIBS="-lpcap $LIBS"
261 AC_DEFINE([HAVE_PCAP], [1], [Define to 1 if you have the `pcap' library (-lpcap)])
262 AC_SUBST([HAVE_PCAP], [1])])
Bernardo Torres79e38ae2014-10-10 05:29:36 -0300263
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100264AC_MSG_CHECKING([whether to redirect logging to stdout])
265AC_ARG_ENABLE([log-stdout],
Pascal Bühler88579e62017-01-30 21:05:37 +0100266 [AS_HELP_STRING([--enable-log-stdout], [redirecting logging to stdout])],
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100267 [], [enable_log_stdout=no])
Pascal Bühler88579e62017-01-30 21:05:37 +0100268if test "$enable_log_stdout" = "yes"; then
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100269 AC_DEFINE([ERR_REPORTING_STDOUT], [1], [Define to redirect logging to stdout.])
Cullen Jennings235513a2005-09-21 22:51:36 +0000270fi
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100271AC_MSG_RESULT([$enable_log_stdout])
Cullen Jennings235513a2005-09-21 22:51:36 +0000272
Pascal Bühlerb969ed52017-02-10 09:03:54 +0100273AC_MSG_CHECKING([wheather to use a file for logging])
274AC_ARG_WITH([log-file],
Pascal Bühler88579e62017-01-30 21:05:37 +0100275 [AS_HELP_STRING([--with-log-file], [Use file for logging])],
276 [AS_CASE([x$with_log_file],
277 [x], [valid_with_log_file="no"],
278 [xyes], [valid_with_log_file="no"],
279 [valid_with_error_file="yes"])
280 AS_IF([test "$valid_with_log_file" = "no"],
281 [AC_MSG_RESULT([invalid])
282 AC_MSG_FAILURE([Invalid value for --with-log-file: "$with_log_file"])],
283 [AC_DEFINE_UNQUOTED([ERR_REPORTING_FILE], ["$with_log_file"], [Logging statments will be writen to this file.])
284 AC_MSG_RESULT([using log file: "$with_log_file"])])],
285 [AC_MSG_RESULT([no])])
286
287AS_IF(
288 [test "$enable_log_stdout" = "yes" && test "x$with_log_file" != "x"],
289 [AC_MSG_FAILURE([Can only use one of --enable-log-stdout and --with-log-file; they are mutually exclusive])])
Cullen Jennings235513a2005-09-21 22:51:36 +0000290
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100291AC_CONFIG_HEADER([crypto/include/config.h:config_in.h])
Cullen Jennings235513a2005-09-21 22:51:36 +0000292
Idar Tollefsen3edfcef2017-01-20 16:14:51 +0100293AC_CONFIG_FILES([Makefile crypto/Makefile doc/Makefile libsrtp2.pc])
Saúl Ibarra Corretgéb86063c2014-10-01 11:23:24 +0200294AC_OUTPUT
Marcus Sundberg4ce29b22005-09-29 14:29:53 +0000295
296# This is needed when building outside the source dir.
Idar Tollefsen5e67d392017-01-20 13:03:52 +0100297AS_MKDIR_P([crypto/cipher])
298AS_MKDIR_P([crypto/hash])
299AS_MKDIR_P([crypto/kernel])
300AS_MKDIR_P([crypto/math])
301AS_MKDIR_P([crypto/replay])
302AS_MKDIR_P([crypto/test])
303AS_MKDIR_P([doc])
304AS_MKDIR_P([srtp])
305AS_MKDIR_P([test])