configure.ac 124 KB
Newer Older
1
dnl Autoconf settings for vlc
2

3
AC_COPYRIGHT([Copyright 1999-2017 VLC authors and VideoLAN])
4

5 6 7
AC_INIT(vlc, 3.0.0-git)
VERSION_MAJOR=3
VERSION_MINOR=0
8 9
VERSION_REVISION=0
VERSION_EXTRA=0
10
VERSION_DEV=git
11

12 13
PKGDIR="vlc"
AC_SUBST(PKGDIR)
14

15
CONFIGURE_LINE="`echo "$0 $ac_configure_args" | sed -e 's/\\\/\\\\\\\/g'`"
16
CODENAME="Vetinari"
17
COPYRIGHT_YEARS="1996-2017"
18

19
AC_CONFIG_SRCDIR(src/libvlc.c)
20
AC_CONFIG_AUX_DIR(autotools)
21
AC_CONFIG_MACRO_DIR(m4)
22
AC_CONFIG_LIBOBJ_DIR(compat)
23
AC_CANONICAL_BUILD
24
AC_CANONICAL_HOST
25
AC_PRESERVE_HELP_ORDER
26

27
AM_INIT_AUTOMAKE(tar-ustar color-tests foreign)
28
AC_CONFIG_HEADERS([config.h])
29

30
AM_SILENT_RULES([yes])
31
AM_MAINTAINER_MODE([enable])
32

33 34 35 36 37 38 39 40 41 42
dnl
dnl Directories
dnl
dnl vlcincludedir="\${includedir}/\${PKGDIR}"
dnl AC_SUBST(vlcincludedir)
vlcdatadir="\${datadir}/\${PKGDIR}"
AC_SUBST(vlcdatadir)
vlclibdir="\${libdir}/\${PKGDIR}"
AC_SUBST(vlclibdir)

Sam Hocevar's avatar
Sam Hocevar committed
43
dnl
44
dnl Check for tools
Sam Hocevar's avatar
Sam Hocevar committed
45
dnl
46
AC_PROG_CC_C99
47
AC_USE_SYSTEM_EXTENSIONS
48
VLC_PROG_CC_C11
49 50
AC_DEFINE([_FORTIFY_SOURCE], 2, [Define to 2 to get glibc warnings.])
AC_DEFINE([_FILE_OFFSET_BITS], 64, [Define to 64 for large files support.])
51 52 53 54 55
AH_TOP([
#ifndef _REENTRANT
# define _REENTRANT
#endif
])
56 57
AC_DEFINE([_THREAD_SAFE],, [Same as _REENTANT for some other OSes.])
AC_DEFINE([__LIBVLC__],, [Define within the LibVLC source code tree.])
58
AC_DEFINE([WIN32_LEAN_AND_MEAN],, [Define to limit the scope of <windows.h>.])
59

60 61
AM_PROG_CC_C_O
AC_PROG_CXX
62
AC_PROG_CPP
63 64
AC_PROG_OBJC
AC_PROG_EGREP
65 66
AC_PROG_MAKE_SET
AC_PROG_INSTALL
67
AM_PROG_AS
68

69 70
AC_ARG_VAR([DESKTOP_FILE_VALIDATE], [Validator for desktop entry files])
AC_CHECK_PROGS(DESKTOP_FILE_VALIDATE, [${DESKTOP_FILE_VALIDATE} desktop-file-validate], :)
71
AC_ARG_VAR([BUILDCC], [Build system C11 or C99 compiler command])
72
AC_CHECK_PROGS(BUILDCC, [c11-gcc c11 c99-gcc c99], [false])
73
AS_IF([test "$BUILDCC" = "false"], [
74 75
  AC_MSG_ERROR([Cannot find native C99 compiler: please define BUILDCC.])
])
76

77 78 79
dnl Check for compiler properties
AC_C_CONST
AC_C_INLINE
80
AC_C_RESTRICT
81
AX_CXX_COMPILE_STDCXX_11(noext, mandatory)
82

83 84 85
dnl Extend the --help string at the current spot.
AC_DEFUN([EXTEND_HELP_STRING], [m4_divert_once([HELP_ENABLE], [$1])])

86
dnl Allow binary package maintainer to pass a custom string to avoid
87
dnl cache problem
88
AC_ARG_WITH(binary-version,
89 90
    AS_HELP_STRING([--with-binary-version=STRING],
         [To avoid plugins cache problem between binary version]),[],[])
91
AS_IF([test -n "${with_binary_version}"],[
92 93 94
    AC_DEFINE_UNQUOTED([DISTRO_VERSION],["${with_binary_version}"],
         [Binary specific version])
])
95

96 97 98 99
dnl Prevent clang from accepting unknown flags with a mere warning
AX_APPEND_COMPILE_FLAGS([-Werror=unknown-warning-option -Werror=invalid-command-line-argument], [CFLAGS])
AX_APPEND_COMPILE_FLAGS([-Werror=unknown-warning-option -Werror=invalid-command-line-argument], [CXXFLAGS])

100 101 102
dnl
dnl  Check the operating system
dnl
103
HAVE_WIN64="0"
104 105
HAVE_IOS="0"
HAVE_OSX="0"
106
HAVE_TVOS="0"
107

108
case "${host_os}" in
109
  "")
110 111
    SYS=unknown
    ;;
112
  linux*)
113 114
    SYS=linux
    ;;
115
  bsdi*)
116
    SYS=bsdi
117
    CFLAGS="${CFLAGS} -pthread"
118
    ;;
119 120
  freebsd*)
    SYS=freebsd
121
    CFLAGS="${CFLAGS} -pthread"
122 123
    CPPFLAGS="${CPPFLAGS} -I/usr/local/include"
    LDFLAGS="${LDFLAGS} -L/usr/local/lib"
124
    ac_cv_ld_z_defs=no
125 126 127 128 129 130 131 132 133 134 135
    ;;
  openbsd*)
    SYS=openbsd
    CPPFLAGS="${CPPFLAGS} -I/usr/local/include -I/usr/X11R6/include"
    LDFLAGS="${LDFLAGS} -L/usr/local/lib -L/usr/X11R6/lib/"
    ;;
  netbsd*)
    SYS=netbsd
    ;;
  dragonfly*)
    SYS=dragonfly
136
    ;;
137
  darwin*)
138 139 140 141

    dnl Force gcc "-arch" flag
    ARCH_flag=""
    case "${host}" in
142
      i?86*)
143 144 145 146 147 148 149 150 151 152 153
        ARCH_flag="-arch i386"
      ;;
      ppc64*)
        ARCH_flag="-arch ppc64"
      ;;
      ppc*)
        ARCH_flag="-arch ppc"
      ;;
      x86_64*)
        ARCH_flag="-arch x86_64"
      ;;
154 155
      arm*)
        ac_cv_c_bigendian="no"
156
        ac_cv_c_attribute_packed="no"
157
      ;;
158 159
    esac

160
    SYS=darwin
161
    CFLAGS="${CFLAGS} -D_INTL_REDIRECT_MACROS -std=gnu11 ${ARCH_flag}"
162 163
    CXX="${CXX} -stdlib=libc++ -std=c++11"
    CXXFLAGS="${CXXFLAGS} -D_INTL_REDIRECT_MACROS ${ARCH_flag}"
164
    CPPFLAGS="${CPPFLAGS} ${ARCH_flag}"
165
    OBJCFLAGS="${OBJCFLAGS} -D_INTL_REDIRECT_MACROS -std=gnu11 ${ARCH_flag} -Werror=partial-availability"
166
    LDFLAGS="${LDFLAGS} -Wl,-headerpad_max_install_names ${ARCH_flag}"
167
    VLC_ADD_LIBS([libvlc vlc],[-Wl,-undefined,dynamic_lookup,-framework,AppKit])
168
    VLC_ADD_LIBS([libvlccore],[-Wl,-framework,CoreFoundation,-framework,CoreServices])
169

