configure.ac 11.8 KB
Newer Older
Cullen Jennings's avatar
Cullen Jennings committed
1
dnl Process this file with autoconf to produce a configure script.
Pascal Buhler's avatar
Pascal Buhler committed
2
AC_INIT([libsrtp2], [2.2.0], [https://github.com/cisco/libsrtp/issues])
Cullen Jennings's avatar
Cullen Jennings committed
3

4
dnl Must come before AC_PROG_CC
5
EMPTY_CFLAGS="no"
6
if test "x$CFLAGS" = "x"; then
7
   dnl Default value for CFLAGS if not specified.
8
   EMPTY_CFLAGS="yes"
9 10
fi

Cullen Jennings's avatar
Cullen Jennings committed
11
dnl Checks for programs.
12 13 14 15 16
AC_PROG_CC
AC_PROG_CPP
AC_ARG_VAR(
  [EXTRA_CFLAGS],
  [C compiler flags appended to the regular C compiler flags instead of overriding them])
17
AM_PROG_AR
Cullen Jennings's avatar
Cullen Jennings committed
18
AC_PROG_RANLIB
19
AC_PROG_INSTALL
20
AC_PROG_SED
Cullen Jennings's avatar
Cullen Jennings committed
21

22 23 24 25 26 27 28
dnl Check the byte order
AC_C_BIGENDIAN

AC_CANONICAL_HOST

dnl check host_cpu type, set defines appropriately
case $host_cpu in
29
  i*86 | x86_64 )
30 31
    AC_DEFINE([CPU_CISC], [1], [Define if building for a CISC machine (e.g. Intel).])
    AC_DEFINE([HAVE_X86], [1], [Define to use X86 inlined assembly code])
32 33
    ;;
  * )
34
    AC_DEFINE([CPU_RISC], [1], [Define if building for a RISC machine (assume slow byte access).])
35 36
    ;;
esac
37 38 39

dnl Check if we are on a Windows platform.
case $host_os in
40 41 42 43 44 45
  *cygwin*|*mingw* )
    EXE=.exe
    ;;
  * )
    EXE=""
    ;;
46
esac
47
AC_SUBST([EXE])   # define executable suffix; this is needed for `make clean'
48

49 50 51 52 53 54 55 56 57 58 59 60 61
dnl Checks for supported compiler flags.
supported_cflags=""
if test "$EMPTY_CFLAGS" = "no"; then
  supported_cflags="$CFLAGS"
fi

dnl For accurate detection, we need warnings as errors.
dnl I.e. Clang will issue a warning about unsupported flags.
dnl For the compilation to fail, those warnings needs to be upgraded to errors.
dnl This will be removed again once the tests are complete (see below).
WERROR=""
for w in -Werror -errwarn; do
  if test "x$WERROR" = "x"; then
62
    AC_MSG_CHECKING([whether ${CC-c} accepts $w])
63 64
    save_cflags="$CFLAGS"
    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$w"], [CFLAGS="$CFLAGS $w"])
65
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
66 67 68 69 70 71 72
      [WERROR="$w"
       AC_MSG_RESULT([yes])],
      [CFLAGS="$save_cflags"
       AC_MSG_RESULT([no])])
  fi
done

73 74 75 76 77
dnl Note that -fPIC is not explicitly added to LDFLAGS.
dnl Since the compiler is used as the link driver, CFLAGS will be part of the
dnl link line as well and the linker will get the flag from there.
dnl Adding it to LDFLAGS explicitly would duplicate the flag on the link line,
dnl but otherwise do no harm.
78
AC_MSG_CHECKING([whether ${CC-c} accepts -fPIC])
79 80
save_cflags="$CFLAGS"
AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="-fPIC"], [CFLAGS="$CFLAGS -fPIC"])
81
AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
82 83 84 85 86 87
  [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="-fPIC"], [supported_cflags="$supported_cflags -fPIC"])
   AC_MSG_RESULT([yes])],
  [CFLAGS="$save_cflags"
   AC_MSG_RESULT([no])])

if test "$EMPTY_CFLAGS" = "yes"; then
88 89
  for f in -Wall -pedantic -Wstrict-prototypes; do
    AC_MSG_CHECKING([whether ${CC-c} accepts $f])
90 91
    save_cflags="$CFLAGS"
    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
