Skip to content
Snippets Groups Projects
configure 167 KiB
Newer Older
  • Learn to ignore specific revisions
  • objcc_default="${cross_prefix}${objcc_default}"
    
    x86asmexe_default="${cross_prefix}${x86asmexe_default}"
    
    nm_default="${cross_prefix}${nm_default}"
    pkg_config_default="${cross_prefix}${pkg_config_default}"
    ranlib="${cross_prefix}${ranlib}"
    strip="${cross_prefix}${strip}"
    
    sysinclude_default="${sysroot}/usr/include"
    
    
    set_default arch cc pkg_config sysinclude target_exec target_os x86asmexe
    
    enabled cross_compile || host_cc_default=$cc
    set_default host_cc
    
    if ! $pkg_config --version >/dev/null 2>&1; then
        warn "$pkg_config not found, library detection may fail."
        pkg_config=false
    fi
    
    
            mingw32*|mingw64*|win32|win64|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;;
    
        esac
    }
    
    EXESUF=$(exesuf $target_os)
    HOSTEXESUF=$(exesuf $host_os)
    
    # set temporary file name
    
    : ${TMPDIR:=$TEMPDIR}
    
    : ${TMPDIR:=/tmp}
    
    if ! check_cmd mktemp -u XXXXXX; then
    
        # simple replacement for missing mktemp
        # NOT SAFE FOR GENERAL USE
        mktemp(){
    
            tmpname="${2%%XXX*}.${HOSTNAME}.${UID}.$$"
            echo "$tmpname"
            mkdir "$tmpname"
    
    AVTMPDIR=$(mktemp -d "${TMPDIR}/avconf.XXXXXXXX" 2> /dev/null) ||
        die "Unable to create temporary directory in $TMPDIR."
    
    
        tmp="${AVTMPDIR}/test"$2
        (set -C; exec > $tmp) 2> /dev/null ||
            die "Unable to create temporary file in $AVTMPDIR."
    
    trap 'rm -rf -- "$AVTMPDIR"' EXIT
    
    tmpfile TMPASM .asm
    
    tmpfile TMPC   .c
    tmpfile TMPE   $EXESUF
    tmpfile TMPH   .h
    tmpfile TMPO   .o
    tmpfile TMPS   .S
    tmpfile TMPSH  .sh
    tmpfile TMPV   .ver
    
    chmod +x $TMPE
    
    
    # make sure we can execute files in $TMPDIR
    cat > $TMPSH 2>> $logfile <<EOF
    #! /bin/sh
    EOF
    chmod +x $TMPSH >> $logfile 2>&1
    if ! $TMPSH >> $logfile 2>&1; then
        cat <<EOF
    Unable to create and execute files in $TMPDIR.  Set the TMPDIR environment
    variable to another directory and make sure that it is not mounted noexec.
    EOF
        die "Sanity test failed."
    fi
    
    
    armasm_flags(){
        for flag; do
            case $flag in
                # Filter out MSVC cl.exe options from cflags that shouldn't
                # be passed to gas-preprocessor
                -M[TD]*)                                            ;;
                *)                  echo $flag                      ;;
            esac
       done
    }
    
    
    ccc_flags(){
        for flag; do
            case $flag in
                -std=c99)           echo -c99                       ;;
                -mcpu=*)            echo -arch ${flag#*=}           ;;
                -mieee)             echo -ieee                      ;;
                -O*|-fast)          echo $flag                      ;;
                -fno-math-errno)    echo -assume nomath_errno       ;;
                -g)                 echo -g3                        ;;
                -Wall)              echo -msg_enable level2         ;;
                -Wno-pointer-sign)  echo -msg_disable ptrmismatch1  ;;
                -Wl,*)              echo $flag                      ;;
                -f*|-W*)                                            ;;
                *)                  echo $flag                      ;;
            esac
       done
    }
    
    
    Luca Barbato's avatar
    Luca Barbato committed
    cparser_flags(){
        for flag; do
            case $flag in
                -Wno-switch)             echo -Wno-switch-enum ;;
                -Wno-format-zero-length) ;;
                -Wdisabled-optimization) ;;
                -Wno-pointer-sign)       echo -Wno-other ;;
                *)                       echo $flag ;;
            esac
        done
    }
    
    
        for flag; do
            case $flag in
    
                # In addition to specifying certain flags under the compiler
                # specific filters, they must be specified here as well or else the
                # generic catch all at the bottom will print the original flag.
                -Wall)                ;;
    
                -std=c99)             ;;
                # Common flags
    
                -fomit-frame-pointer) ;;
    
                -g)                   echo -Z7 ;;
                -fno-math-errno)      ;;
                -fno-common)          ;;
                -fno-signed-zeros)    ;;
    
                -lz)                  echo zlib.lib ;;
    
                -lx264)               echo libx264.lib ;;
    
                -l*)                  echo ${flag#-l}.lib ;;
    
                -L*)                  echo -libpath:${flag#-L} ;;
    
    msvc_flags(){
        msvc_common_flags "$@"
        for flag; do
            case $flag in
    
                -Wall)                echo -W3 -wd4018 -wd4146 -wd4244 -wd4305     \
                                           -wd4554 ;;
                -Wextra)              echo -W4 -wd4244 -wd4127 -wd4018 -wd4389     \
    
                                           -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \
                                           -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \
    
                                           -wd4273 -wd4554 -wd4701 -wd4703 ;;
    
            esac
        done
    }
    
    icl_flags(){
        msvc_common_flags "$@"
        for flag; do
            case $flag in
                # Despite what Intel's documentation says -Wall, which is supported
                # on Windows, does enable remarks so disable them here.
                -Wall)                echo $flag -Qdiag-disable:remark ;;
                -std=c99)             echo -Qstd=c99 ;;
            esac
        done
    }
    
    
    pgi_flags(){
        for flag; do
            case $flag in
    
                -flto)                echo -Mipa=fast,libopt,libinline,vestigial ;;
    
                -fomit-frame-pointer) echo -Mnoframe ;;
                -g)                   echo -gopt ;;
                *)                    echo $flag ;;
            esac
        done
    }
    
    suncc_flags(){
        for flag; do
            case $flag in
                -march=*|-mcpu=*)
                    case "${flag#*=}" in
                        native)                   echo -xtarget=native       ;;
                        v9|niagara)               echo -xarch=sparc          ;;
                        ultrasparc)               echo -xarch=sparcvis       ;;
                        ultrasparc3|niagara2)     echo -xarch=sparcvis2      ;;
                        i586|pentium)             echo -xchip=pentium        ;;
                        i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
                        pentium3*|c3-2)           echo -xtarget=pentium3     ;;
                        pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
                        pentium4*)          echo -xtarget=pentium4           ;;
                        prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
                        *-sse3)             echo -xarch=sse3                 ;;
                        core2)              echo -xarch=ssse3 -xchip=core2   ;;
    
                        corei7)           echo -xarch=sse4_2 -xchip=nehalem  ;;
                        corei7-avx)       echo -xarch=avx -xchip=sandybridge ;;
    
                        amdfam10|barcelona|bdver*) echo -xarch=sse4_1        ;;
    
                        athlon-4|athlon-[mx]p)     echo -xarch=ssea          ;;
    
                        k8|opteron|athlon64|athlon-fx)
    
                                                   echo -xarch=sse2a         ;;
                        athlon*)                   echo -xarch=pentium_proa  ;;
    
                    esac
                    ;;
                -std=c99)             echo -xc99              ;;
                -fomit-frame-pointer) echo -xregs=frameptr    ;;
                -fPIC)                echo -KPIC -xcode=pic32 ;;
                -W*,*)                echo $flag              ;;
    
                -f*-*|-W*|-mimpure-text)                      ;;
                -shared)              echo -G                 ;;
    
                *)                    echo $flag              ;;
            esac
        done
    }
    
    tms470_flags(){
        for flag; do
            case $flag in
                -march=*|-mcpu=*)
                    case "${flag#*=}" in
                        armv7-a|cortex-a*)      echo -mv=7a8 ;;
                        armv7-r|cortex-r*)      echo -mv=7r4 ;;
                        armv7-m|cortex-m*)      echo -mv=7m3 ;;
                        armv6*|arm11*)          echo -mv=6   ;;
                        armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
                                                echo -mv=5e  ;;
                        armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
                    esac
                    ;;
                -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
                -mfpu=vfp)      echo --float_support=vfpv2        ;;
                -mfpu=vfpv3)    echo --float_support=vfpv3        ;;
    
                -mfpu=vfpv3-d16) echo --float_support=vfpv3d16    ;;
    
                -msoft-float)   echo --float_support=vfplib       ;;
                -O[0-3]|-mf=*)  echo $flag                        ;;
                -g)             echo -g -mn                       ;;
                -pds=*)         echo $flag                        ;;
    
                -D*|-I*)        echo $flag                        ;;
                --gcc|--abi=*)  echo $flag                        ;;
                -me)            echo $flag                        ;;
    
        unset _type _ident _cc_c _cc_e _cc_o _flags _cflags
        unset _ld_o _ldflags _ld_lib _ld_path
    
        unset _depflags _DEPCMD _DEPFLAGS
    
        _flags_filter=echo
    
        if $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
            _type=llvm_gcc
    
            gcc_extra_ver=$(expr "$($_cc --version 2>/dev/null | head -n1)" : '.*\((.*)\)')
            _ident="llvm-gcc $($_cc -dumpversion 2>/dev/null) $gcc_extra_ver"
    
            _depflags='-MMD -MF $(@:.o=.d) -MT $@'
            _cflags_speed='-O3'
            _cflags_size='-Os'
        elif $_cc -v 2>&1 | grep -qi ^gcc; then
            _type=gcc
            gcc_version=$($_cc --version | head -n1)
            gcc_basever=$($_cc -dumpversion)
            gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)')
            gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)")
            _ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver")
            if ! $_cc -dumpversion | grep -q '^2\.'; then
                _depflags='-MMD -MF $(@:.o=.d) -MT $@'
            fi
            _cflags_speed='-O3'
            _cflags_size='-Os'
    
        elif $_cc --version 2>/dev/null | grep -q ^icc; then
    
            _type=icc
            _ident=$($_cc --version | head -n1)
            _depflags='-MMD'
            _cflags_speed='-O3'
            _cflags_size='-Os'
            _cflags_noopt='-O1'
        elif $_cc -v 2>&1 | grep -q xlc; then
            _type=xlc
            _ident=$($_cc -qversion 2>/dev/null | head -n1)
            _cflags_speed='-O5'
            _cflags_size='-O5 -qcompact'
        elif $_cc -V 2>/dev/null | grep -q Compaq; then
            _type=ccc
            _ident=$($_cc -V | head -n1 | cut -d' ' -f1-3)
            _DEPFLAGS='-M'
            _cflags_speed='-fast'
            _cflags_size='-O1'
    
            _flags_filter=ccc_flags
    
        elif $_cc --vsn 2>/dev/null | grep -Eq "ARM (C/C\+\+ )?Compiler"; then
    
            test -d "$sysroot" || die "No valid sysroot specified."
            _type=armcc
    
            _ident=$($_cc --vsn | grep -i build | head -n1 | sed 's/.*: //')
    
            armcc_conf="$PWD/armcc.conf"
            $_cc --arm_linux_configure                 \
                 --arm_linux_config_file="$armcc_conf" \
                 --configure_sysroot="$sysroot"        \
                 --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
                 die "Error creating armcc configuration file."
            $_cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc
            _flags="--arm_linux_config_file=$armcc_conf --translate_gcc"
            as_default="${cross_prefix}gcc"
            _depflags='-MMD'
            _cflags_speed='-O3'
            _cflags_size='-Os'
    
        elif $_cc -version 2>/dev/null | grep -Eq 'TMS470|TI ARM'; then
    
            _type=tms470
            _ident=$($_cc -version | head -n1 | tr -s ' ')
            _flags='--gcc --abi=eabi -me'
    
            _cc_o='-fe=$@'
            _depflags='-ppa -ppd=$(@:.o=.d)'
            _cflags_speed='-O3 -mf=5'
            _cflags_size='-O3 -mf=2'
            _flags_filter=tms470_flags
        elif $_cc -v 2>&1 | grep -q clang; then
            _type=clang
    
            _ident=$($_cc --version 2>/dev/null | head -n1)
    
            _depflags='-MMD -MF $(@:.o=.d) -MT $@'
    
            _cflags_speed='-O3'
            _cflags_size='-Os'
        elif $_cc -V 2>&1 | grep -q Sun; then
            _type=suncc
            _ident=$($_cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
            _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
    
            _ldflags='-std=c99'
            _cflags_speed='-O5'
            _cflags_size='-O5 -xspace'
            _flags_filter=suncc_flags
        elif $_cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
            _type=pathscale
            _ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
            _depflags='-MMD -MF $(@:.o=.d) -MT $@'
            _cflags_speed='-O2'
            _cflags_size='-Os'
            _flags_filter='filter_out -Wdisabled-optimization'
        elif $_cc -v 2>&1 | grep -q Open64; then
            _type=open64
            _ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
            _depflags='-MMD -MF $(@:.o=.d) -MT $@'
            _cflags_speed='-O2'
            _cflags_size='-Os'
            _flags_filter='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
        elif $_cc -V 2>&1 | grep -q Portland; then
            _type=pgi
            _ident="PGI $($_cc -V 2>&1 | awk '/^pgcc/ { print $2; exit }')"
    
            opt_common='-alias=ansi -Mdse -Mlre -Mpre'
    
            _cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common"
            _cflags_size="-O2 -Munroll=c:1 $opt_common"
            _cflags_noopt="-O1"
            _flags_filter=pgi_flags
    
        elif $_cc 2>&1 | grep -q 'Microsoft.*ARM.*Assembler'; then
            _type=armasm
            _ident=$($_cc | head -n1)
            # 4509: "This form of conditional instruction is deprecated"
            _flags="-nologo -ignore 4509"
    
        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
    
            _flags_filter=msvc_flags
            _ld_lib='lib%.a'
            _ld_path='-libpath:'
            _flags='-nologo'
    
        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 for consistency
            # with MSVC which enables it by default.
    
        elif $_cc -? 2>/dev/null | grep -q 'LLVM.*Linker'; then
            # lld can emulate multiple different linkers; in ms link.exe mode,
            # the -? parameter gives the help output which contains an identifyable
            # string, while it gives an error in other modes.
            _type=lld-link
            # The link.exe mode doesn't have a switch for getting the version,
            # but we can force it back to gnu mode and get the version from there.
    
            _ident=$($_cc -flavor gnu --version 2>/dev/null)
    
            _ld_o='-out:$@'
            _flags_filter=msvc_flags
            _ld_lib='lib%.a'
            _ld_path='-libpath:'
    
    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"
    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
    
    host_cflags_speed=$_cflags_speed
    
    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}
    
    Luca Barbato's avatar
    Luca Barbato committed
    set_default ar as objcc dep_cc ld host_ld
    
    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='$@'
    
    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"
            ;;
    
            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)
            ;;
        esac
    
    
        test "${cpu:-host}" = host &&
            die "--cpu=host not supported with compiler $cc"
    
    # Deal with common $arch aliases
    case "$arch" in
    
        aarch64|arm64)
            arch="aarch64"
        ;;
    
            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"
        ;;
    
        sun4u|sparc*)
    
        tilegx|tile-gx)
            arch="tilegx"
        ;;
    
        i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64)
    
    is_in $arch $ARCH_LIST || warn "unknown architecture $arch"
    
    # Add processor-specific flags
    
    
        case $cpu in
            armv*)
                cpuflags="-march=$cpu"
            ;;
            *)
                cpuflags="-mcpu=$cpu"
            ;;
        esac
    
    elif enabled alpha; then
    
        cpuflags="-mcpu=$cpu"
    
    elif enabled arm; then
    
    
        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')
            ;;
            *)
                cpuflags="-mcpu=$cpu"
                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 fast_unaligned ;;
        esac
    
    
    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
    
    elif enabled bfin; then
    
        cpuflags="-mcpu=$cpu"
    
    elif enabled mips; then
    
        cpuflags="-march=$cpu"
    
    
    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
            ;;
    
                cpuflags="-mcpu=$cpu"
    
                disable vsx
            ;;
            power[7-8]*)
                cpuflags="-mcpu=$cpu"
                enable ldbrx
    
    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
    
        case $cpu in
            cypress|f93[04]|tsc701|sparcl*|supersparc|hypersparc|niagara|v[789])
                cpuflags="-mcpu=$cpu"
            ;;
            ultrasparc*|niagara[234])
                cpuflags="-mcpu=$cpu"
            ;;
        esac
    
    
    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|core2|corei7*|amdfam10|barcelona|atom|bdver*)
    
    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
    
    
    
    # some compilers silently accept -std=c11, so we also need to check that the
    # version macro is defined properly
    
    check_cpp_condition stdlib.h  "__STDC_VERSION__ >= 201112L" -std=c11 &&
        add_cflags -std=c11 ||
    
        check_cflags -std=c99
    
    
    check_cppflags -D_FILE_OFFSET_BITS=64
    check_cppflags -D_LARGEFILE_SOURCE
    
    check_host_cflags -std=c99
    
    check_host_cflags $host_cflags_speed
    
    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'
    
            if test "$subarch" = "x86_64"; then
    
                spic=$shared
    
    enable $subarch
    
    enabled spic && enable_weak pic
    
    enabled x86_64 && objformat=elf64 || objformat="elf32"
    
    
            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)'
    
            SHFLAGS='-shared -Wl,-h,$$(@F)'
    
            enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
    
            # 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"
    
    Brad Smith's avatar
    Brad Smith 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
    
            SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(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
    
            check_cflags -Werror=partial-availability
    
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
    
            enabled x86_64 && objformat="macho64" || objformat="macho32"
    
            enabled_any pic shared ||
    
                { 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'
    
            die "Native MSYS builds are discouraged, please use the MINGW environment."
    
        mingw32*|mingw64*)
    
            if test $target_os = "mingw32ce"; then
    
            LIBTARGET=i386
    
                LIBTARGET="i386:x86-64"
    
            check_ldflags -Wl,--nxcompat
            check_ldflags -Wl,--dynamicbase
    
            SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
            SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)'
    
            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,--enable-auto-image-base'
    
            enabled x86_64 && objformat="win64" || objformat="win32"
    
            dlltool="${cross_prefix}dlltool"
    
            ranlib=:
    
            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.