170 171 172 173 174 175 176 177
    AC_EGREP_CPP(yes,
            [#import <TargetConditionals.h>
             #if TARGET_OS_IPHONE
             yes
             #endif],
             [HAVE_IOS="1"],
             [HAVE_OSX="1"])

178 179 180 181 182 183 184 185 186 187
    AC_EGREP_CPP(yes,
            [#import <TargetConditionals.h>
             #if TARGET_OS_TV
             yes
             #endif],
             [HAVE_TVOS="1"
             HAVE_IOS="0"
             HAVE_OSX="0"
             ],)

188
    dnl Allow binaries created on Lion to run on earlier releases
189 190 191 192 193 194
    AC_EGREP_CPP(yes,
           [#import <Cocoa/Cocoa.h>
            #ifdef MAC_OS_X_VERSION_10_7
            yes
            #endif],
            [AC_MSG_RESULT([yes])
195 196 197
            AC_LIBOBJ([getdelim])
            AC_LIBOBJ([strndup])
            AC_LIBOBJ([strnlen])],)
198

199
    dnl
200
    dnl  Handle Mac OS X SDK flags
201 202
    dnl
    AC_ARG_WITH(macosx-sdk,
203 204
      [AS_HELP_STRING([--with-macosx-sdk=DIR],
        [compile using the SDK in DIR])])
205 206 207 208 209 210 211 212
    if test "${with_macosx_sdk}" != "" ; then
        test ! -d "${with_macosx_sdk}" && AC_MSG_ERROR([SDK "${with_macosx_sdk}" not found])
        CPP="${CPP} -isysroot ${with_macosx_sdk}"
        CC="${CC} -isysroot ${with_macosx_sdk}"
        CXX="${CXX} -isysroot ${with_macosx_sdk}"
        OBJC="${OBJC} -isysroot ${with_macosx_sdk}"
        LD="${LD} -syslibroot ${with_macosx_sdk}"
    fi
213
    AC_ARG_WITH(macosx-version-min,
214
      [AS_HELP_STRING([--with-macosx-version-min=VERSION],
215 216 217 218 219 220 221
        [compile for Mac OS X VERSION and above])])
    if test "${with_macosx_version_min}" != "" ; then
        CPP="${CPP} -mmacosx-version-min=${with_macosx_version_min}"
        CC="${CC} -mmacosx-version-min=${with_macosx_version_min}"
        CXX="${CXX} -mmacosx-version-min=${with_macosx_version_min}"
        OBJC="${OBJC} -mmacosx-version-min=${with_macosx_version_min}"
        LD="${LD} -mmacosx_version_min=${with_macosx_version_min}"
222
    fi
223
    ;;
224
  *mingw32* | *cygwin* | *wince* | *mingwce*)
225 226 227
    dnl Force libtool to not link to (shared) libgcc_s when detecting C++ dependencies
    dnl When doing this test with -static-libgcc it will link on (static) libgcc_eh
    CXXFLAGS="${CXXFLAGS} -static-libgcc"
228
    AC_CHECK_TOOL(WINDRES, windres, :)
229
    AC_CHECK_TOOL(OBJCOPY, objcopy, :)
230
    AH_TOP([#if defined(_WIN32) && !defined(_WIN32_WINNT)])
231 232
    AH_TOP([# define _WIN32_WINNT 0x0502 /* Windows XP SP2 */])
    AH_TOP([#endif])
233
    AC_DEFINE([_WIN32_IE], 0x0600, [Define to '0x0600' for IE 6.0 (and shell) APIs.])
234 235
    AC_DEFINE([_UNICODE], [1], [Define to 1 for Unicode (Wide Chars) APIs.])
    AC_DEFINE([UNICODE], [1], [Define to 1 for Unicode (Wide Chars) APIs.])
236 237 238 239 240 241 242 243
    AC_DEFINE([_ISOC99_SOURCE], [1], [Extensions to ISO C89 from ISO C99.])
    AC_DEFINE([_ISOC11_SOURCE], [1], [Extensions to ISO C99 from ISO C11.])
    AC_DEFINE([_POSIX_SOURCE], [1], [IEEE Std 1003.1.])
    AC_DEFINE([_POSIX_C_SOURCE], [200809L], [IEEE Std 1003.1.])
    AC_DEFINE([_XOPEN_SOURCE], [700], [POSIX and XPG 7th edition])
    AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], [XPG things and X/Open Unix extensions.])
    AC_DEFINE([_BSD_SOURCE], [1], [ISO C, POSIX, and 4.3BSD things.])
    AC_DEFINE([_SVID_SOURCE], [1], [ISO C, POSIX, and SVID things.])
244

245
    case "${host_os}" in
246
      *mingw32*)
247 248
        SYS=mingw32
        ;;
249
      *cygwin*)
250 251 252
        dnl Check if we are using the mno-cygwin mode in which case we are
        dnl actually dealing with a mingw32 compiler.
        AC_EGREP_CPP(yes,
253
            [#ifdef _WIN32
254 255
             yes
             #endif],
256
            SYS=mingw32, AC_MSG_ERROR([VLC requires -mno-cygwin]))
257 258 259
        ;;
    esac

260
    if test "${SYS}" = "mingw32"; then
261 262 263
        # DEP, ASLR, NO SEH
        LDFLAGS="${LDFLAGS} -Wl,--nxcompat -Wl,--no-seh -Wl,--dynamicbase"

264
        AC_CHECK_PROGS(U2D, [unix2dos todos], unix2dos)
265 266
        ac_default_prefix="`pwd`/_win32"
        DESTDIR="`pwd`/_win32/"
267 268

        dnl
Ludovic Fauvet's avatar
Ludovic Fauvet committed
269
        dnl NSIS/MSI Installer prefix and WIN64
270 271
        dnl
        case "${host}" in
272
            amd64*|x86_64*)
273
                HAVE_WIN64="1"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
274
                WINDOWS_ARCH="x64"
275
                PROGRAMFILES="PROGRAMFILES64"
276
                LDFLAGS="${LDFLAGS} -Wl,--high-entropy-va -Wl,--image-base,0x140000000"
277 278
            ;;
            *)
Ludovic Fauvet's avatar
Ludovic Fauvet committed
279
                WINDOWS_ARCH="x86"
280 281 282
                PROGRAMFILES="PROGRAMFILES"
            ;;
        esac
Ludovic Fauvet's avatar
Ludovic Fauvet committed
283
        AC_SUBST(WINDOWS_ARCH)
284 285
        AC_SUBST(PROGRAMFILES)

286
    fi
287
    ;;
288
  *nto*)
289 290
    SYS=nto
    ;;
291
  solaris*)
292 293
    SYS=solaris
    ;;
294
  hpux*)
295 296
    SYS=hpux
    ;;
297 298
  *os2*)
    SYS=os2
299
    LDFLAGS="${LDFLAGS} -Zomf -Zbin-files -Zargs-wild -Zhigh-mem"
300
    AC_LIBOBJ([freeaddrinfo])
301
    AC_LIBOBJ([gai_strerror])
302
    ;;
303 304 305
  *nacl*)
    SYS=nacl
    AC_DEFINE([_XOPEN_SOURCE], [700], [POSIX and XPG 7th edition])
306
    AC_LIBOBJ([sigwait])
307 308
    AC_LIBOBJ([recvmsg])
    AC_LIBOBJ([sendmsg])
309
    ;;
310
  *)
311
    SYS="${host_os}"
312
    ;;
313
esac
314 315 316 317 318 319 320 321

dnl WinRT
AC_ARG_ENABLE(winstore_app,
     AS_HELP_STRING([--enable-winstore-app],
                    [Build targetted for Windows Store apps (default disabled)]))

vlc_winstore_app=0
AS_IF([test "${SYS}" = "mingw32"],[
322
  LIBCOM="-lole32"
323 324
  AS_IF([test "${enable_winstore_app}" = "yes"], [
    vlc_winstore_app=1
325
    LIBCOM=""
326
     VLC_ADD_LIBS([libvlccore], [-lruntimeobject])
327
     AC_LIBOBJ([gai_strerror])
328
    ],[])
329
  AC_SUBST(LIBCOM)
330 331 332
  ])
AC_DEFINE_UNQUOTED(VLC_WINSTORE_APP, ${vlc_winstore_app}, [Define to 1 if you want to build for Windows Store apps])

