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