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