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