Rémi Duraffort's avatar
Rémi Duraffort committed
333 334
AM_CONDITIONAL(HAVE_LINUX,   test "${SYS}" = "linux")
AM_CONDITIONAL(HAVE_OS2,     test "${SYS}" = "os2")
335 336

AM_CONDITIONAL(HAVE_DARWIN,  test "${SYS}" = "darwin")
337 338 339
AM_CONDITIONAL(HAVE_IOS,     test "${HAVE_IOS}" = "1")
AM_CONDITIONAL(HAVE_OSX,     test "${HAVE_OSX}" = "1")
AM_CONDITIONAL(HAVE_TVOS,    test "${HAVE_TVOS}" = "1")
340

341 342
AM_CONDITIONAL(HAVE_NACL,    test "${SYS}" = "nacl")

343 344 345
AM_CONDITIONAL(HAVE_WIN32,   test "${SYS}" = "mingw32")
AM_CONDITIONAL(HAVE_WIN64,   test "${HAVE_WIN64}" = "1") dnl Only used for the packaging
AM_CONDITIONAL([HAVE_WINSTORE], [test "$vlc_winstore_app" = "1"])
346
AM_CONDITIONAL([HAVE_WIN32_DESKTOP], [test "${SYS}" = "mingw32" -a "$vlc_winstore_app" = "0"])
347

348 349 350 351
dnl
dnl Sadly autoconf does not think about testing foo.exe when ask to test
dnl for program foo on win32
case "${build_os}" in
352
    cygwin|msys|mingw32)
353
        ac_executable_extensions=".exe"
354
        BUILDEXEEXT=".exe"
355
    ;;
356 357 358
    os2*)
        BUILDEXEEXT=".exe"
    ;;
359 360 361
    *)
    ;;
esac
362
AC_SUBST(BUILDEXEEXT)
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380

dnl Android is linux, but a bit different
AS_IF([test "$SYS" = linux],[
    AC_MSG_CHECKING([for an Android system])
    AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
        [[#ifndef __ANDROID__
         # error Not Android
         #endif
        ]],[[;]])
    ],[
      HAVE_ANDROID="1"
      AC_MSG_RESULT([yes])
    ],[
      AC_MSG_RESULT([no])
    ])
])
AM_CONDITIONAL(HAVE_ANDROID, test "${HAVE_ANDROID}" = "1")

381 382 383
dnl Tizen (minimum SDK version: 2.3)
AS_IF([test "$SYS" = linux],[
    AC_MSG_CHECKING([for Tizen])
384 385 386 387
    AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
        [[#include <tizen.h>
        ]],[[;]])
    ],[
388
      HAVE_TIZEN="1"
389
      AC_DEFINE([HAVE_TIZEN_SDK], [1], [Define to 1 if vlc is built against Tizen SDK])
390 391 392 393 394 395
      AC_MSG_RESULT([yes])
    ],[
      AC_MSG_RESULT([no])
    ])
])
AM_CONDITIONAL(HAVE_TIZEN, test "${HAVE_TIZEN}" = "1")
396

397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
dnl
dnl  Check for the contrib directory
dnl
AC_ARG_WITH(contrib,
  [AS_HELP_STRING([--with-contrib[=DIR]],
    [search for 3rd party libraries in DIR/include and DIR/lib])
])
AC_MSG_CHECKING([for 3rd party libraries path])
AS_IF([test -z "${with_contrib}" || test "${with_contrib}" = "yes"], [
  CONTRIB_DIR="${srcdir}/contrib/${host}"
  AS_IF([test ! -d "${CONTRIB_DIR}"], [
    echo "${CONTRIB_DIR} not found" >&AS_MESSAGE_LOG_FD
    CONTRIB_DIR="${srcdir}/contrib/`$CC -dumpmachine`"
    AS_IF([test ! -d "${CONTRIB_DIR}"], [
      echo "${CONTRIB_DIR} not found" >&AS_MESSAGE_LOG_FD
412 413
      CONTRIB_DIR=""
      AC_MSG_RESULT([not found])
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    ])
  ])
], [
  AS_IF([test "${with_contrib}" != "no"], [
    CONTRIB_DIR="${with_contrib}"
  ], [
    CONTRIB_DIR=""
    AC_MSG_RESULT([disabled])
  ])
])
AS_IF([test -n "${CONTRIB_DIR}"], [
  AS_IF([test -d "${CONTRIB_DIR}/lib"],[
    CONTRIB_DIR=`cd "${CONTRIB_DIR}" && pwd`
  ], [
    echo "${CONTRIB_DIR}/lib not found" >&AS_MESSAGE_LOG_FD
    CONTRIB_DIR=""
    AC_MSG_RESULT([not usable])
  ])

])
AS_IF([test -n "${CONTRIB_DIR}"], [
  AC_MSG_RESULT([${CONTRIB_DIR}])
  CPPFLAGS="${CPPFLAGS} -I${CONTRIB_DIR}/include"
  CFLAGS="${CFLAGS} -I${CONTRIB_DIR}/include"
  CXXFLAGS="${CXXFLAGS} -I${CONTRIB_DIR}/include"
439
  OBJCFLAGS="${OBJCFLAGS} -I${CONTRIB_DIR}/include -F${CONTRIB_DIR} -F${CONTRIB_DIR}/Frameworks"
440
  export PKG_CONFIG_PATH="${CONTRIB_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH"
441
  LDFLAGS="${LDFLAGS} -L${CONTRIB_DIR}/lib"
442

443 444
  AS_IF([test -z "$LUAC"], [
    dnl Old contribs mixed cross-tools and cross-compiled executables
445 446
    AS_IF([test -x "${CONTRIB_DIR}/bin/luac${BUILDEXEEXT}"], [
      LUAC="${CONTRIB_DIR}/bin/luac${BUILDEXEEXT}"
447 448 449
    ])

    dnl Newer contribs follow usual name space rules
450 451
    AS_IF([test -x "${CONTRIB_DIR}/../bin/${host_alias}-luac${BUILDEXEEXT}"], [
      LUAC="${CONTRIB_DIR}/../bin/${host_alias}-luac${BUILDEXEEXT}"
452 453
    ])
  ])
454

455 456 457 458 459 460 461 462 463 464 465
  AS_IF([test "${SYS}" = "darwin"], [
    export LD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$LD_LIBRARY_PATH"
    export DYLD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$DYLD_LIBRARY_PATH"
  ])
], [
  AS_IF([test -n "${with_contrib}" && test "${with_contrib}" != "no"], [
    AC_MSG_ERROR([Third party libraries not found!])
  ])
])
AC_SUBST(CONTRIB_DIR)

466
dnl Add extras/tools to the PATH
467
TOOLS_DIR="${srcdir}/extras/tools/build/bin"
468 469
AS_IF([test -d "${TOOLS_DIR}"], [
    TOOLS_DIR=`cd "${TOOLS_DIR}" && pwd`
470
    export PATH="${TOOLS_DIR}":$PATH
471 472
])

473
dnl
474 475 476 477
dnl  Libtool
dnl  It's very bad, but our former custom system was worst
dnl  -- Courmisch
dnl
478 479 480 481

dnl override platform specific check for dependent libraries
dnl otherwise libtool linking of shared libraries will
dnl fail on anything other than pass_all.
482 483
AC_CACHE_VAL(lt_cv_deplibs_check_method,
    [lt_cv_deplibs_check_method=pass_all])
484

485 486 487
LT_INIT([dlopen win32-dll shared disable-static])
LT_LANG([C++])
LT_LANG([Windows Resource])
488

Luca Barbato's avatar
Luca Barbato committed
489 490
DOLT

491 492
lt_cv_deplibs_check_method=pass_all

493
AS_IF([test "${enable_shared}" = "no" -a "${enable_vlc}" != "no"], [
494 495 496
  AC_MSG_ERROR([VLC is based on plugins. Shared libraries cannot be disabled.])
])

497 498 499
dnl
dnl Gettext stuff
dnl
500
AM_GNU_GETTEXT_VERSION([0.19.8])
501
AM_GNU_GETTEXT([external], [need-formatstring-macros])
502

