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