blob: c7385045f15fd03f18e0965039cb865045c6e1b4 [file] [log] [blame]
David Ghandehari8c5039b2016-08-17 19:39:30 -07001#!/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_codec(){
190 enabled $1 || echo " enabling $1"
191 set_all yes $1
192
193 is_in $1 vp8 vp9 vp10 && \
194 set_all yes $1_encoder && \
195 set_all yes $1_decoder
196}
197
198disable_codec(){
199 disabled $1 || echo " disabling $1"
200 set_all no $1
201
202 is_in $1 vp8 vp9 vp10 && \
203 set_all no $1_encoder && \
204 set_all no $1_decoder
205}
206
207enable_feature(){
208 set_all yes $*
209}
210
211disable_feature(){
212 set_all no $*
213}
214
215enabled(){
216 eval test "x\$$1" = "xyes"
217}
218
219disabled(){
220 eval test "x\$$1" = "xno"
221}
222
223# Iterates through positional parameters, checks to confirm the parameter has
224# not been explicitly (force) disabled, and enables the setting controlled by
225# the parameter when the setting is not disabled.
226# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
227soft_enable() {
228 for var in $*; do
229 if ! disabled $var; then
230 enabled $var || log_echo " enabling $var"
231 enable_feature $var
232 fi
233 done
234}
235
236# Iterates through positional parameters, checks to confirm the parameter has
237# not been explicitly (force) enabled, and disables the setting controlled by
238# the parameter when the setting is not enabled.
239# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
240soft_disable() {
241 for var in $*; do
242 if ! enabled $var; then
243 disabled $var || log_echo " disabling $var"
244 disable_feature $var
245 fi
246 done
247}
248
249#
250# Text Processing Functions
251#
252toupper(){
253 echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
254}
255
256tolower(){
257 echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
258}
259
260#
261# Temporary File Functions
262#
263source_path=${0%/*}
264enable_feature source_path_used
265if [ -z "$source_path" ] || [ "$source_path" = "." ]; then
266 # rjogrady: Hack for Cygwin / PS4 interaction.
267 # PS4 compiler doesn't understand cygdrive.
268 #source_path="`pwd`"
269 source_path='.'
270 disable_feature source_path_used
271fi
272
273if test ! -z "$TMPDIR" ; then
274 TMPDIRx="${TMPDIR}"
275elif test ! -z "$TEMPDIR" ; then
276 TMPDIRx="${TEMPDIR}"
277else
278 TMPDIRx="/tmp"
279fi
280RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}')
281TMP_H="${TMPDIRx}/vpx-conf-$$-${RAND}.h"
282TMP_C="${TMPDIRx}/vpx-conf-$$-${RAND}.c"
283TMP_CC="${TMPDIRx}/vpx-conf-$$-${RAND}.cc"
284TMP_O="${TMPDIRx}/vpx-conf-$$-${RAND}.o"
285TMP_X="${TMPDIRx}/vpx-conf-$$-${RAND}.x"
286TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RAND}.asm"
287
288clean_temp_files() {
289 rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM}
290 enabled gcov && rm -f ${TMP_C%.c}.gcno ${TMP_CC%.cc}.gcno
291}
292
293#
294# Toolchain Check Functions
295#
296check_cmd() {
297 enabled external_build && return
298 log "$@"
299 "$@" >>${logfile} 2>&1
300}
301
302check_cc() {
303 log check_cc "$@"
304 cat >${TMP_C}
305 log_file ${TMP_C}
306 check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C}
307}
308
309check_cxx() {
310 log check_cxx "$@"
311 cat >${TMP_CC}
312 log_file ${TMP_CC}
313 check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC}
314}
315
316check_cpp() {
317 log check_cpp "$@"
318 cat > ${TMP_C}
319 log_file ${TMP_C}
320 check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C}
321}
322
323check_ld() {
324 log check_ld "$@"
325 check_cc $@ \
326 && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs}
327}
328
329check_header(){
330 log check_header "$@"
331 header=$1
332 shift
333 var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
334 disable_feature $var
335 check_cpp "$@" <<EOF && enable_feature $var
336#include "$header"
337int x;
338EOF
339}
340
341check_cflags() {
342 log check_cflags "$@"
343 check_cc -Werror "$@" <<EOF
344int x;
345EOF
346}
347
348check_cxxflags() {
349 log check_cxxflags "$@"
350
351 # Catch CFLAGS that trigger CXX warnings
352 case "$CXX" in
353 *c++-analyzer|*clang++|*g++*)
354 check_cxx -Werror "$@" <<EOF
355int x;
356EOF
357 ;;
358 *)
359 check_cxx -Werror "$@" <<EOF
360int x;
361EOF
362 ;;
363 esac
364}
365
366check_add_cflags() {
367 check_cxxflags "$@" && add_cxxflags_only "$@"
368 check_cflags "$@" && add_cflags_only "$@"
369}
370
371check_add_cxxflags() {
372 check_cxxflags "$@" && add_cxxflags_only "$@"
373}
374
375check_add_asflags() {
376 log add_asflags "$@"
377 add_asflags "$@"
378}
379
380check_add_ldflags() {
381 log add_ldflags "$@"
382 add_ldflags "$@"
383}
384
385check_asm_align() {
386 log check_asm_align "$@"
387 cat >${TMP_ASM} <<EOF
388section .rodata
389align 16
390EOF
391 log_file ${TMP_ASM}
392 check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM}
393 readelf -WS ${TMP_O} >${TMP_X}
394 log_file ${TMP_X}
395 if ! grep -q '\.rodata .* 16$' ${TMP_X}; then
396 die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)"
397 fi
398}
399
400# tests for -m$1 toggling the feature given in $2. If $2 is empty $1 is used.
401check_gcc_machine_option() {
402 opt="$1"
403 feature="$2"
404 [ -n "$feature" ] || feature="$opt"
405
406 if enabled gcc && ! disabled "$feature" && ! check_cflags "-m$opt"; then
407 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature "
408 else
409 soft_enable "$feature"
410 fi
411}
412
413write_common_config_banner() {
414 print_webm_license config.mk "##" ""
415 echo '# This file automatically generated by configure. Do not edit!' >> config.mk
416 echo "TOOLCHAIN := ${toolchain}" >> config.mk
417
418 case ${toolchain} in
419 *-linux-rvct)
420 echo "ALT_LIBC := ${alt_libc}" >> config.mk
421 ;;
422 esac
423}
424
425write_common_config_targets() {
426 for t in ${all_targets}; do
427 if enabled ${t}; then
428 if enabled child; then
429 fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}"
430 else
431 fwrite config.mk "ALL_TARGETS += ${t}"
432 fi
433 fi
434 true;
435 done
436 true
437}
438
439write_common_target_config_mk() {
440 saved_CC="${CC}"
441 saved_CXX="${CXX}"
442 enabled ccache && CC="ccache ${CC}"
443 enabled ccache && CXX="ccache ${CXX}"
444 print_webm_license $1 "##" ""
445
446 cat >> $1 << EOF
447# This file automatically generated by configure. Do not edit!
448SRC_PATH="$source_path"
449SRC_PATH_BARE=$source_path
450BUILD_PFX=${BUILD_PFX}
451TOOLCHAIN=${toolchain}
452ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl}
453GEN_VCPROJ=${gen_vcproj_cmd}
454MSVS_ARCH_DIR=${msvs_arch_dir}
455
456CC=${CC}
457CXX=${CXX}
458AR=${AR}
459LD=${LD}
460AS=${AS}
461STRIP=${STRIP}
462NM=${NM}
463
464CFLAGS = ${CFLAGS}
465CXXFLAGS = ${CXXFLAGS}
466ARFLAGS = -crs\$(if \$(quiet),,v)
467LDFLAGS = ${LDFLAGS}
468ASFLAGS = ${ASFLAGS}
469extralibs = ${extralibs}
470AS_SFX = ${AS_SFX:-.asm}
471EXE_SFX = ${EXE_SFX}
472VCPROJ_SFX = ${VCPROJ_SFX}
473RTCD_OPTIONS = ${RTCD_OPTIONS}
474EOF
475
476 if enabled rvct; then cat >> $1 << EOF
477fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide
478EOF
479elif enabled orbis; then cat >> $1 << EOF
480fmt_deps = python fix_orbis_deps.py
481EOF
482 else cat >> $1 << EOF
483fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;'
484EOF
485 fi
486
487 print_config_mk ARCH "${1}" ${ARCH_LIST}
488 print_config_mk HAVE "${1}" ${HAVE_LIST}
489 print_config_mk CONFIG "${1}" ${CONFIG_LIST}
490 print_config_mk HAVE "${1}" gnu_strip
491
492 enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}"
493
494 CC="${saved_CC}"
495 CXX="${saved_CXX}"
496}
497
498write_common_target_config_h() {
499 print_webm_license ${TMP_H} "/*" " */"
500 cat >> ${TMP_H} << EOF
501/* This file automatically generated by configure. Do not edit! */
502#ifndef VPX_CONFIG_H
503#define VPX_CONFIG_H
504#define RESTRICT ${RESTRICT}
505#define INLINE ${INLINE}
506EOF
507 print_config_h ARCH "${TMP_H}" ${ARCH_LIST}
508 print_config_h HAVE "${TMP_H}" ${HAVE_LIST}
509 print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST}
510 print_config_vars_h "${TMP_H}" ${VAR_LIST}
511 echo "#endif /* VPX_CONFIG_H */" >> ${TMP_H}
512 mkdir -p `dirname "$1"`
513 cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1"
514}
515
516process_common_cmdline() {
517 for opt in "$@"; do
518 optval="${opt#*=}"
519 case "$opt" in
520 --child)
521 enable_feature child
522 ;;
523 --log*)
524 logging="$optval"
525 if ! disabled logging ; then
526 enabled logging || logfile="$logging"
527 else
528 logfile=/dev/null
529 fi
530 ;;
531 --target=*)
532 toolchain="${toolchain:-${optval}}"
533 ;;
534 --force-target=*)
535 toolchain="${toolchain:-${optval}}"
536 enable_feature force_toolchain
537 ;;
538 --cpu=*)
539 tune_cpu="$optval"
540 ;;
541 --extra-cflags=*)
542 extra_cflags="${optval}"
543 ;;
544 --extra-cxxflags=*)
545 extra_cxxflags="${optval}"
546 ;;
547 --enable-?*|--disable-?*)
548 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
549 if is_in ${option} ${ARCH_EXT_LIST}; then
550 [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${option} "
551 elif [ $action = "disable" ] && ! disabled $option ; then
552 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
553 log_echo " disabling $option"
554 elif [ $action = "enable" ] && ! enabled $option ; then
555 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
556 log_echo " enabling $option"
557 fi
558 ${action}_feature $option
559 ;;
560 --require-?*)
561 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
562 if is_in ${option} ${ARCH_EXT_LIST}; then
563 RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
564 else
565 die_unknown $opt
566 fi
567 ;;
568 --force-enable-?*|--force-disable-?*)
569 eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'`
570 ${action}_feature $option
571 ;;
572 --libc=*)
573 [ -d "${optval}" ] || die "Not a directory: ${optval}"
574 disable_feature builtin_libc
575 alt_libc="${optval}"
576 ;;
577 --as=*)
578 [ "${optval}" = yasm ] || [ "${optval}" = nasm ] \
579 || [ "${optval}" = auto ] \
580 || die "Must be yasm, nasm or auto: ${optval}"
581 alt_as="${optval}"
582 ;;
583 --size-limit=*)
584 w="${optval%%x*}"
585 h="${optval##*x}"
586 VAR_LIST="DECODE_WIDTH_LIMIT ${w} DECODE_HEIGHT_LIMIT ${h}"
587 [ ${w} -gt 0 ] && [ ${h} -gt 0 ] || die "Invalid size-limit: too small."
588 [ ${w} -lt 65536 ] && [ ${h} -lt 65536 ] \
589 || die "Invalid size-limit: too big."
590 enable_feature size_limit
591 ;;
592 --prefix=*)
593 prefix="${optval}"
594 ;;
595 --libdir=*)
596 libdir="${optval}"
597 ;;
598 --sdk-path=*)
599 [ -d "${optval}" ] || die "Not a directory: ${optval}"
600 sdk_path="${optval}"
601 ;;
602 --libc|--as|--prefix|--libdir|--sdk-path)
603 die "Option ${opt} requires argument"
604 ;;
605 --help|-h)
606 show_help
607 ;;
608 *)
609 die_unknown $opt
610 ;;
611 esac
612 done
613}
614
615process_cmdline() {
616 for opt do
617 optval="${opt#*=}"
618 case "$opt" in
619 *)
620 process_common_cmdline $opt
621 ;;
622 esac
623 done
624}
625
626post_process_common_cmdline() {
627 prefix="${prefix:-/usr/local}"
628 prefix="${prefix%/}"
629 libdir="${libdir:-${prefix}/lib}"
630 libdir="${libdir%/}"
631 if [ "${libdir#${prefix}}" = "${libdir}" ]; then
632 die "Libdir ${libdir} must be a subdirectory of ${prefix}"
633 fi
634}
635
636post_process_cmdline() {
637 true;
638}
639
640setup_gnu_toolchain() {
641 CC=${CC:-${CROSS}gcc}
642 CXX=${CXX:-${CROSS}g++}
643 AR=${AR:-${CROSS}ar}
644 LD=${LD:-${CROSS}${link_with_cc:-ld}}
645 AS=${AS:-${CROSS}as}
646 STRIP=${STRIP:-${CROSS}strip}
647 NM=${NM:-${CROSS}nm}
648 AS_SFX=.s
649 EXE_SFX=
650}
651
652setup_clang_toolchain() {
653 CC=${CC:-${CROSS}clang}
654 CXX=${CXX:-${CROSS}clang++}
655 AR=${AR:-${CROSS}ar}
656 LD=${LD:-${CROSS}ld}
657 AS=${AS:-${CROSS}as}
658 STRIP=${STRIP:-${CROSS}strip}
659 NM=${NM:-${CROSS}nm}
660 AS_SFX=.s
661 EXE_SFX=
662}
663
664# Reliably find the newest available Darwin SDKs. (Older versions of
665# xcrun don't support --show-sdk-path.)
666show_darwin_sdk_path() {
667 xcrun --sdk $1 --show-sdk-path 2>/dev/null ||
668 xcodebuild -sdk $1 -version Path 2>/dev/null
669}
670
671# Print the major version number of the Darwin SDK specified by $1.
672show_darwin_sdk_major_version() {
673 xcrun --sdk $1 --show-sdk-version 2>/dev/null | cut -d. -f1
674}
675
676# Print the Xcode version.
677show_xcode_version() {
678 xcodebuild -version | head -n1 | cut -d' ' -f2
679}
680
681# Fails when Xcode version is less than 6.3.
682check_xcode_minimum_version() {
683 xcode_major=$(show_xcode_version | cut -f1 -d.)
684 xcode_minor=$(show_xcode_version | cut -f2 -d.)
685 xcode_min_major=6
686 xcode_min_minor=3
687 if [ ${xcode_major} -lt ${xcode_min_major} ]; then
688 return 1
689 fi
690 if [ ${xcode_major} -eq ${xcode_min_major} ] \
691 && [ ${xcode_minor} -lt ${xcode_min_minor} ]; then
692 return 1
693 fi
694}
695
696process_common_toolchain() {
697 if [ -z "$toolchain" ]; then
698 gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}"
699
700 # detect tgt_isa
701 case "$gcctarget" in
702 aarch64*)
703 tgt_isa=arm64
704 ;;
705 armv6*)
706 tgt_isa=armv6
707 ;;
708 armv7*-hardfloat* | armv7*-gnueabihf | arm-*-gnueabihf)
709 tgt_isa=armv7
710 float_abi=hard
711 ;;
712 armv7*)
713 tgt_isa=armv7
714 float_abi=softfp
715 ;;
716 *x86_64*|*amd64*)
717 tgt_isa=x86_64
718 ;;
719 *i[3456]86*)
720 tgt_isa=x86
721 ;;
722 *sparc*)
723 tgt_isa=sparc
724 ;;
725 esac
726
727 # detect tgt_os
728 case "$gcctarget" in
729 *darwin10*)
730 tgt_isa=x86_64
731 tgt_os=darwin10
732 ;;
733 *darwin11*)
734 tgt_isa=x86_64
735 tgt_os=darwin11
736 ;;
737 *darwin12*)
738 tgt_isa=x86_64
739 tgt_os=darwin12
740 ;;
741 *darwin13*)
742 tgt_isa=x86_64
743 tgt_os=darwin13
744 ;;
745 *darwin14*)
746 tgt_isa=x86_64
747 tgt_os=darwin14
748 ;;
749 *darwin15*)
750 tgt_isa=x86_64
751 tgt_os=darwin15
752 ;;
753 x86_64*mingw32*)
754 tgt_os=win64
755 ;;
756 *mingw32*|*cygwin*)
757 [ -z "$tgt_isa" ] && tgt_isa=x86
758 tgt_os=win32
759 ;;
760 *linux*|*bsd*)
761 tgt_os=linux
762 ;;
763 *solaris2.10)
764 tgt_os=solaris
765 ;;
766 *os2*)
767 tgt_os=os2
768 ;;
769 esac
770
771 if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then
772 toolchain=${tgt_isa}-${tgt_os}-gcc
773 fi
774 fi
775
776 toolchain=${toolchain:-generic-gnu}
777
778 is_in ${toolchain} ${all_platforms} || enabled force_toolchain \
779 || die "Unrecognized toolchain '${toolchain}'"
780
781 enabled child || log_echo "Configuring for target '${toolchain}'"
782
783 #
784 # Set up toolchain variables
785 #
786 tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}')
787 tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}')
788 tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}')
789
790 # Mark the specific ISA requested as enabled
791 soft_enable ${tgt_isa}
792 enable_feature ${tgt_os}
793 enable_feature ${tgt_cc}
794
795 # Enable the architecture family
796 case ${tgt_isa} in
797 arm*)
798 enable_feature arm
799 ;;
800 mips*)
801 enable_feature mips
802 ;;
803 esac
804
805 # PIC is probably what we want when building shared libs
806 enabled shared && soft_enable pic
807 enabled orbis && soft_enable pic
808
809 # Minimum iOS version for all target platforms (darwin and iphonesimulator).
810 # Shared library framework builds are only possible on iOS 8 and later.
811 if enabled shared; then
812 IOS_VERSION_OPTIONS="--enable-shared"
813 IOS_VERSION_MIN="8.0"
814 else
815 IOS_VERSION_OPTIONS=""
816 IOS_VERSION_MIN="6.0"
817 fi
818
819 # Handle darwin variants. Newer SDKs allow targeting older
820 # platforms, so use the newest one available.
821 case ${toolchain} in
822 arm*-darwin*)
823 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
824 iphoneos_sdk_dir="$(show_darwin_sdk_path iphoneos)"
825 if [ -d "${iphoneos_sdk_dir}" ]; then
826 add_cflags "-isysroot ${iphoneos_sdk_dir}"
827 add_ldflags "-isysroot ${iphoneos_sdk_dir}"
828 fi
829 ;;
830 x86*-darwin*)
831 osx_sdk_dir="$(show_darwin_sdk_path macosx)"
832 if [ -d "${osx_sdk_dir}" ]; then
833 add_cflags "-isysroot ${osx_sdk_dir}"
834 add_ldflags "-isysroot ${osx_sdk_dir}"
835 fi
836 ;;
837 esac
838
839 case ${toolchain} in
840 *-darwin8-*)
841 add_cflags "-mmacosx-version-min=10.4"
842 add_ldflags "-mmacosx-version-min=10.4"
843 ;;
844 *-darwin9-*)
845 add_cflags "-mmacosx-version-min=10.5"
846 add_ldflags "-mmacosx-version-min=10.5"
847 ;;
848 *-darwin10-*)
849 add_cflags "-mmacosx-version-min=10.6"
850 add_ldflags "-mmacosx-version-min=10.6"
851 ;;
852 *-darwin11-*)
853 add_cflags "-mmacosx-version-min=10.7"
854 add_ldflags "-mmacosx-version-min=10.7"
855 ;;
856 *-darwin12-*)
857 add_cflags "-mmacosx-version-min=10.8"
858 add_ldflags "-mmacosx-version-min=10.8"
859 ;;
860 *-darwin13-*)
861 add_cflags "-mmacosx-version-min=10.9"
862 add_ldflags "-mmacosx-version-min=10.9"
863 ;;
864 *-darwin14-*)
865 add_cflags "-mmacosx-version-min=10.10"
866 add_ldflags "-mmacosx-version-min=10.10"
867 ;;
868 *-darwin15-*)
869 add_cflags "-mmacosx-version-min=10.11"
870 add_ldflags "-mmacosx-version-min=10.11"
871 ;;
872 *-iphonesimulator-*)
873 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
874 add_ldflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
875 iossim_sdk_dir="$(show_darwin_sdk_path iphonesimulator)"
876 if [ -d "${iossim_sdk_dir}" ]; then
877 add_cflags "-isysroot ${iossim_sdk_dir}"
878 add_ldflags "-isysroot ${iossim_sdk_dir}"
879 fi
880 ;;
881 esac
882
883 # Handle Solaris variants. Solaris 10 needs -lposix4
884 case ${toolchain} in
885 sparc-solaris-*)
886 add_extralibs -lposix4
887 ;;
888 *-solaris-*)
889 add_extralibs -lposix4
890 ;;
891 esac
892
893 # Process ARM architecture variants
894 case ${toolchain} in
895 arm*)
896 # on arm, isa versions are supersets
897 case ${tgt_isa} in
898 arm64|armv8)
899 soft_enable neon
900 ;;
901 armv7|armv7s)
902 soft_enable neon
903 # Only enable neon_asm when neon is also enabled.
904 enabled neon && soft_enable neon_asm
905 # If someone tries to force it through, die.
906 if disabled neon && enabled neon_asm; then
907 die "Disabling neon while keeping neon-asm is not supported"
908 fi
909 case ${toolchain} in
910 # Apple iOS SDKs no longer support armv6 as of the version 9
911 # release (coincides with release of Xcode 7). Only enable media
912 # when using earlier SDK releases.
913 *-darwin*)
914 if [ "$(show_darwin_sdk_major_version iphoneos)" -lt 9 ]; then
915 soft_enable media
916 else
917 soft_disable media
918 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-media "
919 fi
920 ;;
921 *)
922 soft_enable media
923 ;;
924 esac
925 ;;
926 armv6)
927 case ${toolchain} in
928 *-darwin*)
929 if [ "$(show_darwin_sdk_major_version iphoneos)" -lt 9 ]; then
930 soft_enable media
931 else
932 die "Your iOS SDK does not support armv6."
933 fi
934 ;;
935 *)
936 soft_enable media
937 ;;
938 esac
939 ;;
940 esac
941
942 asm_conversion_cmd="cat"
943
944 case ${tgt_cc} in
945 gcc)
946 link_with_cc=gcc
947 setup_gnu_toolchain
948 arch_int=${tgt_isa##armv}
949 arch_int=${arch_int%%te}
950 check_add_asflags --defsym ARCHITECTURE=${arch_int}
951 tune_cflags="-mtune="
952 if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then
953 if [ -z "${float_abi}" ]; then
954 check_cpp <<EOF && float_abi=hard || float_abi=softfp
955#ifndef __ARM_PCS_VFP
956#error "not hardfp"
957#endif
958EOF
959 fi
960 check_add_cflags -march=armv7-a -mfloat-abi=${float_abi}
961 check_add_asflags -march=armv7-a -mfloat-abi=${float_abi}
962
963 if enabled neon || enabled neon_asm; then
964 check_add_cflags -mfpu=neon #-ftree-vectorize
965 check_add_asflags -mfpu=neon
966 fi
967 else
968 check_add_cflags -march=${tgt_isa}
969 check_add_asflags -march=${tgt_isa}
970 fi
971
972 enabled debug && add_asflags -g
973 asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
974 if enabled thumb; then
975 asm_conversion_cmd="$asm_conversion_cmd -thumb"
976 check_add_cflags -mthumb
977 check_add_asflags -mthumb -mimplicit-it=always
978 fi
979 ;;
980 vs*)
981 asm_conversion_cmd="${source_path}/build/make/ads2armasm_ms.pl"
982 AS_SFX=.s
983 msvs_arch_dir=arm-msvs
984 disable_feature multithread
985 disable_feature unit_tests
986 vs_version=${tgt_cc##vs}
987 if [ $vs_version -ge 12 ]; then
988 # MSVC 2013 doesn't allow doing plain .exe projects for ARM,
989 # only "AppContainerApplication" which requires an AppxManifest.
990 # Therefore disable the examples, just build the library.
991 disable_feature examples
992 fi
993 ;;
994 rvct)
995 CC=armcc
996 AR=armar
997 AS=armasm
998 LD="${source_path}/build/make/armlink_adapter.sh"
999 STRIP=arm-none-linux-gnueabi-strip
1000 NM=arm-none-linux-gnueabi-nm
1001 tune_cflags="--cpu="
1002 tune_asflags="--cpu="
1003 if [ -z "${tune_cpu}" ]; then
1004 if [ ${tgt_isa} = "armv7" ]; then
1005 if enabled neon || enabled neon_asm
1006 then
1007 check_add_cflags --fpu=softvfp+vfpv3
1008 check_add_asflags --fpu=softvfp+vfpv3
1009 fi
1010 check_add_cflags --cpu=Cortex-A8
1011 check_add_asflags --cpu=Cortex-A8
1012 else
1013 check_add_cflags --cpu=${tgt_isa##armv}
1014 check_add_asflags --cpu=${tgt_isa##armv}
1015 fi
1016 fi
1017 arch_int=${tgt_isa##armv}
1018 arch_int=${arch_int%%te}
1019 check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\""
1020 enabled debug && add_asflags -g
1021 add_cflags --gnu
1022 add_cflags --enum_is_int
1023 add_cflags --wchar32
1024 ;;
1025 esac
1026
1027 case ${tgt_os} in
1028 none*)
1029 disable_feature multithread
1030 disable_feature os_support
1031 ;;
1032
1033 android*)
1034 SDK_PATH=${sdk_path}
1035 COMPILER_LOCATION=`find "${SDK_PATH}" \
1036 -name "arm-linux-androideabi-gcc*" -print -quit`
1037 TOOLCHAIN_PATH=${COMPILER_LOCATION%/*}/arm-linux-androideabi-
1038 CC=${TOOLCHAIN_PATH}gcc
1039 CXX=${TOOLCHAIN_PATH}g++
1040 AR=${TOOLCHAIN_PATH}ar
1041 LD=${TOOLCHAIN_PATH}gcc
1042 AS=${TOOLCHAIN_PATH}as
1043 STRIP=${TOOLCHAIN_PATH}strip
1044 NM=${TOOLCHAIN_PATH}nm
1045
1046 if [ -z "${alt_libc}" ]; then
1047 alt_libc=`find "${SDK_PATH}" -name arch-arm -print | \
1048 awk '{n = split($0,a,"/"); \
1049 split(a[n-1],b,"-"); \
1050 print $0 " " b[2]}' | \
1051 sort -g -k 2 | \
1052 awk '{ print $1 }' | tail -1`
1053 fi
1054
1055 if [ -d "${alt_libc}" ]; then
1056 add_cflags "--sysroot=${alt_libc}"
1057 add_ldflags "--sysroot=${alt_libc}"
1058 fi
1059
1060 # linker flag that routes around a CPU bug in some
1061 # Cortex-A8 implementations (NDK Dev Guide)
1062 add_ldflags "-Wl,--fix-cortex-a8"
1063
1064 enable_feature pic
1065 soft_enable realtime_only
1066 if [ ${tgt_isa} = "armv7" ]; then
1067 soft_enable runtime_cpu_detect
1068 fi
1069 if enabled runtime_cpu_detect; then
1070 add_cflags "-I${SDK_PATH}/sources/android/cpufeatures"
1071 fi
1072 ;;
1073
1074 darwin*)
1075 XCRUN_FIND="xcrun --sdk iphoneos --find"
1076 CXX="$(${XCRUN_FIND} clang++)"
1077 CC="$(${XCRUN_FIND} clang)"
1078 AR="$(${XCRUN_FIND} ar)"
1079 AS="$(${XCRUN_FIND} as)"
1080 STRIP="$(${XCRUN_FIND} strip)"
1081 NM="$(${XCRUN_FIND} nm)"
1082 RANLIB="$(${XCRUN_FIND} ranlib)"
1083 AS_SFX=.s
1084 LD="${CXX:-$(${XCRUN_FIND} ld)}"
1085
1086 # ASFLAGS is written here instead of using check_add_asflags
1087 # because we need to overwrite all of ASFLAGS and purge the
1088 # options that were put in above
1089 ASFLAGS="-arch ${tgt_isa} -g"
1090
1091 add_cflags -arch ${tgt_isa}
1092 add_ldflags -arch ${tgt_isa}
1093
1094 alt_libc="$(show_darwin_sdk_path iphoneos)"
1095 if [ -d "${alt_libc}" ]; then
1096 add_cflags -isysroot ${alt_libc}
1097 fi
1098
1099 if [ "${LD}" = "${CXX}" ]; then
1100 add_ldflags -miphoneos-version-min="${IOS_VERSION_MIN}"
1101 else
1102 add_ldflags -ios_version_min "${IOS_VERSION_MIN}"
1103 fi
1104
1105 for d in lib usr/lib usr/lib/system; do
1106 try_dir="${alt_libc}/${d}"
1107 [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}"
1108 done
1109
1110 case ${tgt_isa} in
1111 armv7|armv7s|armv8|arm64)
1112 if enabled neon && ! check_xcode_minimum_version; then
1113 soft_disable neon
1114 log_echo " neon disabled: upgrade Xcode (need v6.3+)."
1115 if enabled neon_asm; then
1116 soft_disable neon_asm
1117 log_echo " neon_asm disabled: upgrade Xcode (need v6.3+)."
1118 fi
1119 fi
1120 ;;
1121 esac
1122
1123 asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl"
1124
1125 if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then
1126 check_add_cflags -fembed-bitcode
1127 check_add_asflags -fembed-bitcode
1128 check_add_ldflags -fembed-bitcode
1129 fi
1130 ;;
1131
1132 linux*)
1133 enable_feature linux
1134 if enabled rvct; then
1135 # Check if we have CodeSourcery GCC in PATH. Needed for
1136 # libraries
1137 which arm-none-linux-gnueabi-gcc 2>&- || \
1138 die "Couldn't find CodeSourcery GCC from PATH"
1139
1140 # Use armcc as a linker to enable translation of
1141 # some gcc specific options such as -lm and -lpthread.
1142 LD="armcc --translate_gcc"
1143
1144 # create configuration file (uses path to CodeSourcery GCC)
1145 armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg
1146
1147 add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1148 add_asflags --no_hide_all --apcs=/interwork
1149 add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1150 enabled pic && add_cflags --apcs=/fpic
1151 enabled pic && add_asflags --apcs=/fpic
1152 enabled shared && add_cflags --shared
1153 fi
1154 ;;
1155 esac
1156 ;;
1157 mips*)
1158 link_with_cc=gcc
1159 setup_gnu_toolchain
1160 tune_cflags="-mtune="
1161 if enabled dspr2; then
1162 check_add_cflags -mips32r2 -mdspr2
1163 fi
1164
1165 if enabled runtime_cpu_detect; then
1166 disable_feature runtime_cpu_detect
1167 fi
1168
1169 if [ -n "${tune_cpu}" ]; then
1170 case ${tune_cpu} in
1171 p5600)
1172 check_add_cflags -mips32r5 -funroll-loops -mload-store-pairs
1173 check_add_cflags -msched-weight -mhard-float -mfp64
1174 check_add_asflags -mips32r5 -mhard-float -mfp64
1175 check_add_ldflags -mfp64
1176 ;;
1177 i6400)
1178 check_add_cflags -mips64r6 -mabi=64 -funroll-loops -msched-weight
1179 check_add_cflags -mload-store-pairs -mhard-float -mfp64
1180 check_add_asflags -mips64r6 -mabi=64 -mhard-float -mfp64
1181 check_add_ldflags -mips64r6 -mabi=64 -mfp64
1182 ;;
1183 esac
1184
1185 if enabled msa; then
1186 add_cflags -mmsa
1187 add_asflags -mmsa
1188 add_ldflags -mmsa
1189 fi
1190 fi
1191
1192 check_add_cflags -march=${tgt_isa}
1193 check_add_asflags -march=${tgt_isa}
1194 check_add_asflags -KPIC
1195 ;;
1196 x86*)
1197 case ${tgt_os} in
1198 win*)
1199 enabled gcc && add_cflags -fno-common
1200 ;;
1201 solaris*)
1202 CC=${CC:-${CROSS}gcc}
1203 CXX=${CXX:-${CROSS}g++}
1204 LD=${LD:-${CROSS}gcc}
1205 CROSS=${CROSS-g}
1206 ;;
1207 os2)
1208 disable_feature pic
1209 AS=${AS:-nasm}
1210 add_ldflags -Zhigh-mem
1211 ;;
1212 orbis)
1213 CROSS=${CROSS:-orbis-}
1214 ;;
1215 esac
1216
1217 AS="${alt_as:-${AS:-auto}}"
1218 case ${tgt_cc} in
1219 icc*)
1220 CC=${CC:-icc}
1221 LD=${LD:-icc}
1222 setup_gnu_toolchain
1223 add_cflags -use-msasm # remove -use-msasm too?
1224 # add -no-intel-extensions to suppress warning #10237
1225 # refer to http://software.intel.com/en-us/forums/topic/280199
1226 add_ldflags -i-static -no-intel-extensions
1227 enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div
1228 enabled x86_64 && AR=xiar
1229 case ${tune_cpu} in
1230 atom*)
1231 tune_cflags="-x"
1232 tune_cpu="SSE3_ATOM"
1233 ;;
1234 *)
1235 tune_cflags="-march="
1236 ;;
1237 esac
1238 ;;
1239 gcc*)
1240 link_with_cc=gcc
1241 tune_cflags="-march="
1242 setup_gnu_toolchain
1243 #for 32 bit x86 builds, -O3 did not turn on this flag
1244 enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer
1245 ;;
1246 clang*)
1247 link_with_cc=clang
1248 tune_cflags="-march="
1249 setup_clang_toolchain
1250 ;;
1251 vs*)
1252 # When building with Microsoft Visual Studio the assembler is
1253 # invoked directly. Checking at configure time is unnecessary.
1254 # Skip the check by setting AS arbitrarily
1255 AS=msvs
1256 msvs_arch_dir=x86-msvs
1257 vc_version=${tgt_cc##vs}
1258 case $vc_version in
1259 7|8|9|10)
1260 echo "${tgt_cc} does not support avx/avx2, disabling....."
1261 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx --disable-avx2 "
1262 soft_disable avx
1263 soft_disable avx2
1264 ;;
1265 esac
1266 case $vc_version in
1267 7|8|9)
1268 echo "${tgt_cc} omits stdint.h, disabling webm-io..."
1269 soft_disable webm_io
1270 ;;
1271 esac
1272 ;;
1273 esac
1274
1275 bits=32
1276 enabled x86_64 && bits=64
1277 check_cpp <<EOF && bits=x32
1278#if !defined(__ILP32__) || !defined(__x86_64__)
1279#error "not x32"
1280#endif
1281EOF
1282 case ${tgt_cc} in
1283 gcc*)
1284 add_cflags -m${bits}
1285 add_ldflags -m${bits}
1286 ;;
1287 esac
1288
1289 disabled orbis && soft_enable runtime_cpu_detect
1290 # We can't use 'check_cflags' until the compiler is configured and CC is
1291 # populated.
1292 for ext in ${ARCH_EXT_LIST_X86}; do
1293 # disable higher order extensions to simplify asm dependencies
1294 if [ "$disable_exts" = "yes" ]; then
1295 if ! disabled $ext; then
1296 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} "
1297 disable_feature $ext
1298 fi
1299 elif disabled $ext; then
1300 disable_exts="yes"
1301 elif [ "$ext" = "avx2" ]; then
1302 # on orbis never enable avx2.
1303 disabled orbis && check_gcc_machine_option ${ext%_*} $ext
1304 else
1305 # use the shortened version for the flag: sse4_1 -> sse4
1306 check_gcc_machine_option ${ext%_*} $ext
1307 fi
1308 done
1309
1310 if enabled external_build; then
1311 log_echo " skipping assembler detection"
1312 else
1313 case "${AS}" in
1314 auto|"")
1315 which nasm >/dev/null 2>&1 && AS=nasm
1316 which yasm >/dev/null 2>&1 && AS=yasm
1317 if [ "${AS}" = nasm ] ; then
1318 # Apple ships version 0.98 of nasm through at least Xcode 6. Revisit
1319 # this check if they start shipping a compatible version.
1320 apple=`nasm -v | grep "Apple"`
1321 [ -n "${apple}" ] \
1322 && echo "Unsupported version of nasm: ${apple}" \
1323 && AS=""
1324 fi
1325 [ "${AS}" = auto ] || [ -z "${AS}" ] \
1326 && die "Neither yasm nor nasm have been found." \
1327 "See the prerequisites section in the README for more info."
1328 ;;
1329 esac
1330 log_echo " using $AS"
1331 fi
1332 [ "${AS##*/}" = nasm ] && add_asflags -Ox
1333 AS_SFX=.asm
1334 case ${tgt_os} in
1335 win32)
1336 add_asflags -f win32
1337 enabled debug && add_asflags -g cv8
1338 EXE_SFX=.exe
1339 ;;
1340 win64)
1341 add_asflags -f x64
1342 enabled debug && add_asflags -g cv8
1343 EXE_SFX=.exe
1344 ;;
1345 linux*|solaris*|android*)
1346 add_asflags -f elf${bits}
1347 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
1348 enabled debug && [ "${AS}" = nasm ] && add_asflags -g
1349 [ "${AS##*/}" = nasm ] && check_asm_align
1350 ;;
1351 darwin*)
1352 add_asflags -f macho${bits}
1353 enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64"
1354 add_cflags ${darwin_arch}
1355 add_ldflags ${darwin_arch}
1356 # -mdynamic-no-pic is still a bit of voodoo -- it was required at
1357 # one time, but does not seem to be now, and it breaks some of the
1358 # code that still relies on inline assembly.
1359 # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic
1360 enabled icc && ! enabled pic && add_cflags -fno-pic
1361 ;;
1362 iphonesimulator)
1363 add_asflags -f macho${bits}
1364 enabled x86 && sim_arch="-arch i386" || sim_arch="-arch x86_64"
1365 add_cflags ${sim_arch}
1366 add_ldflags ${sim_arch}
1367
1368 if [ "$(show_darwin_sdk_major_version iphonesimulator)" -gt 8 ]; then
1369 # yasm v1.3.0 doesn't know what -fembed-bitcode means, so turning it
1370 # on is pointless (unless building a C-only lib). Warn the user, but
1371 # do nothing here.
1372 log "Warning: Bitcode embed disabled for simulator targets."
1373 fi
1374 ;;
1375 os2)
1376 add_asflags -f aout
1377 enabled debug && add_asflags -g
1378 EXE_SFX=.exe
1379 ;;
1380 orbis*)
1381 add_asflags -f elf${bits}
1382 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
1383 enabled debug && [ "${AS}" = nasm ] && add_asflags -g
1384 [ "${AS##*/}" = nasm ] && check_asm_align
1385 add_ldflags "-L\"${SCE_ORBIS_SDK_DIR}/target/lib/\""
1386 add_ldflags "-Wl,--fself-flags=videoservice"
1387 add_ldflags "-Wl,--target=orbis"
1388 add_ldflags "-Wl,-lc_stub_weak"
1389 add_ldflags "-Wl,-lkernel_stub_weak"
1390 add_ldflags "-Wl,-lScePosix_stub_weak"
1391 EXE_SFX=.elf
1392 disable_feature os_support
1393 soft_disable avx2
1394 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx2 "
1395 ;;
1396 *)
1397 log "Warning: Unknown os $tgt_os while setting up $AS flags"
1398 ;;
1399 esac
1400 ;;
1401 *-gcc|generic-gnu)
1402 link_with_cc=gcc
1403 enable_feature gcc
1404 setup_gnu_toolchain
1405 ;;
1406 esac
1407
1408 # Try to enable CPU specific tuning
1409 if [ -n "${tune_cpu}" ]; then
1410 if [ -n "${tune_cflags}" ]; then
1411 check_add_cflags ${tune_cflags}${tune_cpu} || \
1412 die "Requested CPU '${tune_cpu}' not supported by compiler"
1413 fi
1414 if [ -n "${tune_asflags}" ]; then
1415 check_add_asflags ${tune_asflags}${tune_cpu} || \
1416 die "Requested CPU '${tune_cpu}' not supported by assembler"
1417 fi
1418 if [ -z "${tune_cflags}${tune_asflags}" ]; then
1419 log_echo "Warning: CPU tuning not supported by this toolchain"
1420 fi
1421 fi
1422
1423 if enabled debug; then
1424 check_add_cflags -g && check_add_ldflags -g
1425 else
1426 check_add_cflags -DNDEBUG
1427 fi
1428
1429 enabled gprof && check_add_cflags -pg && check_add_ldflags -pg
1430 enabled gcov &&
1431 check_add_cflags -fprofile-arcs -ftest-coverage &&
1432 check_add_ldflags -fprofile-arcs -ftest-coverage
1433
1434 if enabled optimizations; then
1435 if enabled rvct; then
1436 enabled small && check_add_cflags -Ospace || check_add_cflags -Otime
1437 else
1438 enabled small && check_add_cflags -O2 || check_add_cflags -O3
1439 fi
1440 fi
1441
1442 if [ "${tgt_isa}" = "x86_64" ] || [ "${tgt_isa}" = "x86" ]; then
1443 soft_enable use_x86inc
1444 fi
1445
1446 # Position Independent Code (PIC) support, for building relocatable
1447 # shared objects
1448 enabled gcc && enabled pic && check_add_cflags -fPIC
1449
1450 # Work around longjmp interception on glibc >= 2.11, to improve binary
1451 # compatibility. See http://code.google.com/p/webm/issues/detail?id=166
1452 enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
1453
1454 # Check for strip utility variant
1455 ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip
1456
1457 # Try to determine target endianness
1458 check_cc <<EOF
1459unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E';
1460EOF
1461 [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' |
1462 grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian
1463
1464 # Try to find which inline keywords are supported
1465 check_cc <<EOF && INLINE="inline"
1466static inline function() {}
1467EOF
1468
1469 # Almost every platform uses pthreads.
1470 if enabled multithread; then
1471 case ${toolchain} in
1472 *-win*-vs*)
1473 ;;
1474 *-android-gcc)
1475 ;;
1476 *orbis*)
1477 ;;
1478 *)
1479 check_header pthread.h && add_extralibs -lpthread
1480 ;;
1481 esac
1482 fi
1483
1484 # only for MIPS platforms
1485 case ${toolchain} in
1486 mips*)
1487 if enabled big_endian; then
1488 if enabled dspr2; then
1489 echo "dspr2 optimizations are available only for little endian platforms"
1490 disable_feature dspr2
1491 fi
1492 if enabled msa; then
1493 echo "msa optimizations are available only for little endian platforms"
1494 disable_feature msa
1495 fi
1496 fi
1497 ;;
1498 esac
1499
1500 # glibc needs these
1501 if enabled linux; then
1502 add_cflags -D_LARGEFILE_SOURCE
1503 add_cflags -D_FILE_OFFSET_BITS=64
1504 fi
1505}
1506
1507process_toolchain() {
1508 process_common_toolchain
1509}
1510
1511print_config_mk() {
1512 saved_prefix="${prefix}"
1513 prefix=$1
1514 makefile=$2
1515 shift 2
1516 for cfg; do
1517 if enabled $cfg; then
1518 upname="`toupper $cfg`"
1519 echo "${prefix}_${upname}=yes" >> $makefile
1520 fi
1521 done
1522 prefix="${saved_prefix}"
1523}
1524
1525print_config_h() {
1526 saved_prefix="${prefix}"
1527 prefix=$1
1528 header=$2
1529 shift 2
1530 for cfg; do
1531 upname="`toupper $cfg`"
1532 if enabled $cfg; then
1533 echo "#define ${prefix}_${upname} 1" >> $header
1534 else
1535 echo "#define ${prefix}_${upname} 0" >> $header
1536 fi
1537 done
1538 prefix="${saved_prefix}"
1539}
1540
1541print_config_vars_h() {
1542 header=$1
1543 shift
1544 while [ $# -gt 0 ]; do
1545 upname="`toupper $1`"
1546 echo "#define ${upname} $2" >> $header
1547 shift 2
1548 done
1549}
1550
1551print_webm_license() {
1552 saved_prefix="${prefix}"
1553 destination=$1
1554 prefix="$2"
1555 suffix="$3"
1556 shift 3
1557 cat <<EOF > ${destination}
1558${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix}
1559${prefix} ${suffix}
1560${prefix} Use of this source code is governed by a BSD-style license${suffix}
1561${prefix} that can be found in the LICENSE file in the root of the source${suffix}
1562${prefix} tree. An additional intellectual property rights grant can be found${suffix}
1563${prefix} in the file PATENTS. All contributing project authors may${suffix}
1564${prefix} be found in the AUTHORS file in the root of the source tree.${suffix}
1565EOF
1566 prefix="${saved_prefix}"
1567}
1568
1569process_targets() {
1570 true;
1571}
1572
1573process_detect() {
1574 true;
1575}
1576
1577enable_feature logging
1578logfile="config.log"
1579self=$0
1580process() {
1581 cmdline_args="$@"
1582 process_cmdline "$@"
1583 if enabled child; then
1584 echo "# ${self} $@" >> ${logfile}
1585 else
1586 echo "# ${self} $@" > ${logfile}
1587 fi
1588 post_process_common_cmdline
1589 post_process_cmdline
1590 process_toolchain
1591 process_detect
1592 process_targets
1593
1594 OOT_INSTALLS="${OOT_INSTALLS}"
1595 if enabled source_path_used; then
1596 # Prepare the PWD for building.
1597 for f in ${OOT_INSTALLS}; do
1598 install -D "${source_path}/$f" "$f"
1599 done
1600 fi
1601 cp "${source_path}/build/make/Makefile" .
1602
1603 clean_temp_files
1604 true
1605}