503 504 505
dnl
dnl Iconv stuff
dnl
506
AM_ICONV
507

508 509
dnl
dnl checks for mingw
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
510
AS_IF([test "${SYS}" = "mingw32"], [
511

512 513 514 515 516 517
AC_PREPROC_IFELSE([AC_LANG_SOURCE([
#if !defined(__MINGW32__)
# error Not compiling with mingw
#endif
    ])], [

518
dnl Check for broken versions of mingw-runtime compatability library
519
    AC_MSG_CHECKING(for broken mingw-runtime)
520
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([
521
#include <_mingw.h>
522 523
#if defined(__MINGW64_VERSION_MAJOR)
# if __MINGW64_VERSION_MAJOR < 3
524
#  error Attempting to use mingw-runtime with broken vsnprintf support
525 526
# endif
#elif __MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION < 15
527 528
# error Attempting to use mingw-runtime with broken vsnprintf support
#endif
529
    ])], [
530
        AC_MSG_RESULT([ok])
531
    ], [
532
        AC_MSG_RESULT([present])
533
        AC_MSG_ERROR([LibVLC requires mingw-runtime version 3.15 or higher, or mingw-w64 version 3.0 or higher!])
534
    ])
535

536 537 538
    dnl force use of mingw provided c99 *printf over msvcrt
    CPPFLAGS="${CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=1"

539
    dnl Check for the need to include the mingwex lib for mingw32
540
    VLC_SAVE_FLAGS
541
    AC_CHECK_LIB(mingwex,opendir,
542
        AC_CHECK_LIB(mingw32,opendir,,
543
            [VLC_ADD_LIBS([libvlccore],[-lmingwex])])
544
    )
545
    VLC_RESTORE_FLAGS
546 547 548
    ], [
        AC_MSG_RESULT([Not compiling with mingw])
    ])
549

550
    dnl Check for fnative-struct or mms-bitfields support for mingw32
551 552 553
    VLC_SAVE_FLAGS
    CFLAGS="${CFLAGS} -mms-bitfields"
    CXXFLAGS="${CXXFLAGS} -mms-bitfields"
554 555
    AC_CACHE_CHECK([if \$CC accepts -mms-bitfields],
        [ac_cv_c_mms_bitfields],
556 557 558 559 560
        [AC_TRY_COMPILE([],,ac_cv_c_mms_bitfields=yes, ac_cv_c_mms_bitfields=no)])
    if test "${ac_cv_c_mms_bitfields}" = "no"; then
        VLC_RESTORE_FLAGS
        CFLAGS="${CFLAGS} -fnative-struct"
        CXXFLAGS="${CXXFLAGS} -fnative-struct"
561 562
        AC_CACHE_CHECK([if \$CC accepts -fnative-struct],
            [ac_cv_c_fnative_struct],
563 564
            [AC_TRY_COMPILE([],,ac_cv_c_fnative_struct=yes, ac_cv_c_fnative_struct=no)])
        "${ac_cv_c_fnative_struct}" = "no" && VLC_RESTORE_FLAGS
565
    fi
566
])
567

568

569 570
dnl
dnl Buggy glibc prevention. Purposedly not cached.
571
dnl See sourceware.org bugs 5058 and 5443.
572 573 574
dnl Ubuntu alone has 20 bug numbers for this...
dnl
AC_MSG_CHECKING(for buggy GNU/libc versions)
575
AC_PREPROC_IFELSE([AC_LANG_SOURCE([
576 577 578 579 580
#include <limits.h>
#if defined (__GLIBC__) && (__GLIBC__ == 2) \
  && (__GLIBC_MINOR__ >= 5) && (__GLIBC_MINOR__ <= 7)
# error GNU/libc with dcgettext killer bug!
#endif
581
])], [
582 583 584
  AC_MSG_RESULT([not present])
], [
  AC_MSG_RESULT([found])
585
  AS_IF([test "x${enable_nls}" != "xno"], [
586 587
    AC_MSG_ERROR([Buggy GNU/libc (version 2.5 - 2.7) present. VLC would crash; there is no viable
work-around for this. Check with your distribution vendor on how to update the
588
glibc run-time. Alternatively, build with --disable-nls.])
589
  ])
590 591
])

592 593 594 595
dnl Plugin compilation stuff

VLC_LIBRARY_SUFFIX

596
dnl Check for system libs needed
597
need_libc=false
598

599
dnl Check for usual libc functions
600 601
AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime tdestroy uselocale])
AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp pathconf])
602
AC_REPLACE_FUNCS([gettimeofday])
603
AC_CHECK_FUNC(fdatasync,,
604 605
  [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
])
606

