Skip to content
Snippets Groups Projects
configure 220 KiB
Newer Older
  • Learn to ignore specific revisions
  •         _type=armasm
            _ident=$($_cc | head -n1)
            # 4509: "This form of conditional instruction is deprecated"
            _flags="-nologo -ignore 4509"
    
        elif $_cc 2>&1 | grep -q Intel; then
            _type=icl
    
            _depflags='-QMMD -QMF$(@:.o=.d) -QMT$@'
    
            # Not only is O3 broken on 13.x+ but it is slower on all previous
            # versions (tested) as well.
    
            _cflags_speed="-O2"
            _cflags_size="-O1 -Oi" # -O1 without -Oi miscompiles stuff
            if $_cc 2>&1 | grep -q Linker; then
    
            _flags_filter=icl_flags
    
            _ld_lib='lib%.a'
            _ld_path='-libpath:'
    
            # -Qdiag-error to make icl error when seeing certain unknown arguments
    
            _flags='-nologo -Qdiag-error:4044,10157'
    
            # -Qvec- -Qsimd- to prevent miscompilation, -GS, fp:precise for consistency
    
            # with MSVC which enables it by default.
    
            _cflags='-D_USE_MATH_DEFINES -Qms0 -Qvec- -Qsimd- -GS -fp:precise'
    
            disable stripping
    
        elif $_cc -nologo- 2>&1 | grep -q Microsoft; then
    
            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
            _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
            _cflags_speed="-O2"
            _cflags_size="-O1"
    
            if $_cc -nologo- 2>&1 | grep -q Linker; then
    
                _ld_o='-out:$@'
            else
                _ld_o='-Fe$@'
            fi
            _cc_o='-Fo$@'
            _cc_e='-P -Fi$@'
            _flags_filter=msvc_flags
            _ld_lib='lib%.a'
            _ld_path='-libpath:'
            _flags='-nologo'
    
            _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS'
    
    Luca Barbato's avatar
    Luca Barbato committed
        elif $_cc --version 2>/dev/null | grep -q ^cparser; then
            _type=cparser
            _ident=$($_cc --version | head -n1)
            _depflags='-MMD'
            _cflags_speed='-O4'
            _cflags_size='-O2'
            _flags_filter=cparser_flags
    
    
        eval ${pfx}_type=\$_type
        eval ${pfx}_ident=\$_ident
    }
    
    set_ccvars(){
    
        eval ${1}_C=\${_cc_c-\${${1}_C}}
    
        eval ${1}_E=\${_cc_e-\${${1}_E}}
    
        eval ${1}_O=\${_cc_o-\${${1}_O}}
    
        if [ -n "$_depflags" ]; then
            eval ${1}_DEPFLAGS=\$_depflags
        else
            eval ${1}DEP=\${_DEPCMD:-\$DEPCMD}
            eval ${1}DEP_FLAGS=\${_DEPFLAGS:-\$DEPFLAGS}
            eval DEP${1}FLAGS=\$_flags
        fi
    }
    
    
    probe_cc cc "$cc" "true"
    
    cflags_filter=$_flags_filter
    cflags_speed=$_cflags_speed
    cflags_size=$_cflags_size
    cflags_noopt=$_cflags_noopt
    add_cflags $_flags $_cflags
    cc_ldflags=$_ldflags
    set_ccvars CC
    
    probe_cc hostcc "$host_cc"
    host_cflags_filter=$_flags_filter
    add_host_cflags  $_flags $_cflags
    set_ccvars HOSTCC
    
    test -n "$cc_type" && enable $cc_type ||
        warn "Unknown C compiler $cc, unable to select optimal CFLAGS"
    
    Luca Barbato's avatar
    Luca Barbato committed
    : ${objcc_default:=$cc}
    
    : ${dep_cc_default:=$cc}
    
    : ${ld_default:=$cc}
    
    : ${host_ld_default:=$host_cc}
    
    set_default ar as objcc dep_cc ld ln_s host_ld windres
    
    probe_cc as "$as"
    asflags_filter=$_flags_filter
    add_asflags $_flags $_cflags
    set_ccvars AS
    
    
    Luca Barbato's avatar
    Luca Barbato committed
    probe_cc objcc "$objcc"
    objcflags_filter=$_flags_filter
    add_objcflags $_flags $_cflags
    set_ccvars OBJC
    
    
    probe_cc ld "$ld"
    ldflags_filter=$_flags_filter
    add_ldflags $_flags $_ldflags
    test "$cc_type" != "$ld_type" && add_ldflags $cc_ldflags
    
    LD_LIB=${_ld_lib-$LD_LIB}
    LD_PATH=${_ld_path-$LD_PATH}
    
    probe_cc hostld "$host_ld"
    host_ldflags_filter=$_flags_filter
    add_host_ldflags $_flags $_ldflags
    HOSTLD_O=${_ld_o-$HOSTLD_O}
    
    
    if [ -z "$CC_DEPFLAGS" ] && [ "$dep_cc" != "$cc" ]; then
        probe_cc depcc "$dep_cc"
        CCDEP=${_DEPCMD:-$DEPCMD}
        CCDEP_FLAGS=${_DEPFLAGS:=$DEPFLAGS}
        DEPCCFLAGS=$_flags
    fi
    
    if $ar 2>&1 | grep -q Microsoft; then
        arflags="-nologo"
        ar_o='-out:$@'
    elif $ar 2>&1 | grep -q 'Texas Instruments'; then
        arflags="rq"
        ar_o='$@'
    
    elif $ar 2>&1 | grep -q 'Usage: ar.*-X.*any'; then
        arflags='-Xany -r -c'
        ar_o='$@'
    
    elif $ar 2>&1 | grep -q "\[D\] "; then
        arflags="rcD"
        ar_o='$@'
    
    Mohamed Naufal's avatar
    Mohamed Naufal committed
    add_cxxflags $extra_cxxflags
    
    Luca Barbato's avatar
    Luca Barbato committed
    add_objcflags $extra_objcflags
    
    add_asflags $extra_cflags
    
    if test -n "$sysroot"; then
        case "$cc_type" in
    
            gcc|llvm_gcc|clang)
    
                add_cppflags --sysroot="$sysroot"
    
                add_ldflags --sysroot="$sysroot"
    
    # On Darwin --sysroot may be ignored, -isysroot always affects headers and linking
                add_cppflags -isysroot "$sysroot"
                add_ldflags -isysroot "$sysroot"
    
            tms470)
                add_cppflags -I"$sysinclude"
                add_ldflags  --sysroot="$sysroot"
            ;;
    
    if test "$cpu" = host; then
    
        enabled cross_compile &&
            die "--cpu=host makes no sense when cross-compiling."
    
                check_native(){
                    $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
    
                    sed -n "/cc1.*$1=/{
    
                                s/.*$1=\\([^ ]*\\).*/\\1/
                                p
                                q
                            }" $TMPE
    
                }
                cpu=$(check_native -march || check_native -mcpu)
            ;;
    
            clang)
                check_native(){
                    $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
                    sed -n "/cc1.*-target-cpu /{
                                s/.*-target-cpu \\([^ ]*\\).*/\\1/
                                p
                                q
                            }" $TMPE
                }
                cpu=$(check_native -march)
            ;;
    
        test "${cpu:-host}" = host &&
            die "--cpu=host not supported with compiler $cc"
    
    # Deal with common $arch aliases
    case "$arch" in
    
        aarch64|arm64)
            arch="aarch64"
        ;;
    
        arm*|iPad*|iPhone*)
    
            case "$arch" in
            *el)
                add_cppflags -EL
                add_ldflags -EL
            ;;
            *eb)
                add_cppflags -EB
                add_ldflags -EB
            ;;
            esac
    
        parisc*|hppa*)
    
            arch="parisc"
        ;;
    
        "Power Macintosh"|ppc*|powerpc*)
    
            arch="ppc"
        ;;
        s390|s390x)
            arch="s390"
        ;;
        sh4|sh)
            arch="sh4"
        ;;
    
        tilegx|tile-gx)
            arch="tilegx"
        ;;
    
        i[3-6]86*|i86pc|BePC|x86pc|x86_64|x86_32|amd64)
    
    is_in $arch $ARCH_LIST || warn "unknown architecture $arch"
    
    # Add processor-specific flags
    
    Måns Rullgård's avatar
    Måns Rullgård committed
        case $cpu in
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-march=$cpu"
            ;;
    
            *)
                cpuflags="-mcpu=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
        esac
    
    elif enabled alpha; then
    
        cpuflags="-mcpu=$cpu"
    
        check_arm_arch() {
            check_cpp_condition stddef.h \
                "defined __ARM_ARCH_${1}__ || defined __TARGET_ARCH_${2:-$1}" \
                $cpuflags
        }
    
        probe_arm_arch() {
    
            if   check_arm_arch 4;        then echo armv4
            elif check_arm_arch 4T;       then echo armv4t
            elif check_arm_arch 5;        then echo armv5
            elif check_arm_arch 5E;       then echo armv5e
            elif check_arm_arch 5T;       then echo armv5t
            elif check_arm_arch 5TE;      then echo armv5te
            elif check_arm_arch 5TEJ;     then echo armv5te
            elif check_arm_arch 6;        then echo armv6
            elif check_arm_arch 6J;       then echo armv6j
            elif check_arm_arch 6K;       then echo armv6k
            elif check_arm_arch 6Z;       then echo armv6z
            elif check_arm_arch 6ZK;      then echo armv6zk
            elif check_arm_arch 6T2;      then echo armv6t2
            elif check_arm_arch 7;        then echo armv7
            elif check_arm_arch 7A  7_A;  then echo armv7-a
            elif check_arm_arch 7S;       then echo armv7-a
            elif check_arm_arch 7R  7_R;  then echo armv7-r
            elif check_arm_arch 7M  7_M;  then echo armv7-m
            elif check_arm_arch 7EM 7E_M; then echo armv7-m
            elif check_arm_arch 8A  8_A;  then echo armv8-a
    
            fi
        }
    
        [ "$cpu" = generic ] && cpu=$(probe_arm_arch)
    
    
        case $cpu in
            armv*)
                cpuflags="-march=$cpu"
    
                subarch=$(echo $cpu | sed 's/[^a-z0-9]//g')
    
                case $cpu in
                    cortex-a*)                               subarch=armv7a  ;;
                    cortex-r*)                               subarch=armv7r  ;;
    
                    cortex-m*)                 enable thumb; subarch=armv7m  ;;
    
                    arm11*)                                  subarch=armv6   ;;
                    arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) subarch=armv5te ;;
                    armv4*|arm7*|arm9[24]*)                  subarch=armv4   ;;
    
                    *)                             subarch=$(probe_arm_arch) ;;
    
        case "$subarch" in
            armv5t*)    enable fast_clz                ;;
    
            armv[6-8]*)
                enable fast_clz
                disabled fast_unaligned || enable fast_unaligned
                ;;
    
    elif enabled avr32; then
    
        case $cpu in
            ap7[02]0[0-2])
                subarch="avr32_ap"
                cpuflags="-mpart=$cpu"
            ;;
            ap)
                subarch="avr32_ap"
                cpuflags="-march=$cpu"
            ;;
            uc3[ab]*)
                subarch="avr32_uc"
                cpuflags="-mcpu=$cpu"
            ;;
            uc)
                subarch="avr32_uc"
                cpuflags="-march=$cpu"
            ;;
        esac
    
        if [ "$cpu" != "generic" ]; then
            disable mips32r2
            disable mips32r5
            disable mips64r2
            disable mips32r6
            disable mips64r6
            disable loongson2
            disable loongson3
    
            case $cpu in
                24kc|24kf*|24kec|34kc|1004kc|24kef*|34kf*|1004kf*|74kc|74kf)
                    enable mips32r2
                    disable msa
                ;;
    
                p5600|i6400|p6600)
    
                    disable mipsdsp
                    disable mipsdspr2
                ;;
                loongson*)
                    enable loongson2
                    enable loongson3
                    enable local_aligned_8 local_aligned_16 local_aligned_32
                    enable simd_align_16
                    enable fast_64bit
                    enable fast_clz
                    enable fast_cmov
                    enable fast_unaligned
                    disable aligned_stack
    
                    disable mipsfpu
                    disable mipsdsp
                    disable mipsdspr2
    
                    case $cpu in
                        loongson3*)
                            cpuflags="-march=loongson3a -mhard-float -fno-expensive-optimizations"
                        ;;
                        loongson2e)
                            cpuflags="-march=loongson2e -mhard-float -fno-expensive-optimizations"
                        ;;
                        loongson2f)
                            cpuflags="-march=loongson2f -mhard-float -fno-expensive-optimizations"
                        ;;
                    esac
                ;;
                *)
                    # Unknown CPU. Disable everything.
                    warn "unknown CPU. Disabling all MIPS optimizations."
                    disable mipsfpu
                    disable mipsdsp
                    disable mipsdspr2
                    disable msa
                    disable mmi
                ;;
            esac
    
            case $cpu in
                24kc)
                    disable mipsfpu
                    disable mipsdsp
                    disable mipsdspr2
                ;;
                24kf*)
                    disable mipsdsp
                    disable mipsdspr2
                ;;
                24kec|34kc|1004kc)
                    disable mipsfpu
                    disable mipsdspr2
                ;;
                24kef*|34kf*|1004kf*)
                    disable mipsdspr2
                ;;
                74kc)
                    disable mipsfpu
                ;;
                p5600)
                    enable mips32r5
                    check_cflags "-mtune=p5600" && check_cflags "-msched-weight -mload-store-pairs -funroll-loops"
                ;;
                i6400)
                    enable mips64r6
                    check_cflags "-mtune=i6400 -mabi=64" && check_cflags "-msched-weight -mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
                ;;
    
                p6600)
                    enable mips64r6
                    check_cflags "-mtune=p6600 -mabi=64" && check_cflags "-msched-weight -mload-store-pairs -funroll-loops" && check_ldflags "-mabi=64"
                ;;
    
            esac
        else
            # We do not disable anything. Is up to the user to disable the unwanted features.
            warn 'generic cpu selected'
        fi
    
    elif enabled ppc; then
    
        case $(tolower $cpu) in
            601|ppc601|powerpc601)
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-mcpu=601"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            603*|ppc603*|powerpc603*)
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-mcpu=603"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            604*|ppc604*|powerpc604*)
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-mcpu=604"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            g3|75*|ppc75*|powerpc75*)
    
                cpuflags="-mcpu=750"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            g4|745*|ppc745*|powerpc745*)
    
                cpuflags="-mcpu=7450"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            74*|ppc74*|powerpc74*)
    
                cpuflags="-mcpu=7400"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            g5|970|ppc970|powerpc970)
    
                cpuflags="-mcpu=970"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-mcpu=$cpu"
    
                disable vsx
            ;;
            power[7-8]*)
                cpuflags="-mcpu=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-mcpu=cell"
                enable ldbrx
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            e500mc)
                cpuflags="-mcpu=e500mc"
                disable altivec
            ;;
    
            e500v2)
                cpuflags="-mcpu=8548 -mhard-float -mfloat-gprs=double"
                disable altivec
    
            ;;
            e500)
                cpuflags="-mcpu=8540 -mhard-float"
                disable altivec
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
        esac
    
    elif enabled sparc; then
    
            cypress|f93[04]|tsc701|sparcl*|supersparc|hypersparc|niagara|v[789])
                cpuflags="-mcpu=$cpu"
    
            ultrasparc*|niagara[234])
    
    elif enabled x86; then
    
    
    Måns Rullgård's avatar
    Måns Rullgård committed
        case $cpu in
            i[345]86|pentium)
                cpuflags="-march=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                disable mmx
            ;;
    
            # targets that do NOT support nopl and conditional mov (cmov)
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
                cpuflags="-march=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            ;;
    
            # targets that do support nopl and conditional mov (cmov)
    
            i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64*|k8*|opteron*|athlon-fx\
    
            |core*|atom|bonnell|nehalem|westmere|silvermont|sandybridge|ivybridge|haswell|broadwell|skylake*|knl\
            |amdfam10|barcelona|b[dt]ver*|znver*)
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                cpuflags="-march=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                enable fast_cmov
            ;;
            # targets that do support conditional mov but on which it's slow
            pentium4|pentium4m|prescott|nocona)
                cpuflags="-march=$cpu"
    
    Måns Rullgård's avatar
    Måns Rullgård committed
                disable fast_cmov
            ;;
        esac
    
    if [ "$cpu" != generic ]; then
        add_cflags  $cpuflags
        add_asflags $cpuflags
    
        test "$cc_type" = "$ld_type" && add_ldflags $cpuflags
    
    # compiler sanity check
    check_exec <<EOF
    int main(void){ return 0; }
    EOF
    if test "$?" != 0; then
        echo "$cc is unable to create an executable file."
        if test -z "$cross_prefix" && ! enabled cross_compile ; then
            echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
            echo "Only do this if you know what cross compiling means."
        fi
        die "C compiler test failed."
    fi
    
    
    Mohamed Naufal's avatar
    Mohamed Naufal committed
    add_cxxflags -D__STDC_CONSTANT_MACROS
    
    add_cxxflags -std=c++98
    
    check_cflags -std=c99
    
    check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
    
    check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE
    
    check_host_cflags -std=c99
    
    check_64bit(){
        arch32=$1
        arch64=$2
        expr=$3
        check_code cc "" "int test[2*($expr) - 1]" &&
            subarch=$arch64 || subarch=$arch32
    }
    
    
    case "$arch" in
    
            spic=$shared
    
        mips)
            check_64bit mips mips64 '_MIPS_SIM > 1'
    
            spic=$shared
    
        parisc)
            check_64bit parisc parisc64 'sizeof(void *) > 4'
            spic=$shared
        ;;
    
        ppc)
            check_64bit ppc ppc64 'sizeof(void *) > 4'
    
        s390)
            check_64bit s390 s390x 'sizeof(void *) > 4'
            spic=$shared
        ;;
    
        sparc)
            check_64bit sparc sparc64 'sizeof(void *) > 4'
            spic=$shared
        ;;
    
            check_64bit x86_32 x86_64 'sizeof(void *) > 4'
    
            # Treat x32 as x64 for now. Note it also needs spic=$shared
            test "$subarch" = "x86_32" && check_cpp_condition stddef.h 'defined(__x86_64__)' &&
                subarch=x86_64
    
            if test "$subarch" = "x86_64"; then
    
                spic=$shared
    
        ppc)
            check_cc <<EOF && subarch="ppc64"
            int test[(int)sizeof(char*) - 7];
    EOF
        ;;
    
    enable $subarch
    
    enabled spic && enable_weak pic
    
            SHFLAGS=-shared
    
            add_cppflags '-I\$(SRC_PATH)/compat/aix'
    
            enabled shared && add_ldflags -Wl,-brtl
    
            enable section_data_rel_ro
    
            SLIB_INSTALL_NAME='$(SLIBNAME)'
            SLIB_INSTALL_LINKS=
    
            SHFLAGS='-shared -Wl,-soname,$(SLIBNAME)'
    
    François Revol's avatar
    François Revol committed
            host_libs=
    
            SHFLAGS='-shared -Wl,-h,$$(@F)'
    
            enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
    
            add_cppflags -D__EXTENSIONS__
    
            # When using suncc to build, the Solaris linker will mark
            # an executable with each instruction set encountered by
            # the Solaris assembler.  As our libraries contain their own
            # guards for processor-specific code, instead suppress
            # generation of the HWCAPS ELF section on Solaris x86 only.
    
            enabled_all suncc x86 &&
                echo "hwcap_1 = OVERRIDE;" > mapfile &&
                add_ldflags -Wl,-M,mapfile
    
            nm_default='nm -P -g'
    
            version_script='-M'
            VERSION_SCRIPT_POSTPROCESS_CMD='perl $(SRC_PATH)/compat/solaris/make_sunver.pl - $(OBJS)'
    
            disable symver
    
            oss_indev_extralibs="-lossaudio"
            oss_outdev_extralibs="-lossaudio"
    
            enabled gcc || check_ldflags -Wl,-zmuldefs
    
    David Hill's avatar
    David Hill committed
        openbsd|bitrig)
    
            disable symver
    
            SLIB_INSTALL_NAME='$(SLIBNAME).$(LIBMAJOR).$(LIBMINOR)'
    
            SLIB_INSTALL_LINKS=
    
            oss_indev_extralibs="-lossaudio"
            oss_outdev_extralibs="-lossaudio"
    
        dragonfly)
            disable symver
            ;;
        freebsd)
    
            add_extralibs -lpoll -lgnugetopt
    
            enabled ppc && add_asflags -force_cpusubtype_ALL
    
            install_name_dir_default='$(SHLIBDIR)'
            SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(INSTALL_NAME_DIR)/$(SLIBNAME_WITH_MAJOR),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
    
            enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
    
            add_ldflags -Wl,-dynamic,-search_paths_first
    
            SLIBSUF=".dylib"
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
    
    Loren Merritt's avatar
    Loren Merritt committed
            objformat="macho"
    
            enabled x86_64 && objformat="macho64"
    
            enabled_any pic shared x86_64 ||
    
                { check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
    
    Josh de Kock's avatar
    Josh de Kock committed
            check_header dispatch/dispatch.h &&
                add_cppflags '-I\$(SRC_PATH)/compat/dispatch_semaphore'
    
            version_script='-exported_symbols_list'
            VERSION_SCRIPT_POSTPROCESS_CMD='tr " " "\n" | sed -n /global:/,/local:/p | grep ";" | tr ";" "\n" | sed -E "s/(.+)/_\1/g" | sed -E "s/(.+[^*])$$$$/\1*/"'
    
            die "Native MSYS builds are discouraged, please use the MINGW environment."
    
            if test $target_os = "mingw32ce"; then
    
            decklink_outdev_extralibs="$decklink_outdev_extralibs -lole32 -loleaut32"
            decklink_indev_extralibs="$decklink_indev_extralibs -lole32 -loleaut32"
    
            LIBTARGET=i386
    
            enabled shared && ! enabled small && check_cmd $windres --version && enable gnu_windres
    
            enabled x86_32 && check_ldflags -Wl,--large-address-aware
    
            SLIBPREF=""
            SLIBSUF=".dll"
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
    
            if check_cmd lib.exe -list; then
    
                SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
    
                if enabled x86_64; then
                    LIBTARGET=x64
                fi
            elif check_cmd $dlltool --version; then
    
                SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
    
            SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
            SLIB_INSTALL_LINKS=
            SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
            SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
    
            SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--disable-auto-image-base'
    
    Loren Merritt's avatar
    Loren Merritt committed
            objformat="win32"
    
            ranlib=:
    
            check_ldflags -Wl,--nxcompat,--dynamicbase
    
            # Lets work around some stupidity in binutils.
            # ld will strip relocations from executables even though we need them
            # for dynamicbase (ASLR).  Using -pie does retain the reloc section
            # however ld then forgets what the entry point should be (oops) so we
            # have to manually (re)set it.
            if enabled x86_32; then
    
                disabled debug && add_ldexeflags -Wl,--pic-executable,-e,_mainCRTStartup
    
            elif enabled x86_64; then
    
                disabled debug && add_ldexeflags -Wl,--pic-executable,-e,mainCRTStartup
    
                check_ldflags -Wl,--high-entropy-va # binutils 2.25
                # Set image base >4GB for extra entropy with HEASLR
                add_ldexeflags -Wl,--image-base,0x140000000
                append SHFLAGS -Wl,--image-base,0x180000000
    
            if enabled shared; then
                # Link to the import library instead of the normal static library
                # for shared libs.
                LD_LIB='%.lib'
    
                # Cannot build both shared and static libs with MSVC or icl.
    
            enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
    
            shlibdir_default="$bindir_default"
            SLIBPREF=""
            SLIBSUF=".dll"
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
    
            SLIB_CREATE_DEF_CMD='$(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
    
            SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
            SLIB_INSTALL_LINKS=
            SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
            SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
            SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) -implib:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
    
            objformat="win32"
            ranlib=:
            enable dos_paths
            ;;
    
            SLIBPREF="cyg"
            SLIBSUF=".dll"
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
    
            SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
            SLIB_INSTALL_LINKS=
            SLIB_INSTALL_EXTRA_LIB='lib$(FULLNAME).dll.a'
            SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(FULLNAME).dll.a'
    
    Loren Merritt's avatar
    Loren Merritt committed
            objformat="win32"
    
            enabled shared && ! enabled small && check_cmd $windres --version && enable gnu_windres
    
            add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
    
    Michael Kostylev's avatar
    Michael Kostylev committed
        *-dos|freedos|opendos)
            network_extralibs="-lsocket"
    
            objformat="coff"
    
            add_cppflags -U__STRICT_ANSI__
    
            enable section_data_rel_ro
    
            objformat="aout"
    
            add_cppflags -D_GNU_SOURCE
    
            add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
    
    Måns Rullgård's avatar
    Måns Rullgård committed
            SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
    
            SLIBPREF=""
            SLIBSUF=".dll"
    
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(FULLNAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)'
            SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(FULLNAME).def; \
                echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(FULLNAME).def; \
                echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(FULLNAME).def; \
                echo EXPORTS >> $(SUBDIR)$(FULLNAME).def; \
                emxexp $(OBJS) >> $(SUBDIR)$(FULLNAME).def'
            SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(FULLNAME)_dll.a $(SUBDIR)$(FULLNAME).def; \
                emximp -o $(SUBDIR)$(LIBPREF)$(FULLNAME)_dll.lib $(SUBDIR)$(FULLNAME).def;'
            SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
            SLIB_INSTALL_LINKS=
            SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(FULLNAME)_dll.a $(LIBPREF)$(FULLNAME)_dll.lib'
    
            enable_weak os2threads
    
            add_cppflags -D_BSD_SOURCE
    
        qnx)
            add_cppflags -D_QNX_SOURCE
            network_extralibs="-lsocket"
            ;;
    
        symbian)
            SLIBSUF=".dll"
            enable dos_paths
    
            add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default
            add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS
            add_ldflags -Wl,--target1-abs,--no-undefined \
                        -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \
                        -Wl,--entry=_E32Startup -Wl,-u,_E32Startup
            add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \
                          -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \
                          -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib
    
        osf1)
            add_cppflags -D_OSF_SOURCE -D_POSIX_PII -D_REENTRANT
            ;;
    
    Mans Rullgard's avatar
    Mans Rullgard committed
        plan9)
            add_cppflags -D_C99_SNPRINTF_EXTENSION  \
                         -D_REENTRANT_SOURCE        \
                         -D_RESEARCH_SOURCE         \
                         -DFD_SETSIZE=96            \
                         -DHAVE_SOCK_OPTS
            add_compat strtod.o strtod=avpriv_strtod
            network_extralibs='-lbsd'
            exeobjs=compat/plan9/main.o
    
    Mans Rullgard's avatar
    Mans Rullgard committed
            cp_f='cp'
            ;;
    
            die "Unknown OS '$target_os'."
    
    # test if creating links works
    link_dest=$(mktemp -u $TMPDIR/dest_XXXXXXXX)
    link_name=$(mktemp -u $TMPDIR/name_XXXXXXXX)
    mkdir "$link_dest"
    $ln_s "$link_dest" "$link_name"
    touch "$link_dest/test_file"
    
    if [ "$source_path" != "." ] && ([ ! -d src ] || [ -L src ]) && [ -e "$link_name/test_file" ]; then
    
        # create link to source path
        [ -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
    
            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
    
            # 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
    
        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