• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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],[CURRENT_VERSION],[opus@xiph.org])
16
17AC_CONFIG_SRCDIR(src/opus_encoder.c)
18AC_CONFIG_MACRO_DIR([m4])
19
20dnl enable silent rules on automake 1.11 and later
21m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
22
23# For libtool.
24dnl Please update these for releases.
25OPUS_LT_CURRENT=8
26OPUS_LT_REVISION=0
27OPUS_LT_AGE=8
28
29AC_SUBST(OPUS_LT_CURRENT)
30AC_SUBST(OPUS_LT_REVISION)
31AC_SUBST(OPUS_LT_AGE)
32
33AM_INIT_AUTOMAKE([no-define])
34AM_MAINTAINER_MODE([enable])
35
36AC_CANONICAL_HOST
37AC_MINGW32
38AM_PROG_LIBTOOL
39AM_PROG_CC_C_O
40
41AC_PROG_CC_C99
42AC_C_CONST
43AC_C_INLINE
44
45AM_PROG_AS
46
47AC_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.
53AC_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
71AH_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
86case $ac_cv_c_restrict in
87   restrict) ;;
88   no) AC_DEFINE([restrict], []) ;;
89   *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
90esac
91
92AC_MSG_CHECKING(for C99 variable-size arrays)
93AC_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    ])
101AC_MSG_RESULT([$has_var_arrays])
102
103AS_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
117LT_LIB_M
118
119AC_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
124AS_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
133AM_CONDITIONAL([FIXED_POINT], [test "$enable_fixed_point" = "yes"])
134
135AC_ARG_ENABLE([fixed-point-debug],
136    [AS_HELP_STRING([--enable-fixed-point-debug], [debug fixed-point implementation])],,
137    [enable_fixed_point_debug=no])
138
139AS_IF([test "$enable_fixed_point_debug" = "yes"],[
140  AC_DEFINE([FIXED_DEBUG], [1], [Debug fixed-point implementation])
141])
142
143AC_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
148AM_CONDITIONAL([DISABLE_FLOAT_API], [test "$enable_float_api" = "no"])
149
150AS_IF([test "$enable_float_api" = "no"],[
151  AC_DEFINE([DISABLE_FLOAT_API], [1], [Do not build the float API])
152])
153
154AC_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
158AS_IF([test "$enable_custom_modes" = "yes"],[
159  AC_DEFINE([CUSTOM_MODES], [1], [Custom modes])
160  PC_BUILD="$PC_BUILD, custom modes"
161])
162
163AM_CONDITIONAL([CUSTOM_MODES], [test "$enable_custom_modes" = "yes"])
164
165has_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
172AC_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
180AS_IF([test "$enable_float_approx" = "yes"],[
181  AC_DEFINE([FLOAT_APPROX], [1], [Float approximations])
182])
183
184AC_ARG_ENABLE([asm],
185    [AS_HELP_STRING([--disable-asm], [Disable assembly optimizations])],,
186    [enable_asm=yes])
187
188AC_ARG_ENABLE([rtcd],
189    [AS_HELP_STRING([--disable-rtcd], [Disable run-time CPU capabilities detection])],,
190    [enable_rtcd=yes])
191
192AC_ARG_ENABLE([intrinsics],
193    [AS_HELP_STRING([--disable-intrinsics], [Disable intrinsics optimizations])],,
194    [enable_intrinsics=yes])
195
196rtcd_support=no
197cpu_arm=no
198cpu_x86=no
199
200AS_IF([test x"${enable_asm}" = x"yes"],[
201    inline_optimization="No inline ASM for your platform, please send patches"
202    case $host_cpu in
203      arm*)
204        dnl Currently we only have asm for fixed-point
205        AS_IF([test "$enable_float" != "yes"],[
206            cpu_arm=yes
207            AC_DEFINE([OPUS_ARM_ASM], [],  [Make use of ARM asm optimization])
208            AS_GCC_INLINE_ASSEMBLY(
209                [inline_optimization="ARM"],
210                [inline_optimization="disabled"]
211            )
212            AS_ASM_ARM_EDSP([OPUS_ARM_INLINE_EDSP=1],[OPUS_ARM_INLINE_EDSP=0])
213            AS_ASM_ARM_MEDIA([OPUS_ARM_INLINE_MEDIA=1],
214                [OPUS_ARM_INLINE_MEDIA=0])
215            AS_ASM_ARM_NEON([OPUS_ARM_INLINE_NEON=1],[OPUS_ARM_INLINE_NEON=0])
216            AS_IF([test x"$inline_optimization" = x"ARM"],[
217                AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],[true])
218                AC_DEFINE([OPUS_ARM_INLINE_ASM], 1,
219                    [Use generic ARMv4 inline asm optimizations])
220                AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"],[
221                    AC_DEFINE([OPUS_ARM_INLINE_EDSP], [1],
222                        [Use ARMv5E inline asm optimizations])
223                    inline_optimization="$inline_optimization (EDSP)"
224                ])
225                AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"],[
226                    AC_DEFINE([OPUS_ARM_INLINE_MEDIA], [1],
227                        [Use ARMv6 inline asm optimizations])
228                    inline_optimization="$inline_optimization (Media)"
229                ])
230                AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"],[
231                    AC_DEFINE([OPUS_ARM_INLINE_NEON], 1,
232                        [Use ARM NEON inline asm optimizations])
233                    inline_optimization="$inline_optimization (NEON)"
234                ])
235            ])
236            dnl We need Perl to translate RVCT-syntax asm to gas syntax.
237            AC_CHECK_PROG([HAVE_PERL], perl, yes, no)
238            AS_IF([test x"$HAVE_PERL" = x"yes"],[
239                AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],[true])
240                asm_optimization="ARM"
241                AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"], [
242                    OPUS_ARM_PRESUME_EDSP=1
243                    OPUS_ARM_MAY_HAVE_EDSP=1
244                ],
245                [
246                    OPUS_ARM_PRESUME_EDSP=0
247                    OPUS_ARM_MAY_HAVE_EDSP=0
248                ])
249                AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"], [
250                    OPUS_ARM_PRESUME_MEDIA=1
251                    OPUS_ARM_MAY_HAVE_MEDIA=1
252                ],
253                [
254                    OPUS_ARM_PRESUME_MEDIA=0
255                    OPUS_ARM_MAY_HAVE_MEDIA=0
256                ])
257                AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"], [
258                    OPUS_ARM_PRESUME_NEON=1
259                    OPUS_ARM_MAY_HAVE_NEON=1
260                ],
261                [
262                    OPUS_ARM_PRESUME_NEON=0
263                    OPUS_ARM_MAY_HAVE_NEON=0
264                ])
265                AS_IF([test x"$enable_rtcd" = x"yes"],[
266                    AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" != x"1"],[
267                        AC_MSG_NOTICE(
268                          [Trying to force-enable armv5e EDSP instructions...])
269                        AS_ASM_ARM_EDSP_FORCE([OPUS_ARM_MAY_HAVE_EDSP=1])
270                    ])
271                    AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" != x"1"],[
272                        AC_MSG_NOTICE(
273                          [Trying to force-enable ARMv6 media instructions...])
274                        AS_ASM_ARM_MEDIA_FORCE([OPUS_ARM_MAY_HAVE_MEDIA=1])
275                    ])
276                    AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" != x"1"],[
277                        AC_MSG_NOTICE(
278                          [Trying to force-enable NEON instructions...])
279                        AS_ASM_ARM_NEON_FORCE([OPUS_ARM_MAY_HAVE_NEON=1])
280                    ])
281                ])
282                rtcd_support=
283                AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" = x"1"],[
284                    AC_DEFINE(OPUS_ARM_MAY_HAVE_EDSP, 1,
285                        [Define if assembler supports EDSP instructions])
286                    AS_IF([test x"$OPUS_ARM_PRESUME_EDSP" = x"1"],[
287                        AC_DEFINE(OPUS_ARM_PRESUME_EDSP, 1,
288                          [Define if binary requires EDSP instruction support])
289                        asm_optimization="$asm_optimization (EDSP)"
290                    ],
291                        [rtcd_support="$rtcd_support (EDSP)"]
292                    )
293                ])
294                AC_SUBST(OPUS_ARM_MAY_HAVE_EDSP)
295                AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" = x"1"],[
296                    AC_DEFINE(OPUS_ARM_MAY_HAVE_MEDIA, 1,
297                      [Define if assembler supports ARMv6 media instructions])
298                    AS_IF([test x"$OPUS_ARM_PRESUME_MEDIA" = x"1"],[
299                        AC_DEFINE(OPUS_ARM_PRESUME_MEDIA, 1,
300                          [Define if binary requires ARMv6 media instruction support])
301                        asm_optimization="$asm_optimization (Media)"
302                    ],
303                        [rtcd_support="$rtcd_support (Media)"]
304                    )
305                ])
306                AC_SUBST(OPUS_ARM_MAY_HAVE_MEDIA)
307                AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" = x"1"],[
308                    AC_DEFINE(OPUS_ARM_MAY_HAVE_NEON, 1,
309                      [Define if compiler supports NEON instructions])
310                    AS_IF([test x"$OPUS_ARM_PRESUME_NEON" = x"1"], [
311                        AC_DEFINE(OPUS_ARM_PRESUME_NEON, 1,
312                          [Define if binary requires NEON instruction support])
313                        asm_optimization="$asm_optimization (NEON)"
314                    ],
315                        [rtcd_support="$rtcd_support (NEON)"]
316                    )
317                ])
318                AC_SUBST(OPUS_ARM_MAY_HAVE_NEON)
319                dnl Make sure turning on RTCD gets us at least one
320                dnl instruction set.
321                AS_IF([test x"$rtcd_support" != x""],
322                    [rtcd_support=ARM"$rtcd_support"],
323                    [rtcd_support="no"]
324                )
325                AC_MSG_CHECKING([for apple style tools])
326                AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
327#ifndef __APPLE__
328#error 1
329#endif],[])],
330                    [AC_MSG_RESULT([yes]); ARM2GNU_PARAMS="--apple"],
331                    [AC_MSG_RESULT([no]); ARM2GNU_PARAMS=""])
332                AC_SUBST(ARM2GNU_PARAMS)
333            ],
334            [
335                AC_MSG_WARN(
336                  [*** ARM assembly requires perl -- disabling optimizations])
337                asm_optimization="(missing perl dependency for ARM)"
338            ])
339        ])
340        ;;
341    esac
342],[
343   inline_optimization="disabled"
344   asm_optimization="disabled"
345])
346
347AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],
348    [test x"${inline_optimization%% *}" = x"ARM"])
349AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],
350    [test x"${asm_optimization%% *}" = x"ARM"])
351
352AM_CONDITIONAL([HAVE_SSE], [false])
353AM_CONDITIONAL([HAVE_SSE2], [false])
354AM_CONDITIONAL([HAVE_SSE4_1], [false])
355AM_CONDITIONAL([HAVE_AVX], [false])
356
357m4_define([DEFAULT_X86_SSE_CFLAGS], [-msse])
358m4_define([DEFAULT_X86_SSE2_CFLAGS], [-msse2])
359m4_define([DEFAULT_X86_SSE4_1_CFLAGS], [-msse4.1])
360m4_define([DEFAULT_X86_AVX_CFLAGS], [-mavx])
361m4_define([DEFAULT_ARM_NEON_INTR_CFLAGS], [-mfpu=neon])
362# With GCC on ARM32 softfp architectures (e.g. Android, or older Ubuntu) you need to specify
363# -mfloat-abi=softfp for -mfpu=neon to work.  However, on ARM32 hardfp architectures (e.g. newer Ubuntu),
364# this option will break things.
365
366# As a heuristic, if host matches arm*eabi* but not arm*hf*, it's probably soft-float.
367m4_define([DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS], [-mfpu=neon -mfloat-abi=softfp])
368
369AS_CASE([$host],
370        [arm*hf*], [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_INTR_CFLAGS")],
371        [arm*eabi*], [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS")],
372        [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_INTR_CFLAGS")])
373
374AC_ARG_VAR([X86_SSE_CFLAGS], [C compiler flags to compile SSE intrinsics @<:@default=]DEFAULT_X86_SSE_CFLAGS[@:>@])
375AC_ARG_VAR([X86_SSE2_CFLAGS], [C compiler flags to compile SSE2 intrinsics @<:@default=]DEFAULT_X86_SSE2_CFLAGS[@:>@])
376AC_ARG_VAR([X86_SSE4_1_CFLAGS], [C compiler flags to compile SSE4.1 intrinsics @<:@default=]DEFAULT_X86_SSE4_1_CFLAGS[@:>@])
377AC_ARG_VAR([X86_AVX_CFLAGS], [C compiler flags to compile AVX intrinsics @<:@default=]DEFAULT_X86_AVX_CFLAGS[@:>@])
378AC_ARG_VAR([ARM_NEON_INTR_CFLAGS], [C compiler flags to compile ARM NEON intrinsics @<:@default=]DEFAULT_ARM_NEON_INTR_CFLAGS / DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS[@:>@])
379
380AS_VAR_SET_IF([X86_SSE_CFLAGS], [], [AS_VAR_SET([X86_SSE_CFLAGS], "DEFAULT_X86_SSE_CFLAGS")])
381AS_VAR_SET_IF([X86_SSE2_CFLAGS], [], [AS_VAR_SET([X86_SSE2_CFLAGS], "DEFAULT_X86_SSE2_CFLAGS")])
382AS_VAR_SET_IF([X86_SSE4_1_CFLAGS], [], [AS_VAR_SET([X86_SSE4_1_CFLAGS], "DEFAULT_X86_SSE4_1_CFLAGS")])
383AS_VAR_SET_IF([X86_AVX_CFLAGS], [], [AS_VAR_SET([X86_AVX_CFLAGS], "DEFAULT_X86_AVX_CFLAGS")])
384AS_VAR_SET_IF([ARM_NEON_INTR_CFLAGS], [], [AS_VAR_SET([ARM_NEON_INTR_CFLAGS], ["$RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS"])])
385
386AC_DEFUN([OPUS_PATH_NE10],
387   [
388      AC_ARG_WITH(NE10,
389                  AC_HELP_STRING([--with-NE10=PFX],[Prefix where libNE10 is installed (optional)]),
390                  NE10_prefix="$withval", NE10_prefix="")
391      AC_ARG_WITH(NE10-libraries,
392                  AC_HELP_STRING([--with-NE10-libraries=DIR],
393                        [Directory where libNE10 library is installed (optional)]),
394                  NE10_libraries="$withval", NE10_libraries="")
395      AC_ARG_WITH(NE10-includes,
396                  AC_HELP_STRING([--with-NE10-includes=DIR],
397                                 [Directory where libNE10 header files are installed (optional)]),
398                  NE10_includes="$withval", NE10_includes="")
399
400      if test "x$NE10_libraries" != "x" ; then
401         NE10_LIBS="-L$NE10_libraries"
402      elif test "x$NE10_prefix" = "xno" || test "x$NE10_prefix" = "xyes" ; then
403         NE10_LIBS=""
404      elif test "x$NE10_prefix" != "x" ; then
405         NE10_LIBS="-L$NE10_prefix/lib"
406      elif test "x$prefix" != "xNONE" ; then
407         NE10_LIBS="-L$prefix/lib"
408      fi
409
410      if test "x$NE10_prefix" != "xno" ; then
411         NE10_LIBS="$NE10_LIBS -lNE10"
412      fi
413
414      if test "x$NE10_includes" != "x" ; then
415         NE10_CFLAGS="-I$NE10_includes"
416      elif test "x$NE10_prefix" = "xno" || test "x$NE10_prefix" = "xyes" ; then
417         NE10_CFLAGS=""
418      elif test "x$NE10_prefix" != "x" ; then
419         NE10_CFLAGS="-I$NE10_prefix/include"
420      elif test "x$prefix" != "xNONE"; then
421         NE10_CFLAGS="-I$prefix/include"
422      fi
423
424      AC_MSG_CHECKING(for NE10)
425      save_CFLAGS="$CFLAGS"; CFLAGS="$CFLAGS $NE10_CFLAGS"
426      save_LIBS="$LIBS"; LIBS="$LIBS $NE10_LIBS $LIBM"
427      AC_LINK_IFELSE(
428         [
429            AC_LANG_PROGRAM(
430               [[#include <NE10_dsp.h>
431               ]],
432               [[
433                  ne10_fft_cfg_float32_t cfg;
434                  cfg = ne10_fft_alloc_c2c_float32_neon(480);
435               ]]
436            )
437         ],[
438            HAVE_ARM_NE10=1
439            AC_MSG_RESULT([yes])
440         ],[
441            HAVE_ARM_NE10=0
442            AC_MSG_RESULT([no])
443            NE10_CFLAGS=""
444            NE10_LIBS=""
445         ]
446      )
447      CFLAGS="$save_CFLAGS"; LIBS="$save_LIBS"
448      #Now we know if libNE10 is installed or not
449      AS_IF([test x"$HAVE_ARM_NE10" = x"1"],
450         [
451            AC_DEFINE([HAVE_ARM_NE10], 1, [NE10 library is installed on host. Make sure it is on target!])
452            AC_SUBST(HAVE_ARM_NE10)
453            AC_SUBST(NE10_CFLAGS)
454            AC_SUBST(NE10_LIBS)
455         ]
456      )
457   ]
458)
459
460AS_IF([test x"$enable_intrinsics" = x"yes"],[
461   intrinsics_support=""
462   AS_CASE([$host_cpu],
463   [arm*|aarch64*],
464   [
465      cpu_arm=yes
466      OPUS_CHECK_INTRINSICS(
467         [ARM Neon],
468         [$ARM_NEON_INTR_CFLAGS],
469         [OPUS_ARM_MAY_HAVE_NEON_INTR],
470         [OPUS_ARM_PRESUME_NEON_INTR],
471         [[#include <arm_neon.h>
472         ]],
473         [[
474            static float32x4_t A0, A1, SUMM;
475            SUMM = vmlaq_f32(SUMM, A0, A1);
476            return (int)vgetq_lane_f32(SUMM, 0);
477         ]]
478      )
479      AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1" && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
480          [
481             OPUS_ARM_NEON_INTR_CFLAGS="$ARM_NEON_INTR_CFLAGS"
482             AC_SUBST([OPUS_ARM_NEON_INTR_CFLAGS])
483          ]
484      )
485
486      AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1"],
487      [
488         AC_DEFINE([OPUS_ARM_MAY_HAVE_NEON_INTR], 1, [Compiler supports ARMv7/Aarch64 Neon Intrinsics])
489         intrinsics_support="$intrinsics_support (NEON)"
490
491         AS_IF([test x"$enable_rtcd" != x"no" && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
492            [AS_IF([test x"$rtcd_support" = x"no"],
493               [rtcd_support="ARM (NEON Intrinsics)"],
494               [rtcd_support="$rtcd_support (NEON Intrinsics)"])])
495
496         AS_IF([test x"$OPUS_ARM_PRESUME_NEON_INTR" = x"1"],
497            [AC_DEFINE([OPUS_ARM_PRESUME_NEON_INTR], 1, [Define if binary requires NEON intrinsics support])])
498
499         OPUS_PATH_NE10()
500         AS_IF([test x"$NE10_LIBS" != x""],
501         [
502              intrinsics_support="$intrinsics_support (NE10)"
503              AS_IF([test x"enable_rtcd" != x"" \
504               && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
505                 [rtcd_support="$rtcd_support (NE10)"])
506         ])
507
508         OPUS_CHECK_INTRINSICS(
509            [Aarch64 Neon],
510            [$ARM_NEON_INTR_CFLAGS],
511            [OPUS_ARM_MAY_HAVE_AARCH64_NEON_INTR],
512            [OPUS_ARM_PRESUME_AARCH64_NEON_INTR],
513            [[#include <arm_neon.h>
514            ]],
515            [[
516               static int32_t IN;
517               static int16_t OUT;
518               OUT = vqmovns_s32(IN);
519            ]]
520         )
521
522         AS_IF([test x"$OPUS_ARM_PRESUME_AARCH64_NEON_INTR" = x"1"],
523         [
524            AC_DEFINE([OPUS_ARM_PRESUME_AARCH64_NEON_INTR], 1, [Define if binary requires Aarch64 Neon Intrinsics])
525            intrinsics_support="$intrinsics_support (NEON [Aarch64])"
526         ])
527
528         AS_IF([test x"$intrinsics_support" = x""],
529            [intrinsics_support=no],
530            [intrinsics_support="ARM$intrinsics_support"])
531      ],
532      [
533         AC_MSG_WARN([Compiler does not support ARM intrinsics])
534         intrinsics_support=no
535      ])
536   ],
537   [i?86|x86_64],
538   [
539      cpu_x86=yes
540      OPUS_CHECK_INTRINSICS(
541         [SSE],
542         [$X86_SSE_CFLAGS],
543         [OPUS_X86_MAY_HAVE_SSE],
544         [OPUS_X86_PRESUME_SSE],
545         [[#include <xmmintrin.h>
546           #include <time.h>
547         ]],
548         [[
549             __m128 mtest;
550             mtest = _mm_set1_ps((float)time(NULL));
551             mtest = _mm_mul_ps(mtest, mtest);
552             return _mm_cvtss_si32(mtest);
553         ]]
554      )
555      AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE" = x"1" && test x"$OPUS_X86_PRESUME_SSE" != x"1"],
556          [
557             OPUS_X86_SSE_CFLAGS="$X86_SSE_CFLAGS"
558             AC_SUBST([OPUS_X86_SSE_CFLAGS])
559          ]
560      )
561      OPUS_CHECK_INTRINSICS(
562         [SSE2],
563         [$X86_SSE2_CFLAGS],
564         [OPUS_X86_MAY_HAVE_SSE2],
565         [OPUS_X86_PRESUME_SSE2],
566         [[#include <emmintrin.h>
567           #include <time.h>
568         ]],
569         [[
570            __m128i mtest;
571            mtest = _mm_set1_epi32((int)time(NULL));
572            mtest = _mm_mul_epu32(mtest, mtest);
573            return _mm_cvtsi128_si32(mtest);
574         ]]
575      )
576      AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1" && test x"$OPUS_X86_PRESUME_SSE2" != x"1"],
577          [
578             OPUS_X86_SSE2_CFLAGS="$X86_SSE2_CFLAGS"
579             AC_SUBST([OPUS_X86_SSE2_CFLAGS])
580          ]
581      )
582      OPUS_CHECK_INTRINSICS(
583         [SSE4.1],
584         [$X86_SSE4_1_CFLAGS],
585         [OPUS_X86_MAY_HAVE_SSE4_1],
586         [OPUS_X86_PRESUME_SSE4_1],
587         [[#include <smmintrin.h>
588           #include <time.h>
589         ]],
590         [[
591            __m128i mtest;
592            mtest = _mm_set1_epi32((int)time(NULL));
593            mtest = _mm_mul_epi32(mtest, mtest);
594            return _mm_cvtsi128_si32(mtest);
595         ]]
596      )
597      AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1" && test x"$OPUS_X86_PRESUME_SSE4_1" != x"1"],
598          [
599             OPUS_X86_SSE4_1_CFLAGS="$X86_SSE4_1_CFLAGS"
600             AC_SUBST([OPUS_X86_SSE4_1_CFLAGS])
601          ]
602      )
603      OPUS_CHECK_INTRINSICS(
604         [AVX],
605         [$X86_AVX_CFLAGS],
606         [OPUS_X86_MAY_HAVE_AVX],
607         [OPUS_X86_PRESUME_AVX],
608         [[#include <immintrin.h>
609           #include <time.h>
610         ]],
611         [[
612             __m256 mtest;
613             mtest = _mm256_set1_ps((float)time(NULL));
614             mtest = _mm256_addsub_ps(mtest, mtest);
615             return _mm_cvtss_si32(_mm256_extractf128_ps(mtest, 0));
616         ]]
617      )
618      AS_IF([test x"$OPUS_X86_MAY_HAVE_AVX" = x"1" && test x"$OPUS_X86_PRESUME_AVX" != x"1"],
619          [
620             OPUS_X86_AVX_CFLAGS="$X86_AVX_CFLAGS"
621             AC_SUBST([OPUS_X86_AVX_CFLAGS])
622          ]
623      )
624         AS_IF([test x"$rtcd_support" = x"no"], [rtcd_support=""])
625         AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE" = x"1"],
626         [
627            AC_DEFINE([OPUS_X86_MAY_HAVE_SSE], 1, [Compiler supports X86 SSE Intrinsics])
628            intrinsics_support="$intrinsics_support SSE"
629
630            AS_IF([test x"$OPUS_X86_PRESUME_SSE" = x"1"],
631               [AC_DEFINE([OPUS_X86_PRESUME_SSE], 1, [Define if binary requires SSE intrinsics support])],
632               [rtcd_support="$rtcd_support SSE"])
633         ],
634         [
635            AC_MSG_WARN([Compiler does not support SSE intrinsics])
636         ])
637
638         AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1"],
639         [
640            AC_DEFINE([OPUS_X86_MAY_HAVE_SSE2], 1, [Compiler supports X86 SSE2 Intrinsics])
641            intrinsics_support="$intrinsics_support SSE2"
642
643            AS_IF([test x"$OPUS_X86_PRESUME_SSE2" = x"1"],
644               [AC_DEFINE([OPUS_X86_PRESUME_SSE2], 1, [Define if binary requires SSE2 intrinsics support])],
645               [rtcd_support="$rtcd_support SSE2"])
646         ],
647         [
648            AC_MSG_WARN([Compiler does not support SSE2 intrinsics])
649         ])
650
651         AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1"],
652         [
653            AC_DEFINE([OPUS_X86_MAY_HAVE_SSE4_1], 1, [Compiler supports X86 SSE4.1 Intrinsics])
654            intrinsics_support="$intrinsics_support SSE4.1"
655
656            AS_IF([test x"$OPUS_X86_PRESUME_SSE4_1" = x"1"],
657               [AC_DEFINE([OPUS_X86_PRESUME_SSE4_1], 1, [Define if binary requires SSE4.1 intrinsics support])],
658               [rtcd_support="$rtcd_support SSE4.1"])
659         ],
660         [
661            AC_MSG_WARN([Compiler does not support SSE4.1 intrinsics])
662         ])
663         AS_IF([test x"$OPUS_X86_MAY_HAVE_AVX" = x"1"],
664         [
665            AC_DEFINE([OPUS_X86_MAY_HAVE_AVX], 1, [Compiler supports X86 AVX Intrinsics])
666            intrinsics_support="$intrinsics_support AVX"
667
668            AS_IF([test x"$OPUS_X86_PRESUME_AVX" = x"1"],
669               [AC_DEFINE([OPUS_X86_PRESUME_AVX], 1, [Define if binary requires AVX intrinsics support])],
670               [rtcd_support="$rtcd_support AVX"])
671         ],
672         [
673            AC_MSG_WARN([Compiler does not support AVX intrinsics])
674         ])
675
676         AS_IF([test x"$intrinsics_support" = x""],
677            [intrinsics_support=no],
678            [intrinsics_support="x86$intrinsics_support"]
679         )
680         AS_IF([test x"$rtcd_support" = x""],
681            [rtcd_support=no],
682            [rtcd_support="x86$rtcd_support"],
683        )
684
685    AS_IF([test x"$enable_rtcd" = x"yes" && test x"$rtcd_support" != x""],[
686            get_cpuid_by_asm="no"
687            AC_MSG_CHECKING([How to get X86 CPU Info])
688            AC_LINK_IFELSE([AC_LANG_PROGRAM([[
689                 #include <stdio.h>
690            ]],[[
691                 unsigned int CPUInfo0;
692                 unsigned int CPUInfo1;
693                 unsigned int CPUInfo2;
694                 unsigned int CPUInfo3;
695                 unsigned int InfoType;
696                #if defined(__i386__) && defined(__PIC__)
697                 __asm__ __volatile__ (
698                 "xchg %%ebx, %1\n"
699                 "cpuid\n"
700                 "xchg %%ebx, %1\n":
701                 "=a" (CPUInfo0),
702                 "=r" (CPUInfo1),
703                 "=c" (CPUInfo2),
704                 "=d" (CPUInfo3) :
705                 "a" (InfoType), "c" (0)
706                );
707               #else
708                 __asm__ __volatile__ (
709                 "cpuid":
710                 "=a" (CPUInfo0),
711                 "=b" (CPUInfo1),
712                 "=c" (CPUInfo2),
713                 "=d" (CPUInfo3) :
714                 "a" (InfoType), "c" (0)
715                );
716               #endif
717            ]])],
718            [get_cpuid_by_asm="yes"
719             AC_MSG_RESULT([Inline Assembly])
720                 AC_DEFINE([CPU_INFO_BY_ASM], [1], [Get CPU Info by asm method])],
721             [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
722                 #include <cpuid.h>
723            ]],[[
724                 unsigned int CPUInfo0;
725                 unsigned int CPUInfo1;
726                 unsigned int CPUInfo2;
727                 unsigned int CPUInfo3;
728                 unsigned int InfoType;
729                 __get_cpuid_count(InfoType, 0, &CPUInfo0, &CPUInfo1, &CPUInfo2, &CPUInfo3);
730            ]])],
731            [AC_MSG_RESULT([C method])
732                 AC_DEFINE([CPU_INFO_BY_C], [1], [Get CPU Info by c method])],
733            [AC_MSG_ERROR([no supported Get CPU Info method, please disable run-time CPU capabilities detection or intrinsics])])])])
734   ],
735   [
736      AC_MSG_WARN([No intrinsics support for your architecture])
737      intrinsics_support="no"
738   ])
739],
740[
741   intrinsics_support="no"
742])
743
744AM_CONDITIONAL([CPU_ARM], [test "$cpu_arm" = "yes"])
745AM_CONDITIONAL([HAVE_ARM_NEON_INTR],
746    [test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1"])
747AM_CONDITIONAL([HAVE_ARM_NE10],
748    [test x"$HAVE_ARM_NE10" = x"1"])
749AM_CONDITIONAL([CPU_X86], [test "$cpu_x86" = "yes"])
750AM_CONDITIONAL([HAVE_SSE],
751    [test x"$OPUS_X86_MAY_HAVE_SSE" = x"1"])
752AM_CONDITIONAL([HAVE_SSE2],
753    [test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1"])
754AM_CONDITIONAL([HAVE_SSE4_1],
755    [test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1"])
756AM_CONDITIONAL([HAVE_AVX],
757    [test x"$OPUS_X86_MAY_HAVE_AVX" = x"1"])
758
759AM_CONDITIONAL([HAVE_RTCD],
760 [test x"$enable_rtcd" = x"yes" -a x"$rtcd_support" != x"no"])
761AS_IF([test x"$enable_rtcd" = x"yes"],[
762    AS_IF([test x"$rtcd_support" != x"no"],[
763        AC_DEFINE([OPUS_HAVE_RTCD], [1],
764            [Use run-time CPU capabilities detection])
765        OPUS_HAVE_RTCD=1
766        AC_SUBST(OPUS_HAVE_RTCD)
767    ])
768],[
769    rtcd_support="disabled"
770])
771
772AC_ARG_ENABLE([assertions],
773    [AS_HELP_STRING([--enable-assertions],[enable additional software error checking])],,
774    [enable_assertions=no])
775
776AS_IF([test "$enable_assertions" = "yes"], [
777  AC_DEFINE([ENABLE_ASSERTIONS], [1], [Assertions])
778])
779
780AC_ARG_ENABLE([hardening],
781    [AS_HELP_STRING([--disable-hardening],[disable run-time checks that are cheap and safe for use in production])],,
782    [enable_hardening=yes])
783
784AS_IF([test "$enable_hardening" = "yes"], [
785  AC_DEFINE([ENABLE_HARDENING], [1], [Hardening])
786])
787
788AC_ARG_ENABLE([fuzzing],
789	      [AS_HELP_STRING([--enable-fuzzing],[causes the encoder to make random decisions (do not use in production)])],,
790    [enable_fuzzing=no])
791
792AS_IF([test "$enable_fuzzing" = "yes"], [
793  AC_DEFINE([FUZZING], [1], [Fuzzing])
794])
795
796AC_ARG_ENABLE([check-asm],
797    [AS_HELP_STRING([--enable-check-asm],
798                    [enable bit-exactness checks between optimized and c implementations])],,
799    [enable_check_asm=no])
800
801AS_IF([test "$enable_check_asm" = "yes"], [
802  AC_DEFINE([OPUS_CHECK_ASM], [1], [Run bit-exactness checks between optimized and c implementations])
803])
804
805AC_ARG_ENABLE([doc],
806    [AS_HELP_STRING([--disable-doc], [Do not build API documentation])],,
807    [enable_doc=yes])
808
809AS_IF([test "$enable_doc" = "yes"], [
810  AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no])
811  AC_CHECK_PROG(HAVE_DOT, [dot], [yes], [no])
812],[
813  HAVE_DOXYGEN=no
814])
815
816AM_CONDITIONAL([HAVE_DOXYGEN], [test "$HAVE_DOXYGEN" = "yes"])
817
818AC_ARG_ENABLE([extra-programs],
819    [AS_HELP_STRING([--disable-extra-programs], [Do not build extra programs (demo and tests)])],,
820    [enable_extra_programs=yes])
821
822AM_CONDITIONAL([EXTRA_PROGRAMS], [test "$enable_extra_programs" = "yes"])
823
824
825AC_ARG_ENABLE([rfc8251],
826	      AS_HELP_STRING([--disable-rfc8251], [Disable bitstream fixes from RFC 8251]),,
827  [enable_rfc8251=yes])
828
829AS_IF([test "$enable_rfc8251" = "no"], [
830       AC_DEFINE([DISABLE_UPDATE_DRAFT], [1], [Disable bitstream fixes from RFC 8251])
831])
832
833
834saved_CFLAGS="$CFLAGS"
835CFLAGS="$CFLAGS -fvisibility=hidden"
836AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
837AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
838    [ AC_MSG_RESULT([yes]) ],
839    [ AC_MSG_RESULT([no])
840      CFLAGS="$saved_CFLAGS"
841    ])
842
843on_x86=no
844case "$host_cpu" in
845i[[3456]]86 | x86_64)
846  on_x86=yes
847  ;;
848esac
849
850on_windows=no
851case $host in
852*cygwin*|*mingw*)
853  on_windows=yes
854  ;;
855esac
856
857dnl Enable stack-protector-all only on x86 where it's well supported.
858dnl on some platforms it causes crashes. Hopefully the OS's default's
859dnl include this on platforms that work but have been missed here.
860AC_ARG_ENABLE([stack-protector],
861    [AS_HELP_STRING([--disable-stack-protector],[Disable compiler stack hardening])],,
862    [
863      AS_IF([test "$ac_cv_c_compiler_gnu" = "yes" && test "$on_x86" = "yes" && test "$on_windows" = "no"],
864            [enable_stack_protector=yes],[enable_stack_protector=no])
865    ])
866
867AS_IF([test "$enable_stack_protector" = "yes"],
868 [
869  saved_CFLAGS="$CFLAGS"
870  CFLAGS="$CFLAGS -fstack-protector-strong"
871  AC_MSG_CHECKING([if ${CC} supports -fstack-protector-strong])
872  AC_LINK_IFELSE([AC_LANG_PROGRAM([],[[char foo;]])],
873    [ AC_MSG_RESULT([yes]) ],
874    [
875      AC_MSG_RESULT([no])
876      enable_stack_protector=no
877      CFLAGS="$saved_CFLAGS"
878    ])
879 ])
880
881AS_IF([test x$ac_cv_c_compiler_gnu = xyes],
882    [AX_ADD_FORTIFY_SOURCE]
883)
884
885CFLAGS="$CFLAGS -W"
886
887warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
888saved_CFLAGS="$CFLAGS"
889CFLAGS="$CFLAGS $warn_CFLAGS"
890AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
891AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
892    [ AC_MSG_RESULT([yes]) ],
893    [ AC_MSG_RESULT([no])
894      CFLAGS="$saved_CFLAGS"
895    ])
896
897saved_LIBS="$LIBS"
898LIBS="$LIBS $LIBM"
899AC_CHECK_FUNCS([lrintf])
900AC_CHECK_FUNCS([lrint])
901LIBS="$saved_LIBS"
902
903AC_CHECK_FUNCS([__malloc_hook])
904
905AC_SUBST([PC_BUILD])
906
907AC_CONFIG_FILES([
908    Makefile
909    opus.pc
910    opus-uninstalled.pc
911    celt/arm/armopts.s
912    doc/Makefile
913    doc/Doxyfile
914])
915AC_CONFIG_HEADERS([config.h])
916
917AC_OUTPUT
918
919AC_MSG_NOTICE([
920------------------------------------------------------------------------
921  $PACKAGE_NAME $PACKAGE_VERSION:  Automatic configuration OK.
922
923    Compiler support:
924
925      C99 var arrays: ................ ${has_var_arrays}
926      C99 lrintf: .................... ${ac_cv_func_lrintf}
927      Use alloca: .................... ${use_alloca}
928
929    General configuration:
930
931      Floating point support: ........ ${enable_float}
932      Fast float approximations: ..... ${enable_float_approx}
933      Fixed point debugging: ......... ${enable_fixed_point_debug}
934      Inline Assembly Optimizations: . ${inline_optimization}
935      External Assembly Optimizations: ${asm_optimization}
936      Intrinsics Optimizations: ...... ${intrinsics_support}
937      Run-time CPU detection: ........ ${rtcd_support}
938      Custom modes: .................. ${enable_custom_modes}
939      Assertion checking: ............ ${enable_assertions}
940      Hardening: ..................... ${enable_hardening}
941      Fuzzing: ....................... ${enable_fuzzing}
942      Check ASM: ..................... ${enable_check_asm}
943
944      API documentation: ............. ${enable_doc}
945      Extra programs: ................ ${enable_extra_programs}
946------------------------------------------------------------------------
947
948 Type "make; make install" to compile and install
949 Type "make check" to run the test suite
950])
951
952