607 608
VLC_REPLACE_DECL([realpath], [#include <stdlib.h>])

609
dnl mingw64 implements those as static inline, not functions with C linkage
610 611
VLC_REPLACE_DECL([asprintf], [#include <stdio.h>])
VLC_REPLACE_DECL([vasprintf], [#include <stdio.h>])
612 613
VLC_REPLACE_DECL([gmtime_r], [#include <time.h>])
VLC_REPLACE_DECL([localtime_r], [#include <time.h>])
614

615 616
dnl C11 static_assert()
AC_MSG_CHECKING([for static_assert in assert.h])
617 618
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <assert.h>], [
static_assert(1, "The impossible happened.");
619 620 621 622 623 624 625
])], [
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_STATIC_ASSERT], [1], [Define to 1 if <assert.h> defines static_assert.])
], [
  AC_MSG_RESULT([no])
])

Rafaël Carré's avatar
Rafaël Carré committed
626
# Windows CE does not have strcoll()
627 628
AC_FUNC_STRCOLL

629
dnl Check for non-standard system calls
630 631
case "$SYS" in
  "linux")
632
    AC_CHECK_FUNCS([accept4 pipe2 eventfd vmsplice sched_getaffinity recvmmsg])
633
    ;;
634 635 636
  "mingw32")
    AC_CHECK_FUNCS([_lock_file])
    ;;
637
esac
638

639 640
AH_BOTTOM([#include <vlc_fixups.h>])

641 642 643 644 645
dnl Check for struct pollfd
AC_CHECK_TYPES([struct pollfd],,,
[#include <sys/types.h>
#if HAVE_POLL
# include <poll.h>
646
#elif defined (_WIN32)
647 648 649 650
# include <winsock2.h>
#endif
])

651 652 653 654
dnl Check for struct timespec
AC_CHECK_TYPES([struct timespec],,,
[#include <time.h>])

655 656 657 658
dnl Check for max_align_t
AC_CHECK_TYPES([max_align_t],,,
[#include <stddef.h>])

659
dnl Checks for socket stuff
660
VLC_SAVE_FLAGS
661 662 663 664 665 666 667 668 669 670
SOCKET_LIBS=""
AC_SEARCH_LIBS(connect, [socket], [
  AS_IF([test "$ac_cv_search_connect" != "none required"], [
    SOCKET_LIBS="$ac_cv_search_connect"
  ])
], [
  AS_IF([test "${SYS}" = "mingw32"], [
    SOCKET_LIBS="-lws2_32"
  ])
])
671

672
AC_SEARCH_LIBS([inet_pton], [nsl], [
Fabrizio Ge's avatar
Fabrizio Ge committed
673 674
 AS_IF([test "$ac_cv_search_inet_pton" != "none required"], [
    SOCKET_LIBS="$ac_cv_search_inet_pton $SOCKET_LIBS"
675 676 677
  ])
],, [${SOCKET_LIBS}])

678 679
LIBS="${LIBS} ${SOCKET_LIBS}"
AC_LINK_IFELSE([
680
    AC_LANG_PROGRAM([#ifdef _WIN32
681 682 683
        # if _WIN32_WINNT < 0x600
        #  error Needs vista+
        # endif
684 685
        #include <ws2tcpip.h>
        #else
686
        #include <sys/socket.h>
687 688 689 690 691
        #include <arpa/inet.h>
        #endif], [
        char dst[[sizeof(struct in_addr)]];
        inet_pton(AF_INET, "127.0.0.1", dst);
    ])],[AC_DEFINE([HAVE_INET_PTON],[1],[Define to 1 if you have inet_pton function])],[AC_LIBOBJ([inet_pton])])
692
AC_CHECK_FUNCS([if_nameindex if_nametoindex])
693
VLC_RESTORE_FLAGS
694
AC_SUBST(SOCKET_LIBS)
695

696
dnl Check for socklen_t
697
AH_TEMPLATE(socklen_t, [Define to `int' if <sys/socket.h> does not define.])
698
AC_CACHE_CHECK([for socklen_t in sys/socket.h], dnl ` (fix VIM syntax highlight
699 700
ac_cv_type_socklen_t,
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
701
[#include <sys/types.h>
702
#ifdef _WIN32
703
# include <winsock2.h>
704
# include <ws2tcpip.h>
705 706
#else
# include <sys/socket.h>
707 708 709 710 711
#endif]], [[socklen_t len; len = 0;]])],
ac_cv_type_socklen_t=yes,
ac_cv_type_socklen_t=no)])
AS_IF([test "$ac_cv_type_socklen_t" = no],
 [AC_DEFINE(socklen_t, int)])
712

713
dnl Check for struct sockaddr_storage
Rafaël Carré's avatar
Rafaël Carré committed
714 715
AH_TEMPLATE(sockaddr_storage, [Define to `sockaddr' if <sys/socket.h> does not define.]) dnl ` (fix VIM syntax highlight
AH_TEMPLATE(ss_family, [Define to `sa_family' if <sys/socket.h> does not define.]) dnl ` (fix VIM syntax highlight
716 717 718
AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_struct_sockaddr_storage,
  [AC_TRY_COMPILE(
    [#include <sys/types.h>
719
     #if defined( _WIN32 )
720 721 722 723 724 725
     # include <winsock2.h>
     #else
     # include <sys/socket.h>
     #endif], [struct sockaddr_storage addr;],
     ac_cv_struct_sockaddr_storage=yes,
     ac_cv_struct_sockaddr_storage=no)])
726
AS_IF([test "${ac_cv_struct_sockaddr_storage}" = no], [
727 728
  AC_DEFINE(sockaddr_storage, sockaddr)
  AC_DEFINE(ss_family, sa_family)
729
])
730

731 732 733 734 735 736 737 738
dnl FreeBSD has a gnugetopt library for this:
GNUGETOPT_LIBS=""
AC_CHECK_FUNC(getopt_long,, [
  AC_CHECK_LIB([gnugetopt],[getopt_long], [
    GNUGETOPT_LIBS="-lgnugetopt"
  ])
])
AC_SUBST(GNUGETOPT_LIBS)
739

Sam Hocevar's avatar
Sam Hocevar committed
740
AC_CHECK_LIB(m,cos,[
741 742 743
  LIBM="-lm"
], [
  LIBM=""
744
])
745
AC_SUBST(LIBM)
746

747 748 749 750
AC_CHECK_LIB(m,lrintf, [
  AC_DEFINE(HAVE_LRINTF, 1, [Define to 1 if you have the lrintf function])
  VLC_ADD_LIBS([skins2],[-lm])
])
751 752 753
AC_CHECK_LIB(m,nanf,
  AC_DEFINE(HAVE_NANF, 1, [Define to 1 if you have the NANF function])
)
754 755 756 757 758
AC_CHECK_LIB(m,sincos, [
  AC_DEFINE(HAVE_SINCOS, 1, [Define to 1 if you have the sincos function.])
], [
  AC_LIBOBJ([sincos])
])
759

760 761 762 763 764 765 766 767 768 769 770
AC_MSG_CHECKING([_Thread_local support])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_Thread_local int foo = 0;
                   int main() {}])], [
    AC_MSG_RESULT([ok])
    AC_DEFINE(HAVE_THREAD_LOCAL, 1, [Defined to 1 if C11 _Thread_local storage qualifier is supported])
],[ AC_MSG_RESULT([no])])

dnl __STDC_NO_THREADS__ can't be trusted on some platforms.
dnl check for its availability explicitely
AC_CHECK_HEADERS([threads.h])

Sam Hocevar's avatar
Sam Hocevar committed
771
dnl Check for dynamic plugins
772 773
LIBDL=""
have_dynamic_objects="no"
774
VLC_SAVE_FLAGS
775
AC_SEARCH_LIBS(dlsym, [dl svld], [
776 777
  AS_IF([test "$ac_cv_search_dlsym" != "none required"], [
    LIBDL="$ac_cv_search_dlsym"
778
  ])
779
  have_dynamic_objects="yes"
780
])
781
VLC_RESTORE_FLAGS
Sam Hocevar's avatar
Sam Hocevar committed
782

783
# Windows
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
784
AS_IF([test "${SYS}" = "mingw32"], [
785
  LIBDL=""
786
  have_dynamic_objects="yes" #assume we can use shared objects
787
])
788

789 790
AS_IF([test "${enable_shared}" = "no"], [
  have_dynamic_objects=no
791
])
Rafaël Carré's avatar
Rafaël Carré committed
792 793
AM_CONDITIONAL(HAVE_DYNAMIC_PLUGINS, [test "${have_dynamic_objects}" != "no"])

794
AC_SUBST(LIBDL)
Sam Hocevar's avatar
Sam Hocevar committed
795

796
dnl Check for thread library
797 798
LIBPTHREAD=""
AS_IF([test "${SYS}" != "mingw32"], [
799
  VLC_SAVE_FLAGS
800 801
  LIBS=""
  AC_SEARCH_LIBS(pthread_rwlock_init, pthread pthreads c_r, [
802 803 804
    AS_IF([test "$ac_cv_search_pthread_rwlock_init" != "none required"], [
      LIBPTHREAD="$ac_cv_search_pthread_rwlock_init"
    ])
805 806
  ])
  VLC_RESTORE_FLAGS
807 808
])
AC_SUBST(LIBPTHREAD)
809

810 811 812 813 814 815 816 817
AC_SEARCH_LIBS([clock_nanosleep], [rt pthread], [
  AS_IF([test "$ac_cv_search_clock_nanosleep" != "none required"], [
    LIBRT="$ac_cv_search_clock_nanosleep"
  ])
], [
  AC_SEARCH_LIBS([nanosleep], [rt pthread posix4], [
    AS_IF([test "$ac_cv_search_nanosleep" != "none required"], [
      LIBRT="$ac_cv_search_nanosleep"
818
    ])
819
  ])
820
])
821
AC_SUBST(LIBRT)
822

823
dnl
824
dnl Check for headers
825 826
dnl

827
dnl  POSIX
828
AC_CHECK_HEADERS([arpa/inet.h pthread.h search.h sys/shm.h sys/socket.h sys/uio.h])
829 830 831 832 833
AC_CHECK_HEADERS([net/if.h], [], [],
[
#include <sys/types.h>
#include <sys/socket.h>
])
834 835 836
AC_CHECK_HEADER([syslog.h], [have_syslog="yes"], [have_syslog="no"])
AM_CONDITIONAL([HAVE_SYSLOG], [test "$have_syslog" = "yes"])

837
dnl  BSD
838
AC_CHECK_HEADERS([netinet/tcp.h netinet/udplite.h sys/param.h sys/mount.h])
839

840
dnl  GNU/Linux
841
AC_CHECK_HEADERS([features.h getopt.h linux/dccp.h linux/magic.h mntent.h sys/eventfd.h])
842

843 844
dnl  MacOS
AC_CHECK_HEADERS([xlocale.h])
845

846
dnl LP64 and LLP64 architectures had better define ssize_t by themselves...
847
AH_TEMPLATE(ssize_t, [Define to `int' if <stddef.h> does not define.]) dnl ` (fix VIM syntax highlight
848 849 850 851
AC_CHECK_TYPE(ssize_t,, [
  AC_DEFINE(ssize_t, int)
])

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
852 853 854
dnl It seems that autoconf detects pkg-config only during the first
dnl PKG_CHECK_MODULES from configure.ac - which makes sense. But in our case,
dnl it is nested within a conditional block, so it was not working right.
855
dnl Make PKG_CONFIG_PATH precious so that it appears in the help and get saved
856
AC_ARG_VAR(PKG_CONFIG_PATH,
857
       [Paths where to find .pc not at the default location])
858 859
PKG_PROG_PKG_CONFIG()

860
dnl On some OS we need static linking
861
AS_IF([test -n "${PKG_CONFIG}" ],[
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
862
    AS_IF([test "${SYS}" = "mingw32" -o "${SYS}" = "darwin" -o "${SYS}" = "os2" ],[
863 864 865
        PKG_CONFIG="${PKG_CONFIG} --static"
    ])
])
866 867


868 869
dnl
dnl Check for zlib.h and -lz along with system -lminizip if available
870
dnl
871 872 873 874
AC_CHECK_HEADERS(zlib.h, [ have_zlib=yes ], [ have_zlib=no ])
AM_CONDITIONAL(HAVE_ZLIB, [ test "${have_zlib}" = "yes" ])
if test "${have_zlib}" = "yes"
then
875
  VLC_ADD_LIBS([sap],[-lz])
876
  PKG_CHECK_MODULES([MINIZIP], [minizip] , [ have_minizip=yes ], [
877
    AC_CHECK_HEADERS([unzip.h], [
878 879 880 881 882 883 884
      have_minizip=yes
      MINIZIP_LIBS="-lminizip -lz"
    ], [
      have_minizip=no
    ])
  ])
fi
885
AM_CONDITIONAL(HAVE_MINIZIP, [ test "${have_minizip}" = "yes" ])
886 887


888 889 890 891 892 893 894 895 896 897 898
dnl
dnl Domain name i18n support via GNU libidn
dnl
PKG_CHECK_MODULES([IDN], [libidn], [
  have_libidn="yes"
  AC_DEFINE([HAVE_IDN], 1, [Define to 1 if you have GNU libidn.])
], [
  have_libidn="no"
])


899 900
dnl Check for dbus
AC_ARG_ENABLE(dbus,
901 902
  [AS_HELP_STRING([--enable-dbus],
    [compile D-Bus message bus support (default enabled)])])
903 904
have_dbus="no"
AS_IF([test "${enable_dbus}" != "no"], [
905
  PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.6.0], [
906 907 908 909 910 911 912 913 914 915
    have_dbus="yes"
  ], [
    AS_IF([test -n "${enable_dbus}"], [
      AC_MSG_ERROR([${DBUS_PKG_ERRORS}.])
    ], [
      AC_MSG_WARN([${DBUS_PKG_ERRORS}.])
    ])
  ])
])
AM_CONDITIONAL([HAVE_DBUS], [test "${have_dbus}" = "yes"])
916

917 918 919 920 921 922 923 924 925 926

dnl Check for systemd
PKG_CHECK_MODULES([SYSTEMD], [libsystemd], [
  have_systemd="yes"
], [
  AC_MSG_WARN([${SYSTEMD_PKG_ERRORS}.])
])
AM_CONDITIONAL([HAVE_SYSTEMD], [test "${have_systemd}" = "yes"])


927 928 929 930
EXTEND_HELP_STRING([Optimization options:])
dnl
dnl  Compiler warnings
dnl
931

932 933 934 935 936
AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wsign-compare -Wundef -Wpointer-arith -Wvolatile-register-var -Wformat -Wformat-security], [CFLAGS])
AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wsign-compare -Wundef -Wpointer-arith -Wvolatile-register-var -Wformat -Wformat-security], [CXXFLAGS])

AX_APPEND_COMPILE_FLAGS([-Wbad-function-cast -Wwrite-strings -Wmissing-prototypes -Werror-implicit-function-declaration -Winit-self -Wlogical-op -Wshadow=local], [CFLAGS])
AX_APPEND_COMPILE_FLAGS([-pipe], [CFLAGS])
937

938 939 940 941 942
dnl
dnl  Debugging mode
dnl
AC_ARG_ENABLE(debug,
  [AS_HELP_STRING([--enable-debug],
943
    [build with run-time assertions (default disabled)])],,
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
  [enable_debug="no"])
AH_TEMPLATE(NDEBUG,
            [Define to 1 if debug code should NOT be compiled])
AS_IF([test "${enable_debug}" != "no"], [
  AC_CHECK_HEADERS([valgrind/valgrind.h])
], [
  AC_DEFINE(NDEBUG)
])

dnl
dnl  Profiling
dnl
AC_ARG_ENABLE(gprof,
  [AS_HELP_STRING([--enable-gprof],[profile with gprof (default disabled)])],,
  [enable_gprof="no"])
AS_IF([test "${enable_gprof}" != "no"], [
  CFLAGS="${CFLAGS} -pg"
  CXXFLAGS="${CXXFLAGS} -pg"
  OBJCFLAGS="${OBJCFLAGS} -pg"
  LDFLAGS="${LDFLAGS} -pg"
])

AC_ARG_ENABLE(cprof,
  [AS_HELP_STRING([--enable-cprof],[profile with cprof (default disabled)])],,
  [enable_cprof="no"])
AS_IF([test "${enable_gprof}" != "no"], [
  CFLAGS="${CFLAGS} -finstrument-functions"
  CXXFLAGS="${CXXFLAGS} -finstrument-functions"
  OBJCFLAGS="${OBJCFLAGS} -finstrument-functions"
  LDFLAGS="${LDFLAGS} -finstrument-functions"
])

dnl
dnl  Test coverage
dnl
AC_ARG_ENABLE(coverage,
  [AS_HELP_STRING([--enable-coverage],
    [build for test coverage (default disabled)])],,
  [enable_coverage="no"])
AS_IF([test "${enable_coverage}" != "no"], [
  CFLAGS="-fprofile-arcs -ftest-coverage ${CFLAGS}"
  CXXFLAGS="-fprofile-arcs -ftest-coverage ${CXXFLAGS}"
  LDFLAGS="-lgcov ${LDFLAGS}"
])

989
AS_IF([test "${SYS}" != "mingw32" -a "${SYS}" != "os2"], [
990 991 992 993
  VLC_SAVE_FLAGS
  CFLAGS="${CFLAGS} -fvisibility=hidden"
  CXXFLAGS="${CXXFLAGS} -fvisibility=hidden"
  OBJCFLAGS="${OBJCFLAGS} -fvisibility=hidden"
994 995 996 997 998 999 1000 1001
  AC_CACHE_CHECK([if $CC accepts -fvisibility=hidden],
                 [ac_cv_c_visibility_hidden], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
      ac_cv_c_visibility_hidden=yes
    ], [
      ac_cv_c_visibility_hidden=no
    ])
  ])
1002
  AS_IF([test "${ac_cv_c_visibility_hidden}" = "no"], [VLC_RESTORE_FLAGS])
1003 1004
])

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
dnl
dnl Sanitizer flags
dnl
AC_ARG_WITH([sanitizer],
    [AS_HELP_STRING([--with-sanitizer=(address/memory/undefined/thread)],
        [build with sanitizer flags (default disabled)])],
     [],
     [with_sanitizer=no])

AS_VAR_IF(with_sanitizer, no, [], [
    AX_CHECK_COMPILE_FLAG([-fsanitize=${with_sanitizer}], [
        AX_APPEND_FLAG([-fsanitize=${with_sanitizer}])
        AX_APPEND_FLAG([-fsanitize=${with_sanitizer}], [CXXFLAGS])
        AX_APPEND_FLAG([-fsanitize=${with_sanitizer}], [LDFLAGS])
    ], [
        AC_MSG_ERROR(["-fsanitize=${with_sanitizer} not supported!"])
    ])
    AX_APPEND_FLAG([-g])
    AX_APPEND_FLAG([-g], [CXXFLAGS])

    AS_IF([test -z "${with_sanitizer##*address*}" ], [
       AX_APPEND_COMPILE_FLAGS([-fsanitize-address-use-after-scope -fno-omit-frame-pointer])
       AX_APPEND_COMPILE_FLAGS([-fsanitize-address-use-after-scope -fno-omit-frame-pointer], [CXXFLAGS])
    ])
    AS_IF([test -z "${with_sanitizer##*memory*}" ], [
        AX_APPEND_COMPILE_FLAGS([-fPIE -pie])
        AX_APPEND_COMPILE_FLAGS([-fPIE -pie], [CXXFLAGS])
    ])
    AS_IF([test -z "${with_sanitizer##*thread*}" ], [
        AX_APPEND_COMPILE_FLAGS([-fPIE -pie])
        AX_APPEND_COMPILE_FLAGS([-fPIE -pie], [CXXFLAGS])
    ])
])
1038

1039 1040 1041 1042 1043 1044 1045 1046
dnl
dnl  Enable/disable optimizations
dnl
AC_ARG_ENABLE(optimizations,
  [AS_HELP_STRING([--disable-optimizations],
    [disable compiler optimizations (default enabled)])],,
  [enable_optimizations="yes"])

1047
dnl Check for various optimization flags
1048 1049
AS_IF([test "${enable_optimizations}" != "no"], [

1050
  dnl -O3 only in production builds
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
1051
  AS_IF([test "${enable_debug}" = "no"], [
1052
    VLC_SAVE_FLAGS
1053 1054 1055 1056
    CFLAGS="${CFLAGS} -O3"
    CXXFLAGS="${CXXFLAGS} -O3"
    OBJCFLAGS="${OBJCFLAGS} -O3"
    AC_CACHE_CHECK([if $CC accepts -O3],  [ac_cv_c_o3], [
1057
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
1058
        ac_cv_c_o3=yes
1059
      ], [
1060
        ac_cv_c_o3=no
1061 1062
      ])
    ])
1063
    AS_IF([test "${ac_cv_c_o3}" = "no"], [VLC_RESTORE_FLAGS])
1064
  ])
1065

1066
  dnl Check for fast maths
1067 1068
  AX_APPEND_COMPILE_FLAGS([-fno-math-errno -funsafe-math-optimizations -fno-rounding-math -fno-signaling-nans -fcx-limited-range], [CFLAGS])
  AX_APPEND_COMPILE_FLAGS([-fno-math-errno -funsafe-math-optimizations -fno-rounding-math -fno-signaling-nans -fcx-limited-range], [CXXFLAGS])
1069 1070

AH_BOTTOM([
1071
#if defined(_MSC_VER) && !defined(__clang__)
1072 1073 1074 1075 1076 1077 1078
# pragma fenv_access(off)
# pragma fp_contract(on)
#elif defined(__GNUC__)
/* Not supported so far */
#else
# pragma STDC FENV_ACCESS OFF
# pragma STDC FP_CONTRACT ON
1079 1080
#endif
])
1081

1082
  dnl Check for -funroll-loops
1083 1084 1085 1086
  VLC_SAVE_FLAGS
  CFLAGS="${CFLAGS} -funroll-loops"
  CXXFLAGS="${CXXFLAGS} -funroll-loops"
  OBJCFLAGS="${OBJCFLAGS} -funroll-loops"
1087 1088 1089 1090 1091 1092 1093
  AC_CACHE_CHECK([if $CC accepts -funroll-loops], [ac_cv_c_unroll_loops], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
      ac_cv_c_unroll_loops=yes
    ], [
      ac_cv_c_unroll_loops=no
    ])
  ])
1094
  AS_IF([test "${ac_cv_c_unroll_loops}" = "no"], [VLC_RESTORE_FLAGS])
1095 1096 1097

  AS_IF([test "$enable_debug" = "no"], [
    dnl Check for -fomit-frame-pointer
1098 1099 1100 1101
    VLC_SAVE_FLAGS
    CFLAGS="${CFLAGS} -fomit-frame-pointer"
    CXXFLAGS="${CXXFLAGS} -fomit-frame-pointer"
    OBJCFLAGS="${OBJCFLAGS} -fomit-frame-pointer"
1102 1103 1104 1105 1106 1107 1108 1109
    AC_CACHE_CHECK([if $CC accepts -fomit-frame-pointer],
      [ac_cv_c_omit_frame_pointer], [
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
        ac_cv_c_omit_frame_pointer=yes
      ], [
        ac_cv_c_omit_frame_pointer=no
      ])
    ])
1110
    AS_IF([test "${ac_cv_c_omit_frame_pointer}" = "no"], [VLC_RESTORE_FLAGS])
1111 1112
  ])
])
1113

