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