92
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
93 94 95 96 97 98 99 100 101
      [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
       AC_MSG_RESULT([yes])],
      [CFLAGS="$save_cflags"
       AC_MSG_RESULT([no])])
  done

  OOPT=""
  for f in -O4 -O3; do
    if test "x$OOPT" = "x"; then
102
      AC_MSG_CHECKING([whether ${CC-c} accepts $f])
103 104
      save_cflags="$CFLAGS"
      AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
105
      AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
106 107 108 109 110 111 112 113 114
        [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
         OOPT="$f"
         AC_MSG_RESULT([yes])],
        [CFLAGS="$save_cflags"
         AC_MSG_RESULT([no])])
    fi
  done

  for f in -fexpensive-optimizations -funroll-loops; do
115
    AC_MSG_CHECKING([whether ${CC-c} accepts $f])
116 117
    save_cflags="$CFLAGS"
    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$f"], [CFLAGS="$CFLAGS $f"])
118
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
119 120 121 122 123 124
      [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
       AC_MSG_RESULT([yes])],
      [CFLAGS="$save_cflags"
       AC_MSG_RESULT([no])])
  done
fi
125

126 127
dnl When turning off warnigns, we're expecting unrecognized command line option errors if they're not
dnl supported. However, the -Wno-<warning> form isn't consulted unless a warning is triggered.
128
dnl At least that's the case for GCC. So to check which warnings we can turn off, we need to check
129 130
dnl if they can be turned on, thereby forcing GCC to take the argument into account right away.
for f in -Wno-language-extension-token; do
131
  AC_MSG_CHECKING([whether ${CC-c} accepts $f])
132 133 134
  save_cflags="$CFLAGS"
  testf=$(echo "$f" | $SED 's|-Wno-\(.*\)|-W\1|g')
  AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="$testf"], [CFLAGS="$CFLAGS $testf"])
135
  AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) { return 0; }])],
136 137 138 139 140 141 142 143
    [AS_IF([test "x$supported_cflags" = "x"], [supported_cflags="$f"], [supported_cflags="$supported_cflags $f"])
     AC_MSG_RESULT([yes])],
    [CFLAGS="$save_cflags"
     AC_MSG_RESULT([no])])
done

dnl Remowing -Werror again
CFLAGS="$supported_cflags"
Cullen Jennings's avatar
Cullen Jennings committed
144 145 146

dnl Checks for header files.
AC_HEADER_STDC
147 148 149
AC_CHECK_HEADERS(
    [unistd.h byteswap.h stdint.h sys/uio.h inttypes.h sys/types.h machine/types.h sys/int_types.h],
    [], [], [AC_INCLUDES_DEFAULT])
Cullen Jennings's avatar
Cullen Jennings committed
150

