Skip to content
Snippets Groups Projects
configure 223 KiB
Newer Older
  • Learn to ignore specific revisions
  •     [ -e src ] && rm src
        $ln_s "$source_path" src
        source_link=src
    else
        # creating directory links doesn't work
        # fall back to using the full source path
        source_link="$source_path"
    fi
    # cleanup
    rm -r "$link_dest"
    rm -r "$link_name"
    
    
    # determine libc flavour
    
    
        # uclibc defines __GLIBC__, so it needs to be checked before glibc.
        if check_${pfx}cpp_condition features.h "defined __UCLIBC__"; then
            eval ${pfx}libc_type=uclibc
            add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
        elif check_${pfx}cpp_condition features.h "defined __GLIBC__"; then
            eval ${pfx}libc_type=glibc
            add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
        # MinGW headers can be installed on Cygwin, so check for newlib first.
        elif check_${pfx}cpp_condition newlib.h "defined _NEWLIB_VERSION"; then
            eval ${pfx}libc_type=newlib
            add_${pfx}cppflags -U__STRICT_ANSI__
        # MinGW64 is backwards compatible with MinGW32, so check for it first.
        elif check_${pfx}cpp_condition _mingw.h "defined __MINGW64_VERSION_MAJOR"; then
            eval ${pfx}libc_type=mingw64
    
            if check_${pfx}cpp_condition _mingw.h "__MINGW64_VERSION_MAJOR < 3"; then
                add_compat msvcrt/snprintf.o
                add_cflags "-include $source_path/compat/msvcrt/snprintf.h"
            fi
    
            add_${pfx}cppflags -U__STRICT_ANSI__ -D__USE_MINGW_ANSI_STDIO=1
    
            eval test \$${pfx_no_}cc_type = "gcc" &&
                add_${pfx}cppflags -D__printf__=__gnu_printf__
    
        elif check_${pfx}cpp_condition _mingw.h "defined __MINGW_VERSION"  ||
             check_${pfx}cpp_condition _mingw.h "defined __MINGW32_VERSION"; then
    
            eval ${pfx}libc_type=mingw32
            check_${pfx}cpp_condition _mingw.h "__MINGW32_MAJOR_VERSION > 3 || \
                (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
                die "ERROR: MinGW32 runtime version must be >= 3.15."
    
            add_${pfx}cppflags -U__STRICT_ANSI__ -D__USE_MINGW_ANSI_STDIO=1
    
            check_${pfx}cpp_condition _mingw.h "defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0502" ||
                add_${pfx}cppflags -D_WIN32_WINNT=0x0502
    
            check_${pfx}cpp_condition _mingw.h "__MSVCRT_VERSION__ < 0x0700__" &&
                add_${pfx}cppflags -D__MSVCRT_VERSION__=0x0700
    
            eval test \$${pfx_no_}cc_type = "gcc" &&
                add_${pfx}cppflags -D__printf__=__gnu_printf__
    
        elif check_${pfx}cpp_condition crtversion.h "defined _VC_CRT_MAJOR_VERSION"; then
            eval ${pfx}libc_type=msvcrt
    
            if check_${pfx}cpp_condition crtversion.h "_VC_CRT_MAJOR_VERSION < 14"; then
                if [ "$pfx" = host_ ]; then
                    add_host_cppflags -Dsnprintf=_snprintf
                else
                    add_compat strtod.o strtod=avpriv_strtod
                    add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf   \
                                                 _snprintf=avpriv_snprintf  \
                                                 vsnprintf=avpriv_vsnprintf
                fi
            fi
    
            add_${pfx}cppflags -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS
    
            # The MSVC 2010 headers (Win 7.0 SDK) set _WIN32_WINNT to
            # 0x601 by default unless something else is set by the user.
            # This can easily lead to us detecting functions only present
            # in such new versions and producing binaries requiring windows 7.0.
            # Therefore explicitly set the default to XP unless the user has
            # set something else on the command line.
    
            # Don't do this if WINAPI_FAMILY is set and is set to a non-desktop
            # family. For these cases, configure is free to use any functions
            # found in the SDK headers by default. (Alternatively, we could force
            # _WIN32_WINNT to 0x0602 in that case.)
    
            check_${pfx}cpp_condition stdlib.h "defined(_WIN32_WINNT)" ||
    
                { check_${pfx}cpp <<EOF && add_${pfx}cppflags -D_WIN32_WINNT=0x0502; }
    #ifdef WINAPI_FAMILY
    #include <winapifamily.h>
    #if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
    #error not desktop
    #endif
    #endif
    EOF
    
            if [ "$pfx" = "" ]; then
                check_func strtoll || add_cflags -Dstrtoll=_strtoi64
    
                check_func strtoull || add_cflags -Dstrtoull=_strtoui64
    
        elif check_${pfx}cpp_condition stddef.h "defined __KLIBC__"; then
            eval ${pfx}libc_type=klibc
        elif check_${pfx}cpp_condition sys/cdefs.h "defined __BIONIC__"; then
            eval ${pfx}libc_type=bionic
    
        elif check_${pfx}cpp_condition sys/brand.h "defined LABELED_BRAND_NAME"; then
    
            eval ${pfx}libc_type=solaris
            add_${pfx}cppflags -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
    
        check_${pfx}cc <<EOF
    #include <time.h>
    void *v = localtime_r;
    EOF
    test "$?" != 0 && check_${pfx}cc -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 <<EOF && add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
    #include <time.h>
    void *v = localtime_r;
    EOF
    
    
    test -n "$libc_type" && enable libc_$libc_type
    
    probe_libc host_
    test -n "$host_libc_type" && enable host_libc_$host_libc_type
    
    case $libc_type in
        bionic)
            add_compat strtod.o strtod=avpriv_strtod
            ;;
    esac
    
    
    # hacks for compiler/libc/os combinations
    
    
    if enabled_all tms470 libc_glibc; then
    
        CPPFLAGS="-I${source_path}/compat/tms470 ${CPPFLAGS}"
    
        add_cppflags -D__USER_LABEL_PREFIX__=
        add_cppflags -D__builtin_memset=memset
        add_cppflags -D__gnuc_va_list=va_list -D_VA_LIST_DEFINED
        add_cflags   -pds=48    # incompatible redefinition of macro
    fi
    
    
    if enabled_all ccc libc_glibc; then
    
        add_ldflags -Wl,-z,now  # calls to libots crash without this
    fi
    
    
    check_compile_assert flt_lim "float.h limits.h" "DBL_MAX == (double)DBL_MAX" ||
        add_cppflags '-I\$(SRC_PATH)/compat/float'
    
    
    esc(){
        echo "$*" | sed 's/%/%25/g;s/:/%3a/g'
    }
    
    
    echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $FFMPEG_CONFIGURATION)" >config.fate
    
    check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
    
    set_default libdir
    : ${shlibdir_default:="$libdir"}
    
    : ${pkgconfigdir_default:="$libdir/pkgconfig"}
    
    set_default $PATHS_LIST
    
    set_default nm
    
    # we need to build at least one lib type
    
    if ! enabled_any static shared; then
    
        cat <<EOF
    At least one library type must be built.
    Specify --enable-static to build the static libraries or --enable-shared to
    build the shared libraries as well. To only build the shared libraries specify
    --disable-static in addition to --enable-shared.
    EOF
    
        enabled $1 || { enabled $v && die "$v is $1 and --enable-$1 is not specified."; }
    
        enabled $1 || { enabled $v && die "$v is incompatible with the gpl and --enable-$1 is not specified."; }
    }
    
    map "die_license_disabled gpl"      $EXTERNAL_LIBRARY_GPL_LIST $EXTERNAL_LIBRARY_GPLV3_LIST
    map "die_license_disabled version3" $EXTERNAL_LIBRARY_VERSION3_LIST $EXTERNAL_LIBRARY_GPLV3_LIST
    
    
    enabled gpl && map "die_license_disabled_gpl nonfree" $EXTERNAL_LIBRARY_NONFREE_LIST
    map "die_license_disabled nonfree" $HWACCEL_LIBRARY_NONFREE_LIST
    
    enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
    
    disabled optimizations || check_cflags -fomit-frame-pointer
    
    enable_weak_pic() {
        disabled pic && return
    
        case "$target_os" in
        mingw*|cygwin*)
            ;;
        *)
            add_cflags -fPIC
            ;;
        esac
    
    enabled pic && enable_weak_pic
    
    check_cc <<EOF || die "Symbol mangling check failed."
    int ff_extern;
    EOF
    
    sym=$($nm $TMPO | awk '/ff_extern/{ print substr($0, match($0, /[^ \t]*ff_extern/)) }')
    
    extern_prefix=${sym%%ff_extern*}
    
    
    check_cc <<EOF && enable_weak inline_asm
    
    void foo(void) { __asm__ volatile ("" ::); }
    EOF
    
    _restrict=
    for restrict_keyword in restrict __restrict__ __restrict; do
        check_cc <<EOF && _restrict=$restrict_keyword && break
    void foo(char * $restrict_keyword p);
    EOF
    done
    
    
    check_cc <<EOF && enable pragma_deprecated
    
    void foo(void) { _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") }
    
    check_cc <<EOF && enable attribute_packed
    struct { int x; } __attribute__((packed)) x;
    EOF
    
    
    check_cc <<EOF && enable attribute_may_alias
    union { int x; } __attribute__((may_alias)) x;
    EOF
    
    
    check_cc <<EOF || die "endian test failed"
    unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
    EOF
    
    od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
    
    if ! enabled ppc64 || enabled bigendian; then
        disable vsx
    fi
    
    check_gas() {
        log "check_gas using '$as' as AS"
        # :vararg is used on aarch64, arm and ppc altivec
        check_as <<EOF || return 1
    .macro m n, y:vararg=0
    \n: .int \y
    
        # .altmacro is only used in arm asm
        ! enabled arm || check_as <<EOF || return 1
    
    if enabled_any arm aarch64 || enabled_all ppc altivec && enabled asm; then
    
        enabled_any arm aarch64 && nogas=die
    
        enabled_all ppc altivec && [ $target_os_default != aix ] && nogas=warn
    
        as_noop=-v
    
        case $as_type in
            arm*) gaspp_as_type=armasm; as_noop=-h ;;
            gcc)  gaspp_as_type=gas ;;
            *)    gaspp_as_type=$as_type ;;
        esac
    
        [ $target_os = "darwin" ] && gaspp_as_type="apple-$gaspp_as_type"
    
    
        test "${as#*gas-preprocessor.pl}" != "$as" ||
        check_cmd gas-preprocessor.pl -arch $arch -as-type $gaspp_as_type -- ${as:=$cc} $as_noop &&
            gas="${gas:=gas-preprocessor.pl} -arch $arch -as-type $gaspp_as_type -- ${as:=$cc}"
    
    
        if ! check_gas ; then
            as=${gas:=$as}
            check_gas || \
    
                $nogas "GNU assembler not found, install/update gas-preprocessor"
    
    
        check_as <<EOF && enable as_func
    .func test
    .endfunc
    
    check_inline_asm inline_asm_labels '"1:\n"'
    
    
    check_inline_asm inline_asm_nonlocal_labels '"Label:\n"'
    
    
    if enabled aarch64; then
    
        enabled armv8 && check_insn armv8 'prfm   pldl1strm, [x0]'
    
        # internal assembler in clang 3.3 does not support this instruction
        enabled neon && check_insn neon 'ext   v0.8B, v0.8B, v1.8B, #1'
        enabled vfp  && check_insn vfp  'fmadd d0,    d0,    d1,    d2'
    
        map 'enabled_any ${v}_external ${v}_inline || disable $v' $ARCH_EXT_LIST_ARM
    
    elif enabled alpha; then
    
    
        check_cflags -mieee
    
    elif enabled arm; then
    
        enabled msvc && check_cpp_condition stddef.h "defined _M_ARMT" && enable thumb
    
        check_cpp_condition stddef.h "defined __thumb__" && check_cc <<EOF && enable_weak thumb
    float func(float a, float b){ return a+b; }
    EOF
    
    
        enabled thumb && check_cflags -mthumb || check_cflags -marm
    
        if     check_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then
            enable vfp_args
    
        elif check_cpp_condition stddef.h "defined _M_ARM_FP && _M_ARM_FP >= 30"; then
            enable vfp_args
    
        elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__" && [ $target_os != darwin ]; then
    
            case "${cross_prefix:-$cc}" in
                *hardfloat*)         enable vfp_args;   fpabi=vfp ;;
    
    Mohamed Naufal's avatar
    Mohamed Naufal committed
                *) check_ld "cc" <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
    
    __asm__ (".eabi_attribute 28, 1");
    int main(void) { return 0; }
    EOF
    
            esac
            warn "Compiler does not indicate floating-point ABI, guessing $fpabi."
        fi
    
        enabled armv5te && check_insn armv5te 'qadd r0, r0, r0'
        enabled armv6   && check_insn armv6   'sadd16 r0, r0, r0'
        enabled armv6t2 && check_insn armv6t2 'movt r0, #0'
        enabled neon    && check_insn neon    'vadd.i16 q0, q0, q0'
    
        enabled vfp     && check_insn vfp     'fadds s0, s0, s0'
    
        enabled vfpv3   && check_insn vfpv3   'vmov.f32 s0, #1.0'
    
        enabled setend  && check_insn setend  'setend be'
    
        [ $target_os = linux ] || [ $target_os = android ] ||
    
            map 'enabled_any ${v}_external ${v}_inline || disable $v' \
                $ARCH_EXT_LIST_ARM
    
        check_inline_asm asm_mod_q '"add r0, %Q0, %R0" :: "r"((long long)0)'
    
        check_as <<EOF && enable as_dn_directive
    ra .dn d0.i16
    .unreq ra
    
    EOF
        check_as <<EOF && enable as_fpu_directive
    .fpu neon
    
    EOF
    
        # llvm's integrated assembler supports .object_arch from llvm 3.5
        [ "$objformat" = elf ] && check_as <<EOF && enable as_object_arch
    .object_arch armv4
    
        [ $target_os != win32 ] && enabled_all armv6t2 shared !pic && enable_weak_pic
    
    elif enabled mips; then
    
        enabled loongson2 && check_inline_asm loongson2 '"dmult.g $8, $9, $10"'
        enabled loongson3 && check_inline_asm loongson3 '"gsldxc1 $f0, 0($2, $3)"'
    
        enabled mmi && check_inline_asm mmi '"punpcklhw $f0, $f0, $f0"'
    
    
        # Enable minimum ISA based on selected options
    
            enabled mips64r6 && check_inline_asm_flags mips64r6 '"dlsa $0, $0, $0, 1"' '-mips64r6'
            enabled mips64r2 && check_inline_asm_flags mips64r2 '"dext $0, $0, 0, 1"' '-mips64r2'
            disabled mips64r6 && disabled mips64r2 && check_inline_asm_flags mips64r1 '"daddi $0, $0, 0"' '-mips64'
    
            enabled mips32r6 && check_inline_asm_flags mips32r6 '"aui $0, $0, 0"' '-mips32r6'
            enabled mips32r5 && check_inline_asm_flags mips32r5 '"eretnc"' '-mips32r5'
            enabled mips32r2 && check_inline_asm_flags mips32r2 '"ext $0, $0, 0, 1"' '-mips32r2'
            disabled mips32r6 && disabled mips32r5 && disabled mips32r2 && check_inline_asm_flags mips32r1 '"addi $0, $0, 0"' '-mips32'
    
        enabled mipsfpu && check_inline_asm_flags mipsfpu '"cvt.d.l $f0, $f2"' '-mhard-float'
    
        enabled mipsfpu && (enabled mips32r5 || enabled mips32r6 || enabled mips64r6) && check_inline_asm_flags mipsfpu '"cvt.d.l $f0, $f1"' '-mfp64'
        enabled mipsfpu && enabled msa && check_inline_asm_flags msa '"addvi.b $w0, $w1, 1"' '-mmsa' && check_header msa.h || disable msa
    
        enabled mipsdsp && check_inline_asm_flags mipsdsp '"addu.qb $t0, $t1, $t2"' '-mdsp'
        enabled mipsdspr2 && check_inline_asm_flags mipsdspr2 '"absq_s.qb $t0, $t1"' '-mdspr2'
    
    elif enabled parisc; then
    
        if enabled gcc; then
            case $($cc -dumpversion) in
    
                4.[3-9].*) check_cflags -fno-optimize-sibling-calls ;;
    
    elif enabled ppc; then
    
    James Almer's avatar
    James Almer committed
        enable local_aligned_8 local_aligned_16 local_aligned_32
    
        check_inline_asm dcbzl     '"dcbzl 0, %0" :: "r"(0)'
        check_inline_asm ibm_asm   '"add 0, 0, 0"'
        check_inline_asm ppc4xx    '"maclhw r10, r11, r12"'
        check_inline_asm xform_asm '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)'
    
    
        # AltiVec flags: The FSF version of GCC differs from the Apple version
        if enabled altivec; then
            check_cflags -maltivec -mabi=altivec &&
            { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
            check_cflags -faltivec
    
            # check if our compiler supports Motorola AltiVec C API
            check_cc <<EOF || disable altivec
    $inc_altivec_h
    int main(void) {
    
        vector signed int v1 = (vector signed int) { 0 };
        vector signed int v2 = (vector signed int) { 1 };
        v1 = vec_add(v1, v2);
    
            enabled altivec || warn "Altivec disabled, possibly missing --cpu flag"
    
            check_cflags -mvsx &&
            check_builtin vec_vsx_ld "altivec.h" "__builtin_vec_vsx_ld" || disable vsx
    
    
        if enabled power8; then
            check_cpp_condition "altivec.h" "defined(_ARCH_PWR8)" || disable power8
        fi
    
    
    elif enabled x86; then
    
        check_builtin rdtsc    intrin.h   "__rdtsc()"
        check_builtin mm_empty mmintrin.h "_mm_empty()"
    
    James Almer's avatar
    James Almer committed
        enable local_aligned_8 local_aligned_16 local_aligned_32
    
        # check whether EBP is available on x86
        # As 'i' is stored on the stack, this program will crash
        # if the base pointer is used to access it because the
        # base pointer is cleared in the inline assembly code.
    
        check_exec_crash <<EOF && enable ebp_available
    
    volatile int i=0;
    __asm__ volatile ("xorl %%ebp, %%ebp" ::: "%ebp");
    return i;
    
    Reimar Döffinger's avatar
    Reimar Döffinger committed
        # check whether EBX is available on x86
    
        check_inline_asm ebx_available '""::"b"(0)' &&
            check_inline_asm ebx_available '"":::"%ebx"'
    
        # check whether xmm clobbers are supported
    
        check_inline_asm xmm_clobbers '"":::"%xmm0"'
    
        check_inline_asm inline_asm_direct_symbol_refs '"movl '$extern_prefix'test, %eax"' ||
            check_inline_asm inline_asm_direct_symbol_refs '"movl '$extern_prefix'test(%rip), %eax"'
    
        # check whether binutils is new enough to compile SSSE3/MMXEXT
    
        enabled ssse3  && check_inline_asm ssse3_inline  '"pabsw %xmm0, %xmm0"'
        enabled mmxext && check_inline_asm mmxext_inline '"pmaxub %mm0, %mm1"'
    
            if check_cmd $yasmexe --version; then
                enabled x86_64 && yasm_extra="-m amd64"
                yasm_debug="-g dwarf2"
            elif check_cmd nasm -v; then
                yasmexe=nasm
                yasm_debug="-g -F dwarf"
    
                if enabled x86_64; then
                    case "$objformat" in
                        elf)   objformat=elf64 ;;
                        win32) objformat=win64 ;;
                    esac
                fi
    
            fi
    
            YASMFLAGS="-f $objformat $yasm_extra"
            enabled pic               && append YASMFLAGS "-DPIC"
            test -n "$extern_prefix"  && append YASMFLAGS "-DPREFIX"
            case "$objformat" in
                elf*) enabled debug && append YASMFLAGS $yasm_debug ;;
            esac
    
    
            check_yasm "movbe ecx, [5]" && enable yasm ||
                die "yasm/nasm not found or too old. Use --disable-yasm for a crippled build."
    
            check_yasm "vextracti128 xmm0, ymm0, 0"      || disable avx2_external
    
            check_yasm "vpmacsdd xmm0, xmm1, xmm2, xmm3" || disable xop_external
    
            check_yasm "vfmaddps ymm0, ymm1, ymm2, ymm3" || disable fma4_external
    
            check_yasm "CPU amdnop" || disable cpunop
    
        case "$cpu" in
            athlon*|opteron*|k8*|pentium|pentium-mmx|prescott|nocona|atom|geode)
                disable fast_clz
            ;;
        esac
    
    
    check_code cc arm_neon.h "int16x8_t test = vdupq_n_s16(0)" && enable intrinsics_neon
    
    check_ldflags -Wl,--as-needed
    
    check_ldflags -Wl,-z,noexecstack
    
    if check_func dlopen && check_func dlsym; then
    
    elif check_func dlopen -ldl && check_func dlsym -ldl; then
    
    avisynth_demuxer_extralibs='$ldl'
    
    decklink_outdev_extralibs="$decklink_outdev_extralibs $ldl"
    decklink_indev_extralibs="$decklink_indev_extralibs $ldl"
    
    frei0r_filter_extralibs='$ldl'
    frei0r_src_filter_extralibs='$ldl'
    ladspa_filter_extralibs='$ldl'
    
    coreimage_filter_extralibs="-framework QuartzCore -framework AppKit -framework OpenGL"
    coreimagesrc_filter_extralibs="-framework QuartzCore -framework AppKit -framework OpenGL"
    
        check_func getaddrinfo $network_extralibs
        check_func inet_aton $network_extralibs
    
    
        check_type netdb.h "struct addrinfo"
    
        check_type netinet/in.h "struct group_source_req" -D_BSD_SOURCE
        check_type netinet/in.h "struct ip_mreq_source" -D_BSD_SOURCE
    
        check_type netinet/in.h "struct ipv6_mreq" -D_DARWIN_C_SOURCE
    
        check_type poll.h "struct pollfd"
    
        check_type netinet/sctp.h "struct sctp_event_subscribe"
    
        check_struct "sys/socket.h" "struct msghdr" msg_flags
    
        check_struct "sys/types.h sys/socket.h" "struct sockaddr" sa_len
        check_type netinet/in.h "struct sockaddr_in6"
        check_type "sys/types.h sys/socket.h" "struct sockaddr_storage"
        check_type "sys/types.h sys/socket.h" socklen_t
    
    
        # Prefer arpa/inet.h over winsock2
        if check_header arpa/inet.h ; then
            check_func closesocket
        elif check_header winsock2.h ; then
    
            check_func_headers winsock2.h closesocket -lws2 &&
                network_extralibs="-lws2" ||
            { check_func_headers winsock2.h closesocket -lws2_32 &&
    
                network_extralibs="-lws2_32"; } || disable winsock2_h network
    
            check_func_headers ws2tcpip.h getaddrinfo $network_extralibs
    
            check_type ws2tcpip.h socklen_t
            check_type ws2tcpip.h "struct addrinfo"
    
            check_type ws2tcpip.h "struct group_source_req"
            check_type ws2tcpip.h "struct ip_mreq_source"
    
            check_type ws2tcpip.h "struct ipv6_mreq"
    
            check_type winsock2.h "struct pollfd"
    
            check_struct winsock2.h "struct sockaddr" sa_len
    
            check_type ws2tcpip.h "struct sockaddr_in6"
            check_type ws2tcpip.h "struct sockaddr_storage"
        else
            disable network
        fi
    fi
    
    
    check_builtin atomic_cas_ptr atomic.h "void **ptr; void *oldval, *newval; atomic_cas_ptr(ptr, oldval, newval)"
    check_builtin machine_rw_barrier mbarrier.h "__machine_rw_barrier()"
    check_builtin MemoryBarrier windows.h "MemoryBarrier()"
    
    check_builtin sarestart signal.h "SA_RESTART"
    
    check_builtin sem_timedwait semaphore.h "sem_t *s; sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)" -lpthread
    
    check_builtin sync_val_compare_and_swap "" "int *ptr; int oldval, newval; __sync_val_compare_and_swap(ptr, oldval, newval)"
    
    check_builtin gmtime_r time.h "time_t *time; struct tm *tm; gmtime_r(time, tm)"
    check_builtin localtime_r time.h "time_t *time; struct tm *tm; localtime_r(time, tm)"
    
    check_builtin x264_csp_bgr "stdint.h x264.h" "X264_CSP_BGR"
    
    case "$custom_allocator" in
        jemalloc)
            # jemalloc by default does not use a prefix
            require libjemalloc jemalloc/jemalloc.h malloc -ljemalloc
        ;;
        tcmalloc)
            require_pkg_config libtcmalloc gperftools/tcmalloc.h tc_malloc
            malloc_prefix=tc_
        ;;
    esac
    
    
    check_func_headers malloc.h _aligned_malloc     && enable aligned_malloc
    check_func  ${malloc_prefix}memalign            && enable memalign
    check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
    
    check_func  access
    
    check_func_headers stdlib.h arc4random
    
    check_func_headers time.h clock_gettime ||
    
        { check_lib time.h clock_gettime -lrt && LIBRT="-lrt"; }
    
    Måns Rullgård's avatar
    Måns Rullgård committed
    check_func  fcntl
    
    check_func  gettimeofday
    
    check_func  isatty
    
    check_func  mach_absolute_time
    
    check_func  mprotect
    
    # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
    
    check_func_headers time.h nanosleep ||
    
        { check_lib time.h nanosleep -lrt && LIBRT="-lrt"; }
    
    check_func  sched_getaffinity
    
    Måns Rullgård's avatar
    Måns Rullgård committed
    check_func  setrlimit
    
    check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
    
    check_func  strerror_r
    
    check_func  usleep
    
    check_func_headers conio.h kbhit
    
    check_func_headers io.h setmode
    
    check_func_headers lzo/lzo1x.h lzo1x_999_compress
    
    check_func_headers stdlib.h getenv
    
    check_func_headers sys/stat.h lstat
    
    check_func_headers windows.h CoTaskMemFree -lole32
    
    check_func_headers windows.h GetProcessAffinityMask
    
    check_func_headers windows.h GetProcessTimes
    
    check_func_headers windows.h GetSystemTimeAsFileTime
    
    check_func_headers windows.h LoadLibrary
    
    check_func_headers windows.h MapViewOfFile
    
    check_func_headers windows.h PeekNamedPipe
    
    check_func_headers windows.h SetConsoleTextAttribute
    
    check_func_headers windows.h SetConsoleCtrlHandler
    
    check_func_headers windows.h Sleep
    
    check_func_headers windows.h VirtualAlloc
    
    check_struct windows.h "CONDITION_VARIABLE" Ptr
    
    check_func_headers glob.h glob
    
    enabled xlib &&
        check_func_headers "X11/Xlib.h X11/extensions/Xvlib.h" XvGetPortAttribute -lXv -lX11 -lXext
    
    check_header AudioToolbox/AudioToolbox.h
    
    check_header dirent.h
    
    check_header dlfcn.h
    
    check_header dxva.h
    
    check_header dxva2api.h -D_WIN32_WINNT=0x0600
    
    check_header io.h
    
    check_header libcrystalhd/libcrystalhd_if.h
    
    check_header mach/mach_time.h
    
    check_header malloc.h
    
    check_header net/udplite.h
    
    check_header sys/resource.h
    
    check_header sys/time.h
    
    Luca Barbato's avatar
    Luca Barbato committed
    check_header sys/un.h
    
    check_header unistd.h
    
    check_header vdpau/vdpau.h
    check_header vdpau/vdpau_x11.h
    
    check_header VideoDecodeAcceleration/VDADecoder.h
    
    check_header VideoToolbox/VideoToolbox.h
    
    check_func_headers VideoToolbox/VTCompressionSession.h VTCompressionSessionPrepareToEncodeFrames -framework VideoToolbox
    
    enabled videotoolbox && check_func_headers CoreVideo/CVImageBuffer.h kCVImageBufferColorPrimaries_ITU_R_2020 -framework CoreVideo
    
    check_header windows.h
    
    check_header X11/extensions/XvMClib.h
    
    check_header asm/types.h
    
    # it seems there are versions of clang in some distros that try to use the
    # gcc headers, which explodes for stdatomic
    # so we also check that atomics actually work here
    
    check_builtin stdatomic_h stdatomic.h "atomic_int foo, bar = ATOMIC_VAR_INIT(-1); atomic_store(&foo, 0)"
    
    check_lib "windows.h shellapi.h" CommandLineToArgvW   -lshell32
    check_lib "windows.h wincrypt.h" CryptGenRandom       -ladvapi32
    check_lib "windows.h psapi.h"    GetProcessMemoryInfo -lpsapi
    
    check_lib "CoreServices/CoreServices.h" UTGetOSTypeFromString "-framework CoreServices"
    
    
    check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
    
    
    check_type "windows.h dxva.h" "DXVA_PicParams_HEVC" -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D_CRT_BUILD_DESKTOP_APP=0
    
    check_type "windows.h dxva.h" "DXVA_PicParams_VP9" -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D_CRT_BUILD_DESKTOP_APP=0
    
    check_type "windows.h d3d11.h" "ID3D11VideoDecoder"
    
    check_type "windows.h d3d11.h" "ID3D11VideoContext"
    
    check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602
    
    check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC"
    
    check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth
    
    Mark Thompson's avatar
    Mark Thompson committed
    check_type "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer"
    
    check_type "va/va.h va/va_enc_h264.h" "VAEncPictureParameterBufferH264"
    
    check_type "va/va.h va/va_enc_hevc.h" "VAEncPictureParameterBufferHEVC"
    
    check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
    
    check_type "va/va.h va/va_enc_mpeg2.h" "VAEncPictureParameterBufferMPEG2"
    
    check_type "va/va.h va/va_enc_vp8.h"  "VAEncPictureParameterBufferVP8"
    
    check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
    
    
    wang-bin's avatar
    wang-bin committed
    check_cpp_condition windows.h "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)" && enable winrt || disable winrt
    
    
    if ! disabled w32threads && ! enabled pthreads; then
    
        check_func_headers "windows.h process.h" _beginthreadex &&
            enable w32threads || disable w32threads
    
    wang-bin's avatar
    wang-bin committed
        if ! enabled w32threads && enabled winrt; then
            check_func_headers "windows.h" CreateThread &&
                enable w32threads || disable w32threads
        fi
    
    # check for some common methods of building with pthread support
    # do this before the optional library checks as some of them require pthreads
    
    if ! disabled pthreads && ! enabled w32threads && ! enabled os2threads; then
    
        if check_func pthread_join -pthread && check_func pthread_create -pthread; then
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            add_cflags -pthread
    
        elif check_func pthread_join -pthreads && check_func pthread_create -pthreads; then
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            add_cflags -pthreads
    
        elif check_func pthread_join -ldl -pthread && check_func pthread_create -ldl -pthread; then
            add_cflags -ldl -pthread
            add_extralibs -ldl -pthread
    
        elif check_func pthread_join -lpthreadGC2 && check_func pthread_create -lpthreadGC2; then
    
            add_extralibs -lpthreadGC2
    
        elif check_lib pthread.h pthread_join -lpthread && check_lib pthread.h pthread_create -lpthread; then
    
        elif ! check_func pthread_join && ! check_func pthread_create; then
    
        check_code cc "pthread.h" "static pthread_mutex_t atomic_lock = PTHREAD_MUTEX_INITIALIZER" || disable pthreads
    
    if enabled pthreads; then
      check_func pthread_cancel
    fi
    
    
    Josh de Kock's avatar
    Josh de Kock committed
    enabled pthreads &&
        check_builtin sem_timedwait semaphore.h "sem_t *s; sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)"
    
    
    disabled  zlib || check_lib  zlib.h      zlibVersion    -lz    || disable  zlib
    disabled bzlib || check_lib bzlib.h BZ2_bzlibVersion    -lbz2  || disable bzlib
    disabled  lzma || check_lib  lzma.h lzma_version_number -llzma || disable lzma
    
    check_lib math.h sin -lm && LIBM="-lm"
    
    disabled crystalhd || check_lib "stdint.h libcrystalhd/libcrystalhd_if.h" DtsCrystalHDVersion -lcrystalhd || disable crystalhd
    
    Måns Rullgård's avatar
    Måns Rullgård committed
    
    
    copysign_args=2
    
    ldexpf_args=2
    powf_args=2
    
    for func in $MATH_FUNCS; do
    
        eval check_mathfunc $func \${${func}_args:-1}
    
    for func in $COMPLEX_FUNCS; do
        eval check_complexfunc $func \${${func}_args:-1}
    done
    
    
    # these are off by default, so fail if requested and not available
    
    enabled avfoundation_indev && { check_header_objcc AVFoundation/AVFoundation.h || disable avfoundation_indev; }
    
    enabled avfoundation_indev && { check_lib CoreGraphics/CoreGraphics.h CGGetActiveDisplayList -framework CoreGraphics ||
                                    check_lib ApplicationServices/ApplicationServices.h CGGetActiveDisplayList -framework ApplicationServices; }
    
    enabled cuda              && check_header cuda.h # this is not a dependency
    
                                   die "ERROR: CUVID requires CUDA"; }
    
    enabled chromaprint       && require chromaprint chromaprint.h chromaprint_get_version -lchromaprint
    
    enabled coreimage_filter  && { check_header_objcc QuartzCore/CoreImage.h || disable coreimage_filter; }
    enabled coreimagesrc_filter && { check_header_objcc QuartzCore/CoreImage.h || disable coreimagesrc_filter; }
    
    enabled decklink          && { { check_header DeckLinkAPI.h || die "ERROR: DeckLinkAPI.h header not found"; } &&
                                   { check_cpp_condition DeckLinkAPIVersion.h "BLACKMAGIC_DECKLINK_API_VERSION >= 0x0a060100" || die "ERROR: Decklink API version must be >= 10.6.1."; } }
    
    enabled frei0r            && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
    
    enabled gmp               && require gmp gmp.h mpz_export -lgmp
    
    enabled gnutls            && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
    
    Matthieu Bouron's avatar
    Matthieu Bouron committed
    enabled jni               && { [ $target_os = "android" ] && check_header jni.h && enabled pthreads &&
    
                                   check_lib "dlfcn.h" dlopen -ldl || die "ERROR: jni not found"; }
    
    enabled ladspa            && { check_header ladspa.h || die "ERROR: ladspa.h header not found"; }
    
    enabled libiec61883       && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
    enabled libass            && require_pkg_config libass ass/ass.h ass_library_init
    
    enabled libbluray         && require_pkg_config libbluray libbluray/bluray.h bd_open
    
    enabled libbs2b           && require_pkg_config libbs2b bs2b.h bs2b_open
    
    enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
                                 { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 ||
                                   die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
    enabled libcaca           && require_pkg_config caca caca.h caca_create_canvas
    
    enabled libfdk_aac        && { use_pkg_config fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
                                   { require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac &&
                                     warn "using libfdk without pkg-config"; } }
    
    flite_libs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite"
    
    enabled libflite          && require libflite "flite/flite.h" flite_init $flite_libs
    
    enabled fontconfig        && enable libfontconfig
    
    enabled libfontconfig     && require_pkg_config fontconfig "fontconfig/fontconfig.h" FcInit
    
    enabled libfreetype       && require_libfreetype
    
    enabled libfribidi        && require_pkg_config fribidi fribidi.h fribidi_version_info
    
    enabled libgme            && require  libgme gme/gme.h gme_new_emu -lgme -lstdc++
    
    enabled libgsm            && { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do
                                       check_lib "${gsm_hdr}" gsm_create -lgsm && break;
                                   done || die "ERROR: libgsm not found"; }
    enabled libilbc           && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
    
    enabled libkvazaar        && require_pkg_config "kvazaar >= 0.8.1" kvazaar.h kvz_api_get
    
    enabled libmfx            && require_pkg_config libmfx "mfx/mfxvideo.h" MFXInit
    
    enabled libmodplug        && require_pkg_config libmodplug libmodplug/modplug.h ModPlug_Load
    
    enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
    
    enabled libnut            && require libnut libnut.h nut_demuxer_init -lnut
    
    enabled libnpp            && require libnpp npp.h nppGetLibVersion -lnppi -lnppc
    
    enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
    enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
    
    enabled libopencv         && { check_header opencv2/core/core_c.h &&
    
                                   { use_pkg_config opencv opencv2/core/core_c.h cvCreateImageHeader ||
                                     require opencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
    
                                   require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader; }
    
    enabled libopenh264       && require_pkg_config openh264 wels/codec_api.h WelsGetCodecVersion
    
    enabled libopenjpeg       && { { check_lib openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
                                   check_lib openjpeg-2.1/openjpeg.h opj_version -lopenjp2 ||
                                   { check_lib openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
                                   { check_lib openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
                                   { check_lib openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
    
                                   die "ERROR: libopenjpeg not found"; }
    
    enabled libopenmpt        && require_pkg_config "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create
    
    enabled libopus           && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
    
    enabled libpulse          && require_pkg_config libpulse pulse/pulseaudio.h pa_context_new
    
    enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
    
    enabled librubberband     && require_pkg_config "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
    
    enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
    
    Romain Beauxis's avatar
    Romain Beauxis committed
    enabled libshine          && require_pkg_config shine shine/layer3.h shine_encode_buffer
    
    enabled libsmbclient      && { use_pkg_config smbclient libsmbclient.h smbc_init ||
    
                                   require smbclient libsmbclient.h smbc_init -lsmbclient; }
    
    enabled libsnappy         && require snappy snappy-c.h snappy_compress -lsnappy
    
    enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr && LIBSOXR="-lsoxr"
    
    enabled libssh            && require_pkg_config libssh libssh/sftp.h sftp_init
    
    enabled libspeex          && require_pkg_config speex speex/speex.h speex_decoder_init -lspeex
    
    Paul B Mahol's avatar
    Paul B Mahol committed
    enabled libtesseract      && require_pkg_config tesseract tesseract/capi.h TessBaseAPICreate
    
    enabled libtheora         && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
    
    enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame &&
                                 { check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
                                   die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
    enabled libv4l2           && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl
    
    enabled libvidstab        && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
    
    enabled libvo_amrwbenc    && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
    enabled libvorbis         && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
    
    enabled libvpx            && {
    
        enabled libvpx_vp8_decoder && {
    
            use_pkg_config "vpx >= 0.9.1" "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp8_dx ||
    
                check_lib "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
    
                    die "ERROR: libvpx decoder version must be >=0.9.1";
    
        }
        enabled libvpx_vp8_encoder && {
    
            use_pkg_config "vpx >= 0.9.7" "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp8_cx ||
    
                check_lib "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VP8E_SET_MAX_INTRA_BITRATE_PCT" -lvpx ||
    
                    die "ERROR: libvpx encoder version must be >=0.9.7";
    
        }
        enabled libvpx_vp9_decoder && {
    
            use_pkg_config "vpx >= 1.3.0" "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp9_dx ||
    
                check_lib "vpx/vpx_decoder.h vpx/vp8dx.h" "vpx_codec_vp9_dx" -lvpx ||
    
        }
        enabled libvpx_vp9_encoder && {
    
            use_pkg_config "vpx >= 1.3.0" "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp9_cx ||
    
                check_lib "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx VP9E_SET_AQ_MODE" -lvpx ||
    
        }
        if disabled_all libvpx_vp8_decoder libvpx_vp9_decoder libvpx_vp8_encoder libvpx_vp9_encoder; then
            die "libvpx enabled but no supported decoders found"
        fi
    }
    
    enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput  -lwavpack
    
        enabled libwebp_encoder      && require_pkg_config "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
        enabled libwebp_anim_encoder && { use_pkg_config "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit || disable libwebp_anim_encoder; } }
    
    enabled libx264           && { use_pkg_config x264 "stdint.h x264.h" x264_encoder_encode ||
    
                                   { require libx264 "stdint.h x264.h" x264_encoder_encode -lx264 &&
    
                                     warn "using libx264 without pkg-config"; } } &&
    
                                 { check_cpp_condition x264.h "X264_BUILD >= 118" ||
    
                                   die "ERROR: libx264 must be installed and version must be >= 0.118."; } &&
    
                                 { check_cpp_condition x264.h "X264_MPEG2" &&
                                   enable libx262; }
    
    enabled libx265           && require_pkg_config x265 x265.h x265_api_get &&
    
                                 { check_cpp_condition x265.h "X265_BUILD >= 68" ||
                                   die "ERROR: libx265 version must be >= 68."; }
    
    enabled libxavs           && require libxavs "stdint.h xavs.h" xavs_encoder_encode -lxavs
    
    enabled libxvid           && require libxvid xvid.h xvid_global -lxvidcore
    
    enabled libzimg           && require_pkg_config "zimg >= 2.3.0" zimg.h zimg_get_api_version
    
    enabled libzmq            && require_pkg_config libzmq zmq.h zmq_ctx_new
    
    enabled libzvbi           && require libzvbi libzvbi.h vbi_decoder_new -lzvbi &&
                                 { check_cpp_condition libzvbi.h "VBI_VERSION_MAJOR > 0 || VBI_VERSION_MINOR > 2 || VBI_VERSION_MINOR == 2 && VBI_VERSION_MICRO >= 28" ||
                                   enabled gpl || die "ERROR: libzvbi requires version 0.2.28 or --enable-gpl."; }
    
    enabled mediacodec        && { enabled jni || die "ERROR: mediacodec requires --enable-jni"; }
    
    enabled mmal              && { check_lib interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host ||
                                    { ! enabled cross_compile && {
                                        add_cflags -isystem/opt/vc/include/ -isystem/opt/vc/include/interface/vmcs_host/linux -isystem/opt/vc/include/interface/vcos/pthreads -fgnu89-inline ;
                                        add_extralibs -L/opt/vc/lib/ -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host ;
                                        check_lib interface/mmal/mmal.h mmal_port_connect ; }
                                    check_lib interface/mmal/mmal.h mmal_port_connect ; } ||
                                   die "ERROR: mmal not found"; }
    
    wm4's avatar
    wm4 committed
    enabled mmal && check_func_headers interface/mmal/mmal.h "MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS"
    
    enabled netcdf            && require_pkg_config netcdf netcdf.h nc_inq_libvers
    
    enabled openal            && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
                                   check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } ||
                                   die "ERROR: openal not found"; } &&
                                 { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
                                   die "ERROR: openal must be installed and version must be 1.1 or compatible"; }
    
    enabled opencl            && { check_lib OpenCL/cl.h clEnqueueNDRangeKernel -Wl,-framework,OpenCL ||
                                   check_lib CL/cl.h clEnqueueNDRangeKernel -lOpenCL ||
    
                                   die "ERROR: opencl not found"; } &&
                                 { check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
                                   check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
                                   die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
    
    Lukasz Marek's avatar
    Lukasz Marek committed
    enabled opengl            && { check_lib GL/glx.h glXGetProcAddress "-lGL" ||
    
                                   check_lib windows.h wglGetProcAddress "-lopengl32 -lgdi32" ||
                                   check_lib OpenGL/gl3.h glGetError "-Wl,-framework,OpenGL" ||
                                   check_lib ES2/gl.h glGetError "-isysroot=${sysroot} -Wl,-framework,OpenGLES" ||
    
    Lukasz Marek's avatar
    Lukasz Marek committed
                                   die "ERROR: opengl not found."
                                 }
    
    enabled omx_rpi && enable omx
    enabled omx               && { check_header OMX_Core.h ||
                                    { ! enabled cross_compile && enabled omx_rpi && {
                                        add_cflags -isystem/opt/vc/include/IL ; }
                                    check_header OMX_Core.h ; } ||
                                   die "ERROR: OpenMAX IL headers not found"; }
    
    enabled openssl           && { use_pkg_config openssl openssl/ssl.h OPENSSL_init_ssl ||
                                   use_pkg_config openssl openssl/ssl.h SSL_library_init ||
    
                                   check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
    
                                   check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                                   check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                                   die "ERROR: openssl not found"; }
    
    enabled qtkit_indev      && { check_header_objcc QTKit/QTKit.h || disable qtkit_indev; }
    
        { require_pkg_config libdc1394-2 dc1394/dc1394.h dc1394_new &&
    
            enable libdc1394_2; } ||
        { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 &&
            enable libdc1394_1; } ||
        die "ERROR: No version of libdc1394 found "
    fi
    
    
    if enabled gcrypt; then
        GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
        if "${GCRYPT_CONFIG}" --version > /dev/null 2>&1; then
    
            gcrypt_cflags=$("${GCRYPT_CONFIG}" --cflags)
    
            gcrypt_libs=$("${GCRYPT_CONFIG}" --libs)
    
            check_func_headers gcrypt.h gcry_mpi_new $gcrypt_cflags $gcrypt_libs ||
                die "ERROR: gcrypt not found"
            add_cflags $gcrypt_cflags && add_extralibs $gcrypt_libs
    
            require gcrypt gcrypt.h gcry_mpi_new -lgcrypt
    
    Josh de Kock's avatar
    Josh de Kock committed
    disabled sdl && disable sdl2
    
    if ! disabled sdl2; then
    
        SDL2_CONFIG="${cross_prefix}sdl2-config"
        if check_pkg_config sdl2 SDL_events.h SDL_PollEvent; then
            check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
            check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags &&
            check_func SDL_Init $sdl2_libs $sdl2_cflags && enable sdl2
        else
          if "${SDL2_CONFIG}" --version > /dev/null 2>&1; then
            sdl2_cflags=$("${SDL2_CONFIG}" --cflags)
            sdl2_libs=$("${SDL2_CONFIG}" --libs)
            check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
            check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags &&
            check_func SDL_Init $sdl2_libs $sdl2_cflags && enable sdl2
          fi
        fi
        if test $target_os = "mingw32"; then
            sdl2_libs="$sdl2_libs -mconsole"
        fi
    fi
    
    enabled sdl2 && enable sdl && add_cflags $sdl2_cflags && add_extralibs $sdl2_libs
    
    disabled securetransport || { check_func SecIdentityCreate "-Wl,-framework,CoreFoundation -Wl,-framework,Security" &&
    
        check_lib "Security/SecureTransport.h Security/Security.h" "SSLCreateContext SecItemImport" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" &&
    
        enable securetransport; }
    
    
    disabled schannel || { check_func_headers "windows.h security.h" InitializeSecurityContext -DSECURITY_WIN32 -lsecur32 &&
    
                           check_cpp_condition winerror.h "defined(SEC_I_CONTEXT_EXPIRED)" && enable schannel && add_extralibs -lsecur32; }
    
    makeinfo --version > /dev/null 2>&1 && enable makeinfo  || disable makeinfo
    
    enabled makeinfo \
        && [ 0$(makeinfo --version | grep "texinfo" | sed 's/.*texinfo[^0-9]*\([0-9]*\)\..*/\1/') -ge 5 ] \
    
        && enable makeinfo_html || disable makeinfo_html
    disabled makeinfo_html && texi2html --help 2> /dev/null | grep -q 'init-file' && enable texi2html || disable texi2html
    
    perl -v            > /dev/null 2>&1 && enable perl      || disable perl
    
    pod2man --help     > /dev/null 2>&1 && enable pod2man   || disable pod2man
    
    rsync --help 2> /dev/null | grep -q 'contimeout' && enable rsync_contimeout || disable rsync_contimeout
    
    check_header linux/fb.h
    
    check_header linux/videodev.h
    check_header linux/videodev2.h
    
    check_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_safe struct_v4l2_frmivalenum_discrete
    
    check_header sys/videoio.h
    
    check_code cc sys/videoio.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_safe struct_v4l2_frmivalenum_discrete
    
    check_func_headers "windows.h vfw.h" capCreateCaptureWindow "$vfwcap_indev_extralibs"
    
    # check that WM_CAP_DRIVER_CONNECT is defined to the proper value
    # w32api 3.12 had it defined wrong
    check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
    
    Ramiro Polla's avatar
    Ramiro Polla committed
    
    
    Ramiro Polla's avatar
    Ramiro Polla committed
    check_type "dshow.h" IBaseFilter
    
    
    # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
    
    Ramiro Polla's avatar
    Ramiro Polla committed
    { check_header dev/bktr/ioctl_meteor.h &&
      check_header dev/bktr/ioctl_bt848.h; } ||
    { check_header machine/ioctl_meteor.h &&
      check_header machine/ioctl_bt848.h; } ||
    { check_header dev/video/meteor/ioctl_meteor.h &&