1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
VLC_SAVE_FLAGS
LDFLAGS="${LDFLAGS} -Wl,-Bsymbolic"
AC_CACHE_CHECK([if linker supports -Bsymbolic], [ac_cv_ld_bsymbolic], [
  AC_TRY_LINK([],, [
    ac_cv_ld_bsymbolic="-Wl,-Bsymbolic"
  ], [
    ac_cv_ld_bsymbolic=""
  ])
])
VLC_RESTORE_FLAGS
SYMBOLIC_LDFLAGS="${ac_cv_ld_bsymbolic}"
AC_SUBST(SYMBOLIC_LDFLAGS)

1127 1128 1129 1130 1131 1132 1133 1134 1135
VLC_SAVE_FLAGS
LDFLAGS="${LDFLAGS} -Wl,-z,defs"
AC_CACHE_CHECK([if linker supports -z,defs], [ac_cv_ld_z_defs], [
  AC_TRY_LINK([],, [
    ac_cv_ld_z_defs="yes"
  ], [
    ac_cv_ld_z_defs="no"
  ])
])
1136
AS_IF([test "${ac_cv_ld_z_defs}" = "no" -o "${with_sanitizer}" != "no"], [VLC_RESTORE_FLAGS])
1137

1138
dnl Check for __attribute__((packed))
1139 1140 1141
AC_CACHE_CHECK([for __attribute__((packed))],
  [ac_cv_c_attribute_packed],
  [ac_cv_c_attribute_packed=no
1142
   AC_TRY_COMPILE(, [struct __attribute__((__packed__)) foo { int a; } b; (void)b;],
1143
                    [ac_cv_c_attribute_packed=yes])])
