Add ARMv4/ARMv5E macros.
[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([ if test -e package_version || ./update_version; then
8                            . ./package_version
9                            printf "$PACKAGE_VERSION"
10                        else
11                            printf "unknown"
12                        fi ]))
13
14 AC_INIT([opus],[CURRENT_VERSION],[opus@xiph.org])
15
16 AC_CONFIG_SRCDIR(src/opus_encoder.c)
17
18 dnl enable silent rules on automake 1.11 and later
19 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
20
21 # For libtool.
22 dnl Please update these for releases.
23 OPUS_LT_CURRENT=4
24 OPUS_LT_REVISION=0
25 OPUS_LT_AGE=4
26
27 AC_SUBST(OPUS_LT_CURRENT)
28 AC_SUBST(OPUS_LT_REVISION)
29 AC_SUBST(OPUS_LT_AGE)
30
31 AM_INIT_AUTOMAKE([no-define])
32 AM_MAINTAINER_MODE([enable])
33
34 AC_CANONICAL_HOST
35 AC_MINGW32
36 AM_PROG_LIBTOOL
37 AM_PROG_CC_C_O
38
39 AC_PROG_CC_C99
40 AC_C_CONST
41 AC_C_INLINE
42
43 #Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
44 #strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
45 AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
46   [ac_cv_c_restrict=no
47    # The order here caters to the fact that C++ does not require restrict.
48    for ac_kw in __restrict __restrict__ _Restrict restrict; do
49      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
50       [[typedef int * int_ptr;
51         int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
52         return ip[0];
53        }]],
54       [[int s[1];
55         int * $ac_kw t = s;
56         t[0] = 0;
57         return foo(t, (void *)0)]])],
58       [ac_cv_c_restrict=$ac_kw])
59      test "$ac_cv_c_restrict" != no && break
60    done
61   ])
62  AH_VERBATIM([restrict],
63 [/* Define to the equivalent of the C99 'restrict' keyword, or to
64    nothing if this is not supported.  Do not define if restrict is
65    supported directly.  */
66 #undef restrict
67 /* Work around a bug in Sun C++: it does not support _Restrict or
68    __restrict__, even though the corresponding Sun C compiler ends up with
69    "#define restrict _Restrict" or "#define restrict __restrict__" in the
70    previous line.  Perhaps some future version of Sun C++ will work with
71    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
72 #if defined __SUNPRO_CC && !defined __RESTRICT
73 # define _Restrict
74 # define __restrict__
75 #endif])
76  case $ac_cv_c_restrict in
77    restrict) ;;
78    no) AC_DEFINE([restrict], []) ;;
79    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
80  esac
81
82 AC_DEFINE([OPUS_BUILD], [], [This is a build of OPUS])
83
84 AC_MSG_CHECKING(for C99 variable-size arrays)
85 AC_TRY_COMPILE( [], [static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];],
86 [has_var_arrays=yes;AC_DEFINE([VAR_ARRAYS], [], [Use C99 variable-size arrays])
87 ],
88 has_var_arrays=no
89 )
90 AC_MSG_RESULT($has_var_arrays)
91
92 AC_CHECK_HEADERS([alloca.h getopt.h])
93 AC_MSG_CHECKING(for alloca)
94 AC_TRY_COMPILE( [#include <alloca.h>], [
95 int foo=10;
96 int *array = alloca(foo);
97 ],
98 [
99 has_alloca=yes;
100 if test x$has_var_arrays = "xno" ; then
101 AC_DEFINE([USE_ALLOCA], [], [Make use of alloca])
102 fi
103 ],
104 has_alloca=no
105 )
106 AC_MSG_RESULT($has_alloca)
107
108 AC_CHECK_FUNC(exp,[fp_libm_not_needed=yes;LIBM=],[fp_libm_not_needed=dunno])
109 if test x"$fp_libm_not_needed" = xdunno; then
110   AC_CHECK_LIB([m], [exp], [LIBS="-lm $LIBS"; LIBM="-lm"],[LIBM=])
111 fi
112 AC_SUBST([LIBM])
113
114 has_float_approx=no
115 #case "$host_cpu" in
116 #i[[3456]]86 | x86_64 | powerpc64 | powerpc32 | ia64)
117 #  has_float_approx=yes
118 #  ;;
119 #esac    
120
121 ac_enable_fixed="no";
122 ac_enable_float="yes";
123 AC_ARG_ENABLE(fixed-point, [  --enable-fixed-point       compile without floating point (for machines without a fast enough FPU)],
124 [if test "$enableval" = yes; then
125   ac_enable_fixed="yes";
126   ac_enable_float="no";
127   AC_DEFINE([FIXED_POINT], [1], [Compile as fixed-point (for machines without a fast enough FPU)])
128 fi])
129
130 ac_enable_fixed_debug="no"
131 AC_ARG_ENABLE(fixed-point-debug, [  --enable-fixed-point-debug debug fixed-point implementation],
132 [if test "$enableval" = yes; then
133   ac_enable_fixed_debug="yes"
134   AC_DEFINE([FIXED_DEBUG], , [Debug fixed-point implementation])
135 fi])
136
137 ac_enable_custom_modes="no"
138 AC_ARG_ENABLE(custom-modes, [  --enable-custom-modes      enable non-Opus modes, e.g. 44.1 kHz & 2^n frames],
139 [if test "$enableval" = yes; then
140   ac_enable_custom_modes="yes"
141   AC_DEFINE([CUSTOM_MODES], , [Custom modes])
142 fi])
143
144 float_approx=$has_float_approx
145 AC_ARG_ENABLE(float-approx, [  --enable-float-approx      enable fast approximations for floating point],
146     [ if test "$enableval" = yes; then
147     AC_WARN([Floating point approximations are not supported on all platforms.])
148     float_approx=yes
149     else
150     float_approx=no
151     fi], [ float_approx=$has_float_approx ])
152
153 if test "x${float_approx}" = "xyes"; then
154     AC_DEFINE([FLOAT_APPROX], , [Float approximations])
155 fi
156
157 cpu_arm=no
158 AC_ARG_ENABLE(asm,
159     AS_HELP_STRING([--disable-asm], [Disable assembly optimizations]),
160     [ ac_enable_asm=$enableval ], [ ac_enable_asm=yes] )
161 if test "x${ac_enable_asm}" = xyes ; then
162     asm_optimization="no asm for your platform, please send patches"
163     case $host_cpu in
164     arm*)
165         cpu_arm=yes
166         AS_GCC_INLINE_ASSEMBLY([asm_optimization="ARM"],
167             [asm_optimization="disabled"])
168         if test "x${asm_optimization}" = "xARM" ; then
169             AC_DEFINE([ARMv4_ASM], [], [Use generic ARMv4 asm optimizations])
170             AS_ASM_ARM_EDSP([ARMv5E_ASM=1],[ARMv5E_ASM=0])
171             if test "x${ARMv5E_ASM}" = "x1" ; then
172                 AC_DEFINE(ARMv5E_ASM, 1, [Use ARMv5E asm optimizations])
173                 asm_optimization="${asm_optimization} (EDSP)"
174             fi
175             AS_ASM_ARM_MEDIA([ARMv6_ASM=1],[ARMv6_ASM=0])
176             if test "x${ARMv6_ASM}" = "x1" ; then
177                 AC_DEFINE(ARMv6_ASM, 1, [Use ARMv6 asm optimizations])
178                 asm_optimization="${asm_optimization} (Media)"
179             fi
180         fi
181         ;;
182     esac
183 else
184     asm_optimization="disabled"
185 fi
186
187 ac_enable_assertions="no"
188 AC_ARG_ENABLE(assertions, [  --enable-assertions        enable additional software error checking],
189 [if test "$enableval" = yes; then
190   ac_enable_assertions="yes"
191   AC_DEFINE([ENABLE_ASSERTIONS], , [Assertions])
192 fi])
193
194 ac_enable_fuzzing="no"
195 AC_ARG_ENABLE(fuzzing, [  --enable-fuzzing           causes the encoder to make random decisions],
196 [if test "$enableval" = yes; then
197   ac_enable_fuzzing="yes"
198   AC_DEFINE([FUZZING], , [Fuzzing])
199 fi])
200
201 ac_enable_doc="yes"
202 AC_ARG_ENABLE([doc],
203   AS_HELP_STRING([--disable-doc], [Do not build API documentation]),
204                  [ac_enable_doc=$enableval])
205 AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no])
206 if test "$HAVE_DOXYGEN" != "yes" -o "$ac_enable_doc" != "yes"; then
207   HAVE_DOXYGEN="false"
208   ac_enable_doc="no"
209 fi
210 AM_CONDITIONAL(HAVE_DOXYGEN, [test $HAVE_DOXYGEN = yes])
211
212 saved_CFLAGS="$CFLAGS"
213 CFLAGS="$CFLAGS -fvisibility=hidden"
214 AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
215 AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
216       [ AC_MSG_RESULT([yes])
217         SYMBOL_VISIBILITY="-fvisibility=hidden" ],
218         AC_MSG_RESULT([no]))
219 CFLAGS="$saved_CFLAGS $SYMBOL_VISIBILITY"
220 AC_SUBST(SYMBOL_VISIBILITY)
221
222 CFLAGS="$CFLAGS -W"
223
224 warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
225 saved_CFLAGS="$CFLAGS"
226 CFLAGS="$CFLAGS $warn_CFLAGS"
227 AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
228 AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
229       [ AC_MSG_RESULT([yes])
230         EXTRA_WARNS=$warn_CFLAGS ],
231         AC_MSG_RESULT([no]))
232 CFLAGS="$saved_CFLAGS $EXTRA_WARNS"
233
234 AC_CHECK_FUNCS([lrintf])
235 AC_CHECK_FUNCS([lrint])
236 AC_CHECK_FUNCS([__malloc_hook])
237
238 AC_CHECK_SIZEOF(short)
239 AC_CHECK_SIZEOF(int)
240 AC_CHECK_SIZEOF(long)
241 AC_CHECK_SIZEOF(long long)
242
243 if test x$has_char16 = "xyes" ; then
244         case 1 in
245                 $ac_cv_sizeof_short) SIZE16="short";;
246                 $ac_cv_sizeof_int) SIZE16="int";;
247         esac
248 else
249         case 2 in
250                 $ac_cv_sizeof_short) SIZE16="short";;
251                 $ac_cv_sizeof_int) SIZE16="int";;
252         esac
253 fi
254
255 if test x$has_char16 = "xyes" ; then
256         case 2 in
257                 $ac_cv_sizeof_int) SIZE32="int";;
258                 $ac_cv_sizeof_long) SIZE32="long";;
259                 $ac_cv_sizeof_short) SIZE32="short";;
260         esac
261 else
262         case 4 in
263                 $ac_cv_sizeof_int) SIZE32="int";;
264                 $ac_cv_sizeof_long) SIZE32="long";;
265                 $ac_cv_sizeof_short) SIZE32="short";;
266         esac
267 fi
268
269 AC_SUBST(SIZE16)
270 AC_SUBST(SIZE32)
271
272 AM_CONDITIONAL([FIXED_POINT], [test x$ac_enable_fixed = xyes])
273 AM_CONDITIONAL([CUSTOM_MODES], [test x$ac_enable_custom_modes = xyes])
274
275 dnl subsitutions for the pkg-config files
276 if test x$ac_enable_float = xyes; then
277   PC_BUILD="floating-point"
278   PC_LIBM=$LIBM
279 else
280   PC_BUILD="fixed-point"
281   PC_LIBM=
282 fi
283 dnl opus_custom requires libm as well
284 if test x$ac_enable_custom_modes = xyes; then
285   PC_BUILD="${PC_BUILD}, custom modes"
286   PC_LIBM=$LIBM
287 fi
288 AC_SUBST([PC_BUILD])
289 AC_SUBST([PC_LIBM])
290
291
292 AC_CONFIG_FILES([Makefile opus.pc opus-uninstalled.pc
293                  doc/Makefile doc/Doxyfile])
294 AC_CONFIG_HEADERS([config.h])
295
296 AC_OUTPUT
297
298 AC_MSG_RESULT([
299 ------------------------------------------------------------------------
300   $PACKAGE_NAME $PACKAGE_VERSION:  Automatic configuration OK.
301
302     Compiler support:
303
304       C99 var arrays: ................ ${has_var_arrays}
305       C99 lrintf: .................... ${ac_cv_func_lrintf}
306       Alloca: ........................ ${has_alloca}
307     
308     General configuration:
309     
310       Floating point support: ........ ${ac_enable_float}
311       Fast float approximations: ..... ${float_approx}
312       Fixed point debugging: ......... ${ac_enable_fixed_debug}
313       Assembly optimization: ......... ${asm_optimization}
314       Custom modes: .................. ${ac_enable_custom_modes}
315       Assertion checking: ............ ${ac_enable_assertions}
316       Fuzzing: ....................... ${ac_enable_fuzzing}
317
318       API documentation: ............. ${ac_enable_doc}
319 ------------------------------------------------------------------------
320 ])
321
322 echo "Type \"make; make install\" to compile and install";
323 echo "Type \"make check\" to run the test suite";