• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl Process this file with autoconf to produce a configure script.
2AC_INIT([libsrtp2], [2.3.0-pre], [https://github.com/cisco/libsrtp/issues])
3
4dnl Must come before AC_PROG_CC
5EMPTY_CFLAGS="no"
6if test "x$CFLAGS" = "x"; then
7   dnl Default value for CFLAGS if not specified.
8   EMPTY_CFLAGS="yes"
9fi
10
11dnl Checks for programs.
12AC_PROG_CC
13AC_PROG_CPP
14AC_PROG_CXX
15AC_ARG_VAR(
16  [EXTRA_CFLAGS],
17  [C compiler flags appended to the regular C compiler flags instead of overriding them])
18AM_PROG_AR
19AC_PROG_RANLIB
20AC_PROG_INSTALL
21AC_PROG_SED
22
23dnl Check the byte order
24AC_C_BIGENDIAN
25
26AC_CANONICAL_HOST
27
28dnl check host_cpu type, set defines appropriately
29case $host_cpu in
30  i*86 | x86_64 )
31    AC_DEFINE([CPU_CISC], [1], [Define if building for a CISC machine (e.g. Intel).])
32    AC_DEFINE([HAVE_X86], [1], [Define to use X86 inlined assembly code])
33    ;;
34  * )
35    AC_DEFINE([CPU_RISC], [1], [Define if building for a RISC machine (assume slow byte access).])
36    ;;
37esac
38
39dnl Check if we are on a Windows platform.
40case $host_os in
41  *cygwin*|*mingw* )
42    EXE=.exe
43    ;;
44  * )
45    EXE=""
46    ;;
47esac
48AC_SUBST([EXE])   # define executable suffix; this is needed for `make clean'
49
50dnl Checks for supported compiler flags.
51supported_cflags=""
52if test "$EMPTY_CFLAGS" = "no"; then
53  supported_cflags="$CFLAGS"
54fi
55
56dnl For accurate detection, we need warnings as errors.
57dnl I.e. Clang will issue a warning about unsupported flags.
58dnl For the compilation to fail, those warnings needs to be upgraded to errors.
59dnl This will be removed again once the tests are complete (see below).
60WERROR=""
61for w in -Werror -errwarn; do
62  if test "x$WERROR" = "x"; then
63    AC_MSG_CHECKING([whether ${CC-c} accepts $w])
64    save_cflags="$CFLAGS"
65    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$w"], [CFLAGS="$CFLAGS $w"])
66    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
67      [WERROR="$w"
68       AC_MSG_RESULT([yes])],
69      [CFLAGS="$save_cflags"
70       AC_MSG_RESULT([no])])
71  fi
72done
73
74dnl Note that -fPIC is not explicitly added to LDFLAGS.
75dnl Since the compiler is used as the link driver, CFLAGS will be part of the
76dnl link line as well and the linker will get the flag from there.
77dnl Adding it to LDFLAGS explicitly would duplicate the flag on the link line,
78dnl but otherwise do no harm.
79AC_MSG_CHECKING([whether ${CC-c} accepts -fPIC])
80save_cflags="$CFLAGS"
81AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="-fPIC"], [CFLAGS="$CFLAGS -fPIC"])
82AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
83  [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="-fPIC"], [supported_cflags="$supported_cflags -fPIC"])
84   AC_MSG_RESULT([yes])],
85  [CFLAGS="$save_cflags"
86   AC_MSG_RESULT([no])])
87
88if test "$EMPTY_CFLAGS" = "yes"; then
89  for f in -Wall -pedantic -Wstrict-prototypes; do
90    AC_MSG_CHECKING([whether ${CC-c} accepts $f])
91    save_cflags="$CFLAGS"
92    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
93    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
94      [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
95       AC_MSG_RESULT([yes])],
96      [CFLAGS="$save_cflags"
97       AC_MSG_RESULT([no])])
98  done
99
100  OOPT=""
101  for f in -O4 -O3; do
102    if test "x$OOPT" = "x"; then
103      AC_MSG_CHECKING([whether ${CC-c} accepts $f])
104      save_cflags="$CFLAGS"
105      AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
106      AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
107        [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
108         OOPT="$f"
109         AC_MSG_RESULT([yes])],
110        [CFLAGS="$save_cflags"
111         AC_MSG_RESULT([no])])
112    fi
113  done
114
115  for f in -fexpensive-optimizations -funroll-loops; do
116    AC_MSG_CHECKING([whether ${CC-c} accepts $f])
117    save_cflags="$CFLAGS"
118    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
119    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
120      [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
121       AC_MSG_RESULT([yes])],
122      [CFLAGS="$save_cflags"
123       AC_MSG_RESULT([no])])
124  done
125fi
126
127dnl When turning off warnigns, we're expecting unrecognized command line option errors if they're not
128dnl supported. However, the -Wno-<warning> form isn't consulted unless a warning is triggered.
129dnl At least that's the case for GCC. So to check which warnings we can turn off, we need to check
130dnl if they can be turned on, thereby forcing GCC to take the argument into account right away.
131for f in -Wno-language-extension-token; do
132  AC_MSG_CHECKING([whether ${CC-c} accepts $f])
133  save_cflags="$CFLAGS"
134  testf=$(echo "$f" | $SED 's|-Wno-\(.*\)|-W\1|g')
135  AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$testf"], [CFLAGS="$CFLAGS $testf"])
136  AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
137    [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
138     AC_MSG_RESULT([yes])],
139    [CFLAGS="$save_cflags"
140     AC_MSG_RESULT([no])])
141done
142
143dnl Remowing -Werror again
144CFLAGS="$supported_cflags"
145
146dnl Checks for header files.
147AC_HEADER_STDC
148AC_CHECK_HEADERS(
149    [unistd.h byteswap.h stdint.h sys/uio.h inttypes.h sys/types.h machine/types.h sys/int_types.h],
150    [], [], [AC_INCLUDES_DEFAULT])
151
152dnl socket() and friends
153AC_CHECK_HEADERS([sys/socket.h netinet/in.h arpa/inet.h], [], [], [AC_INCLUDES_DEFAULT])
154AC_CHECK_HEADERS(
155    [windows.h],
156    [AC_CHECK_HEADERS([winsock2.h], [], [], [AC_INCLUDES_DEFAULT])],
157    [], [AC_INCLUDES_DEFAULT])
158
159AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, uint64_t])
160AC_CHECK_SIZEOF([unsigned long])
161AC_CHECK_SIZEOF([unsigned long long])
162
163dnl Checks for typedefs, structures, and compiler characteristics.
164AC_C_CONST
165AC_C_INLINE
166AC_TYPE_SIZE_T
167
168dnl Checks for library functions.
169AC_CHECK_FUNCS([socket inet_aton usleep sigaction])
170
171dnl Find socket function if not found yet.
172if test "x$ac_cv_func_socket" = "xno"; then
173  AC_CHECK_LIB([socket], [socket])
174  AC_MSG_CHECKING([for socket in -lwsock32])
175  SAVELIBS="$LIBS"
176  LIBS="$LIBS -lwsock32"
177  AC_LINK_IFELSE(
178    [AC_LANG_SOURCE([
179#include <winsock2.h>
180int main(void)
181{
182    int fd = socket(0, 0, 0);
183    if (fd < 0)
184      return -1;
185    else
186      return 0;
187}
188    ])],
189    [ac_cv_func_socket=yes
190     AC_MSG_RESULT([yes])],
191    [LIBS="$SAVELIBS"
192     AC_MSG_RESULT([no])])
193fi
194
195AC_MSG_CHECKING([whether to enable debug logging in all modules])
196AC_ARG_ENABLE([debug-logging],
197  [AS_HELP_STRING([--enable-debug-logging], [Enable debug logging in all modules])],
198  [], enable_debug_logging=no)
199if test "$enable_debug_logging" = "yes"; then
200   AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to enabled debug logging for all mudules.])
201fi
202AC_MSG_RESULT([$enable_debug_logging])
203
204PKG_PROG_PKG_CONFIG
205AS_IF([test "x$PKG_CONFIG" != "x"], [PKG_CONFIG="$PKG_CONFIG --static"])
206
207AC_MSG_CHECKING([whether to leverage OpenSSL crypto])
208AC_ARG_ENABLE([openssl],
209  [AS_HELP_STRING([--enable-openssl], [compile in OpenSSL crypto engine])],
210  [], [enable_openssl=no])
211AC_MSG_RESULT([$enable_openssl])
212
213AC_MSG_CHECKING([whether to leverage NSS crypto])
214AC_ARG_ENABLE([nss],
215  [AS_HELP_STRING([--enable-nss], [compile in NSS crypto engine])],
216  [], [enable_nss=no])
217AC_MSG_RESULT([$enable_nss])
218
219if test "$enable_openssl" = "yes"; then
220   AC_MSG_CHECKING([for user specified OpenSSL directory])
221   AC_ARG_WITH([openssl-dir],
222      [AS_HELP_STRING([--with-openssl-dir], [Location of OpenSSL installation])],
223      [if test "x$PKG_CONFIG" != "x" && test -f $with_openssl_dir/lib/pkgconfig/libcrypto.pc; then
224         if test "x$PKG_CONFIG_PATH" = "x"; then
225           export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig"
226         else
227           export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig:$PKG_CONFIG_PATH"
228         fi
229         AC_MSG_RESULT([$with_openssl_dir])
230       elif test -d $with_openssl_dir/lib; then
231         CFLAGS="$CFLAGS -I$with_openssl_dir/include"
232         if test "x$LDFLAGS" = "x"; then
233           LDFLAGS="-L$with_openssl_dir/lib"
234         else
235           LDFLAGS="$LDFLAGS -L$with_openssl_dir/lib"
236         fi
237         AC_MSG_RESULT([$with_openssl_dir])
238       else
239         AC_MSG_RESULT([invalid])
240         AC_MSG_FAILURE([Invalid OpenSSL location: $with_openssl_dir])
241       fi],
242      [AC_MSG_RESULT([no])])
243
244   if test "x$PKG_CONFIG" != "x"; then
245     PKG_CHECK_MODULES([crypto], [libcrypto >= 1.0.1],
246       [CFLAGS="$CFLAGS $crypto_CFLAGS"
247        LIBS="$crypto_LIBS $LIBS"])
248   else
249     AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_WARN([can't find libdl])])
250     AC_CHECK_LIB([z], [inflate], [], [AC_MSG_WARN([can't find libz])])
251   fi
252
253   AC_SEARCH_LIBS([EVP_EncryptInit], [crypto],
254     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
255   AC_SEARCH_LIBS([EVP_aes_128_ctr], [crypto],
256     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
257   AC_SEARCH_LIBS([EVP_aes_128_gcm], [crypto],
258     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
259
260   AC_DEFINE([GCM], [1], [Define this to use AES-GCM.])
261   AC_DEFINE([OPENSSL], [1], [Define this to use OpenSSL crypto.])
262   AES_ICM_OBJS="crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o"
263   HMAC_OBJS=crypto/hash/hmac_ossl.o
264   AC_SUBST([USE_EXTERNAL_CRYPTO], [1])
265
266   AC_MSG_CHECKING([if OPENSSL_cleanse is broken])
267   AC_RUN_IFELSE([AC_LANG_PROGRAM([
268     #include <stdio.h>
269     #include <openssl/crypto.h>
270   ], [
271     #define BUFFER_SIZE (16)
272     char buffer[[BUFFER_SIZE]];
273     int i;
274     for (i = 0; i < BUFFER_SIZE; i++) {
275       buffer[[i]] = i & 0xff;
276     }
277     OPENSSL_cleanse(buffer, BUFFER_SIZE);
278     for (i = 0; i < BUFFER_SIZE; i++) {
279       if (buffer[[i]]) {
280         printf("Buffer contents not zero at position %d (is %d)\n", i,
281             buffer[[i]]);
282         return 1;
283       }
284     }
285   ])], [openssl_cleanse_broken=no], [
286     openssl_cleanse_broken=yes
287     AC_DEFINE([OPENSSL_CLEANSE_BROKEN], [1], [Define this if OPENSSL_cleanse is broken.])
288   ])
289   AC_MSG_RESULT([$openssl_cleanse_broken])
290
291   AC_MSG_CHECKING([whether to leverage OpenSSL KDF algorithm])
292   AC_ARG_ENABLE([openssl-kdf],
293      [AS_HELP_STRING([--enable-openssl-kdf], [Use OpenSSL KDF algorithm])],
294      [], [enable_openssl_kdf=no])
295   AC_MSG_RESULT([$enable_openssl_kdf])
296   if test "$enable_openssl_kdf" = "yes"; then
297     AC_SEARCH_LIBS([kdf_srtp], [crypto],
298       [], [AC_MSG_FAILURE([can't find openssl KDF lib])])
299     AC_DEFINE([OPENSSL_KDF], [1], [Define this to use OpenSSL KDF for SRTP.])
300   fi
301elif test "$enable_nss" = "yes"; then
302   AC_MSG_CHECKING([for user specified NSS directory])
303   AC_ARG_WITH([nss-dir],
304      [AS_HELP_STRING([--with-nss-dir], [Location of NSS installation])],
305      [if test "x$PKG_CONFIG" != "x" && test -f $with_nss_dir/lib/pkgconfig/nss.pc; then
306         if test "x$PKG_CONFIG_PATH" = "x"; then
307           export PKG_CONFIG_PATH="$with_nss_dir/lib/pkgconfig"
308         else
309           export PKG_CONFIG_PATH="$with_nss_dir/lib/pkgconfig:$PKG_CONFIG_PATH"
310         fi
311         AC_MSG_RESULT([$with_nss_dir])
312       elif test -d $with_nss_dir/lib; then
313         CFLAGS="$CFLAGS -I$with_nss_dir/include"
314         CFLAGS="$CFLAGS -I$with_nss_dir/../public/nss"
315         if test "x$LDFLAGS" = "x"; then
316           LDFLAGS="-L$with_nss_dir/lib"
317         else
318           LDFLAGS="$LDFLAGS -L$with_nss_dir/lib"
319         fi
320         nss_skip_pkg_config=yes
321         AC_MSG_RESULT([$with_nss_dir])
322       else
323         AC_MSG_RESULT([invalid])
324         AC_MSG_FAILURE([Invalid NSS location: $with_nss_dir])
325       fi
326       AC_SUBST([CRYPTO_LIBDIR], [$with_nss_dir/lib])],
327      [AC_MSG_RESULT([no])])
328
329   if test "x$PKG_CONFIG" != "x" && test "$nss_skip_pkg_config" != "yes"; then
330     PKG_CHECK_MODULES([nss], [nss],
331       [CFLAGS="$CFLAGS $nss_CFLAGS"
332         LIBS="$nss_LIBS $LIBS"])
333   else
334     AC_CHECK_HEADERS(
335       [nss.h],
336       [], [AC_MSG_FAILURE([can't find useable NSS headers])],
337       [AC_INCLUDES_DEFAULT])
338     AC_CHECK_LIB(
339       [nspr4], [PR_GetError],
340       [], [AC_MSG_WARN([can't find libnspr4])])
341     AC_CHECK_LIB(
342       [nss3], [NSS_NoDB_Init],
343       [], [AC_MSG_FAILURE([can't find useable libnss3])])
344   fi
345
346   AC_DEFINE([GCM], [1], [Define this to use AES-GCM.])
347   AC_DEFINE([NSS], [1], [Define this to use NSS crypto.])
348   AES_ICM_OBJS="crypto/cipher/aes_icm_nss.o crypto/cipher/aes_gcm_nss.o"
349
350   # TODO(RLB): Use NSS for HMAC
351   HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
352
353   # TODO(RLB): Use NSS for KDF
354
355   AC_SUBST([USE_EXTERNAL_CRYPTO], [1])
356else
357   AES_ICM_OBJS="crypto/cipher/aes_icm.o crypto/cipher/aes.o"
358   HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
359fi
360AC_SUBST([AES_ICM_OBJS])
361AC_SUBST([HMAC_OBJS])
362
363dnl Checking for PCAP
364
365PCAP_LIB=""
366AC_CHECK_LIB([pcap], [pcap_create],
367  [PCAP_LIB="-lpcap"
368   AC_DEFINE([HAVE_PCAP], [1], [Define to 1 if you have the `pcap' library (-lpcap)])
369   AC_SUBST([HAVE_PCAP], [1])])
370
371AC_CHECK_LIB([wpcap], [pcap_create],
372  [PCAP_LIB="-lwpcap"
373   AC_DEFINE([HAVE_PCAP], [1], [Define to 1 if you have the `winpcap' library (-lwpcap)])
374   AC_SUBST([HAVE_PCAP], [1])])
375AC_SUBST([PCAP_LIB])
376
377AC_MSG_CHECKING([whether to redirect logging to stdout])
378AC_ARG_ENABLE([log-stdout],
379  [AS_HELP_STRING([--enable-log-stdout], [redirecting logging to stdout])],
380  [], [enable_log_stdout=no])
381if test "$enable_log_stdout" = "yes"; then
382   AC_DEFINE([ERR_REPORTING_STDOUT], [1], [Define to redirect logging to stdout.])
383fi
384AC_MSG_RESULT([$enable_log_stdout])
385
386AC_MSG_CHECKING([wheather to use a file for logging])
387AC_ARG_WITH([log-file],
388  [AS_HELP_STRING([--with-log-file], [Use file for logging])],
389  [AS_CASE([x$with_log_file],
390     [x], [valid_with_log_file="no"],
391     [xyes], [valid_with_log_file="no"],
392     [valid_with_error_file="yes"])
393   AS_IF([test "$valid_with_log_file" = "no"],
394     [AC_MSG_RESULT([invalid])
395      AC_MSG_FAILURE([Invalid value for --with-log-file: "$with_log_file"])],
396     [AC_DEFINE_UNQUOTED([ERR_REPORTING_FILE], ["$with_log_file"], [Logging statments will be writen to this file.])
397      AC_MSG_RESULT([using log file: "$with_log_file"])])],
398  [AC_MSG_RESULT([no])])
399
400AS_IF(
401  [test "$enable_log_stdout" = "yes" && test "x$with_log_file" != "x"],
402  [AC_MSG_FAILURE([Can only use one of --enable-log-stdout and --with-log-file; they are mutually exclusive])])
403
404dnl Appending EXTRA_CFLAGS, if given
405AC_MSG_CHECKING([for extra C compiler flags])
406AS_IF([test "x$EXTRA_CFLAGS" != "x"],
407   [AS_IF([test "x$CFLAGS" = "x"],
408      [CFLAGS="$EXTRA_CFLAGS"], [CFLAGS="$CFLAGS $EXTRA_CFLAGS"])
409    AC_MSG_RESULT([$EXTRA_CFLAGS])],
410   [AC_MSG_RESULT(no)])
411
412AC_CONFIG_HEADER([crypto/include/config.h:config_in.h])
413
414AC_CONFIG_FILES([Makefile crypto/Makefile doc/Makefile fuzzer/Makefile libsrtp2.pc])
415AC_OUTPUT
416
417# This is needed when building outside the source dir.
418AS_MKDIR_P([crypto/cipher])
419AS_MKDIR_P([crypto/hash])
420AS_MKDIR_P([crypto/kernel])
421AS_MKDIR_P([crypto/math])
422AS_MKDIR_P([crypto/replay])
423AS_MKDIR_P([crypto/test])
424AS_MKDIR_P([doc])
425AS_MKDIR_P([srtp])
426AS_MKDIR_P([test])
427