1144
if test "${ac_cv_c_attribute_packed}" != "no"; then
1145 1146 1147
  AC_DEFINE(HAVE_ATTRIBUTE_PACKED, 1, Support for __attribute__((packed)) for structs)
fi

1148 1149 1150
dnl
dnl  Check the CPU
dnl
1151
case "${host_cpu}" in
1152
  "")
1153 1154 1155
    ARCH=unknown
    ;;
  *)
1156
    ARCH="${host_cpu}"
1157 1158 1159
    ;;
esac

1160 1161 1162 1163
dnl Check for backtrace() support
AC_CHECK_HEADERS(execinfo.h)
AC_CHECK_FUNCS(backtrace)

1164 1165 1166
dnl
dnl  default modules
dnl
1167
ALIASES="${ALIASES} cvlc rvlc"
1168

1169 1170 1171
dnl
dnl  Accelerated modules
dnl
1172 1173

dnl  Check for fully working MMX intrinsics
1174 1175
dnl  We need support for -mmmx, we need <mmintrin.h>, and we also need a
dnl  working compiler (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23963)
1176
AC_ARG_ENABLE(mmx,
1177 1178
  [AS_HELP_STRING([--disable-mmx],
    [disable MMX optimizations (default auto)])],,[
1179 1180 1181 1182 1183 1184 1185 1186 1187
  case "${host_cpu}" in
    i?86|x86_64)
      enable_mmx="yes"
      ;;
    *)
      enable_mmx="no"
      ;;
  esac
])
1188
have_mmx="no"
1189
have_mmxext="no"
1190 1191
AS_IF([test "${enable_mmx}" != "no"], [
  ARCH="${ARCH} mmx"
1192
  VLC_SAVE_FLAGS
1193
  CFLAGS="${CFLAGS} -mmmx"
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212
  AC_CACHE_CHECK([if $CC groks MMX intrinsics], [ac_cv_c_mmx_intrinsics], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
[#include <mmintrin.h>
#include <stdint.h>
uint64_t frobzor;]], [
[__m64 a, b, c;
a = b = c = (__m64)frobzor;
a = _mm_slli_pi16(a, 3);
a = _mm_adds_pi16(a, b);
c = _mm_srli_pi16(c, 8);
c = _mm_slli_pi16(c, 3);
b = _mm_adds_pi16(b, c);
a = _mm_unpacklo_pi8(a, b);
frobzor = (uint64_t)a;]])], [
      ac_cv_c_mmx_intrinsics=yes
    ], [
      ac_cv_c_mmx_intrinsics=no
    ])
  ])
