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