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