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