configure.ac 14 KB

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