configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. dnl Process this file with autoconf to produce a configure script. -*-m4-*-
  2. dnl The package_version file will be automatically synced to the git revision
  3. dnl by the update_version script when configured in the repository, but will
  4. dnl remain constant in tarball releases unless it is manually edited.
  5. m4_define([CURRENT_VERSION],
  6. m4_esyscmd([ ./update_version 2>/dev/null || true
  7. if test -e package_version; then
  8. . ./package_version
  9. printf "$PACKAGE_VERSION"
  10. else
  11. printf "unknown"
  12. fi ]))
  13. AC_INIT([opus-tools],[CURRENT_VERSION],[opus@xiph.org])
  14. AC_CONFIG_SRCDIR([src/opusenc.c])
  15. AC_CONFIG_MACRO_DIR([m4])
  16. dnl enable silent rules on automake 1.11 and later
  17. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  18. AM_INIT_AUTOMAKE([1.11 foreign no-define])
  19. AM_MAINTAINER_MODE([enable])
  20. AC_CANONICAL_HOST
  21. AM_PROG_CC_C_O
  22. AC_PROG_CC_C99
  23. AC_CHECK_HEADERS([inttypes.h alloca.h])
  24. AC_C_BIGENDIAN
  25. AC_C_CONST
  26. AC_C_INLINE
  27. LT_INIT
  28. #Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
  29. #strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
  30. #Note: Both this and the test for variable-size arrays below are also
  31. # done by AC_PROG_CC_C99, but not thoroughly enough apparently.
  32. AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
  33. [ac_cv_c_restrict=no
  34. # The order here caters to the fact that C++ does not require restrict.
  35. for ac_kw in __restrict __restrict__ _Restrict restrict; do
  36. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  37. [[typedef int * int_ptr;
  38. int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
  39. return ip[0];
  40. }]],
  41. [[int s[1];
  42. int * $ac_kw t = s;
  43. t[0] = 0;
  44. return foo(t, (void *)0)]])],
  45. [ac_cv_c_restrict=$ac_kw])
  46. test "$ac_cv_c_restrict" != no && break
  47. done
  48. ])
  49. AH_VERBATIM([restrict],
  50. [/* Define to the equivalent of the C99 'restrict' keyword, or to
  51. nothing if this is not supported. Do not define if restrict is
  52. supported directly. */
  53. #undef restrict
  54. /* Work around a bug in Sun C++: it does not support _Restrict or
  55. __restrict__, even though the corresponding Sun C compiler ends up with
  56. "#define restrict _Restrict" or "#define restrict __restrict__" in the
  57. previous line. Perhaps some future version of Sun C++ will work with
  58. restrict; if so, hopefully it defines __RESTRICT like Sun C does. */
  59. #if defined __SUNPRO_CC && !defined __RESTRICT
  60. # define _Restrict
  61. # define __restrict__
  62. #endif])
  63. case $ac_cv_c_restrict in
  64. restrict) ;;
  65. no) AC_DEFINE([restrict], []) ;;
  66. *) AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
  67. esac
  68. AC_MSG_CHECKING(for C99 variable-size arrays)
  69. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  70. [[static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];]])],
  71. [ has_var_arrays=yes
  72. AC_DEFINE([VAR_ARRAYS], [1], [Use C99 variable-size arrays])
  73. ],[
  74. has_var_arrays=no
  75. ])
  76. AC_MSG_RESULT([$has_var_arrays])
  77. AC_ARG_ENABLE([assertions],
  78. [AS_HELP_STRING([--enable-assertions],[enable additional software error checking])],,
  79. [enable_assertions=no])
  80. AS_IF([test "$enable_assertions" = "yes"], [
  81. AC_DEFINE([ENABLE_ASSERTIONS], [1], [Assertions])
  82. ])
  83. if test "$CFLAGS" = "-g -O2"; then
  84. saved_CFLAGS="$CFLAGS"
  85. CFLAGS="-O3 -ffast-math"
  86. AC_MSG_CHECKING([if ${CC} supports -O3 -g -ffast-math])
  87. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
  88. [ AC_MSG_RESULT([yes])
  89. saved_CFLAGS="-O3 -g -ffast-math"
  90. ],[
  91. AC_MSG_RESULT([no])
  92. ])
  93. CFLAGS="$saved_CFLAGS"
  94. fi
  95. LT_LIB_M
  96. AC_CHECK_LIB([winmm], [main])
  97. on_x86=no
  98. case "$host_cpu" in
  99. i[[3456]]86 | x86_64)
  100. on_x86=yes
  101. ;;
  102. esac
  103. dnl check for sse
  104. AC_ARG_ENABLE([sse],
  105. [AS_HELP_STRING([--enable-sse],[Build binaries that require SSE])],,
  106. [enable_sse=no])
  107. AS_IF([test "$on_x86" = "yes" && test "$enable_sse" = "yes"],
  108. [
  109. saved_CFLAGS="$CFLAGS"
  110. CFLAGS="$CFLAGS -msse"
  111. AC_MSG_CHECKING([if ${CC} supports -msse])
  112. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[[char foo;]])],
  113. [ AC_MSG_RESULT([yes]) ],
  114. [
  115. AC_MSG_RESULT([no])
  116. enable_sse=no
  117. CFLAGS="$saved_CFLAGS"
  118. ])
  119. ])
  120. saved_LIBS="$LIBS"
  121. LIBS="$LIBS $LIBM"
  122. AC_CHECK_FUNCS([lrintf])
  123. AC_CHECK_FUNCS([fminf])
  124. AC_CHECK_FUNCS([fmaxf])
  125. LIBS="$saved_LIBS"
  126. AC_FUNC_FSEEKO
  127. AC_CHECK_FUNCS([clock_gettime mach_absolute_time])
  128. AC_CHECK_FUNCS([usleep nanosleep clock_nanosleep])
  129. dnl check for pkg-config itself so we don't try the m4 macro without pkg-config
  130. AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
  131. dnl check for Ogg
  132. AS_IF([test "$HAVE_PKG_CONFIG" = "yes"],
  133. dnl first try via pkg-config
  134. [PKG_CHECK_MODULES([OGG],[ogg >= 1.3])],
  135. [
  136. dnl fall back to the old school test
  137. XIPH_PATH_OGG(, AC_MSG_ERROR([
  138. libogg is required to build this package!
  139. Please see https://www.xiph.org/ for how to obtain a copy.
  140. ]))
  141. saved_CFLAGS="$CFLAGS"
  142. saved_LIBS="$LIBS"
  143. CFLAGS="$CFLAGS $OGG_CFLAGS"
  144. LIBS="$LIBS $OGG_LIBS"
  145. AC_CHECK_FUNC([ogg_stream_flush_fill],,[
  146. AC_MSG_ERROR([newer libogg version (1.3 or later) required])
  147. ])
  148. CFLAGS="$saved_CFLAGS"
  149. LIBS="$saved_LIBS"
  150. ])
  151. dnl check for Opus
  152. AS_IF([test "$HAVE_PKG_CONFIG" = "yes"],
  153. [PKG_CHECK_MODULES([OPUS],[opus >= 1.1])],
  154. [
  155. dnl fall back to the old school test
  156. XIPH_PATH_OPUS(, AC_MSG_ERROR([
  157. Opus is required to build this package!
  158. Please see https://opus-codec.org/ for how to obtain a copy.
  159. ]))
  160. ])
  161. dnl check for opusfile (specifically, we need libopusurl)
  162. AS_IF([test "$HAVE_PKG_CONFIG" = "yes"],
  163. [
  164. dnl checking for opusfile first will offer a more helpful message if it is
  165. dnl not installed, since the package that is needed is likely opusfile
  166. PKG_CHECK_MODULES([OPUSFILE],[opusfile >= 0.5])
  167. PKG_CHECK_MODULES([OPUSURL],[opusurl >= 0.5])
  168. ],
  169. [
  170. dnl fall back to the old school test
  171. XIPH_PATH_OPUSFILE(, AC_MSG_ERROR([
  172. libopusfile is required to build this package!
  173. Please see https://opus-codec.org/ for how to obtain a copy.
  174. ]))
  175. OPUSURL_CFLAGS="$OPUSFILE_CFLAGS"
  176. OPUSURL_LIBS="$OPUSFILE_LIBS -lopusurl"
  177. ])
  178. dnl check for libopusenc
  179. AS_IF([test "$HAVE_PKG_CONFIG" = "yes"],
  180. [PKG_CHECK_MODULES([LIBOPUSENC],[libopusenc >= 0.2])],
  181. [
  182. dnl fall back to the old school test
  183. XIPH_PATH_LIBOPUSENC(, AC_MSG_ERROR([
  184. libopusenc is required to build this package!
  185. Please see https://opus-codec.org/ for how to obtain a copy.
  186. ]))
  187. ])
  188. dnl check for OSS
  189. HAVE_OSS=no
  190. AC_CHECK_HEADERS([sys/soundcard.h soundcard.h machine/soundcard.h],[
  191. HAVE_OSS=yes
  192. break
  193. ])
  194. dnl check for sndio
  195. AC_CHECK_LIB([sndio], [sio_open])
  196. if test "$HAVE_OSS" != "yes" && test "$ac_cv_lib_sndio_sio_open" != "yes"; then
  197. AC_MSG_WARN([Audio support not found -- no direct audio output in opusdec])
  198. fi
  199. dnl check for flac
  200. AC_ARG_WITH([flac],
  201. [AS_HELP_STRING([--without-flac],[disable FLAC support])],,
  202. [with_flac=yes])
  203. AS_IF([test "$with_flac" = "yes"],
  204. [
  205. AS_IF([test "$HAVE_PKG_CONFIG" = "yes"],
  206. [PKG_CHECK_MODULES([FLAC],[flac >= 1.1.3])],
  207. [
  208. dnl fall back to AC_CHECK_LIB
  209. AC_CHECK_LIB([FLAC],[FLAC__stream_decoder_init_ogg_stream],
  210. [
  211. FLAC_LIBS="-lFLAC"
  212. ],
  213. [
  214. AC_MSG_ERROR([
  215. FLAC 1.1.3 or later is required to build this package!
  216. Please install it or configure with --disable-flac.
  217. ])
  218. ]
  219. )
  220. AC_CHECK_HEADER([FLAC/stream_decoder.h],,
  221. [
  222. AC_MSG_ERROR([
  223. FLAC headers are required to build this package!
  224. Please install the development version of FLAC
  225. or configure with --disable-flac.
  226. ])
  227. ]
  228. )
  229. ])
  230. AC_DEFINE([HAVE_LIBFLAC],[1],[FLAC])
  231. ])
  232. dnl opusrtp socket and pcap support
  233. saved_LIBS="$LIBS"
  234. AC_SEARCH_LIBS([setsockopt], [bsd socket inet])
  235. AC_SEARCH_LIBS([pcap_open_live], [pcap wpcap], [
  236. AC_DEFINE([HAVE_PCAP], 1, [Define if building with libpcap support])
  237. ])
  238. AC_MSG_CHECKING([socket support])
  239. AC_LINK_IFELSE([
  240. AC_LANG_PROGRAM(
  241. [[
  242. #include <sys/types.h>
  243. #include <sys/socket.h>
  244. #include <netinet/in.h>
  245. #include <arpa/inet.h>
  246. #include <netdb.h>
  247. ]],
  248. [[
  249. struct addrinfo *addrs;
  250. struct addrinfo hints = { 0 };
  251. hints.ai_family = AF_UNSPEC;
  252. hints.ai_socktype = SOCK_DGRAM;
  253. hints.ai_flags = 0;
  254. hints.ai_protocol = IPPROTO_UDP;
  255. if (getaddrinfo("localhost", "1234", &hints, &addrs) == 0)
  256. socket(addrs->ai_addr->sa_family, SOCK_DGRAM, IPPROTO_UDP);
  257. freeaddrinfo(addrs);
  258. ]])],
  259. [
  260. AC_MSG_RESULT([yes])
  261. AC_DEFINE([HAVE_SOCKETS], [1], [Define if building with socket support])
  262. ],
  263. [
  264. AC_MSG_RESULT([no])
  265. ])
  266. AC_CHECK_FUNCS([inet_ntop])
  267. OPUSRTP_LIBS="$LIBS"
  268. LIBS="$saved_LIBS"
  269. AC_SUBST(OPUSRTP_LIBS)
  270. on_windows=no
  271. case "$host" in
  272. *cygwin*|*mingw*)
  273. on_windows=yes
  274. ;;
  275. esac
  276. dnl Enable stack-protector-strong only on x86 where it's well supported,
  277. dnl but not on Windows because it creates a dependency on libssp.dll.
  278. dnl On some platforms it causes crashes. Hopefully the OS defaults to
  279. dnl enabling this on platforms that work but have been missed here.
  280. AC_ARG_ENABLE([stack-protector],
  281. [AS_HELP_STRING([--disable-stack-protector],[Disable compiler stack hardening])],,
  282. [
  283. AS_IF([test "$ac_cv_c_compiler_gnu" = "yes" && test "$on_x86" = "yes" && test "$on_windows" = "no"],
  284. [enable_stack_protector=yes],[enable_stack_protector=no])
  285. ])
  286. AS_IF([test "$enable_stack_protector" = "yes"],
  287. [
  288. saved_CFLAGS="$CFLAGS"
  289. CFLAGS="$CFLAGS -fstack-protector-strong"
  290. AC_MSG_CHECKING([if ${CC} supports -fstack-protector-strong])
  291. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[[char foo;]])],
  292. [ AC_MSG_RESULT([yes]) ],
  293. [
  294. AC_MSG_RESULT([no])
  295. enable_stack_protector=no
  296. CFLAGS="$saved_CFLAGS"
  297. ])
  298. ])
  299. AC_ARG_ENABLE([pie],
  300. [AS_HELP_STRING([--disable-pie],[Disable PIE/RELRO hardening])],,
  301. [enable_pie=yes])
  302. AS_IF([test "$enable_pie" = "yes"],
  303. [
  304. saved_CFLAGS="$CFLAGS"
  305. saved_LDFLAGS="$LDFLAGS"
  306. saved_LIBS="$LIBS"
  307. CFLAGS="$CFLAGS $OPUS_CFLAGS -fPIE"
  308. LDFLAGS="$LDFLAGS -pie -Wl,-z,relro -Wl,-z,now"
  309. LIBS="$LIBS $OPUS_LIBS"
  310. AC_MSG_CHECKING([for PIE support])
  311. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <opus.h>]],
  312. [[OpusDecoder *dec = opus_decoder_create(48000, 2, 0L)]])],
  313. [ AC_MSG_RESULT([yes]) ],
  314. [ AC_MSG_RESULT([no])
  315. enable_pie=no
  316. CFLAGS="$saved_CFLAGS"
  317. LDFLAGS="$saved_LDFLAGS"
  318. ])
  319. LIBS="$saved_LIBS"
  320. ])
  321. CFLAGS="$CFLAGS -W"
  322. saved_CFLAGS="$CFLAGS"
  323. CFLAGS="$CFLAGS -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-sign-compare"
  324. AC_MSG_CHECKING([if ${CC} supports -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-sign-compare])
  325. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
  326. [ AC_MSG_RESULT([yes]) ],
  327. [ AC_MSG_RESULT([no])
  328. CFLAGS="$saved_CFLAGS"
  329. ])
  330. AC_CONFIG_FILES([Makefile])
  331. AC_CONFIG_HEADERS([config.h])
  332. AC_OUTPUT
  333. AC_MSG_NOTICE([
  334. ------------------------------------------------------------------------
  335. $PACKAGE_NAME $PACKAGE_VERSION: Automatic configuration OK.
  336. Compiler support:
  337. C99 var arrays: ................ ${has_var_arrays}
  338. C99 lrintf: .................... ${ac_cv_func_lrintf}
  339. Stack protector: ............... ${enable_stack_protector}
  340. PIE: ........................... ${enable_pie}
  341. General configuration:
  342. Assertion checking: ............ ${enable_assertions}
  343. FLAC input: .................... ${with_flac}
  344. ------------------------------------------------------------------------
  345. Type "make; make install" to compile and install
  346. ])