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