1#!/bin/sh 2## 3## configure.sh 4## 5## This script is sourced by the main configure script and contains 6## utility functions and other common bits that aren't strictly libvpx 7## related. 8## 9## This build system is based in part on the FFmpeg configure script. 10## 11 12 13# 14# Logging / Output Functions 15# 16die_unknown(){ 17 echo "Unknown option \"$1\"." 18 echo "See $0 --help for available options." 19 clean_temp_files 20 exit 1 21} 22 23die() { 24 echo "$@" 25 echo 26 echo "Configuration failed. This could reflect a misconfiguration of your" 27 echo "toolchains, improper options selected, or another problem. If you" 28 echo "don't see any useful error messages above, the next step is to look" 29 echo "at the configure error log file ($logfile) to determine what" 30 echo "configure was trying to do when it died." 31 clean_temp_files 32 exit 1 33} 34 35log(){ 36 echo "$@" >>$logfile 37} 38 39log_file(){ 40 log BEGIN $1 41 cat -n $1 >>$logfile 42 log END $1 43} 44 45log_echo() { 46 echo "$@" 47 log "$@" 48} 49 50fwrite () { 51 outfile=$1 52 shift 53 echo "$@" >> ${outfile} 54} 55 56show_help_pre(){ 57 for opt in ${CMDLINE_SELECT}; do 58 opt2=`echo $opt | sed -e 's;_;-;g'` 59 if enabled $opt; then 60 eval "toggle_${opt}=\"--disable-${opt2}\"" 61 else 62 eval "toggle_${opt}=\"--enable-${opt2} \"" 63 fi 64 done 65 66 cat <<EOF 67Usage: configure [options] 68Options: 69 70Build options: 71 --help print this message 72 --log=yes|no|FILE file configure log is written to [config.log] 73 --target=TARGET target platform tuple [generic-gnu] 74 --cpu=CPU optimize for a specific cpu rather than a family 75 --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] 76 --extra-cxxflags=ECXXFLAGS add ECXXFLAGS to CXXFLAGS [$CXXFLAGS] 77 --use-profile=PROFILE_FILE 78 Use PROFILE_FILE for PGO 79 ${toggle_extra_warnings} emit harmless warnings (always non-fatal) 80 ${toggle_werror} treat warnings as errors, if possible 81 (not available with all compilers) 82 ${toggle_optimizations} turn on/off compiler optimization flags 83 ${toggle_pic} turn on/off Position Independent Code 84 ${toggle_ccache} turn on/off compiler cache 85 ${toggle_debug} enable/disable debug mode 86 ${toggle_profile} enable/disable profiling 87 ${toggle_gprof} enable/disable gprof profiling instrumentation 88 ${toggle_gcov} enable/disable gcov coverage instrumentation 89 ${toggle_thumb} enable/disable building arm assembly in thumb mode 90 ${toggle_dependency_tracking} 91 disable to speed up one-time build 92 93Install options: 94 ${toggle_install_docs} control whether docs are installed 95 ${toggle_install_bins} control whether binaries are installed 96 ${toggle_install_libs} control whether libraries are installed 97 ${toggle_install_srcs} control whether sources are installed 98 99 100EOF 101} 102 103show_help_post(){ 104 cat <<EOF 105 106 107NOTES: 108 Object files are built at the place where configure is launched. 109 110 All boolean options can be negated. The default value is the opposite 111 of that shown above. If the option --disable-foo is listed, then 112 the default value for foo is enabled. 113 114Supported targets: 115EOF 116 show_targets ${all_platforms} 117 echo 118 exit 1 119} 120 121show_targets() { 122 while [ -n "$*" ]; do 123 if [ "${1%%-*}" = "${2%%-*}" ]; then 124 if [ "${2%%-*}" = "${3%%-*}" ]; then 125 printf " %-24s %-24s %-24s\n" "$1" "$2" "$3" 126 shift; shift; shift 127 else 128 printf " %-24s %-24s\n" "$1" "$2" 129 shift; shift 130 fi 131 else 132 printf " %-24s\n" "$1" 133 shift 134 fi 135 done 136} 137 138show_help() { 139 show_help_pre 140 show_help_post 141} 142 143# 144# List Processing Functions 145# 146set_all(){ 147 value=$1 148 shift 149 for var in $*; do 150 eval $var=$value 151 done 152} 153 154is_in(){ 155 value=$1 156 shift 157 for var in $*; do 158 [ $var = $value ] && return 0 159 done 160 return 1 161} 162 163add_cflags() { 164 CFLAGS="${CFLAGS} $@" 165 CXXFLAGS="${CXXFLAGS} $@" 166} 167 168add_cflags_only() { 169 CFLAGS="${CFLAGS} $@" 170} 171 172add_cxxflags_only() { 173 CXXFLAGS="${CXXFLAGS} $@" 174} 175 176add_ldflags() { 177 LDFLAGS="${LDFLAGS} $@" 178} 179 180add_asflags() { 181 ASFLAGS="${ASFLAGS} $@" 182} 183 184add_extralibs() { 185 extralibs="${extralibs} $@" 186} 187 188# 189# Boolean Manipulation Functions 190# 191 192enable_feature(){ 193 set_all yes $* 194} 195 196disable_feature(){ 197 set_all no $* 198} 199 200enabled(){ 201 eval test "x\$$1" = "xyes" 202} 203 204disabled(){ 205 eval test "x\$$1" = "xno" 206} 207 208enable_codec(){ 209 enabled "${1}" || echo " enabling ${1}" 210 enable_feature "${1}" 211 212 is_in "${1}" vp8 vp9 && enable_feature "${1}_encoder" "${1}_decoder" 213} 214 215disable_codec(){ 216 disabled "${1}" || echo " disabling ${1}" 217 disable_feature "${1}" 218 219 is_in "${1}" vp8 vp9 && disable_feature "${1}_encoder" "${1}_decoder" 220} 221 222# Iterates through positional parameters, checks to confirm the parameter has 223# not been explicitly (force) disabled, and enables the setting controlled by 224# the parameter when the setting is not disabled. 225# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS). 226soft_enable() { 227 for var in $*; do 228 if ! disabled $var; then 229 enabled $var || log_echo " enabling $var" 230 enable_feature $var 231 fi 232 done 233} 234 235# Iterates through positional parameters, checks to confirm the parameter has 236# not been explicitly (force) enabled, and disables the setting controlled by 237# the parameter when the setting is not enabled. 238# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS). 239soft_disable() { 240 for var in $*; do 241 if ! enabled $var; then 242 disabled $var || log_echo " disabling $var" 243 disable_feature $var 244 fi 245 done 246} 247 248# 249# Text Processing Functions 250# 251toupper(){ 252 echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 253} 254 255tolower(){ 256 echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 257} 258 259# 260# Temporary File Functions 261# 262source_path=${0%/*} 263enable_feature source_path_used 264if [ -z "$source_path" ] || [ "$source_path" = "." ]; then 265 source_path="`pwd`" 266 disable_feature source_path_used 267fi 268# Makefiles greedily process the '#' character as a comment, even if it is 269# inside quotes. So, this character must be escaped in all paths in Makefiles. 270source_path_mk=$(echo $source_path | sed -e 's;\#;\\\#;g') 271 272if test ! -z "$TMPDIR" ; then 273 TMPDIRx="${TMPDIR}" 274elif test ! -z "$TEMPDIR" ; then 275 TMPDIRx="${TEMPDIR}" 276else 277 TMPDIRx="/tmp" 278fi 279RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}') 280TMP_H="${TMPDIRx}/vpx-conf-$$-${RAND}.h" 281TMP_C="${TMPDIRx}/vpx-conf-$$-${RAND}.c" 282TMP_CC="${TMPDIRx}/vpx-conf-$$-${RAND}.cc" 283TMP_O="${TMPDIRx}/vpx-conf-$$-${RAND}.o" 284TMP_X="${TMPDIRx}/vpx-conf-$$-${RAND}.x" 285TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RAND}.asm" 286 287clean_temp_files() { 288 rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM} 289 enabled gcov && rm -f ${TMP_C%.c}.gcno ${TMP_CC%.cc}.gcno 290} 291 292# 293# Toolchain Check Functions 294# 295check_cmd() { 296 enabled external_build && return 297 log "$@" 298 "$@" >>${logfile} 2>&1 299} 300 301check_cc() { 302 log check_cc "$@" 303 cat >${TMP_C} 304 log_file ${TMP_C} 305 check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C} 306} 307 308check_cxx() { 309 log check_cxx "$@" 310 cat >${TMP_CC} 311 log_file ${TMP_CC} 312 check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC} 313} 314 315check_cpp() { 316 log check_cpp "$@" 317 cat > ${TMP_C} 318 log_file ${TMP_C} 319 check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C} 320} 321 322check_ld() { 323 log check_ld "$@" 324 check_cc $@ \ 325 && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs} 326} 327 328check_lib() { 329 log check_lib "$@" 330 check_cc $@ \ 331 && check_cmd ${LD} ${LDFLAGS} -o ${TMP_X} ${TMP_O} "$@" ${extralibs} 332} 333 334check_header(){ 335 log check_header "$@" 336 header=$1 337 shift 338 var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'` 339 disable_feature $var 340 check_cpp "$@" <<EOF && enable_feature $var 341#include "$header" 342int x; 343EOF 344} 345 346check_cflags() { 347 log check_cflags "$@" 348 check_cc -Werror "$@" <<EOF 349int x; 350EOF 351} 352 353check_cxxflags() { 354 log check_cxxflags "$@" 355 356 # Catch CFLAGS that trigger CXX warnings 357 case "$CXX" in 358 *c++-analyzer|*clang++|*g++*) 359 check_cxx -Werror "$@" <<EOF 360int x; 361EOF 362 ;; 363 *) 364 check_cxx -Werror "$@" <<EOF 365int x; 366EOF 367 ;; 368 esac 369} 370 371check_add_cflags() { 372 check_cxxflags "$@" && add_cxxflags_only "$@" 373 check_cflags "$@" && add_cflags_only "$@" 374} 375 376check_add_cxxflags() { 377 check_cxxflags "$@" && add_cxxflags_only "$@" 378} 379 380check_add_asflags() { 381 log add_asflags "$@" 382 add_asflags "$@" 383} 384 385check_add_ldflags() { 386 log add_ldflags "$@" 387 add_ldflags "$@" 388} 389 390check_asm_align() { 391 log check_asm_align "$@" 392 cat >${TMP_ASM} <<EOF 393section .rodata 394align 16 395EOF 396 log_file ${TMP_ASM} 397 check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM} 398 readelf -WS ${TMP_O} >${TMP_X} 399 log_file ${TMP_X} 400 if ! grep -q '\.rodata .* 16$' ${TMP_X}; then 401 die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)" 402 fi 403} 404 405# tests for -m$1 toggling the feature given in $2. If $2 is empty $1 is used. 406check_gcc_machine_option() { 407 opt="$1" 408 feature="$2" 409 [ -n "$feature" ] || feature="$opt" 410 411 if enabled gcc && ! disabled "$feature" && ! check_cflags "-m$opt"; then 412 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature " 413 else 414 soft_enable "$feature" 415 fi 416} 417 418# tests for -m$2, -m$3, -m$4... toggling the feature given in $1. 419check_gcc_machine_options() { 420 feature="$1" 421 shift 422 flags="-m$1" 423 shift 424 for opt in $*; do 425 flags="$flags -m$opt" 426 done 427 428 if enabled gcc && ! disabled "$feature" && ! check_cflags $flags; then 429 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature " 430 else 431 soft_enable "$feature" 432 fi 433} 434 435check_neon_sve_bridge_compiles() { 436 if enabled sve; then 437 check_cc -march=armv8.2-a+dotprod+i8mm+sve <<EOF 438#ifndef __ARM_NEON_SVE_BRIDGE 439#error 1 440#endif 441#include <arm_sve.h> 442#include <arm_neon_sve_bridge.h> 443EOF 444 compile_result=$? 445 if [ ${compile_result} -eq 0 ]; then 446 # Check whether the compiler can compile SVE functions that require 447 # backup/restore of SVE registers according to AAPCS. Clang for Windows 448 # used to fail this, see 449 # https://github.com/llvm/llvm-project/issues/80009. 450 check_cc -march=armv8.2-a+dotprod+i8mm+sve <<EOF 451#include <arm_sve.h> 452void other(void); 453svfloat32_t func(svfloat32_t a) { 454 other(); 455 return a; 456} 457EOF 458 compile_result=$? 459 fi 460 461 if [ ${compile_result} -ne 0 ]; then 462 log_echo " disabling sve: arm_neon_sve_bridge.h not supported by compiler" 463 log_echo " disabling sve2: arm_neon_sve_bridge.h not supported by compiler" 464 disable_feature sve 465 disable_feature sve2 466 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-sve --disable-sve2 " 467 fi 468 fi 469} 470 471check_gcc_avx512_compiles() { 472 if disabled gcc; then 473 return 474 fi 475 476 check_cc -mavx512f <<EOF 477#include <immintrin.h> 478void f(void) { 479 __m512i x = _mm512_set1_epi16(0); 480 (void)x; 481} 482EOF 483 compile_result=$? 484 if [ ${compile_result} -ne 0 ]; then 485 log_echo " disabling avx512: not supported by compiler" 486 disable_feature avx512 487 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 " 488 fi 489} 490 491check_inline_asm() { 492 log check_inline_asm "$@" 493 name="$1" 494 code="$2" 495 shift 2 496 disable_feature $name 497 check_cc "$@" <<EOF && enable_feature $name 498void foo(void) { __asm__ volatile($code); } 499EOF 500} 501 502write_common_config_banner() { 503 print_webm_license config.mk "##" "" 504 echo '# This file automatically generated by configure. Do not edit!' >> config.mk 505 echo "TOOLCHAIN := ${toolchain}" >> config.mk 506 507 case ${toolchain} in 508 *-linux-rvct) 509 echo "ALT_LIBC := ${alt_libc}" >> config.mk 510 ;; 511 esac 512} 513 514write_common_config_targets() { 515 for t in ${all_targets}; do 516 if enabled ${t}; then 517 if enabled child; then 518 fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}" 519 else 520 fwrite config.mk "ALL_TARGETS += ${t}" 521 fi 522 fi 523 true; 524 done 525 true 526} 527 528write_common_target_config_mk() { 529 saved_CC="${CC}" 530 saved_CXX="${CXX}" 531 enabled ccache && CC="ccache ${CC}" 532 enabled ccache && CXX="ccache ${CXX}" 533 print_webm_license $1 "##" "" 534 535 cat >> $1 << EOF 536# This file automatically generated by configure. Do not edit! 537SRC_PATH="$source_path_mk" 538SRC_PATH_BARE=$source_path_mk 539BUILD_PFX=${BUILD_PFX} 540TOOLCHAIN=${toolchain} 541ASM_CONVERSION=${asm_conversion_cmd:-${source_path_mk}/build/make/ads2gas.pl} 542GEN_VCPROJ=${gen_vcproj_cmd} 543MSVS_ARCH_DIR=${msvs_arch_dir} 544 545CC=${CC} 546CXX=${CXX} 547AR=${AR} 548LD=${LD} 549AS=${AS} 550STRIP=${STRIP} 551 552CFLAGS = ${CFLAGS} 553CXXFLAGS = ${CXXFLAGS} 554ARFLAGS = -crs\$(if \$(quiet),,v) 555LDFLAGS = ${LDFLAGS} 556ASFLAGS = ${ASFLAGS} 557extralibs = ${extralibs} 558AS_SFX = ${AS_SFX:-.asm} 559EXE_SFX = ${EXE_SFX} 560VCPROJ_SFX = ${VCPROJ_SFX} 561RTCD_OPTIONS = ${RTCD_OPTIONS} 562LIBWEBM_CXXFLAGS = ${LIBWEBM_CXXFLAGS} 563LIBYUV_CXXFLAGS = ${LIBYUV_CXXFLAGS} 564EOF 565 566 if enabled rvct; then cat >> $1 << EOF 567fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide 568EOF 569 else cat >> $1 << EOF 570fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;' 571EOF 572 fi 573 574 print_config_mk VPX_ARCH "${1}" ${ARCH_LIST} 575 print_config_mk HAVE "${1}" ${HAVE_LIST} 576 print_config_mk CONFIG "${1}" ${CONFIG_LIST} 577 print_config_mk HAVE "${1}" gnu_strip 578 579 enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}" 580 581 CC="${saved_CC}" 582 CXX="${saved_CXX}" 583} 584 585write_common_target_config_h() { 586 print_webm_license ${TMP_H} "/*" " */" 587 cat >> ${TMP_H} << EOF 588/* This file automatically generated by configure. Do not edit! */ 589#ifndef VPX_CONFIG_H 590#define VPX_CONFIG_H 591#define RESTRICT ${RESTRICT} 592#define INLINE ${INLINE} 593EOF 594 print_config_h VPX_ARCH "${TMP_H}" ${ARCH_LIST} 595 print_config_h HAVE "${TMP_H}" ${HAVE_LIST} 596 print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST} 597 print_config_vars_h "${TMP_H}" ${VAR_LIST} 598 echo "#endif /* VPX_CONFIG_H */" >> ${TMP_H} 599 mkdir -p `dirname "$1"` 600 cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1" 601} 602 603write_win_arm64_neon_h_workaround() { 604 print_webm_license ${TMP_H} "/*" " */" 605 cat >> ${TMP_H} << EOF 606/* This file automatically generated by configure. Do not edit! */ 607#ifndef VPX_WIN_ARM_NEON_H_WORKAROUND 608#define VPX_WIN_ARM_NEON_H_WORKAROUND 609/* The Windows SDK has arm_neon.h, but unlike on other platforms it is 610 * ARM32-only. ARM64 NEON support is provided by arm64_neon.h, a proper 611 * superset of arm_neon.h. Work around this by providing a more local 612 * arm_neon.h that simply #includes arm64_neon.h. 613 */ 614#include <arm64_neon.h> 615#endif /* VPX_WIN_ARM_NEON_H_WORKAROUND */ 616EOF 617 mkdir -p `dirname "$1"` 618 cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1" 619} 620 621process_common_cmdline() { 622 for opt in "$@"; do 623 optval="${opt#*=}" 624 case "$opt" in 625 --child) 626 enable_feature child 627 ;; 628 --log*) 629 logging="$optval" 630 if ! disabled logging ; then 631 enabled logging || logfile="$logging" 632 else 633 logfile=/dev/null 634 fi 635 ;; 636 --target=*) 637 toolchain="${toolchain:-${optval}}" 638 ;; 639 --force-target=*) 640 toolchain="${toolchain:-${optval}}" 641 enable_feature force_toolchain 642 ;; 643 --cpu=*) 644 tune_cpu="$optval" 645 ;; 646 --extra-cflags=*) 647 extra_cflags="${optval}" 648 ;; 649 --extra-cxxflags=*) 650 extra_cxxflags="${optval}" 651 ;; 652 --use-profile=*) 653 pgo_file=${optval} 654 ;; 655 --enable-?*|--disable-?*) 656 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` 657 if is_in ${option} ${ARCH_EXT_LIST}; then 658 [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${option} " 659 elif [ $action = "disable" ] && ! disabled $option ; then 660 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt 661 log_echo " disabling $option" 662 elif [ $action = "enable" ] && ! enabled $option ; then 663 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt 664 log_echo " enabling $option" 665 fi 666 ${action}_feature $option 667 ;; 668 --require-?*) 669 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` 670 if is_in ${option} ${ARCH_EXT_LIST}; then 671 RTCD_OPTIONS="${RTCD_OPTIONS}${opt} " 672 else 673 die_unknown $opt 674 fi 675 ;; 676 --force-enable-?*|--force-disable-?*) 677 eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'` 678 ${action}_feature $option 679 ;; 680 --libc=*) 681 [ -d "${optval}" ] || die "Not a directory: ${optval}" 682 disable_feature builtin_libc 683 alt_libc="${optval}" 684 ;; 685 --as=*) 686 [ "${optval}" = yasm ] || [ "${optval}" = nasm ] \ 687 || [ "${optval}" = auto ] \ 688 || die "Must be yasm, nasm or auto: ${optval}" 689 alt_as="${optval}" 690 ;; 691 --size-limit=*) 692 w="${optval%%x*}" 693 h="${optval##*x}" 694 VAR_LIST="DECODE_WIDTH_LIMIT ${w} DECODE_HEIGHT_LIMIT ${h}" 695 [ ${w} -gt 0 ] && [ ${h} -gt 0 ] || die "Invalid size-limit: too small." 696 [ ${w} -lt 65536 ] && [ ${h} -lt 65536 ] \ 697 || die "Invalid size-limit: too big." 698 enable_feature size_limit 699 ;; 700 --prefix=*) 701 prefix="${optval}" 702 ;; 703 --libdir=*) 704 libdir="${optval}" 705 ;; 706 --libc|--as|--prefix|--libdir) 707 die "Option ${opt} requires argument" 708 ;; 709 --help|-h) 710 show_help 711 ;; 712 *) 713 die_unknown $opt 714 ;; 715 esac 716 done 717} 718 719process_cmdline() { 720 for opt do 721 optval="${opt#*=}" 722 case "$opt" in 723 *) 724 process_common_cmdline $opt 725 ;; 726 esac 727 done 728} 729 730post_process_common_cmdline() { 731 prefix="${prefix:-/usr/local}" 732 prefix="${prefix%/}" 733 libdir="${libdir:-${prefix}/lib}" 734 libdir="${libdir%/}" 735 if [ "${libdir#${prefix}}" = "${libdir}" ]; then 736 die "Libdir ${libdir} must be a subdirectory of ${prefix}" 737 fi 738} 739 740post_process_cmdline() { 741 true; 742} 743 744setup_gnu_toolchain() { 745 CC=${CC:-${CROSS}gcc} 746 CXX=${CXX:-${CROSS}g++} 747 AR=${AR:-${CROSS}ar} 748 LD=${LD:-${CROSS}${link_with_cc:-ld}} 749 AS=${AS:-${CROSS}as} 750 STRIP=${STRIP:-${CROSS}strip} 751 AS_SFX=.S 752 EXE_SFX= 753} 754 755# Reliably find the newest available Darwin SDKs. (Older versions of 756# xcrun don't support --show-sdk-path.) 757show_darwin_sdk_path() { 758 xcrun --sdk $1 --show-sdk-path 2>/dev/null || 759 xcodebuild -sdk $1 -version Path 2>/dev/null 760} 761 762# Print the major version number of the Darwin SDK specified by $1. 763show_darwin_sdk_major_version() { 764 xcrun --sdk $1 --show-sdk-version 2>/dev/null | cut -d. -f1 765} 766 767# Print the Xcode version. 768show_xcode_version() { 769 xcodebuild -version | head -n1 | cut -d' ' -f2 770} 771 772# Fails when Xcode version is less than 6.3. 773check_xcode_minimum_version() { 774 xcode_major=$(show_xcode_version | cut -f1 -d.) 775 xcode_minor=$(show_xcode_version | cut -f2 -d.) 776 xcode_min_major=6 777 xcode_min_minor=3 778 if [ ${xcode_major} -lt ${xcode_min_major} ]; then 779 return 1 780 fi 781 if [ ${xcode_major} -eq ${xcode_min_major} ] \ 782 && [ ${xcode_minor} -lt ${xcode_min_minor} ]; then 783 return 1 784 fi 785} 786 787process_common_toolchain() { 788 if [ -z "$toolchain" ]; then 789 gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}" 790 # detect tgt_isa 791 case "$gcctarget" in 792 aarch64*) 793 tgt_isa=arm64 794 ;; 795 armv7*-hardfloat* | armv7*-gnueabihf | arm-*-gnueabihf) 796 tgt_isa=armv7 797 float_abi=hard 798 ;; 799 armv7*) 800 tgt_isa=armv7 801 float_abi=softfp 802 ;; 803 *x86_64*|*amd64*) 804 tgt_isa=x86_64 805 ;; 806 *i[3456]86*) 807 tgt_isa=x86 808 ;; 809 *sparc*) 810 tgt_isa=sparc 811 ;; 812 power*64le*-*) 813 tgt_isa=ppc64le 814 ;; 815 *mips64el*) 816 tgt_isa=mips64 817 ;; 818 *mips32el*) 819 tgt_isa=mips32 820 ;; 821 loongarch32*) 822 tgt_isa=loongarch32 823 ;; 824 loongarch64*) 825 tgt_isa=loongarch64 826 ;; 827 esac 828 829 # detect tgt_os 830 case "$gcctarget" in 831 *darwin1[0-9]*) 832 tgt_isa=x86_64 833 tgt_os=`echo $gcctarget | sed 's/.*\(darwin1[0-9]\).*/\1/'` 834 ;; 835 *darwin2[0-3]*) 836 tgt_isa=`uname -m` 837 tgt_os=`echo $gcctarget | sed 's/.*\(darwin2[0-9]\).*/\1/'` 838 ;; 839 x86_64*mingw32*) 840 tgt_os=win64 841 ;; 842 x86_64*cygwin*) 843 tgt_os=win64 844 ;; 845 *mingw32*|*cygwin*) 846 [ -z "$tgt_isa" ] && tgt_isa=x86 847 tgt_os=win32 848 ;; 849 *linux*|*bsd*) 850 tgt_os=linux 851 ;; 852 *solaris2.10) 853 tgt_os=solaris 854 ;; 855 *os2*) 856 tgt_os=os2 857 ;; 858 esac 859 860 if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then 861 toolchain=${tgt_isa}-${tgt_os}-gcc 862 fi 863 fi 864 865 toolchain=${toolchain:-generic-gnu} 866 867 is_in ${toolchain} ${all_platforms} || enabled force_toolchain \ 868 || die "Unrecognized toolchain '${toolchain}'" 869 870 enabled child || log_echo "Configuring for target '${toolchain}'" 871 872 # 873 # Set up toolchain variables 874 # 875 tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}') 876 tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}') 877 tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}') 878 879 # Mark the specific ISA requested as enabled 880 soft_enable ${tgt_isa} 881 enable_feature ${tgt_os} 882 enable_feature ${tgt_cc} 883 884 # Enable the architecture family 885 case ${tgt_isa} in 886 arm64 | armv8) 887 enable_feature arm 888 enable_feature aarch64 889 ;; 890 arm*) 891 enable_feature arm 892 ;; 893 mips*) 894 enable_feature mips 895 ;; 896 ppc*) 897 enable_feature ppc 898 ;; 899 loongarch*) 900 soft_enable lsx 901 soft_enable lasx 902 enable_feature loongarch 903 ;; 904 esac 905 906 # Position independent code (PIC) is probably what we want when building 907 # shared libs or position independent executable (PIE) targets. 908 enabled shared && soft_enable pic 909 check_cpp << EOF || soft_enable pic 910#if !(__pie__ || __PIE__) 911#error Neither __pie__ or __PIE__ are set 912#endif 913EOF 914 915 # Minimum iOS version for all target platforms (darwin and iphonesimulator). 916 # Shared library framework builds are only possible on iOS 8 and later. 917 if enabled shared; then 918 IOS_VERSION_OPTIONS="--enable-shared" 919 IOS_VERSION_MIN="8.0" 920 else 921 IOS_VERSION_OPTIONS="" 922 IOS_VERSION_MIN="7.0" 923 fi 924 925 # Handle darwin variants. Newer SDKs allow targeting older 926 # platforms, so use the newest one available. 927 case ${toolchain} in 928 arm*-darwin-*) 929 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}" 930 iphoneos_sdk_dir="$(show_darwin_sdk_path iphoneos)" 931 if [ -d "${iphoneos_sdk_dir}" ]; then 932 add_cflags "-isysroot ${iphoneos_sdk_dir}" 933 add_ldflags "-isysroot ${iphoneos_sdk_dir}" 934 fi 935 ;; 936 *-darwin*) 937 osx_sdk_dir="$(show_darwin_sdk_path macosx)" 938 if [ -d "${osx_sdk_dir}" ]; then 939 add_cflags "-isysroot ${osx_sdk_dir}" 940 add_ldflags "-isysroot ${osx_sdk_dir}" 941 fi 942 ;; 943 esac 944 945 case ${toolchain} in 946 *-darwin8-*) 947 add_cflags "-mmacosx-version-min=10.4" 948 add_ldflags "-mmacosx-version-min=10.4" 949 ;; 950 *-darwin9-*) 951 add_cflags "-mmacosx-version-min=10.5" 952 add_ldflags "-mmacosx-version-min=10.5" 953 ;; 954 *-darwin10-*) 955 add_cflags "-mmacosx-version-min=10.6" 956 add_ldflags "-mmacosx-version-min=10.6" 957 ;; 958 *-darwin11-*) 959 add_cflags "-mmacosx-version-min=10.7" 960 add_ldflags "-mmacosx-version-min=10.7" 961 ;; 962 *-darwin12-*) 963 add_cflags "-mmacosx-version-min=10.8" 964 add_ldflags "-mmacosx-version-min=10.8" 965 ;; 966 *-darwin13-*) 967 add_cflags "-mmacosx-version-min=10.9" 968 add_ldflags "-mmacosx-version-min=10.9" 969 ;; 970 *-darwin14-*) 971 add_cflags "-mmacosx-version-min=10.10" 972 add_ldflags "-mmacosx-version-min=10.10" 973 ;; 974 *-darwin15-*) 975 add_cflags "-mmacosx-version-min=10.11" 976 add_ldflags "-mmacosx-version-min=10.11" 977 ;; 978 *-darwin16-*) 979 add_cflags "-mmacosx-version-min=10.12" 980 add_ldflags "-mmacosx-version-min=10.12" 981 ;; 982 *-darwin17-*) 983 add_cflags "-mmacosx-version-min=10.13" 984 add_ldflags "-mmacosx-version-min=10.13" 985 ;; 986 *-darwin18-*) 987 add_cflags "-mmacosx-version-min=10.14" 988 add_ldflags "-mmacosx-version-min=10.14" 989 ;; 990 *-darwin19-*) 991 add_cflags "-mmacosx-version-min=10.15" 992 add_ldflags "-mmacosx-version-min=10.15" 993 ;; 994 *-darwin2[0-3]-*) 995 add_cflags "-arch ${toolchain%%-*}" 996 add_ldflags "-arch ${toolchain%%-*}" 997 ;; 998 *-iphonesimulator-*) 999 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}" 1000 add_ldflags "-miphoneos-version-min=${IOS_VERSION_MIN}" 1001 iossim_sdk_dir="$(show_darwin_sdk_path iphonesimulator)" 1002 if [ -d "${iossim_sdk_dir}" ]; then 1003 add_cflags "-isysroot ${iossim_sdk_dir}" 1004 add_ldflags "-isysroot ${iossim_sdk_dir}" 1005 fi 1006 ;; 1007 esac 1008 1009 # Handle Solaris variants. Solaris 10 needs -lposix4 1010 case ${toolchain} in 1011 sparc-solaris-*) 1012 add_extralibs -lposix4 1013 ;; 1014 *-solaris-*) 1015 add_extralibs -lposix4 1016 ;; 1017 esac 1018 1019 # Process architecture variants 1020 case ${toolchain} in 1021 arm*) 1022 case ${toolchain} in 1023 armv7*-darwin*) 1024 # Runtime cpu detection is not defined for these targets. 1025 enabled runtime_cpu_detect && disable_feature runtime_cpu_detect 1026 ;; 1027 *) 1028 soft_enable runtime_cpu_detect 1029 ;; 1030 esac 1031 1032 if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then 1033 soft_enable neon 1034 # Only enable neon_asm when neon is also enabled. 1035 enabled neon && soft_enable neon_asm 1036 # If someone tries to force it through, die. 1037 if disabled neon && enabled neon_asm; then 1038 die "Disabling neon while keeping neon-asm is not supported" 1039 fi 1040 fi 1041 1042 asm_conversion_cmd="cat" 1043 case ${tgt_cc} in 1044 gcc) 1045 link_with_cc=gcc 1046 setup_gnu_toolchain 1047 arch_int=${tgt_isa##armv} 1048 arch_int=${arch_int%%te} 1049 tune_cflags="-mtune=" 1050 if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then 1051 if [ -z "${float_abi}" ]; then 1052 check_cpp <<EOF && float_abi=hard || float_abi=softfp 1053#ifndef __ARM_PCS_VFP 1054#error "not hardfp" 1055#endif 1056EOF 1057 fi 1058 check_add_cflags -march=armv7-a -mfloat-abi=${float_abi} 1059 check_add_asflags -march=armv7-a -mfloat-abi=${float_abi} 1060 1061 if enabled neon || enabled neon_asm; then 1062 check_add_cflags -mfpu=neon #-ftree-vectorize 1063 check_add_asflags -mfpu=neon 1064 fi 1065 elif [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then 1066 check_add_cflags -march=armv8-a 1067 check_add_asflags -march=armv8-a 1068 else 1069 check_add_cflags -march=${tgt_isa} 1070 check_add_asflags -march=${tgt_isa} 1071 fi 1072 1073 enabled debug && add_asflags -g 1074 asm_conversion_cmd="${source_path_mk}/build/make/ads2gas.pl" 1075 1076 case ${tgt_os} in 1077 win*) 1078 asm_conversion_cmd="$asm_conversion_cmd -noelf" 1079 AS="$CC -c" 1080 EXE_SFX=.exe 1081 enable_feature thumb 1082 ;; 1083 esac 1084 1085 if enabled thumb; then 1086 asm_conversion_cmd="$asm_conversion_cmd -thumb" 1087 check_add_cflags -mthumb 1088 check_add_asflags -mthumb -mimplicit-it=always 1089 fi 1090 ;; 1091 vs*) 1092 # A number of ARM-based Windows platforms are constrained by their 1093 # respective SDKs' limitations. Fortunately, these are all 32-bit ABIs 1094 # and so can be selected as 'win32'. 1095 if [ ${tgt_os} = "win32" ]; then 1096 asm_conversion_cmd="${source_path_mk}/build/make/ads2armasm_ms.pl" 1097 AS_SFX=.S 1098 msvs_arch_dir=arm-msvs 1099 disable_feature multithread 1100 disable_feature unit_tests 1101 if [ ${tgt_cc##vs} -ge 12 ]; then 1102 # MSVC 2013 doesn't allow doing plain .exe projects for ARM32, 1103 # only "AppContainerApplication" which requires an AppxManifest. 1104 # Therefore disable the examples, just build the library. 1105 disable_feature examples 1106 disable_feature tools 1107 fi 1108 else 1109 # Windows 10 on ARM, on the other hand, has full Windows SDK support 1110 # for building Win32 ARM64 applications in addition to ARM64 1111 # Windows Store apps. It is the only 64-bit ARM ABI that 1112 # Windows supports, so it is the default definition of 'win64'. 1113 # ARM64 build support officially shipped in Visual Studio 15.9.0. 1114 1115 # Because the ARM64 Windows SDK's arm_neon.h is ARM32-specific 1116 # while LLVM's is not, probe its validity. 1117 if enabled neon; then 1118 if [ -n "${CC}" ]; then 1119 check_header arm_neon.h || check_header arm64_neon.h && \ 1120 enable_feature win_arm64_neon_h_workaround 1121 else 1122 # If a probe is not possible, assume this is the pure Windows 1123 # SDK and so the workaround is necessary when using Visual 1124 # Studio < 2019. 1125 if [ ${tgt_cc##vs} -lt 16 ]; then 1126 enable_feature win_arm64_neon_h_workaround 1127 fi 1128 fi 1129 fi 1130 fi 1131 ;; 1132 rvct) 1133 CC=armcc 1134 AR=armar 1135 AS=armasm 1136 LD="${source_path}/build/make/armlink_adapter.sh" 1137 STRIP=arm-none-linux-gnueabi-strip 1138 tune_cflags="--cpu=" 1139 tune_asflags="--cpu=" 1140 if [ -z "${tune_cpu}" ]; then 1141 if [ ${tgt_isa} = "armv7" ]; then 1142 if enabled neon || enabled neon_asm 1143 then 1144 check_add_cflags --fpu=softvfp+vfpv3 1145 check_add_asflags --fpu=softvfp+vfpv3 1146 fi 1147 check_add_cflags --cpu=Cortex-A8 1148 check_add_asflags --cpu=Cortex-A8 1149 else 1150 check_add_cflags --cpu=${tgt_isa##armv} 1151 check_add_asflags --cpu=${tgt_isa##armv} 1152 fi 1153 fi 1154 arch_int=${tgt_isa##armv} 1155 arch_int=${arch_int%%te} 1156 enabled debug && add_asflags -g 1157 add_cflags --gnu 1158 add_cflags --enum_is_int 1159 add_cflags --wchar32 1160 ;; 1161 esac 1162 1163 case ${tgt_os} in 1164 none*) 1165 disable_feature multithread 1166 disable_feature os_support 1167 ;; 1168 1169 android*) 1170 echo "Assuming standalone build with NDK toolchain." 1171 echo "See build/make/Android.mk for details." 1172 check_add_ldflags -static 1173 soft_enable unit_tests 1174 case "$AS" in 1175 *clang) 1176 # The GNU Assembler was removed in the r24 version of the NDK. 1177 # clang's internal assembler works, but `-c` is necessary to 1178 # avoid linking. 1179 add_asflags -c 1180 ;; 1181 esac 1182 ;; 1183 1184 darwin) 1185 if ! enabled external_build; then 1186 XCRUN_FIND="xcrun --sdk iphoneos --find" 1187 CXX="$(${XCRUN_FIND} clang++)" 1188 CC="$(${XCRUN_FIND} clang)" 1189 AR="$(${XCRUN_FIND} ar)" 1190 AS="$(${XCRUN_FIND} as)" 1191 STRIP="$(${XCRUN_FIND} strip)" 1192 AS_SFX=.S 1193 LD="${CXX:-$(${XCRUN_FIND} ld)}" 1194 1195 # ASFLAGS is written here instead of using check_add_asflags 1196 # because we need to overwrite all of ASFLAGS and purge the 1197 # options that were put in above 1198 ASFLAGS="-arch ${tgt_isa} -g" 1199 1200 add_cflags -arch ${tgt_isa} 1201 add_ldflags -arch ${tgt_isa} 1202 1203 alt_libc="$(show_darwin_sdk_path iphoneos)" 1204 if [ -d "${alt_libc}" ]; then 1205 add_cflags -isysroot ${alt_libc} 1206 fi 1207 1208 if [ "${LD}" = "${CXX}" ]; then 1209 add_ldflags -miphoneos-version-min="${IOS_VERSION_MIN}" 1210 else 1211 add_ldflags -ios_version_min "${IOS_VERSION_MIN}" 1212 fi 1213 1214 for d in lib usr/lib usr/lib/system; do 1215 try_dir="${alt_libc}/${d}" 1216 [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}" 1217 done 1218 1219 case ${tgt_isa} in 1220 armv7|armv7s|armv8|arm64) 1221 if enabled neon && ! check_xcode_minimum_version; then 1222 soft_disable neon 1223 log_echo " neon disabled: upgrade Xcode (need v6.3+)." 1224 if enabled neon_asm; then 1225 soft_disable neon_asm 1226 log_echo " neon_asm disabled: upgrade Xcode (need v6.3+)." 1227 fi 1228 fi 1229 ;; 1230 esac 1231 1232 if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then 1233 check_add_cflags -fembed-bitcode 1234 check_add_asflags -fembed-bitcode 1235 check_add_ldflags -fembed-bitcode 1236 fi 1237 fi 1238 1239 asm_conversion_cmd="${source_path_mk}/build/make/ads2gas_apple.pl" 1240 ;; 1241 1242 linux*) 1243 enable_feature linux 1244 if enabled rvct; then 1245 # Check if we have CodeSourcery GCC in PATH. Needed for 1246 # libraries 1247 which arm-none-linux-gnueabi-gcc 2>&- || \ 1248 die "Couldn't find CodeSourcery GCC from PATH" 1249 1250 # Use armcc as a linker to enable translation of 1251 # some gcc specific options such as -lm and -lpthread. 1252 LD="armcc --translate_gcc" 1253 1254 # create configuration file (uses path to CodeSourcery GCC) 1255 armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg 1256 1257 add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg 1258 add_asflags --no_hide_all --apcs=/interwork 1259 add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg 1260 enabled pic && add_cflags --apcs=/fpic 1261 enabled pic && add_asflags --apcs=/fpic 1262 enabled shared && add_cflags --shared 1263 fi 1264 ;; 1265 esac 1266 1267 # AArch64 ISA extensions are treated as supersets. 1268 if [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then 1269 aarch64_arch_flag_neon="arch=armv8-a" 1270 aarch64_arch_flag_neon_dotprod="arch=armv8.2-a+dotprod" 1271 aarch64_arch_flag_neon_i8mm="arch=armv8.2-a+dotprod+i8mm" 1272 aarch64_arch_flag_sve="arch=armv8.2-a+dotprod+i8mm+sve" 1273 aarch64_arch_flag_sve2="arch=armv9-a+sve2" 1274 for ext in ${ARCH_EXT_LIST_AARCH64}; do 1275 if [ "$disable_exts" = "yes" ]; then 1276 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} " 1277 soft_disable $ext 1278 else 1279 # Check the compiler supports the -march flag for the extension. 1280 # This needs to happen after toolchain/OS inspection so we handle 1281 # $CROSS etc correctly when checking for flags, else these will 1282 # always fail. 1283 flag="$(eval echo \$"aarch64_arch_flag_${ext}")" 1284 check_gcc_machine_option "${flag}" "${ext}" 1285 if ! enabled $ext; then 1286 # Disable higher order extensions to simplify dependencies. 1287 disable_exts="yes" 1288 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} " 1289 soft_disable $ext 1290 fi 1291 fi 1292 done 1293 if enabled sve; then 1294 check_neon_sve_bridge_compiles 1295 fi 1296 fi 1297 1298 ;; 1299 mips*) 1300 link_with_cc=gcc 1301 setup_gnu_toolchain 1302 tune_cflags="-mtune=" 1303 if enabled dspr2; then 1304 check_add_cflags -mips32r2 -mdspr2 1305 fi 1306 1307 if enabled runtime_cpu_detect; then 1308 disable_feature runtime_cpu_detect 1309 fi 1310 1311 if [ -n "${tune_cpu}" ]; then 1312 case ${tune_cpu} in 1313 p5600) 1314 check_add_cflags -mips32r5 -mload-store-pairs 1315 check_add_cflags -msched-weight -mhard-float -mfp64 1316 check_add_asflags -mips32r5 -mhard-float -mfp64 1317 check_add_ldflags -mfp64 1318 ;; 1319 i6400|p6600) 1320 check_add_cflags -mips64r6 -mabi=64 -msched-weight 1321 check_add_cflags -mload-store-pairs -mhard-float -mfp64 1322 check_add_asflags -mips64r6 -mabi=64 -mhard-float -mfp64 1323 check_add_ldflags -mips64r6 -mabi=64 -mfp64 1324 ;; 1325 loongson3*) 1326 check_cflags -march=loongson3a && soft_enable mmi \ 1327 || disable_feature mmi 1328 check_cflags -mmsa && soft_enable msa \ 1329 || disable_feature msa 1330 tgt_isa=loongson3a 1331 ;; 1332 esac 1333 1334 if enabled mmi || enabled msa; then 1335 soft_enable runtime_cpu_detect 1336 fi 1337 1338 if enabled msa; then 1339 # TODO(libyuv:793) 1340 # The new mips functions in libyuv do not build 1341 # with the toolchains we currently use for testing. 1342 soft_disable libyuv 1343 fi 1344 fi 1345 1346 check_add_cflags -march=${tgt_isa} 1347 check_add_asflags -march=${tgt_isa} 1348 check_add_asflags -KPIC 1349 ;; 1350 ppc64le*) 1351 link_with_cc=gcc 1352 setup_gnu_toolchain 1353 # Do not enable vsx by default. 1354 # https://bugs.chromium.org/p/webm/issues/detail?id=1522 1355 enabled vsx || RTCD_OPTIONS="${RTCD_OPTIONS}--disable-vsx " 1356 if [ -n "${tune_cpu}" ]; then 1357 case ${tune_cpu} in 1358 power?) 1359 tune_cflags="-mcpu=" 1360 ;; 1361 esac 1362 fi 1363 ;; 1364 x86*) 1365 case ${tgt_os} in 1366 android) 1367 soft_enable realtime_only 1368 ;; 1369 win*) 1370 enabled gcc && add_cflags -fno-common 1371 ;; 1372 solaris*) 1373 CC=${CC:-${CROSS}gcc} 1374 CXX=${CXX:-${CROSS}g++} 1375 LD=${LD:-${CROSS}gcc} 1376 CROSS=${CROSS-g} 1377 ;; 1378 os2) 1379 disable_feature pic 1380 AS=${AS:-nasm} 1381 add_ldflags -Zhigh-mem 1382 ;; 1383 esac 1384 1385 AS="${alt_as:-${AS:-auto}}" 1386 case ${tgt_cc} in 1387 icc*) 1388 CC=${CC:-icc} 1389 LD=${LD:-icc} 1390 setup_gnu_toolchain 1391 add_cflags -use-msasm # remove -use-msasm too? 1392 # add -no-intel-extensions to suppress warning #10237 1393 # refer to http://software.intel.com/en-us/forums/topic/280199 1394 add_ldflags -i-static -no-intel-extensions 1395 enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div 1396 enabled x86_64 && AR=xiar 1397 case ${tune_cpu} in 1398 atom*) 1399 tune_cflags="-x" 1400 tune_cpu="SSE3_ATOM" 1401 ;; 1402 *) 1403 tune_cflags="-march=" 1404 ;; 1405 esac 1406 ;; 1407 gcc*) 1408 link_with_cc=gcc 1409 tune_cflags="-march=" 1410 setup_gnu_toolchain 1411 #for 32 bit x86 builds, -O3 did not turn on this flag 1412 enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer 1413 ;; 1414 vs*) 1415 msvs_arch_dir=x86-msvs 1416 case ${tgt_cc##vs} in 1417 14) 1418 echo "${tgt_cc} does not support avx512, disabling....." 1419 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 " 1420 soft_disable avx512 1421 ;; 1422 esac 1423 ;; 1424 esac 1425 1426 bits=32 1427 enabled x86_64 && bits=64 1428 check_cpp <<EOF && bits=x32 1429#if !defined(__ILP32__) || !defined(__x86_64__) 1430#error "not x32" 1431#endif 1432EOF 1433 case ${tgt_cc} in 1434 gcc*) 1435 add_cflags -m${bits} 1436 add_ldflags -m${bits} 1437 ;; 1438 esac 1439 1440 soft_enable runtime_cpu_detect 1441 # We can't use 'check_cflags' until the compiler is configured and CC is 1442 # populated. 1443 for ext in ${ARCH_EXT_LIST_X86}; do 1444 # disable higher order extensions to simplify asm dependencies 1445 if [ "$disable_exts" = "yes" ]; then 1446 if ! disabled $ext; then 1447 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} " 1448 disable_feature $ext 1449 fi 1450 elif disabled $ext; then 1451 disable_exts="yes" 1452 else 1453 if [ "$ext" = "avx512" ]; then 1454 check_gcc_machine_options $ext avx512f avx512cd avx512bw avx512dq avx512vl 1455 check_gcc_avx512_compiles 1456 else 1457 # use the shortened version for the flag: sse4_1 -> sse4 1458 check_gcc_machine_option ${ext%_*} $ext 1459 fi 1460 fi 1461 done 1462 1463 if enabled external_build; then 1464 log_echo " skipping assembler detection" 1465 else 1466 case "${AS}" in 1467 auto|"") 1468 which nasm >/dev/null 2>&1 && AS=nasm 1469 which yasm >/dev/null 2>&1 && AS=yasm 1470 if [ "${AS}" = nasm ] ; then 1471 # Apple ships version 0.98 of nasm through at least Xcode 6. Revisit 1472 # this check if they start shipping a compatible version. 1473 apple=`nasm -v | grep "Apple"` 1474 [ -n "${apple}" ] \ 1475 && echo "Unsupported version of nasm: ${apple}" \ 1476 && AS="" 1477 fi 1478 [ "${AS}" = auto ] || [ -z "${AS}" ] \ 1479 && die "Neither yasm nor nasm have been found." \ 1480 "See the prerequisites section in the README for more info." 1481 ;; 1482 esac 1483 log_echo " using $AS" 1484 fi 1485 AS_SFX=.asm 1486 case ${tgt_os} in 1487 win32) 1488 add_asflags -f win32 1489 enabled debug && add_asflags -g cv8 1490 EXE_SFX=.exe 1491 ;; 1492 win64) 1493 add_asflags -f win64 1494 enabled debug && add_asflags -g cv8 1495 EXE_SFX=.exe 1496 ;; 1497 linux*|solaris*|android*) 1498 add_asflags -f elf${bits} 1499 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2 1500 enabled debug && [ "${AS}" = nasm ] && add_asflags -g 1501 [ "${AS##*/}" = nasm ] && check_asm_align 1502 ;; 1503 darwin*) 1504 add_asflags -f macho${bits} 1505 enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64" 1506 add_cflags ${darwin_arch} 1507 add_ldflags ${darwin_arch} 1508 # -mdynamic-no-pic is still a bit of voodoo -- it was required at 1509 # one time, but does not seem to be now, and it breaks some of the 1510 # code that still relies on inline assembly. 1511 # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic 1512 enabled icc && ! enabled pic && add_cflags -fno-pic 1513 ;; 1514 iphonesimulator) 1515 add_asflags -f macho${bits} 1516 enabled x86 && sim_arch="-arch i386" || sim_arch="-arch x86_64" 1517 add_cflags ${sim_arch} 1518 add_ldflags ${sim_arch} 1519 1520 if [ "$(disabled external_build)" ] && 1521 [ "$(show_darwin_sdk_major_version iphonesimulator)" -gt 8 ]; then 1522 # yasm v1.3.0 doesn't know what -fembed-bitcode means, so turning it 1523 # on is pointless (unless building a C-only lib). Warn the user, but 1524 # do nothing here. 1525 log "Warning: Bitcode embed disabled for simulator targets." 1526 fi 1527 ;; 1528 os2) 1529 add_asflags -f aout 1530 enabled debug && add_asflags -g 1531 EXE_SFX=.exe 1532 ;; 1533 *) 1534 log "Warning: Unknown os $tgt_os while setting up $AS flags" 1535 ;; 1536 esac 1537 ;; 1538 loongarch*) 1539 link_with_cc=gcc 1540 setup_gnu_toolchain 1541 1542 enabled lsx && check_inline_asm lsx '"vadd.b $vr0, $vr1, $vr1"' 1543 enabled lsx && soft_enable runtime_cpu_detect 1544 enabled lasx && check_inline_asm lasx '"xvadd.b $xr0, $xr1, $xr1"' 1545 enabled lasx && soft_enable runtime_cpu_detect 1546 ;; 1547 *-gcc|generic-gnu) 1548 link_with_cc=gcc 1549 enable_feature gcc 1550 setup_gnu_toolchain 1551 ;; 1552 esac 1553 1554 # Enable PGO 1555 if [ -n "${pgo_file}" ]; then 1556 check_add_cflags -fprofile-use=${pgo_file} || \ 1557 die "-fprofile-use is not supported by compiler" 1558 check_add_ldflags -fprofile-use=${pgo_file} || \ 1559 die "-fprofile-use is not supported by linker" 1560 fi 1561 1562 # Try to enable CPU specific tuning 1563 if [ -n "${tune_cpu}" ]; then 1564 if [ -n "${tune_cflags}" ]; then 1565 check_add_cflags ${tune_cflags}${tune_cpu} || \ 1566 die "Requested CPU '${tune_cpu}' not supported by compiler" 1567 fi 1568 if [ -n "${tune_asflags}" ]; then 1569 check_add_asflags ${tune_asflags}${tune_cpu} || \ 1570 die "Requested CPU '${tune_cpu}' not supported by assembler" 1571 fi 1572 if [ -z "${tune_cflags}${tune_asflags}" ]; then 1573 log_echo "Warning: CPU tuning not supported by this toolchain" 1574 fi 1575 fi 1576 1577 if enabled debug; then 1578 check_add_cflags -g && check_add_ldflags -g 1579 else 1580 check_add_cflags -DNDEBUG 1581 fi 1582 enabled profile && 1583 check_add_cflags -fprofile-generate && 1584 check_add_ldflags -fprofile-generate 1585 1586 enabled gprof && check_add_cflags -pg && check_add_ldflags -pg 1587 enabled gcov && 1588 check_add_cflags -fprofile-arcs -ftest-coverage && 1589 check_add_ldflags -fprofile-arcs -ftest-coverage 1590 1591 if enabled optimizations; then 1592 if enabled rvct; then 1593 enabled small && check_add_cflags -Ospace || check_add_cflags -Otime 1594 else 1595 enabled small && check_add_cflags -O2 || check_add_cflags -O3 1596 fi 1597 fi 1598 1599 # Position Independent Code (PIC) support, for building relocatable 1600 # shared objects 1601 enabled gcc && enabled pic && check_add_cflags -fPIC 1602 1603 # Work around longjmp interception on glibc >= 2.11, to improve binary 1604 # compatibility. See http://code.google.com/p/webm/issues/detail?id=166 1605 enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 1606 1607 # Check for strip utility variant 1608 ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip 1609 1610 # Try to determine target endianness 1611 check_cc <<EOF 1612unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E'; 1613EOF 1614 [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' | 1615 grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian 1616 1617 # Try to find which inline keywords are supported 1618 check_cc <<EOF && INLINE="inline" 1619static inline int function(void) {} 1620EOF 1621 1622 # Almost every platform uses pthreads. 1623 if enabled multithread; then 1624 case ${toolchain} in 1625 *-win*-vs*) 1626 ;; 1627 *-android-gcc) 1628 # bionic includes basic pthread functionality, obviating -lpthread. 1629 ;; 1630 *) 1631 check_header pthread.h && check_lib -lpthread <<EOF && add_extralibs -lpthread || disable_feature pthread_h 1632#include <pthread.h> 1633#include <stddef.h> 1634int main(void) { return pthread_create(NULL, NULL, NULL, NULL); } 1635EOF 1636 ;; 1637 esac 1638 fi 1639 1640 # only for MIPS platforms 1641 case ${toolchain} in 1642 mips*) 1643 if enabled big_endian; then 1644 if enabled dspr2; then 1645 echo "dspr2 optimizations are available only for little endian platforms" 1646 disable_feature dspr2 1647 fi 1648 if enabled msa; then 1649 echo "msa optimizations are available only for little endian platforms" 1650 disable_feature msa 1651 fi 1652 if enabled mmi; then 1653 echo "mmi optimizations are available only for little endian platforms" 1654 disable_feature mmi 1655 fi 1656 fi 1657 ;; 1658 esac 1659 1660 # only for LOONGARCH platforms 1661 case ${toolchain} in 1662 loongarch*) 1663 if enabled big_endian; then 1664 if enabled lsx; then 1665 echo "lsx optimizations are available only for little endian platforms" 1666 disable_feature lsx 1667 fi 1668 if enabled lasx; then 1669 echo "lasx optimizations are available only for little endian platforms" 1670 disable_feature lasx 1671 fi 1672 fi 1673 ;; 1674 esac 1675 1676 # glibc needs these 1677 if enabled linux; then 1678 add_cflags -D_LARGEFILE_SOURCE 1679 add_cflags -D_FILE_OFFSET_BITS=64 1680 fi 1681} 1682 1683process_toolchain() { 1684 process_common_toolchain 1685} 1686 1687print_config_mk() { 1688 saved_prefix="${prefix}" 1689 prefix=$1 1690 makefile=$2 1691 shift 2 1692 for cfg; do 1693 if enabled $cfg; then 1694 upname="`toupper $cfg`" 1695 echo "${prefix}_${upname}=yes" >> $makefile 1696 fi 1697 done 1698 prefix="${saved_prefix}" 1699} 1700 1701print_config_h() { 1702 saved_prefix="${prefix}" 1703 prefix=$1 1704 header=$2 1705 shift 2 1706 for cfg; do 1707 upname="`toupper $cfg`" 1708 if enabled $cfg; then 1709 echo "#define ${prefix}_${upname} 1" >> $header 1710 else 1711 echo "#define ${prefix}_${upname} 0" >> $header 1712 fi 1713 done 1714 prefix="${saved_prefix}" 1715} 1716 1717print_config_vars_h() { 1718 header=$1 1719 shift 1720 while [ $# -gt 0 ]; do 1721 upname="`toupper $1`" 1722 echo "#define ${upname} $2" >> $header 1723 shift 2 1724 done 1725} 1726 1727print_webm_license() { 1728 saved_prefix="${prefix}" 1729 destination=$1 1730 prefix="$2" 1731 suffix="$3" 1732 shift 3 1733 cat <<EOF > ${destination} 1734${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix} 1735${prefix} ${suffix} 1736${prefix} Use of this source code is governed by a BSD-style license${suffix} 1737${prefix} that can be found in the LICENSE file in the root of the source${suffix} 1738${prefix} tree. An additional intellectual property rights grant can be found${suffix} 1739${prefix} in the file PATENTS. All contributing project authors may${suffix} 1740${prefix} be found in the AUTHORS file in the root of the source tree.${suffix} 1741EOF 1742 prefix="${saved_prefix}" 1743} 1744 1745process_targets() { 1746 true; 1747} 1748 1749process_detect() { 1750 true; 1751} 1752 1753enable_feature logging 1754logfile="config.log" 1755self=$0 1756process() { 1757 cmdline_args="$@" 1758 process_cmdline "$@" 1759 if enabled child; then 1760 echo "# ${self} $@" >> ${logfile} 1761 else 1762 echo "# ${self} $@" > ${logfile} 1763 fi 1764 post_process_common_cmdline 1765 post_process_cmdline 1766 process_toolchain 1767 process_detect 1768 process_targets 1769 1770 OOT_INSTALLS="${OOT_INSTALLS}" 1771 if enabled source_path_used; then 1772 # Prepare the PWD for building. 1773 for f in ${OOT_INSTALLS}; do 1774 install -D "${source_path}/$f" "$f" 1775 done 1776 fi 1777 cp "${source_path}/build/make/Makefile" . 1778 1779 clean_temp_files 1780 true 1781} 1782