Delaying allocation of the SILK temporary output buffer to reduce peak stack
[opus.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script. -*-m4-*-
2
3 dnl The package_version file will be automatically synced to the git revision
4 dnl by the update_version script when configured in the repository, but will
5 dnl remain constant in tarball releases unless it is manually edited.
6 m4_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
15 AC_INIT([opus],[CURRENT_VERSION],[opus@xiph.org])
16
17 AC_CONFIG_SRCDIR(src/opus_encoder.c)
18 AC_CONFIG_MACRO_DIR([m4])
19
20 dnl enable silent rules on automake 1.11 and later
21 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
22
23 # For libtool.
24 dnl Please update these for releases.
25 OPUS_LT_CURRENT=5
26 OPUS_LT_REVISION=0
27 OPUS_LT_AGE=5
28
29 AC_SUBST(OPUS_LT_CURRENT)
30 AC_SUBST(OPUS_LT_REVISION)
31 AC_SUBST(OPUS_LT_AGE)
32
33 AM_INIT_AUTOMAKE([no-define])
34 AM_MAINTAINER_MODE([enable])
35
36 AC_CANONICAL_HOST
37 AC_MINGW32
38 AM_PROG_LIBTOOL
39 AM_PROG_CC_C_O
40
41 AC_PROG_CC_C99
42 AC_C_CONST
43 AC_C_INLINE
44
45 AM_PROG_AS
46
47 AC_DEFINE([OPUS_BUILD], [], [This is a build of OPUS])
48
49 #Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
50 #strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
51 #Note: Both this and the test for variable-size arrays below are also
52 #      done by AC_PROG_CC_C99, but not thoroughly enough apparently.
53 AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
54   [ac_cv_c_restrict=no
55    # The order here caters to the fact that C++ does not require restrict.
56    for ac_kw in __restrict __restrict__ _Restrict restrict; do
57      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
58       [[typedef int * int_ptr;
59         int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
60         return ip[0];
61        }]],
62       [[int s[1];
63         int * $ac_kw t = s;
64         t[0] = 0;
65         return foo(t, (void *)0)]])],
66       [ac_cv_c_restrict=$ac_kw])
67      test "$ac_cv_c_restrict" != no && break
68    done
69   ])
70
71 AH_VERBATIM([restrict],
72 [/* Define to the equivalent of the C99 'restrict' keyword, or to
73    nothing if this is not supported.  Do not define if restrict is
74    supported directly.  */
75 #undef restrict
76 /* Work around a bug in Sun C++: it does not support _Restrict or
77    __restrict__, even though the corresponding Sun C compiler ends up with
78    "#define restrict _Restrict" or "#define restrict __restrict__" in the
79    previous line.  Perhaps some future version of Sun C++ will work with
80    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
81 #if defined __SUNPRO_CC && !defined __RESTRICT
82 # define _Restrict
83 # define __restrict__
84 #endif])
85
86 case $ac_cv_c_restrict in
87    restrict) ;;
88    no) AC_DEFINE([restrict], []) ;;
89    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
90 esac
91
92 AC_MSG_CHECKING(for C99 variable-size arrays)
93 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
94                    [[static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];]])],
95     [ has_var_arrays=yes
96       use_alloca="no (using var arrays)"
97       AC_DEFINE([VAR_ARRAYS], [1], [Use C99 variable-size arrays])
98     ],[
99       has_var_arrays=no
100     ])
101 AC_MSG_RESULT([$has_var_arrays])
102
103 AS_IF([test "$has_var_arrays" = "no"],
104   [
105    AC_CHECK_HEADERS([alloca.h])
106    AC_MSG_CHECKING(for alloca)
107    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <alloca.h>]],
108                                       [[int foo=10; int *array = alloca(foo);]])],
109      [ use_alloca=yes;
110        AC_DEFINE([USE_ALLOCA], [], [Make use of alloca])
111      ],[
112        use_alloca=no
113      ])
114    AC_MSG_RESULT([$use_alloca])
115   ])
116
117 LT_LIB_M
118
119 AC_ARG_ENABLE([fixed-point],
120     [AS_HELP_STRING([--enable-fixed-point],
121                     [compile without floating point (for machines without a fast enough FPU)])],,
122     [enable_fixed_point=no])
123
124 AS_IF([test "$enable_fixed_point" = "yes"],[
125   enable_float="no"
126   AC_DEFINE([FIXED_POINT], [1], [Compile as fixed-point (for machines without a fast enough FPU)])
127   PC_BUILD="fixed-point"
128 ],[
129   enable_float="yes";
130   PC_BUILD="floating-point"
131 ])
132
133 AM_CONDITIONAL([FIXED_POINT], [test "$enable_fixed_point" = "yes"])
134
135 AC_ARG_ENABLE([fixed-point-debug],
136     [AS_HELP_STRING([--enable-fixed-point-debug], [debug fixed-point implementation])],,
137     [enable_fixed_point_debug=no])
138
139 AS_IF([test "$enable_fixed_point_debug" = "yes"],[
140   AC_DEFINE([FIXED_DEBUG], [1], [Debug fixed-point implementation])
141 ])
142
143 AC_ARG_ENABLE([float_api],
144     [AS_HELP_STRING([--disable-float-api],
145                     [compile without the floating point API (for machines with no float library)])],,
146     [enable_float_api=yes])
147
148 AM_CONDITIONAL([DISABLE_FLOAT_API], [test "$enable_float_api" = "no"])
149
150 AS_IF([test "$enable_float_api" = "no"],[
151   AC_DEFINE([DISABLE_FLOAT_API], [1], [Do not build the float API])
152 ])
153
154 AC_ARG_ENABLE([custom-modes],
155     [AS_HELP_STRING([--enable-custom-modes], [enable non-Opus modes, e.g. 44.1 kHz & 2^n frames])],,
156     [enable_custom_modes=no])
157
158 AS_IF([test "$enable_custom_modes" = "yes"],[
159   AC_DEFINE([CUSTOM_MODES], [1], [Custom modes])
160   PC_BUILD="$PC_BUILD, custom modes"
161 ])
162
163 AM_CONDITIONAL([CUSTOM_MODES], [test "$enable_custom_modes" = "yes"])
164
165 has_float_approx=no
166 #case "$host_cpu" in
167 #i[[3456]]86 | x86_64 | powerpc64 | powerpc32 | ia64)
168 #  has_float_approx=yes
169 #  ;;
170 #esac
171
172 AC_ARG_ENABLE([float-approx],
173     [AS_HELP_STRING([--enable-float-approx], [enable fast approximations for floating point])],
174     [if test "$enable_float_approx" = "yes"; then
175        AC_WARN([Floating point approximations are not supported on all platforms.])
176      fi
177     ],
178     [enable_float_approx=$has_float_approx])
179
180 AS_IF([test "$enable_float_approx" = "yes"],[
181   AC_DEFINE([FLOAT_APPROX], [1], [Float approximations])
182 ])
183
184 AC_ARG_ENABLE([asm],
185     [AS_HELP_STRING([--disable-asm], [Disable assembly optimizations])],,
186     [enable_asm=yes])
187
188 AC_ARG_ENABLE([rtcd],
189     [AS_HELP_STRING([--disable-rtcd], [Disable run-time CPU capabilities detection])],,
190     [enable_rtcd=yes])
191
192 rtcd_support=no
193 cpu_arm=no
194
195 AS_IF([test x"${enable_asm}" = x"yes"],[
196     inline_optimization="No ASM for your platform, please send patches"
197     case $host_cpu in
198       arm*)
199         dnl Currently we only have asm for fixed-point
200         AS_IF([test "$enable_float" != "yes"],[
201             cpu_arm=yes
202             AC_DEFINE([OPUS_ARM_ASM], [],  [Make use of ARM asm optimization])
203             AS_GCC_INLINE_ASSEMBLY(
204                 [inline_optimization="ARM"],
205                 [inline_optimization="disabled"]
206             )
207             AS_ASM_ARM_EDSP([OPUS_ARM_INLINE_EDSP=1],[OPUS_ARM_INLINE_EDSP=0])
208             AS_ASM_ARM_MEDIA([OPUS_ARM_INLINE_MEDIA=1],
209                 [OPUS_ARM_INLINE_MEDIA=0])
210             AS_ASM_ARM_NEON([OPUS_ARM_INLINE_NEON=1],[OPUS_ARM_INLINE_NEON=0])
211             AS_IF([test x"$inline_optimization" = x"ARM"],[
212                 AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],[true])
213                 AC_DEFINE([OPUS_ARM_INLINE_ASM], 1,
214                     [Use generic ARMv4 inline asm optimizations])
215                 AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"],[
216                     AC_DEFINE([OPUS_ARM_INLINE_EDSP], [1],
217                         [Use ARMv5E inline asm optimizations])
218                     inline_optimization="$inline_optimization (EDSP)"
219                 ])
220                 AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"],[
221                     AC_DEFINE([OPUS_ARM_INLINE_MEDIA], [1],
222                         [Use ARMv6 inline asm optimizations])
223                     inline_optimization="$inline_optimization (Media)"
224                 ])
225                 AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"],[
226                     AC_DEFINE([OPUS_ARM_INLINE_NEON], 1,
227                         [Use ARM NEON inline asm optimizations])
228                     inline_optimization="$inline_optimization (NEON)"
229                 ])
230             ])
231             dnl We need Perl to translate RVCT-syntax asm to gas syntax.
232             AC_CHECK_PROG([HAVE_PERL], perl, yes, no)
233             AS_IF([test x"$HAVE_PERL" = x"yes"],[
234                 AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],[true])
235                 asm_optimization="ARM"
236                 AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"], [
237                     OPUS_ARM_PRESUME_EDSP=1
238                     OPUS_ARM_MAY_HAVE_EDSP=1
239                 ],
240                 [
241                     OPUS_ARM_PRESUME_EDSP=0
242                     OPUS_ARM_MAY_HAVE_EDSP=0
243                 ])
244                 AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"], [
245                     OPUS_ARM_PRESUME_MEDIA=1
246                     OPUS_ARM_MAY_HAVE_MEDIA=1
247                 ],
248                 [
249                     OPUS_ARM_PRESUME_MEDIA=0
250                     OPUS_ARM_MAY_HAVE_MEDIA=0
251                 ])
252                 AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"], [
253                     OPUS_ARM_PRESUME_NEON=1
254                     OPUS_ARM_MAY_HAVE_NEON=1
255                 ],
256                 [
257                     OPUS_ARM_PRESUME_NEON=0
258                     OPUS_ARM_MAY_HAVE_NEON=0
259                 ])
260                 AS_IF([test x"$enable_rtcd" = x"yes"],[
261                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" != x"1"],[
262                         AC_MSG_NOTICE(
263                           [Trying to force-enable armv5e EDSP instructions...])
264                         AS_ASM_ARM_EDSP_FORCE([OPUS_ARM_MAY_HAVE_EDSP=1])
265                     ])
266                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" != x"1"],[
267                         AC_MSG_NOTICE(
268                           [Trying to force-enable ARMv6 media instructions...])
269                         AS_ASM_ARM_MEDIA_FORCE([OPUS_ARM_MAY_HAVE_MEDIA=1])
270                     ])
271                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" != x"1"],[
272                         AC_MSG_NOTICE(
273                           [Trying to force-enable NEON instructions...])
274                         AS_ASM_ARM_NEON_FORCE([OPUS_ARM_MAY_HAVE_NEON=1])
275                     ])
276                 ])
277                 rtcd_support=
278                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" = x"1"],[
279                     AC_DEFINE(OPUS_ARM_MAY_HAVE_EDSP, 1,
280                         [Define if assembler supports EDSP instructions])
281                     AS_IF([test x"$OPUS_ARM_PRESUME_EDSP" = x"1"],[
282                         AC_DEFINE(OPUS_ARM_PRESUME_EDSP, 1,
283                           [Define if binary requires EDSP instruction support])
284                         asm_optimization="$asm_optimization (EDSP)"
285                     ],
286                         [rtcd_support="$rtcd_support (EDSP)"]
287                     )
288                 ])
289                 AC_SUBST(OPUS_ARM_MAY_HAVE_EDSP)
290                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" = x"1"],[
291                     AC_DEFINE(OPUS_ARM_MAY_HAVE_MEDIA, 1,
292                       [Define if assembler supports ARMv6 media instructions])
293                     AS_IF([test x"$OPUS_ARM_PRESUME_MEDIA" = x"1"],[
294                         AC_DEFINE(OPUS_ARM_PRESUME_MEDIA, 1,
295                           [Define if binary requires ARMv6 media instruction support])
296                         asm_optimization="$asm_optimization (Media)"
297                     ],
298                         [rtcd_support="$rtcd_support (Media)"]
299                     )
300                 ])
301                 AC_SUBST(OPUS_ARM_MAY_HAVE_MEDIA)
302                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" = x"1"],[
303                     AC_DEFINE(OPUS_ARM_MAY_HAVE_NEON, 1,
304                       [Define if compiler supports NEON instructions])
305                     AS_IF([test x"$OPUS_ARM_PRESUME_NEON" = x"1"], [
306                         AC_DEFINE(OPUS_ARM_PRESUME_NEON, 1,
307                           [Define if binary requires NEON instruction support])
308                         asm_optimization="$asm_optimization (NEON)"
309                     ],
310                         [rtcd_support="$rtcd_support (NEON)"]
311                     )
312                 ])
313                 AC_SUBST(OPUS_ARM_MAY_HAVE_NEON)
314                 dnl Make sure turning on RTCD gets us at least one
315                 dnl instruction set.
316                 AS_IF([test x"$rtcd_support" != x""],
317                     [rtcd_support=ARM"$rtcd_support"],
318                     [rtcd_support="no"]
319                 )
320             ],
321             [
322                 AC_MSG_WARN(
323                   [*** ARM assembly requires perl -- disabling optimizations])
324                 asm_optimization="(missing perl dependency for ARM)"
325             ])
326         ])
327         ;;
328     esac
329 ],[
330    inline_optimization="disabled"
331    asm_optimization="disabled"
332 ])
333
334 AM_CONDITIONAL([CPU_ARM], [test "$cpu_arm" = "yes"])
335 AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],
336     [test x"${inline_optimization%% *}" = x"ARM"])
337 AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],
338     [test x"${asm_optimization%% *}" = x"ARM"])
339
340 AS_IF([test x"$enable_rtcd" = x"yes"],[
341     AS_IF([test x"$rtcd_support" != x"no"],[
342         AC_DEFINE([OPUS_HAVE_RTCD], [1],
343             [Use run-time CPU capabilities detection])
344         OPUS_HAVE_RTCD=1
345         AC_SUBST(OPUS_HAVE_RTCD)
346     ])
347 ],[
348     rtcd_support="disabled"
349 ])
350
351 AC_ARG_ENABLE([assertions],
352     [AS_HELP_STRING([--enable-assertions],[enable additional software error checking])],,
353     [enable_assertions=no])
354
355 AS_IF([test "$enable_assertions" = "yes"], [
356   AC_DEFINE([ENABLE_ASSERTIONS], [1], [Assertions])
357 ])
358
359 AC_ARG_ENABLE([fuzzing],
360     [AS_HELP_STRING([--enable-fuzzing],[causes the encoder to make random decisions])],,
361     [enable_fuzzing=no])
362
363 AS_IF([test "$enable_fuzzing" = "yes"], [
364   AC_DEFINE([FUZZING], [1], [Fuzzing])
365 ])
366
367 AC_ARG_ENABLE([doc],
368     [AS_HELP_STRING([--disable-doc], [Do not build API documentation])],,
369     [enable_doc=yes])
370
371 AS_IF([test "$enable_doc" = "yes"], [
372   AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no])
373 ],[
374   HAVE_DOXYGEN=no
375 ])
376
377 AM_CONDITIONAL([HAVE_DOXYGEN], [test "$HAVE_DOXYGEN" = "yes"])
378
379 AC_ARG_ENABLE([extra-programs],
380     [AS_HELP_STRING([--disable-extra-programs], [Do not build extra programs (demo and tests)])],,
381     [enable_extra_programs=yes])
382
383 AM_CONDITIONAL([EXTRA_PROGRAMS], [test "$enable_extra_programs" = "yes"])
384
385
386 saved_CFLAGS="$CFLAGS"
387 CFLAGS="$CFLAGS -fvisibility=hidden"
388 AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
389 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
390     [ AC_MSG_RESULT([yes]) ],
391     [ AC_MSG_RESULT([no])
392       CFLAGS="$saved_CFLAGS"
393     ])
394
395 CFLAGS="$CFLAGS -W"
396
397 warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
398 saved_CFLAGS="$CFLAGS"
399 CFLAGS="$CFLAGS $warn_CFLAGS"
400 AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
401 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
402     [ AC_MSG_RESULT([yes]) ],
403     [ AC_MSG_RESULT([no])
404       CFLAGS="$saved_CFLAGS"
405     ])
406
407 saved_LIBS="$LIBS"
408 LIBS="$LIBS $LIBM"
409 AC_CHECK_FUNCS([lrintf])
410 AC_CHECK_FUNCS([lrint])
411 LIBS="$saved_LIBS"
412
413 AC_CHECK_FUNCS([__malloc_hook])
414
415 AC_SUBST([PC_BUILD])
416
417 AC_CONFIG_FILES([
418     Makefile
419     opus.pc
420     opus-uninstalled.pc
421     celt/arm/armopts.s
422     doc/Makefile
423     doc/Doxyfile
424 ])
425 AC_CONFIG_HEADERS([config.h])
426
427 AC_OUTPUT
428
429 AC_MSG_NOTICE([
430 ------------------------------------------------------------------------
431   $PACKAGE_NAME $PACKAGE_VERSION:  Automatic configuration OK.
432
433     Compiler support:
434
435       C99 var arrays: ................ ${has_var_arrays}
436       C99 lrintf: .................... ${ac_cv_func_lrintf}
437       Use alloca: .................... ${use_alloca}
438
439     General configuration:
440
441       Floating point support: ........ ${enable_float}
442       Fast float approximations: ..... ${enable_float_approx}
443       Fixed point debugging: ......... ${enable_fixed_point_debug}
444       Inline Assembly Optimizations: . ${inline_optimization}
445       External Assembly Optimizations: ${asm_optimization}
446       Run-time CPU detection: ........ ${rtcd_support}
447       Custom modes: .................. ${enable_custom_modes}
448       Assertion checking: ............ ${enable_assertions}
449       Fuzzing: ....................... ${enable_fuzzing}
450
451       API documentation: ............. ${enable_doc}
452       Extra programs: ................ ${enable_extra_programs}
453 ------------------------------------------------------------------------
454
455  Type "make; make install" to compile and install
456  Type "make check" to run the test suite
457 ])
458