151
dnl socket() and friends
152 153 154 155 156
AC_CHECK_HEADERS([sys/socket.h netinet/in.h arpa/inet.h], [], [], [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS(
    [windows.h],
    [AC_CHECK_HEADERS([winsock2.h], [], [], [AC_INCLUDES_DEFAULT])],
    [], [AC_INCLUDES_DEFAULT])
157

158 159 160
AC_CHECK_TYPES([int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, uint64_t])
AC_CHECK_SIZEOF([unsigned long])
AC_CHECK_SIZEOF([unsigned long long])
Cullen Jennings's avatar
Cullen Jennings committed
161 162 163 164 165 166 167

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T

dnl Checks for library functions.
168
AC_CHECK_FUNCS([socket inet_aton usleep sigaction])
169 170 171

dnl Find socket function if not found yet.
if test "x$ac_cv_func_socket" = "xno"; then
172
  AC_CHECK_LIB([socket], [socket])
173 174 175
  AC_MSG_CHECKING([for socket in -lwsock32])
  SAVELIBS="$LIBS"
  LIBS="$LIBS -lwsock32"
176 177
  AC_LINK_IFELSE(
    [AC_LANG_SOURCE([
178
#include <winsock2.h>
179 180 181 182 183 184 185 186 187 188 189 190 191
int main(void)
{
    int fd = socket(0, 0, 0);
    if (fd < 0)
      return -1;
    else
      return 0;
}
    ])],
    [ac_cv_func_socket=yes
     AC_MSG_RESULT([yes])],
    [LIBS="$SAVELIBS"
     AC_MSG_RESULT([no])])
192
fi
Cullen Jennings's avatar
Cullen Jennings committed
193

194 195 196
AC_MSG_CHECKING([whether to enable debug logging in all modules])
AC_ARG_ENABLE([debug-logging],
  [AS_HELP_STRING([--enable-debug-logging], [Enable debug logging in all modules])],
197 198
  [], enable_debug_logging=no)
if test "$enable_debug_logging" = "yes"; then
199
   AC_DEFINE([ENABLE_DEBUG_LOGGING], [1], [Define to enabled debug logging for all mudules.])
Cullen Jennings's avatar
Cullen Jennings committed
200
fi
201
AC_MSG_RESULT([$enable_debug_logging])
202

203
PKG_PROG_PKG_CONFIG
204
AS_IF([test "x$PKG_CONFIG" != "x"], [PKG_CONFIG="$PKG_CONFIG --static"])
205

206 207 208 209 210
AC_MSG_CHECKING([whether to leverage OpenSSL crypto])
AC_ARG_ENABLE([openssl],
  [AS_HELP_STRING([--enable-openssl], [compile in OpenSSL crypto engine])],
  [], [enable_openssl=no])
AC_MSG_RESULT([$enable_openssl])
211
if test "$enable_openssl" = "yes"; then
212 213
   AC_MSG_CHECKING([for user specified OpenSSL directory])
   AC_ARG_WITH([openssl-dir],
214
      [AS_HELP_STRING([--with-openssl-dir], [Location of OpenSSL installation])],
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
      [if test "x$PKG_CONFIG" != "x" && test -f $with_openssl_dir/lib/pkgconfig/libcrypto.pc; then
         if test "x$PKG_CONFIG_PATH" = "x"; then
           export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig"
         else
           export PKG_CONFIG_PATH="$with_openssl_dir/lib/pkgconfig:$PKG_CONFIG_PATH"
         fi
         AC_MSG_RESULT([$with_openssl_dir])
       elif test -d $with_openssl_dir/lib; then
         CFLAGS="$CFLAGS -I$with_openssl_dir/include"
         if test "x$LDFLAGS" = "x"; then
           LDFLAGS="-L$with_openssl_dir/lib"
         else
           LDFLAGS="$LDFLAGS -L$with_openssl_dir/lib"
         fi
         AC_MSG_RESULT([$with_openssl_dir])
       else
         AC_MSG_RESULT([invalid])
         AC_MSG_FAILURE([Invalid OpenSSL location: $with_openssl_dir])
       fi],
      [AC_MSG_RESULT([no])])

   if test "x$PKG_CONFIG" != "x"; then
237
     PKG_CHECK_MODULES([crypto], [libcrypto >= 1.0.1],
238 239 240 241 242 243 244 245
       [CFLAGS="$CFLAGS $crypto_CFLAGS"
        LIBS="$crypto_LIBS $LIBS"])
   else
     AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_WARN([can't find libdl])])
     AC_CHECK_LIB([z], [inflate], [], [AC_MSG_WARN([can't find libz])])
   fi

   AC_SEARCH_LIBS([EVP_EncryptInit], [crypto],
246
     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
247
   AC_SEARCH_LIBS([EVP_aes_128_ctr], [crypto],
248
     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
249
   AC_SEARCH_LIBS([EVP_aes_128_gcm], [crypto],
250
     [], [AC_MSG_FAILURE([can't find openssl >= 1.0.1 crypto lib])])
251

252
   AC_DEFINE([OPENSSL], [1], [Define this to use OpenSSL crypto.])
253
   AES_ICM_OBJS="crypto/cipher/aes_icm_ossl.o crypto/cipher/aes_gcm_ossl.o"
254
   HMAC_OBJS=crypto/hash/hmac_ossl.o
255
   AC_SUBST([USE_OPENSSL], [1])
256

257 258
   AC_MSG_CHECKING([whether to leverage OpenSSL KDF algorithm])
   AC_ARG_ENABLE([openssl-kdf],
259
      [AS_HELP_STRING([--enable-openssl-kdf], [Use OpenSSL KDF algorithm])],
260 261
      [], [enable_openssl_kdf=no])
   AC_MSG_RESULT([$enable_openssl_kdf])
262
   if test "$enable_openssl_kdf" = "yes"; then
263 264 265
     AC_SEARCH_LIBS([kdf_srtp], [crypto],
       [], [AC_MSG_FAILURE([can't find openssl KDF lib])])
     AC_DEFINE([OPENSSL_KDF], [1], [Define this to use OpenSSL KDF for SRTP.])
266
   fi
267
else
268
   AES_ICM_OBJS="crypto/cipher/aes_icm.o crypto/cipher/aes.o"
269
   HMAC_OBJS="crypto/hash/hmac.o crypto/hash/sha1.o"
270
fi
271 272
AC_SUBST([AES_ICM_OBJS])
AC_SUBST([HMAC_OBJS])
273

274
dnl Checking for PCAP
275

276
PCAP_LIB=""
277
AC_CHECK_LIB([pcap], [pcap_create],
278
  [PCAP_LIB="-lpcap"
279 280
   AC_DEFINE([HAVE_PCAP], [1], [Define to 1 if you have the `pcap' library (-lpcap)])
   AC_SUBST([HAVE_PCAP], [1])])
281 282
   
AC_CHECK_LIB([wpcap], [pcap_create],
283
  [PCAP_LIB="-lwpcap"
284 285
   AC_DEFINE([HAVE_PCAP], [1], [Define to 1 if you have the `winpcap' library (-lwpcap)])
   AC_SUBST([HAVE_PCAP], [1])])
286 287
AC_SUBST([PCAP_LIB])
   
288 289
AC_MSG_CHECKING([whether to redirect logging to stdout])
AC_ARG_ENABLE([log-stdout],
290
  [AS_HELP_STRING([--enable-log-stdout], [redirecting logging to stdout])],
291
  [], [enable_log_stdout=no])
292
if test "$enable_log_stdout" = "yes"; then
293
   AC_DEFINE([ERR_REPORTING_STDOUT], [1], [Define to redirect logging to stdout.])
Cullen Jennings's avatar
Cullen Jennings committed
294
fi
295
AC_MSG_RESULT([$enable_log_stdout])
296

297 298
AC_MSG_CHECKING([wheather to use a file for logging])
AC_ARG_WITH([log-file],
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  [AS_HELP_STRING([--with-log-file], [Use file for logging])],
  [AS_CASE([x$with_log_file],
     [x], [valid_with_log_file="no"],
     [xyes], [valid_with_log_file="no"],
     [valid_with_error_file="yes"])
   AS_IF([test "$valid_with_log_file" = "no"],
     [AC_MSG_RESULT([invalid])
      AC_MSG_FAILURE([Invalid value for --with-log-file: "$with_log_file"])],
     [AC_DEFINE_UNQUOTED([ERR_REPORTING_FILE], ["$with_log_file"], [Logging statments will be writen to this file.])
      AC_MSG_RESULT([using log file: "$with_log_file"])])],
  [AC_MSG_RESULT([no])])

AS_IF(
  [test "$enable_log_stdout" = "yes" && test "x$with_log_file" != "x"],
  [AC_MSG_FAILURE([Can only use one of --enable-log-stdout and --with-log-file; they are mutually exclusive])])
314

315 316 317 318 319 320 321 322
dnl Appending EXTRA_CFLAGS, if given
AC_MSG_CHECKING([for extra C compiler flags])
AS_IF([test "x$EXTRA_CFLAGS" != "x"],
   [AS_IF([test "x$CFLAGS" = "x"],
      [CFLAGS="$EXTRA_CFLAGS"], [CFLAGS="$CFLAGS $EXTRA_CFLAGS"])
    AC_MSG_RESULT([$EXTRA_CFLAGS])],
   [AC_MSG_RESULT(no)])

323
AC_CONFIG_HEADER([crypto/include/config.h:config_in.h])
Cullen Jennings's avatar
Cullen Jennings committed
324

325
AC_CONFIG_FILES([Makefile crypto/Makefile doc/Makefile libsrtp2.pc])
326
AC_OUTPUT
327 328

# This is needed when building outside the source dir.
329 330 331 332 333 334 335 336 337
AS_MKDIR_P([crypto/cipher])
AS_MKDIR_P([crypto/hash])
AS_MKDIR_P([crypto/kernel])
AS_MKDIR_P([crypto/math])
AS_MKDIR_P([crypto/replay])
AS_MKDIR_P([crypto/test])
AS_MKDIR_P([doc])
AS_MKDIR_P([srtp])
AS_MKDIR_P([test])