1213
  VLC_RESTORE_FLAGS
1214
  AS_IF([test "${ac_cv_c_mmx_intrinsics}" != "no"], [
1215
    AC_DEFINE(HAVE_MMX_INTRINSICS, 1, [Define to 1 if MMX intrinsics are available.])
1216 1217
  ])

1218 1219
  VLC_SAVE_FLAGS
  CFLAGS="${CFLAGS} -mmmx"
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
  AC_CACHE_CHECK([if $CC groks MMX inline assembly], [ac_cv_mmx_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("packuswb %%mm1,%%mm2"::"r"(p):"mm1", "mm2");
]])
    ], [
      ac_cv_mmx_inline=yes
    ], [
      ac_cv_mmx_inline=no
    ])
  ])
1231
  AS_IF([test "${ac_cv_mmx_inline}" != "no"], [
1232
    AC_DEFINE(CAN_COMPILE_MMX, 1, [Define to 1 inline MMX assembly is available.])
1233
    have_mmx="yes"
1234 1235
  ])

1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
  AC_CACHE_CHECK([if $CC groks MMX EXT inline assembly],
                 [ac_cv_mmxext_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("maskmovq %%mm1,%%mm2"::"r"(p):"mm1", "mm2");
]])
    ], [
      ac_cv_mmxext_inline=yes
    ], [
      ac_cv_mmxext_inline=no
    ])
  ])
1248
  VLC_RESTORE_FLAGS
1249 1250 1251 1252
  AS_IF([test "${ac_cv_mmxext_inline}" != "no"], [
    AC_DEFINE(CAN_COMPILE_MMXEXT, 1, [Define to 1 if MMX EXT inline assembly is available.])
    have_mmxext="yes"
  ])
1253
])
1254
AM_CONDITIONAL([HAVE_MMX], [test "${have_mmx}" = "yes"])
1255
AM_CONDITIONAL([HAVE_MMXEXT], [test "${have_mmxext}" = "yes"])
1256

1257 1258 1259
dnl  Check for fully workin SSE2 intrinsics
dnl  We need support for -mmmx, we need <emmintrin.h>, and we also need a
dnl  working compiler (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23963)
1260
AC_ARG_ENABLE(sse,
1261 1262
  [AS_HELP_STRING([--disable-sse],
    [disable SSE (1-4) optimizations (default auto)])],, [
1263
  case "${host_cpu}" in
1264
    i?86|x86_64)
1265 1266 1267 1268 1269 1270 1271
      enable_sse=yes
      ;;
    *)
      enable_sse=no
      ;;
  esac
])
1272
have_sse2="no"
1273 1274 1275
AS_IF([test "${enable_sse}" != "no"], [
  ARCH="${ARCH} sse sse2"

1276
  VLC_SAVE_FLAGS
1277
  CFLAGS="${CFLAGS} -msse2"
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
  AC_CACHE_CHECK([if $CC groks SSE2 intrinsics], [ac_cv_c_sse2_intrinsics], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
[#include <emmintrin.h>
#include <stdint.h>
uint64_t frobzor;]], [
[__m128i a, b, c;
a = b = c = _mm_set1_epi64((__m64)frobzor);
a = _mm_slli_epi16(a, 3);
a = _mm_adds_epi16(a, b);
c = _mm_srli_epi16(c, 8);
c = _mm_slli_epi16(c, 3);
b = _mm_adds_epi16(b, c);
a = _mm_unpacklo_epi8(a, b);
frobzor = (uint64_t)_mm_movepi64_pi64(a);]])], [
      ac_cv_c_sse2_intrinsics=yes
    ], [
      ac_cv_c_sse2_intrinsics=no
    ])
1296 1297
  ])
  VLC_RESTORE_FLAGS
1298
  AS_IF([test "${ac_cv_c_sse2_intrinsics}" != "no"], [
1299
    AC_DEFINE(HAVE_SSE2_INTRINSICS, 1, [Define to 1 if SSE2 intrinsics are available.])
1300
  ])
1301

1302 1303
  VLC_SAVE_FLAGS
  CFLAGS="${CFLAGS} -msse"
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
  AC_CACHE_CHECK([if $CC groks SSE inline assembly], [ac_cv_sse_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("xorps %%xmm1,%%xmm2"::"r"(p):"xmm1", "xmm2");
]])
    ], [
      ac_cv_sse_inline=yes
    ], [
      ac_cv_sse_inline=no
    ])
  ])
1315

1316
  AS_IF([test "${ac_cv_sse_inline}" != "no" -a "${SYS}" != "solaris"], [
1317
    AC_DEFINE(CAN_COMPILE_SSE, 1, [Define to 1 if SSE inline assembly is available.])
1318
  ])
1319

1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
  AC_CACHE_CHECK([if $CC groks SSE2 inline assembly], [ac_cv_sse2_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("punpckhqdq %%xmm1,%%xmm2"::"r"(p):"xmm1", "xmm2");
]])
    ], [
      ac_cv_sse2_inline=yes
    ], [
      ac_cv_sse2_inline=no
    ])
  ])
1331
  AS_IF([test "${ac_cv_sse2_inline}" != "no" -a "${SYS}" != "solaris"], [
1332
    AC_DEFINE(CAN_COMPILE_SSE2, 1, [Define to 1 if SSE2 inline assembly is available.])
1333
    have_sse2="yes"
1334
  ])
1335

1336
  # SSE3
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
  AC_CACHE_CHECK([if $CC groks SSE3 inline assembly], [ac_cv_sse3_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("movsldup %%xmm1,%%xmm0"::"r"(p):"xmm0", "xmm1");
]])
    ], [
      ac_cv_sse3_inline=yes
    ], [
      ac_cv_sse3_inline=no
    ])
  ])
1348

1349
  AS_IF([test "${ac_cv_sse3_inline}" != "no"], [
1350
    AC_DEFINE(CAN_COMPILE_SSE3, 1, [Define to 1 if SSE3 inline assembly is available.]) ])
1351
  # SSSE3
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362
  AC_CACHE_CHECK([if $CC groks SSSE3 inline assembly], [ac_cv_ssse3_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("pabsw %%xmm0,%%xmm0"::"r"(p):"xmm0");
]])
    ], [
      ac_cv_ssse3_inline=yes
    ], [
      ac_cv_ssse3_inline=no
    ])
  ])
1363

1364
  AS_IF([test "${ac_cv_ssse3_inline}" != "no"], [
1365
    AC_DEFINE(CAN_COMPILE_SSSE3, 1, [Define to 1 if SSSE3 inline assembly is available.]) ])
1366

1367 1368
  # SSE4.1
  AC_CACHE_CHECK([if $CC groks SSE4.1 inline assembly],
1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
                 [ac_cv_sse4_1_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("pmaxsb %%xmm1,%%xmm0"::"r"(p):"xmm0", "xmm1");
]])
    ], [
      ac_cv_sse4_1_inline=yes
    ], [
      ac_cv_sse4_1_inline=no
    ])
  ])
1380

1381
  AS_IF([test "${ac_cv_sse4_1_inline}" != "no"], [
1382
    AC_DEFINE(CAN_COMPILE_SSE4_1, 1, [Define to 1 if SSE4_1 inline assembly is available.]) ])
1383 1384 1385

  # SSE4.2
  AC_CACHE_CHECK([if $CC groks SSE4.2 inline assembly],
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
                 [ac_cv_sse4_2_inline], [
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[[
void *p;
asm volatile("pcmpgtq %%xmm1,%%xmm0"::"r"(p):"xmm0", "xmm1");
]])
    ], [
      ac_cv_sse4_2_inline=yes
    ], [
      ac_cv_sse4_2_inline=no
    ])
  ])
1397

1398
  AS_IF([test "${ac_cv_sse4_2_inline}" != "no"], [
1399
    AC_DEFINE(CAN_COMPILE_SSE4_2, 1, [Define to 1 if SSE4_2 inline assembly is available.]) ])
1400 1401

  # SSE4A
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411