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 # 16 die_unknown(){ 17 echo "Unknown option \"$1\"." 18 echo "See $0 --help for available options." 19 clean_temp_files 20 exit 1 21 } 22 23 24 die() { 25 echo "$@" 26 echo 27 echo "Configuration failed. This could reflect a misconfiguration of your" 28 echo "toolchains, improper options selected, or another problem. If you" 29 echo "don't see any useful error messages above, the next step is to look" 30 echo "at the configure error log file ($logfile) to determine what" 31 echo "configure was trying to do when it died." 32 clean_temp_files 33 exit 1 34 } 35 36 37 log(){ 38 echo "$@" >>$logfile 39 } 40 41 42 log_file(){ 43 log BEGIN $1 44 pr -n -t $1 >>$logfile 45 log END $1 46 } 47 48 49 log_echo() { 50 echo "$@" 51 log "$@" 52 } 53 54 55 fwrite () { 56 outfile=$1 57 shift 58 echo "$@" >> ${outfile} 59 } 60 61 62 show_help_pre(){ 63 for opt in ${CMDLINE_SELECT}; do 64 opt2=`echo $opt | sed -e 's;_;-;g'` 65 if enabled $opt; then 66 eval "toggle_${opt}=\"--disable-${opt2}\"" 67 else 68 eval "toggle_${opt}=\"--enable-${opt2} \"" 69 fi 70 done 71 72 cat <<EOF 73 Usage: configure [options] 74 Options: 75 76 Build options: 77 --help print this message 78 --log=yes|no|FILE file configure log is written to [config.log] 79 --target=TARGET target platform tuple [generic-gnu] 80 --cpu=CPU optimize for a specific cpu rather than a family 81 --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] 82 ${toggle_extra_warnings} emit harmless warnings (always non-fatal) 83 ${toggle_werror} treat warnings as errors, if possible 84 (not available with all compilers) 85 ${toggle_optimizations} turn on/off compiler optimization flags 86 ${toggle_pic} turn on/off Position Independent Code 87 ${toggle_ccache} turn on/off compiler cache 88 ${toggle_debug} enable/disable debug mode 89 ${toggle_gprof} enable/disable gprof profiling instrumentation 90 ${toggle_gcov} enable/disable gcov coverage instrumentation 91 ${toggle_thumb} enable/disable building arm assembly in thumb mode 92 93 Install 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 100 EOF 101 } 102 103 104 show_help_post(){ 105 cat <<EOF 106 107 108 NOTES: 109 Object files are built at the place where configure is launched. 110 111 All boolean options can be negated. The default value is the opposite 112 of that shown above. If the option --disable-foo is listed, then 113 the default value for foo is enabled. 114 115 Supported targets: 116 EOF 117 show_targets ${all_platforms} 118 echo 119 exit 1 120 } 121 122 123 show_targets() { 124 while [ -n "$*" ]; do 125 if [ "${1%%-*}" = "${2%%-*}" ]; then 126 if [ "${2%%-*}" = "${3%%-*}" ]; then 127 printf " %-24s %-24s %-24s\n" "$1" "$2" "$3" 128 shift; shift; shift 129 else 130 printf " %-24s %-24s\n" "$1" "$2" 131 shift; shift 132 fi 133 else 134 printf " %-24s\n" "$1" 135 shift 136 fi 137 done 138 } 139 140 141 show_help() { 142 show_help_pre 143 show_help_post 144 } 145 146 # 147 # List Processing Functions 148 # 149 set_all(){ 150 value=$1 151 shift 152 for var in $*; do 153 eval $var=$value 154 done 155 } 156 157 158 is_in(){ 159 value=$1 160 shift 161 for var in $*; do 162 [ $var = $value ] && return 0 163 done 164 return 1 165 } 166 167 168 add_cflags() { 169 CFLAGS="${CFLAGS} $@" 170 CXXFLAGS="${CXXFLAGS} $@" 171 } 172 173 174 add_cflags_only() { 175 CFLAGS="${CFLAGS} $@" 176 } 177 178 179 add_cxxflags_only() { 180 CXXFLAGS="${CXXFLAGS} $@" 181 } 182 183 184 add_ldflags() { 185 LDFLAGS="${LDFLAGS} $@" 186 } 187 188 189 add_asflags() { 190 ASFLAGS="${ASFLAGS} $@" 191 } 192 193 194 add_extralibs() { 195 extralibs="${extralibs} $@" 196 } 197 198 # 199 # Boolean Manipulation Functions 200 # 201 enable_feature(){ 202 set_all yes $* 203 } 204 205 disable_feature(){ 206 set_all no $* 207 } 208 209 enabled(){ 210 eval test "x\$$1" = "xyes" 211 } 212 213 disabled(){ 214 eval test "x\$$1" = "xno" 215 } 216 217 218 soft_enable() { 219 for var in $*; do 220 if ! disabled $var; then 221 log_echo " enabling $var" 222 enable_feature $var 223 fi 224 done 225 } 226 227 soft_disable() { 228 for var in $*; do 229 if ! enabled $var; then 230 log_echo " disabling $var" 231 disable_feature $var 232 fi 233 done 234 } 235 236 237 # 238 # Text Processing Functions 239 # 240 toupper(){ 241 echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 242 } 243 244 245 tolower(){ 246 echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 247 } 248 249 250 # 251 # Temporary File Functions 252 # 253 source_path=${0%/*} 254 enable_feature source_path_used 255 if test -z "$source_path" -o "$source_path" = "." ; then 256 source_path="`pwd`" 257 disable_feature source_path_used 258 fi 259 260 if test ! -z "$TMPDIR" ; then 261 TMPDIRx="${TMPDIR}" 262 elif test ! -z "$TEMPDIR" ; then 263 TMPDIRx="${TEMPDIR}" 264 else 265 TMPDIRx="/tmp" 266 fi 267 RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}') 268 TMP_H="${TMPDIRx}/vpx-conf-$$-${RAND}.h" 269 TMP_C="${TMPDIRx}/vpx-conf-$$-${RAND}.c" 270 TMP_CC="${TMPDIRx}/vpx-conf-$$-${RAND}.cc" 271 TMP_O="${TMPDIRx}/vpx-conf-$$-${RAND}.o" 272 TMP_X="${TMPDIRx}/vpx-conf-$$-${RAND}.x" 273 TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RAND}.asm" 274 275 clean_temp_files() { 276 rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM} 277 } 278 279 # 280 # Toolchain Check Functions 281 # 282 check_cmd() { 283 enabled external_build && return 284 log "$@" 285 "$@" >>${logfile} 2>&1 286 } 287 288 check_cc() { 289 log check_cc "$@" 290 cat >${TMP_C} 291 log_file ${TMP_C} 292 check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C} 293 } 294 295 check_cxx() { 296 log check_cxx "$@" 297 cat >${TMP_CC} 298 log_file ${TMP_CC} 299 check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC} 300 } 301 302 check_cpp() { 303 log check_cpp "$@" 304 cat > ${TMP_C} 305 log_file ${TMP_C} 306 check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C} 307 } 308 309 check_ld() { 310 log check_ld "$@" 311 check_cc $@ \ 312 && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs} 313 } 314 315 check_header(){ 316 log check_header "$@" 317 header=$1 318 shift 319 var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'` 320 disable_feature $var 321 check_cpp "$@" <<EOF && enable_feature $var 322 #include "$header" 323 int x; 324 EOF 325 } 326 327 328 check_cflags() { 329 log check_cflags "$@" 330 check_cc "$@" <<EOF 331 int x; 332 EOF 333 } 334 335 check_cxxflags() { 336 log check_cxxflags "$@" 337 338 # Catch CFLAGS that trigger CXX warnings 339 case "$CXX" in 340 *g++*) check_cxx -Werror "$@" <<EOF 341 int x; 342 EOF 343 ;; 344 *) check_cxx "$@" <<EOF 345 int x; 346 EOF 347 ;; 348 esac 349 } 350 351 check_add_cflags() { 352 check_cxxflags "$@" && add_cxxflags_only "$@" 353 check_cflags "$@" && add_cflags_only "$@" 354 } 355 356 check_add_asflags() { 357 log add_asflags "$@" 358 add_asflags "$@" 359 } 360 361 check_add_ldflags() { 362 log add_ldflags "$@" 363 add_ldflags "$@" 364 } 365 366 check_asm_align() { 367 log check_asm_align "$@" 368 cat >${TMP_ASM} <<EOF 369 section .rodata 370 align 16 371 EOF 372 log_file ${TMP_ASM} 373 check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM} 374 readelf -WS ${TMP_O} >${TMP_X} 375 log_file ${TMP_X} 376 if ! grep -q '\.rodata .* 16$' ${TMP_X}; then 377 die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)" 378 fi 379 } 380 381 write_common_config_banner() { 382 print_webm_license config.mk "##" "" 383 echo '# This file automatically generated by configure. Do not edit!' >> config.mk 384 echo "TOOLCHAIN := ${toolchain}" >> config.mk 385 386 case ${toolchain} in 387 *-linux-rvct) 388 echo "ALT_LIBC := ${alt_libc}" >> config.mk 389 ;; 390 esac 391 } 392 393 write_common_config_targets() { 394 for t in ${all_targets}; do 395 if enabled ${t}; then 396 if enabled universal || enabled child; then 397 fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}" 398 else 399 fwrite config.mk "ALL_TARGETS += ${t}" 400 fi 401 fi 402 true; 403 done 404 true 405 } 406 407 write_common_target_config_mk() { 408 local CC=${CC} 409 local CXX=${CXX} 410 enabled ccache && CC="ccache ${CC}" 411 enabled ccache && CXX="ccache ${CXX}" 412 print_webm_license $1 "##" "" 413 414 cat >> $1 << EOF 415 # This file automatically generated by configure. Do not edit! 416 SRC_PATH="$source_path" 417 SRC_PATH_BARE=$source_path 418 BUILD_PFX=${BUILD_PFX} 419 TOOLCHAIN=${toolchain} 420 ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl} 421 GEN_VCPROJ=${gen_vcproj_cmd} 422 MSVS_ARCH_DIR=${msvs_arch_dir} 423 424 CC=${CC} 425 CXX=${CXX} 426 AR=${AR} 427 LD=${LD} 428 AS=${AS} 429 STRIP=${STRIP} 430 NM=${NM} 431 432 CFLAGS = ${CFLAGS} 433 CXXFLAGS = ${CXXFLAGS} 434 ARFLAGS = -rus\$(if \$(quiet),c,v) 435 LDFLAGS = ${LDFLAGS} 436 ASFLAGS = ${ASFLAGS} 437 extralibs = ${extralibs} 438 AS_SFX = ${AS_SFX:-.asm} 439 EXE_SFX = ${EXE_SFX} 440 VCPROJ_SFX = ${VCPROJ_SFX} 441 RTCD_OPTIONS = ${RTCD_OPTIONS} 442 EOF 443 444 if enabled rvct; then cat >> $1 << EOF 445 fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide 446 EOF 447 else cat >> $1 << EOF 448 fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;' 449 EOF 450 fi 451 452 print_config_mk ARCH "${1}" ${ARCH_LIST} 453 print_config_mk HAVE "${1}" ${HAVE_LIST} 454 print_config_mk CONFIG "${1}" ${CONFIG_LIST} 455 print_config_mk HAVE "${1}" gnu_strip 456 457 enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}" 458 459 } 460 461 462 write_common_target_config_h() { 463 print_webm_license ${TMP_H} "/*" " */" 464 cat >> ${TMP_H} << EOF 465 /* This file automatically generated by configure. Do not edit! */ 466 #ifndef VPX_CONFIG_H 467 #define VPX_CONFIG_H 468 #define RESTRICT ${RESTRICT} 469 #define INLINE ${INLINE} 470 EOF 471 print_config_h ARCH "${TMP_H}" ${ARCH_LIST} 472 print_config_h HAVE "${TMP_H}" ${HAVE_LIST} 473 print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST} 474 echo "#endif /* VPX_CONFIG_H */" >> ${TMP_H} 475 mkdir -p `dirname "$1"` 476 cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1" 477 } 478 479 process_common_cmdline() { 480 for opt in "$@"; do 481 optval="${opt#*=}" 482 case "$opt" in 483 --child) enable_feature child 484 ;; 485 --log*) 486 logging="$optval" 487 if ! disabled logging ; then 488 enabled logging || logfile="$logging" 489 else 490 logfile=/dev/null 491 fi 492 ;; 493 --target=*) toolchain="${toolchain:-${optval}}" 494 ;; 495 --force-target=*) toolchain="${toolchain:-${optval}}"; enable_feature force_toolchain 496 ;; 497 --cpu) 498 ;; 499 --cpu=*) tune_cpu="$optval" 500 ;; 501 --extra-cflags=*) 502 extra_cflags="${optval}" 503 ;; 504 --enable-?*|--disable-?*) 505 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` 506 if echo "${ARCH_EXT_LIST}" | grep "^ *$option\$" >/dev/null; then 507 [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}${opt} " 508 elif [ $action = "disable" ] && ! disabled $option ; then 509 echo "${CMDLINE_SELECT}" | grep "^ *$option\$" >/dev/null || 510 die_unknown $opt 511 elif [ $action = "enable" ] && ! enabled $option ; then 512 echo "${CMDLINE_SELECT}" | grep "^ *$option\$" >/dev/null || 513 die_unknown $opt 514 fi 515 ${action}_feature $option 516 ;; 517 --require-?*) 518 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` 519 if echo "${ARCH_EXT_LIST}" none | grep "^ *$option\$" >/dev/null; then 520 RTCD_OPTIONS="${RTCD_OPTIONS}${opt} " 521 else 522 die_unknown $opt 523 fi 524 ;; 525 --force-enable-?*|--force-disable-?*) 526 eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'` 527 ${action}_feature $option 528 ;; 529 --libc=*) 530 [ -d "${optval}" ] || die "Not a directory: ${optval}" 531 disable_feature builtin_libc 532 alt_libc="${optval}" 533 ;; 534 --as=*) 535 [ "${optval}" = yasm -o "${optval}" = nasm -o "${optval}" = auto ] \ 536 || die "Must be yasm, nasm or auto: ${optval}" 537 alt_as="${optval}" 538 ;; 539 --prefix=*) 540 prefix="${optval}" 541 ;; 542 --libdir=*) 543 libdir="${optval}" 544 ;; 545 --sdk-path=*) 546 [ -d "${optval}" ] || die "Not a directory: ${optval}" 547 sdk_path="${optval}" 548 ;; 549 --libc|--as|--prefix|--libdir|--sdk-path) 550 die "Option ${opt} requires argument" 551 ;; 552 --help|-h) show_help 553 ;; 554 *) die_unknown $opt 555 ;; 556 esac 557 done 558 } 559 560 process_cmdline() { 561 for opt do 562 optval="${opt#*=}" 563 case "$opt" in 564 *) process_common_cmdline $opt 565 ;; 566 esac 567 done 568 } 569 570 571 post_process_common_cmdline() { 572 prefix="${prefix:-/usr/local}" 573 prefix="${prefix%/}" 574 libdir="${libdir:-${prefix}/lib}" 575 libdir="${libdir%/}" 576 if [ "${libdir#${prefix}}" = "${libdir}" ]; then 577 die "Libdir ${libdir} must be a subdirectory of ${prefix}" 578 fi 579 } 580 581 582 post_process_cmdline() { 583 true; 584 } 585 586 setup_gnu_toolchain() { 587 CC=${CC:-${CROSS}gcc} 588 CXX=${CXX:-${CROSS}g++} 589 AR=${AR:-${CROSS}ar} 590 LD=${LD:-${CROSS}${link_with_cc:-ld}} 591 AS=${AS:-${CROSS}as} 592 STRIP=${STRIP:-${CROSS}strip} 593 NM=${NM:-${CROSS}nm} 594 AS_SFX=.s 595 EXE_SFX= 596 } 597 598 process_common_toolchain() { 599 if [ -z "$toolchain" ]; then 600 gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}" 601 602 # detect tgt_isa 603 case "$gcctarget" in 604 armv6*) 605 tgt_isa=armv6 606 ;; 607 armv7*-hardfloat*) 608 tgt_isa=armv7 609 float_abi=hard 610 ;; 611 armv7*) 612 tgt_isa=armv7 613 float_abi=softfp 614 ;; 615 armv5te*) 616 tgt_isa=armv5te 617 ;; 618 *x86_64*|*amd64*) 619 tgt_isa=x86_64 620 ;; 621 *i[3456]86*) 622 tgt_isa=x86 623 ;; 624 *powerpc64*) 625 tgt_isa=ppc64 626 ;; 627 *powerpc*) 628 tgt_isa=ppc32 629 ;; 630 *sparc*) 631 tgt_isa=sparc 632 ;; 633 esac 634 635 # detect tgt_os 636 case "$gcctarget" in 637 *darwin8*) 638 tgt_isa=universal 639 tgt_os=darwin8 640 ;; 641 *darwin9*) 642 tgt_isa=universal 643 tgt_os=darwin9 644 ;; 645 *darwin10*) 646 tgt_isa=x86_64 647 tgt_os=darwin10 648 ;; 649 *darwin11*) 650 tgt_isa=x86_64 651 tgt_os=darwin11 652 ;; 653 *darwin12*) 654 tgt_isa=x86_64 655 tgt_os=darwin12 656 ;; 657 *darwin13*) 658 tgt_isa=x86_64 659 tgt_os=darwin13 660 ;; 661 x86_64*mingw32*) 662 tgt_os=win64 663 ;; 664 *mingw32*|*cygwin*) 665 [ -z "$tgt_isa" ] && tgt_isa=x86 666 tgt_os=win32 667 ;; 668 *linux*|*bsd*) 669 tgt_os=linux 670 ;; 671 *solaris2.10) 672 tgt_os=solaris 673 ;; 674 *os2*) 675 tgt_os=os2 676 ;; 677 esac 678 679 if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then 680 toolchain=${tgt_isa}-${tgt_os}-gcc 681 fi 682 fi 683 684 toolchain=${toolchain:-generic-gnu} 685 686 is_in ${toolchain} ${all_platforms} || enabled force_toolchain \ 687 || die "Unrecognized toolchain '${toolchain}'" 688 689 enabled child || log_echo "Configuring for target '${toolchain}'" 690 691 # 692 # Set up toolchain variables 693 # 694 tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}') 695 tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}') 696 tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}') 697 698 # Mark the specific ISA requested as enabled 699 soft_enable ${tgt_isa} 700 enable_feature ${tgt_os} 701 enable_feature ${tgt_cc} 702 703 # Enable the architecture family 704 case ${tgt_isa} in 705 arm*) enable_feature arm;; 706 mips*) enable_feature mips;; 707 esac 708 709 # PIC is probably what we want when building shared libs 710 enabled shared && soft_enable pic 711 712 # Handle darwin variants. Newer SDKs allow targeting older 713 # platforms, so find the newest SDK available. 714 case ${toolchain} in 715 *-darwin*) 716 if [ -z "${DEVELOPER_DIR}" ]; then 717 DEVELOPER_DIR=`xcode-select -print-path 2> /dev/null` 718 [ $? -ne 0 ] && OSX_SKIP_DIR_CHECK=1 719 fi 720 if [ -z "${OSX_SKIP_DIR_CHECK}" ]; then 721 OSX_SDK_ROOTS="${DEVELOPER_DIR}/SDKs" 722 OSX_SDK_VERSIONS="MacOSX10.4u.sdk MacOSX10.5.sdk MacOSX10.6.sdk" 723 OSX_SDK_VERSIONS="${OSX_SDK_VERSIONS} MacOSX10.7.sdk" 724 for v in ${OSX_SDK_VERSIONS}; do 725 if [ -d "${OSX_SDK_ROOTS}/${v}" ]; then 726 osx_sdk_dir="${OSX_SDK_ROOTS}/${v}" 727 fi 728 done 729 fi 730 ;; 731 esac 732 733 if [ -d "${osx_sdk_dir}" ]; then 734 add_cflags "-isysroot ${osx_sdk_dir}" 735 add_ldflags "-isysroot ${osx_sdk_dir}" 736 fi 737 738 case ${toolchain} in 739 *-darwin8-*) 740 add_cflags "-mmacosx-version-min=10.4" 741 add_ldflags "-mmacosx-version-min=10.4" 742 ;; 743 *-darwin9-*) 744 add_cflags "-mmacosx-version-min=10.5" 745 add_ldflags "-mmacosx-version-min=10.5" 746 ;; 747 *-darwin10-*) 748 add_cflags "-mmacosx-version-min=10.6" 749 add_ldflags "-mmacosx-version-min=10.6" 750 ;; 751 *-darwin11-*) 752 add_cflags "-mmacosx-version-min=10.7" 753 add_ldflags "-mmacosx-version-min=10.7" 754 ;; 755 *-darwin12-*) 756 add_cflags "-mmacosx-version-min=10.8" 757 add_ldflags "-mmacosx-version-min=10.8" 758 ;; 759 *-darwin13-*) 760 add_cflags "-mmacosx-version-min=10.9" 761 add_ldflags "-mmacosx-version-min=10.9" 762 ;; 763 esac 764 765 # Handle Solaris variants. Solaris 10 needs -lposix4 766 case ${toolchain} in 767 sparc-solaris-*) 768 add_extralibs -lposix4 769 disable_feature fast_unaligned 770 ;; 771 *-solaris-*) 772 add_extralibs -lposix4 773 ;; 774 esac 775 776 # Process ARM architecture variants 777 case ${toolchain} in 778 arm*) 779 # on arm, isa versions are supersets 780 case ${tgt_isa} in 781 armv7) 782 soft_enable neon 783 soft_enable media 784 soft_enable edsp 785 soft_enable fast_unaligned 786 ;; 787 armv6) 788 soft_enable media 789 soft_enable edsp 790 soft_enable fast_unaligned 791 ;; 792 armv5te) 793 soft_enable edsp 794 disable_feature fast_unaligned 795 ;; 796 esac 797 798 asm_conversion_cmd="cat" 799 800 case ${tgt_cc} in 801 gcc) 802 CROSS=${CROSS:-arm-none-linux-gnueabi-} 803 link_with_cc=gcc 804 setup_gnu_toolchain 805 arch_int=${tgt_isa##armv} 806 arch_int=${arch_int%%te} 807 check_add_asflags --defsym ARCHITECTURE=${arch_int} 808 tune_cflags="-mtune=" 809 if [ ${tgt_isa} = "armv7" ]; then 810 if [ -z "${float_abi}" ]; then 811 check_cpp <<EOF && float_abi=hard || float_abi=softfp 812 #ifndef __ARM_PCS_VFP 813 #error "not hardfp" 814 #endif 815 EOF 816 fi 817 check_add_cflags -march=armv7-a -mfloat-abi=${float_abi} 818 check_add_asflags -march=armv7-a -mfloat-abi=${float_abi} 819 820 if enabled neon 821 then 822 check_add_cflags -mfpu=neon #-ftree-vectorize 823 check_add_asflags -mfpu=neon 824 fi 825 826 if [ -z "${tune_cpu}" ]; then 827 tune_cpu=cortex-a8 828 fi 829 else 830 check_add_cflags -march=${tgt_isa} 831 check_add_asflags -march=${tgt_isa} 832 fi 833 834 enabled debug && add_asflags -g 835 asm_conversion_cmd="${source_path}/build/make/ads2gas.pl" 836 if enabled thumb; then 837 asm_conversion_cmd="$asm_conversion_cmd -thumb" 838 check_add_cflags -mthumb 839 check_add_asflags -mthumb -mimplicit-it=always 840 fi 841 ;; 842 vs*) 843 asm_conversion_cmd="${source_path}/build/make/ads2armasm_ms.pl" 844 AS_SFX=.s 845 msvs_arch_dir=arm-msvs 846 disable_feature multithread 847 disable_feature unit_tests 848 ;; 849 rvct) 850 CC=armcc 851 AR=armar 852 AS=armasm 853 LD=${source_path}/build/make/armlink_adapter.sh 854 STRIP=arm-none-linux-gnueabi-strip 855 NM=arm-none-linux-gnueabi-nm 856 tune_cflags="--cpu=" 857 tune_asflags="--cpu=" 858 if [ -z "${tune_cpu}" ]; then 859 if [ ${tgt_isa} = "armv7" ]; then 860 if enabled neon 861 then 862 check_add_cflags --fpu=softvfp+vfpv3 863 check_add_asflags --fpu=softvfp+vfpv3 864 fi 865 check_add_cflags --cpu=Cortex-A8 866 check_add_asflags --cpu=Cortex-A8 867 else 868 check_add_cflags --cpu=${tgt_isa##armv} 869 check_add_asflags --cpu=${tgt_isa##armv} 870 fi 871 fi 872 arch_int=${tgt_isa##armv} 873 arch_int=${arch_int%%te} 874 check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\"" 875 enabled debug && add_asflags -g 876 add_cflags --gnu 877 add_cflags --enum_is_int 878 add_cflags --wchar32 879 ;; 880 esac 881 882 case ${tgt_os} in 883 none*) 884 disable_feature multithread 885 disable_feature os_support 886 ;; 887 888 android*) 889 SDK_PATH=${sdk_path} 890 COMPILER_LOCATION=`find "${SDK_PATH}" \ 891 -name "arm-linux-androideabi-gcc*" -print -quit` 892 TOOLCHAIN_PATH=${COMPILER_LOCATION%/*}/arm-linux-androideabi- 893 CC=${TOOLCHAIN_PATH}gcc 894 CXX=${TOOLCHAIN_PATH}g++ 895 AR=${TOOLCHAIN_PATH}ar 896 LD=${TOOLCHAIN_PATH}gcc 897 AS=${TOOLCHAIN_PATH}as 898 STRIP=${TOOLCHAIN_PATH}strip 899 NM=${TOOLCHAIN_PATH}nm 900 901 if [ -z "${alt_libc}" ]; then 902 alt_libc=`find "${SDK_PATH}" -name arch-arm -print | \ 903 awk '{n = split($0,a,"/"); \ 904 split(a[n-1],b,"-"); \ 905 print $0 " " b[2]}' | \ 906 sort -g -k 2 | \ 907 awk '{ print $1 }' | tail -1` 908 fi 909 910 add_cflags "--sysroot=${alt_libc}" 911 add_ldflags "--sysroot=${alt_libc}" 912 913 # linker flag that routes around a CPU bug in some 914 # Cortex-A8 implementations (NDK Dev Guide) 915 add_ldflags "-Wl,--fix-cortex-a8" 916 917 enable_feature pic 918 soft_enable realtime_only 919 if [ ${tgt_isa} = "armv7" ]; then 920 soft_enable runtime_cpu_detect 921 fi 922 if enabled runtime_cpu_detect; then 923 add_cflags "-I${SDK_PATH}/sources/android/cpufeatures" 924 fi 925 ;; 926 927 darwin*) 928 if [ -z "${sdk_path}" ]; then 929 SDK_PATH=`xcode-select -print-path 2> /dev/null` 930 SDK_PATH=${SDK_PATH}/Platforms/iPhoneOS.platform/Developer 931 else 932 SDK_PATH=${sdk_path} 933 fi 934 TOOLCHAIN_PATH=${SDK_PATH}/usr/bin 935 CXX=${TOOLCHAIN_PATH}/g++ 936 CC=${TOOLCHAIN_PATH}/gcc 937 AR=${TOOLCHAIN_PATH}/ar 938 LD=${TOOLCHAIN_PATH}/arm-apple-darwin10-llvm-gcc-4.2 939 AS=${TOOLCHAIN_PATH}/as 940 STRIP=${TOOLCHAIN_PATH}/strip 941 NM=${TOOLCHAIN_PATH}/nm 942 AS_SFX=.s 943 944 # ASFLAGS is written here instead of using check_add_asflags 945 # because we need to overwrite all of ASFLAGS and purge the 946 # options that were put in above 947 ASFLAGS="-version -arch ${tgt_isa} -g" 948 949 add_cflags -arch ${tgt_isa} 950 add_ldflags -arch_only ${tgt_isa} 951 952 if [ -z "${alt_libc}" ]; then 953 alt_libc=${SDK_PATH}/SDKs/iPhoneOS6.0.sdk 954 fi 955 956 add_cflags "-isysroot ${alt_libc}" 957 958 # Add the paths for the alternate libc 959 for d in usr/include; do 960 try_dir="${alt_libc}/${d}" 961 [ -d "${try_dir}" ] && add_cflags -I"${try_dir}" 962 done 963 964 for d in lib usr/lib usr/lib/system; do 965 try_dir="${alt_libc}/${d}" 966 [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}" 967 done 968 969 asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl" 970 ;; 971 972 linux*) 973 enable_feature linux 974 if enabled rvct; then 975 # Check if we have CodeSourcery GCC in PATH. Needed for 976 # libraries 977 hash arm-none-linux-gnueabi-gcc 2>&- || \ 978 die "Couldn't find CodeSourcery GCC from PATH" 979 980 # Use armcc as a linker to enable translation of 981 # some gcc specific options such as -lm and -lpthread. 982 LD="armcc --translate_gcc" 983 984 # create configuration file (uses path to CodeSourcery GCC) 985 armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg 986 987 add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg 988 add_asflags --no_hide_all --apcs=/interwork 989 add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg 990 enabled pic && add_cflags --apcs=/fpic 991 enabled pic && add_asflags --apcs=/fpic 992 enabled shared && add_cflags --shared 993 fi 994 ;; 995 996 esac 997 ;; 998 mips*) 999 link_with_cc=gcc 1000 setup_gnu_toolchain 1001 tune_cflags="-mtune=" 1002 if enabled dspr2; then 1003 check_add_cflags -mips32r2 -mdspr2 1004 disable_feature fast_unaligned 1005 fi 1006 check_add_cflags -march=${tgt_isa} 1007 check_add_asflags -march=${tgt_isa} 1008 check_add_asflags -KPIC 1009 ;; 1010 ppc*) 1011 enable_feature ppc 1012 bits=${tgt_isa##ppc} 1013 link_with_cc=gcc 1014 setup_gnu_toolchain 1015 add_asflags -force_cpusubtype_ALL -I"\$(dir \$<)darwin" 1016 soft_enable altivec 1017 enabled altivec && add_cflags -maltivec 1018 1019 case "$tgt_os" in 1020 linux*) 1021 add_asflags -maltivec -mregnames -I"\$(dir \$<)linux" 1022 ;; 1023 darwin*) 1024 darwin_arch="-arch ppc" 1025 enabled ppc64 && darwin_arch="${darwin_arch}64" 1026 add_cflags ${darwin_arch} -m${bits} -fasm-blocks 1027 add_asflags ${darwin_arch} -force_cpusubtype_ALL -I"\$(dir \$<)darwin" 1028 add_ldflags ${darwin_arch} -m${bits} 1029 enabled altivec && add_cflags -faltivec 1030 ;; 1031 esac 1032 ;; 1033 x86*) 1034 bits=32 1035 enabled x86_64 && bits=64 1036 check_cpp <<EOF && bits=x32 1037 #ifndef __ILP32__ 1038 #error "not x32" 1039 #endif 1040 EOF 1041 1042 case ${tgt_os} in 1043 win*) 1044 enabled gcc && add_cflags -fno-common 1045 ;; 1046 solaris*) 1047 CC=${CC:-${CROSS}gcc} 1048 CXX=${CXX:-${CROSS}g++} 1049 LD=${LD:-${CROSS}gcc} 1050 CROSS=${CROSS:-g} 1051 ;; 1052 os2) 1053 AS=${AS:-nasm} 1054 ;; 1055 esac 1056 1057 AS="${alt_as:-${AS:-auto}}" 1058 case ${tgt_cc} in 1059 icc*) 1060 CC=${CC:-icc} 1061 LD=${LD:-icc} 1062 setup_gnu_toolchain 1063 add_cflags -use-msasm # remove -use-msasm too? 1064 # add -no-intel-extensions to suppress warning #10237 1065 # refer to http://software.intel.com/en-us/forums/topic/280199 1066 add_ldflags -i-static -no-intel-extensions 1067 enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div 1068 enabled x86_64 && AR=xiar 1069 case ${tune_cpu} in 1070 atom*) 1071 tune_cflags="-x" 1072 tune_cpu="SSE3_ATOM" 1073 ;; 1074 *) 1075 tune_cflags="-march=" 1076 ;; 1077 esac 1078 ;; 1079 gcc*) 1080 add_cflags -m${bits} 1081 add_ldflags -m${bits} 1082 link_with_cc=gcc 1083 tune_cflags="-march=" 1084 setup_gnu_toolchain 1085 #for 32 bit x86 builds, -O3 did not turn on this flag 1086 enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer 1087 ;; 1088 vs*) 1089 # When building with Microsoft Visual Studio the assembler is 1090 # invoked directly. Checking at configure time is unnecessary. 1091 # Skip the check by setting AS arbitrarily 1092 AS=msvs 1093 msvs_arch_dir=x86-msvs 1094 vc_version=${tgt_cc##vs} 1095 case $vc_version in 1096 7|8|9) 1097 echo "${tgt_cc} does not support avx/avx2, disabling....." 1098 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx --disable-avx2 " 1099 soft_disable avx 1100 soft_disable avx2 1101 ;; 1102 esac 1103 ;; 1104 esac 1105 1106 soft_enable runtime_cpu_detect 1107 soft_enable mmx 1108 soft_enable sse 1109 soft_enable sse2 1110 soft_enable sse3 1111 soft_enable ssse3 1112 # We can't use 'check_cflags' until the compiler is configured and CC is 1113 # populated. 1114 if enabled gcc && ! disabled sse4_1 && ! check_cflags -msse4; then 1115 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-sse4_1 " 1116 else 1117 soft_enable sse4_1 1118 fi 1119 1120 if enabled gcc && ! disabled avx && ! check_cflags -mavx; then 1121 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx " 1122 else 1123 soft_enable avx 1124 fi 1125 1126 if enabled gcc && ! disabled avx2 && ! check_cflags -mavx2; then 1127 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx2 " 1128 else 1129 soft_enable avx2 1130 fi 1131 1132 case "${AS}" in 1133 auto|"") 1134 which nasm >/dev/null 2>&1 && AS=nasm 1135 which yasm >/dev/null 2>&1 && AS=yasm 1136 [ "${AS}" = auto -o -z "${AS}" ] \ 1137 && die "Neither yasm nor nasm have been found" 1138 ;; 1139 esac 1140 log_echo " using $AS" 1141 [ "${AS##*/}" = nasm ] && add_asflags -Ox 1142 AS_SFX=.asm 1143 case ${tgt_os} in 1144 win32) 1145 add_asflags -f win32 1146 enabled debug && add_asflags -g cv8 1147 EXE_SFX=.exe 1148 ;; 1149 win64) 1150 add_asflags -f x64 1151 enabled debug && add_asflags -g cv8 1152 EXE_SFX=.exe 1153 ;; 1154 linux*|solaris*|android*) 1155 add_asflags -f elf${bits} 1156 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2 1157 enabled debug && [ "${AS}" = nasm ] && add_asflags -g 1158 [ "${AS##*/}" = nasm ] && check_asm_align 1159 ;; 1160 darwin*) 1161 add_asflags -f macho${bits} 1162 enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64" 1163 add_cflags ${darwin_arch} 1164 add_ldflags ${darwin_arch} 1165 # -mdynamic-no-pic is still a bit of voodoo -- it was required at 1166 # one time, but does not seem to be now, and it breaks some of the 1167 # code that still relies on inline assembly. 1168 # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic 1169 enabled icc && ! enabled pic && add_cflags -fno-pic 1170 ;; 1171 os2) 1172 add_asflags -f aout 1173 enabled debug && add_asflags -g 1174 EXE_SFX=.exe 1175 ;; 1176 *) log "Warning: Unknown os $tgt_os while setting up $AS flags" 1177 ;; 1178 esac 1179 ;; 1180 universal*|*-gcc|generic-gnu) 1181 link_with_cc=gcc 1182 enable_feature gcc 1183 setup_gnu_toolchain 1184 ;; 1185 esac 1186 1187 # Try to enable CPU specific tuning 1188 if [ -n "${tune_cpu}" ]; then 1189 if [ -n "${tune_cflags}" ]; then 1190 check_add_cflags ${tune_cflags}${tune_cpu} || \ 1191 die "Requested CPU '${tune_cpu}' not supported by compiler" 1192 fi 1193 if [ -n "${tune_asflags}" ]; then 1194 check_add_asflags ${tune_asflags}${tune_cpu} || \ 1195 die "Requested CPU '${tune_cpu}' not supported by assembler" 1196 fi 1197 if [ -z "${tune_cflags}${tune_asflags}" ]; then 1198 log_echo "Warning: CPU tuning not supported by this toolchain" 1199 fi 1200 fi 1201 1202 enabled debug && check_add_cflags -g && check_add_ldflags -g 1203 enabled gprof && check_add_cflags -pg && check_add_ldflags -pg 1204 enabled gcov && 1205 check_add_cflags -fprofile-arcs -ftest-coverage && 1206 check_add_ldflags -fprofile-arcs -ftest-coverage 1207 1208 if enabled optimizations; then 1209 if enabled rvct; then 1210 enabled small && check_add_cflags -Ospace || check_add_cflags -Otime 1211 else 1212 enabled small && check_add_cflags -O2 || check_add_cflags -O3 1213 fi 1214 fi 1215 1216 # default use_x86inc to yes if pic is no or 64bit or we are not on darwin 1217 echo " checking here for x86inc \"${tgt_isa}\" \"$pic\" " 1218 if [ ${tgt_isa} = x86_64 -o ! "$pic" = "yes" -o "${tgt_os#darwin}" = "${tgt_os}" ]; then 1219 soft_enable use_x86inc 1220 fi 1221 1222 # Position Independent Code (PIC) support, for building relocatable 1223 # shared objects 1224 enabled gcc && enabled pic && check_add_cflags -fPIC 1225 1226 # Work around longjmp interception on glibc >= 2.11, to improve binary 1227 # compatibility. See http://code.google.com/p/webm/issues/detail?id=166 1228 enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 1229 1230 # Check for strip utility variant 1231 ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip 1232 1233 # Try to determine target endianness 1234 check_cc <<EOF 1235 unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E'; 1236 EOF 1237 [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' | 1238 grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian 1239 1240 # Try to find which inline keywords are supported 1241 check_cc <<EOF && INLINE="inline" 1242 static inline function() {} 1243 EOF 1244 check_cc <<EOF && INLINE="__inline__ __attribute__((always_inline))" 1245 static __attribute__((always_inline)) function() {} 1246 EOF 1247 1248 # Almost every platform uses pthreads. 1249 if enabled multithread; then 1250 case ${toolchain} in 1251 *-win*-vs*);; 1252 *-android-gcc);; 1253 *) check_header pthread.h && add_extralibs -lpthread 1254 esac 1255 fi 1256 1257 # only for MIPS platforms 1258 case ${toolchain} in 1259 mips*) 1260 if enabled dspr2; then 1261 if enabled big_endian; then 1262 echo "dspr2 optimizations are available only for little endian platforms" 1263 disable_feature dspr2 1264 fi 1265 fi 1266 ;; 1267 esac 1268 1269 # glibc needs these 1270 if enabled linux; then 1271 add_cflags -D_LARGEFILE_SOURCE 1272 add_cflags -D_FILE_OFFSET_BITS=64 1273 fi 1274 1275 # append any user defined extra cflags 1276 if [ -n "${extra_cflags}" ] ; then 1277 check_add_cflags ${extra_cflags} || \ 1278 die "Requested extra CFLAGS '${extra_cflags}' not supported by compiler" 1279 fi 1280 } 1281 1282 process_toolchain() { 1283 process_common_toolchain 1284 } 1285 1286 print_config_mk() { 1287 local prefix=$1 1288 local makefile=$2 1289 shift 2 1290 for cfg; do 1291 upname="`toupper $cfg`" 1292 if enabled $cfg; then 1293 echo "${prefix}_${upname}=yes" >> $makefile 1294 fi 1295 done 1296 } 1297 1298 print_config_h() { 1299 local prefix=$1 1300 local header=$2 1301 shift 2 1302 for cfg; do 1303 upname="`toupper $cfg`" 1304 if enabled $cfg; then 1305 echo "#define ${prefix}_${upname} 1" >> $header 1306 else 1307 echo "#define ${prefix}_${upname} 0" >> $header 1308 fi 1309 done 1310 } 1311 1312 print_webm_license() { 1313 local destination=$1 1314 local prefix="$2" 1315 local suffix="$3" 1316 shift 3 1317 cat <<EOF > ${destination} 1318 ${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix} 1319 ${prefix} ${suffix} 1320 ${prefix} Use of this source code is governed by a BSD-style license${suffix} 1321 ${prefix} that can be found in the LICENSE file in the root of the source${suffix} 1322 ${prefix} tree. An additional intellectual property rights grant can be found${suffix} 1323 ${prefix} in the file PATENTS. All contributing project authors may${suffix} 1324 ${prefix} be found in the AUTHORS file in the root of the source tree.${suffix} 1325 EOF 1326 } 1327 1328 process_targets() { 1329 true; 1330 } 1331 1332 process_detect() { 1333 true; 1334 } 1335 1336 enable_feature logging 1337 logfile="config.log" 1338 self=$0 1339 process() { 1340 cmdline_args="$@" 1341 process_cmdline "$@" 1342 if enabled child; then 1343 echo "# ${self} $@" >> ${logfile} 1344 else 1345 echo "# ${self} $@" > ${logfile} 1346 fi 1347 post_process_common_cmdline 1348 post_process_cmdline 1349 process_toolchain 1350 process_detect 1351 process_targets 1352 1353 OOT_INSTALLS="${OOT_INSTALLS}" 1354 if enabled source_path_used; then 1355 # Prepare the PWD for building. 1356 for f in ${OOT_INSTALLS}; do 1357 install -D ${source_path}/$f $f 1358 done 1359 fi 1360 cp ${source_path}/build/make/Makefile . 1361 1362 clean_temp_files 1363 true 1364 } 1365