configure.ac 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. dnl Process this file with autoconf to produce a configure script. -*-m4-*-
  2. AC_INIT(src/opusenc.c)
  3. AC_CONFIG_HEADERS([config.h])
  4. dnl enable silent rules on automake 1.11 and later
  5. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  6. OPUSTOOLS_MAJOR_VERSION=0
  7. OPUSTOOLS_MINOR_VERSION=1
  8. OPUSTOOLS_MICRO_VERSION=6
  9. OPUSTOOLS_EXTRA_VERSION=git
  10. OPUSTOOLS_VERSION="$OPUSTOOLS_MAJOR_VERSION.$OPUSTOOLS_MINOR_VERSION.$OPUSTOOLS_MICRO_VERSION$OPUSTOOLS_EXTRA_VERSION"
  11. AC_MSG_CHECKING([git revision])
  12. GIT_VERSION=$(git describe --tags --match 'v*' 2>/dev/null | sed 's/^v//')
  13. if test -z "$GIT_VERSION"; then
  14. AC_MSG_RESULT([no])
  15. else
  16. AC_MSG_RESULT([$GIT_VERSION])
  17. OPUSTOOLS_VERSION="$GIT_VERSION"
  18. fi
  19. # For automake.
  20. VERSION=$OPUSTOOLS_VERSION
  21. PACKAGE=opus-tools
  22. AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
  23. AM_MAINTAINER_MODE([enable])
  24. AC_CANONICAL_HOST
  25. AM_PROG_CC_C_O
  26. AC_PROG_CC_C99
  27. AC_C_BIGENDIAN
  28. AC_C_CONST
  29. AC_C_INLINE
  30. #Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
  31. #strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
  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_TRY_COMPILE( [], [static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];],
  70. [has_var_arrays=yes;AC_DEFINE([VAR_ARRAYS], [], [Use C99 variable-size arrays])
  71. ],
  72. has_var_arrays=no
  73. )
  74. AC_MSG_RESULT($has_var_arrays)
  75. AC_CHECK_FUNC(exp,[fp_libm_not_needed=yes;LIBM=],[fp_libm_not_needed=dunno])
  76. if test x"$fp_libm_not_needed" = xdunno; then
  77. AC_CHECK_LIB([m], [exp], [LIBS="-lm $LIBS"; LIBM="-lm"],[LIBM=])
  78. fi
  79. AC_SUBST([LIBM])
  80. AC_CHECK_LIB(winmm, main)
  81. AC_DEFINE_UNQUOTED(OPUSTOOLS_MAJOR_VERSION, ${OPUSTOOLS_MAJOR_VERSION}, [Version major])
  82. AC_DEFINE_UNQUOTED(OPUSTOOLS_MINOR_VERSION, ${OPUSTOOLS_MINOR_VERSION}, [Version minor])
  83. AC_DEFINE_UNQUOTED(OPUSTOOLS_MICRO_VERSION, ${OPUSTOOLS_MICRO_VERSION}, [Version micro])
  84. AC_DEFINE_UNQUOTED(OPUSTOOLS_EXTRA_VERSION, "${OPUSTOOLS_EXTRA_VERSION}", [Version extra])
  85. ac_enable_assertions="no"
  86. AC_ARG_ENABLE(assertions, [ --enable-assertions enable additional software error checking],
  87. [if test "$enableval" = yes; then
  88. ac_enable_assertions="yes"
  89. AC_DEFINE([ENABLE_ASSERTIONS], , [Assertions])
  90. fi])
  91. ac_enable_flac="yes"
  92. AC_ARG_ENABLE(flac, [ --disable-flac disable FLAC support],
  93. [if test "$enableval" != "yes"; then
  94. ac_enable_flac="no"
  95. fi])
  96. if test "x$CFLAGS" = "x-g -O2"; then
  97. saved_CFLAGS="$CFLAGS"
  98. CFLAGS="-O3 -ffast-math"
  99. AC_MSG_CHECKING([if ${CC} supports -O3 -g -ffast-math])
  100. AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
  101. [ AC_MSG_RESULT([yes])
  102. saved_CFLAGS="-O3 -g -ffast-math" ],
  103. AC_MSG_RESULT([no]))
  104. CFLAGS="$saved_CFLAGS"
  105. fi
  106. dnl check for Ogg
  107. HAVE_OGG=no
  108. dnl first check through pkg-config since it's more flexible
  109. dnl check for pkg-config itself so we don't try the m4 macro without pkg-config
  110. AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
  111. if test "x$HAVE_PKG_CONFIG" = "xyes"
  112. then
  113. PKG_CHECK_MODULES(OGG, ogg >= 1.3, HAVE_OGG=yes, HAVE_OGG=no)
  114. fi
  115. if test "x$HAVE_OGG" = "xno"
  116. then
  117. dnl fall back to the old school test
  118. XIPH_PATH_OGG(, AC_MSG_ERROR([
  119. libogg is required to build this package!
  120. please see http://www.xiph.org/ for how to
  121. obtain a copy.
  122. ]))
  123. cflags_save=$CFLAGS
  124. libs_save=$LIBS
  125. CFLAGS="$CFLAGS $OGG_CFLAGS"
  126. LIBS="$LIBS $OGG_LIBS"
  127. AC_CHECK_FUNC(ogg_stream_flush_fill, , [
  128. AC_MSG_ERROR([newer libogg version (1.3 or later) required])
  129. ])
  130. CFLAGS=$cflags_save
  131. LIBS=$libs_save
  132. fi
  133. dnl check for Opus
  134. HAVE_OPUS=no
  135. if test "x$HAVE_PKG_CONFIG" = "xyes"
  136. then
  137. PKG_CHECK_MODULES(Opus, opus >= 0.9.10, HAVE_OPUS=yes, HAVE_OPUS=no)
  138. fi
  139. if test "x$HAVE_OPUS" = "xno"
  140. then
  141. dnl fall back to the old school test
  142. XIPH_PATH_OPUS(, AC_MSG_ERROR([
  143. Opus is required to build this package!
  144. please see http://opus-codec.org/ for how to
  145. obtain a copy.
  146. ]))
  147. CFLAGS="$CFLAGS $OPUS_CFLAGS"
  148. LIBS="$LIBS $OPUS_LIBS"
  149. fi
  150. dnl check for OSS
  151. HAVE_OSS=no
  152. AC_CHECK_HEADERS([sys/soundcard.h soundcard.h machine/soundcard.h],[
  153. HAVE_OSS=yes
  154. break
  155. ])
  156. dnl check for sndio
  157. HAVE_SNDIO=no
  158. AC_CHECK_LIB([sndio], [sio_open])
  159. if test "x$ac_cv_lib_sndio_sio_open" = "xyes"; then
  160. HAVE_SNDIO=yes
  161. fi
  162. if test "x$HAVE_OSS" != "xyes" && test "x$HAVE_SNDIO" != "xyes"; then
  163. AC_MSG_WARN([Audio support not found -- no direct audio output in opusdec])
  164. fi
  165. dnl check for flac
  166. if test "x$ac_enable_flac" = "xyes" ; then
  167. HAVE_FLAC=no
  168. if test "x$HAVE_PKG_CONFIG" = "xyes"
  169. then
  170. PKG_CHECK_MODULES(FLAC, flac >= 1.1.3, HAVE_FLAC=yes, HAVE_FLAC=no)
  171. fi
  172. if test "x$HAVE_FLAC" = "xno"
  173. then
  174. dnl fall back to AC_CHECK_LIB
  175. AC_CHECK_LIB(m,log,FLAC_LIBS="$FLAC_LIBS -lm")
  176. AC_CHECK_LIB(FLAC, [FLAC__stream_decoder_init_ogg_stream],
  177. [
  178. HAVE_FLAC="yes"
  179. FLAC_LIBS="-lFLAC $FLAC_LIBS"
  180. ],
  181. [
  182. AC_MSG_ERROR([
  183. FLAC 1.1.3 or later is required to build this package!
  184. Please install it or configure with --disable-flac.
  185. ])
  186. HAVE_FLAC="no"
  187. ],
  188. [$FLAC_LIBS]
  189. )
  190. AC_CHECK_HEADER(FLAC/stream_decoder.h,,
  191. [
  192. AC_MSG_ERROR([
  193. FLAC headers are required to build this package!
  194. Please install the development version of FLAC
  195. or configure with --disable-flac.
  196. ])
  197. HAVE_FLAC="no"
  198. ],
  199. [$FLAC_CFLAGS]
  200. )
  201. fi
  202. CFLAGS="$FLAC_CFLAGS $CFLAGS"
  203. LIBS="$FLAC_LIBS $LIBS"
  204. AC_DEFINE([HAVE_LIBFLAC], , [FLAC])
  205. fi
  206. dnl check for pcap
  207. AC_CHECK_LIB([pcap], [pcap_open_live], [
  208. AC_DEFINE([HAVE_PCAP], 1, [Define if building with libpcap support])
  209. LIBPCAP="-lpcap"
  210. ])
  211. AC_SUBST(LIBPCAP)
  212. on_x86=no
  213. case "$host_cpu" in
  214. i[[3456]]86 | x86_64)
  215. on_x86=yes
  216. ;;
  217. esac
  218. if test "x$on_x86" = "xyes"; then
  219. ac_enable_sse="no"
  220. AC_ARG_ENABLE(sse, AS_HELP_STRING([--enable-sse],[Build binaries that require SSE]),
  221. [if test "$enableval" = yes; then
  222. ac_enable_sse="yes"
  223. saved_CFLAGS="$CFLAGS"
  224. CFLAGS="$CFLAGS -msse"
  225. AC_MSG_CHECKING([if ${CC} supports -msse])
  226. AC_LINK_IFELSE([AC_LANG_SOURCE([void main(void){char foo;}])],
  227. [ AC_MSG_RESULT([yes])
  228. SSE="-msse"; ac_build_sse=yes ],
  229. AC_MSG_RESULT([no]))
  230. CFLAGS="$saved_CFLAGS $SSE"
  231. fi])
  232. fi
  233. dnl Enable stack-protector-all only on x86 where it's well supported.
  234. dnl on some platforms it causes crashes. Hopefully the OS's default's
  235. dnl include this on platforms that work but have been missed here.
  236. ac_build_stack_protector=no
  237. if test "x$ac_cv_c_compiler_gnu" = "xyes" && test "x$on_x86" = "xyes"; then
  238. AC_ARG_ENABLE(stack-protector,
  239. AS_HELP_STRING([--disable-stack-protector],[Disable compiler stack hardening]),
  240. [
  241. if test "x$enableval" = "xno"; then
  242. ac_build_stack_protector=$enableval
  243. fi
  244. ], [
  245. ac_build_stack_protector=yes
  246. ])
  247. if test "x$ac_build_stack_protector" = "xyes"; then
  248. saved_CFLAGS="$CFLAGS"
  249. CFLAGS="$CFLAGS -fstack-protector-all"
  250. AC_MSG_CHECKING([if ${CC} supports -fstack-protector-all])
  251. AC_LINK_IFELSE([AC_LANG_SOURCE([void main(void){char foo;}])],
  252. [ AC_MSG_RESULT([yes])
  253. STACK_PROTECTOR="-fstack-protector-all"; ac_build_stack_protector=yes ],
  254. AC_MSG_RESULT([no]))
  255. CFLAGS="$saved_CFLAGS $STACK_PROTECTOR"
  256. fi
  257. fi
  258. ac_build_pie=no
  259. AC_ARG_ENABLE(pie,
  260. AS_HELP_STRING([--disable-pie],[Disable PIE/RELRO hardening]),
  261. [
  262. if test "x$enableval" = "xno"; then
  263. ac_build_pie=$enableval
  264. fi
  265. ], [
  266. ac_build_pie=yes
  267. ])
  268. if test "x$ac_build_pie" = "xyes"; then
  269. save_CFLAGS="$CFLAGS"
  270. save_LDFLAGS="$LDFLAGS"
  271. save_LIBS="$LIBS"
  272. CFLAGS="$CFLAGS -fPIE $Opus_CFLAGS"
  273. LDFLAGS="$LDFLAGS -pie -Wl,-z,relro -Wl,-z,now"
  274. LIBS="$LIBS $Opus_LIBS"
  275. AC_MSG_CHECKING([for PIE support])
  276. AC_LINK_IFELSE([AC_LANG_SOURCE([
  277. #include <opus.h>
  278. void main () {
  279. OpusDecoder *dec = opus_decoder_create(48000, 2, 0L);
  280. }])],
  281. [ac_build_pie=yes],
  282. [ac_build_pie=no])
  283. AC_MSG_RESULT([$ac_build_pie])
  284. if test "x$ac_build_pie" = "xyes"; then
  285. PIE_CFLAGS="-fPIE"
  286. PIE_LDFLAGS="-pie -Wl,-z,relro -Wl,-z,now"
  287. fi
  288. CFLAGS="$save_CFLAGS $PIE_CFLAGS"
  289. LDFLAGS="$save_LDFLAGS $PIE_LDFLAGS"
  290. LIBS="$save_LIBS"
  291. fi
  292. CFLAGS="$CFLAGS -W"
  293. saved_CFLAGS="$CFLAGS"
  294. CFLAGS="$CFLAGS -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
  295. AC_MSG_CHECKING([if ${CC} supports -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes])
  296. AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
  297. [ AC_MSG_RESULT([yes])
  298. EXTRA_WARNS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes" ],
  299. AC_MSG_RESULT([no]))
  300. CFLAGS="$saved_CFLAGS $EXTRA_WARNS"
  301. AC_FUNC_FSEEKO
  302. AC_CHECK_FUNCS([lrintf])
  303. AC_CHECK_FUNCS([lrint])
  304. AC_CHECK_FUNCS([fminf])
  305. AC_CHECK_FUNCS([fmaxf])
  306. AC_CHECK_FUNCS([__malloc_hook])
  307. AC_CHECK_SIZEOF(short)
  308. AC_CHECK_SIZEOF(int)
  309. AC_CHECK_SIZEOF(long)
  310. AC_CHECK_SIZEOF(long long)
  311. if test x$has_char16 = "xyes" ; then
  312. case 1 in
  313. $ac_cv_sizeof_short) SIZE16="short";;
  314. $ac_cv_sizeof_int) SIZE16="int";;
  315. esac
  316. else
  317. case 2 in
  318. $ac_cv_sizeof_short) SIZE16="short";;
  319. $ac_cv_sizeof_int) SIZE16="int";;
  320. esac
  321. fi
  322. if test x$has_char16 = "xyes" ; then
  323. case 2 in
  324. $ac_cv_sizeof_int) SIZE32="int";;
  325. $ac_cv_sizeof_long) SIZE32="long";;
  326. $ac_cv_sizeof_short) SIZE32="short";;
  327. esac
  328. else
  329. case 4 in
  330. $ac_cv_sizeof_int) SIZE32="int";;
  331. $ac_cv_sizeof_long) SIZE32="long";;
  332. $ac_cv_sizeof_short) SIZE32="short";;
  333. esac
  334. fi
  335. AC_SUBST(SIZE16)
  336. AC_SUBST(SIZE32)
  337. AC_OUTPUT([Makefile])
  338. AC_MSG_RESULT([
  339. ------------------------------------------------------------------------
  340. $PACKAGE $VERSION: Automatic configuration OK.
  341. Compiler support:
  342. C99 var arrays: ................ ${has_var_arrays}
  343. C99 lrintf: .................... ${ac_cv_func_lrintf}
  344. Stack protector: ............... ${ac_build_stack_protector}
  345. PIE: ........................... ${ac_build_pie}
  346. General configuration:
  347. Assertion checking: ............ ${ac_enable_assertions}
  348. FLAC input: .................... ${ac_enable_flac}
  349. ------------------------------------------------------------------------
  350. ])
  351. echo "Type \"make; make install\" to compile and install";
  352. echo "Type \"make check\" to run the test suite";