]> granicus.if.org Git - libvpx/blob - build/make/configure.sh
f2b8b37656d06e3ded694c3cae4fcca3f5a7cb4a
[libvpx] / build / make / configure.sh
1 #!/bin/sh
2 ##
3 ##  configure.sh
4 ##
5 ##  This script is sourced by the main configure script and contains
6 ##  utility functions and other common bits that aren't strictly libvpx
7 ##  related.
8 ##
9 ##  This build system is based in part on the FFmpeg configure script.
10 ##
11
12
13 #
14 # Logging / Output Functions
15 #
16 die_unknown(){
17   echo "Unknown option \"$1\"."
18   echo "See $0 --help for available options."
19   clean_temp_files
20   exit 1
21 }
22
23 die() {
24   echo "$@"
25   echo
26   echo "Configuration failed. This could reflect a misconfiguration of your"
27   echo "toolchains, improper options selected, or another problem. If you"
28   echo "don't see any useful error messages above, the next step is to look"
29   echo "at the configure error log file ($logfile) to determine what"
30   echo "configure was trying to do when it died."
31   clean_temp_files
32   exit 1
33 }
34
35 log(){
36   echo "$@" >>$logfile
37 }
38
39 log_file(){
40   log BEGIN $1
41   cat -n $1 >>$logfile
42   log END $1
43 }
44
45 log_echo() {
46   echo "$@"
47   log "$@"
48 }
49
50 fwrite () {
51   outfile=$1
52   shift
53   echo "$@" >> ${outfile}
54 }
55
56 show_help_pre(){
57   for opt in ${CMDLINE_SELECT}; do
58     opt2=`echo $opt | sed -e 's;_;-;g'`
59     if enabled $opt; then
60       eval "toggle_${opt}=\"--disable-${opt2}\""
61     else
62       eval "toggle_${opt}=\"--enable-${opt2} \""
63     fi
64   done
65
66   cat <<EOF
67 Usage: configure [options]
68 Options:
69
70 Build options:
71   --help                      print this message
72   --log=yes|no|FILE           file configure log is written to [config.log]
73   --target=TARGET             target platform tuple [generic-gnu]
74   --cpu=CPU                   optimize for a specific cpu rather than a family
75   --extra-cflags=ECFLAGS      add ECFLAGS to CFLAGS [$CFLAGS]
76   --extra-cxxflags=ECXXFLAGS  add ECXXFLAGS to CXXFLAGS [$CXXFLAGS]
77   ${toggle_extra_warnings}    emit harmless warnings (always non-fatal)
78   ${toggle_werror}            treat warnings as errors, if possible
79                               (not available with all compilers)
80   ${toggle_optimizations}     turn on/off compiler optimization flags
81   ${toggle_pic}               turn on/off Position Independent Code
82   ${toggle_ccache}            turn on/off compiler cache
83   ${toggle_debug}             enable/disable debug mode
84   ${toggle_gprof}             enable/disable gprof profiling instrumentation
85   ${toggle_gcov}              enable/disable gcov coverage instrumentation
86   ${toggle_thumb}             enable/disable building arm assembly in thumb mode
87   ${toggle_dependency_tracking}
88                               disable to speed up one-time build
89
90 Install options:
91   ${toggle_install_docs}      control whether docs are installed
92   ${toggle_install_bins}      control whether binaries are installed
93   ${toggle_install_libs}      control whether libraries are installed
94   ${toggle_install_srcs}      control whether sources are installed
95
96
97 EOF
98 }
99
100 show_help_post(){
101   cat <<EOF
102
103
104 NOTES:
105     Object files are built at the place where configure is launched.
106
107     All boolean options can be negated. The default value is the opposite
108     of that shown above. If the option --disable-foo is listed, then
109     the default value for foo is enabled.
110
111 Supported targets:
112 EOF
113   show_targets ${all_platforms}
114   echo
115   exit 1
116 }
117
118 show_targets() {
119   while [ -n "$*" ]; do
120     if [ "${1%%-*}" = "${2%%-*}" ]; then
121       if [ "${2%%-*}" = "${3%%-*}" ]; then
122         printf "    %-24s %-24s %-24s\n" "$1" "$2" "$3"
123         shift; shift; shift
124       else
125         printf "    %-24s %-24s\n" "$1" "$2"
126         shift; shift
127       fi
128     else
129       printf "    %-24s\n" "$1"
130       shift
131     fi
132   done
133 }
134
135 show_help() {
136   show_help_pre
137   show_help_post
138 }
139
140 #
141 # List Processing Functions
142 #
143 set_all(){
144   value=$1
145   shift
146   for var in $*; do
147     eval $var=$value
148   done
149 }
150
151 is_in(){
152   value=$1
153   shift
154   for var in $*; do
155     [ $var = $value ] && return 0
156   done
157   return 1
158 }
159
160 add_cflags() {
161   CFLAGS="${CFLAGS} $@"
162   CXXFLAGS="${CXXFLAGS} $@"
163 }
164
165 add_cflags_only() {
166   CFLAGS="${CFLAGS} $@"
167 }
168
169 add_cxxflags_only() {
170   CXXFLAGS="${CXXFLAGS} $@"
171 }
172
173 add_ldflags() {
174   LDFLAGS="${LDFLAGS} $@"
175 }
176
177 add_asflags() {
178   ASFLAGS="${ASFLAGS} $@"
179 }
180
181 add_extralibs() {
182   extralibs="${extralibs} $@"
183 }
184
185 #
186 # Boolean Manipulation Functions
187 #
188
189 enable_feature(){
190   set_all yes $*
191 }
192
193 disable_feature(){
194   set_all no $*
195 }
196
197 enabled(){
198   eval test "x\$$1" = "xyes"
199 }
200
201 disabled(){
202   eval test "x\$$1" = "xno"
203 }
204
205 enable_codec(){
206   enabled "${1}" || echo "  enabling ${1}"
207   enable_feature "${1}"
208
209   is_in "${1}" vp8 vp9 && enable_feature "${1}_encoder" "${1}_decoder"
210 }
211
212 disable_codec(){
213   disabled "${1}" || echo "  disabling ${1}"
214   disable_feature "${1}"
215
216   is_in "${1}" vp8 vp9 && disable_feature "${1}_encoder" "${1}_decoder"
217 }
218
219 # Iterates through positional parameters, checks to confirm the parameter has
220 # not been explicitly (force) disabled, and enables the setting controlled by
221 # the parameter when the setting is not disabled.
222 # Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
223 soft_enable() {
224   for var in $*; do
225     if ! disabled $var; then
226       enabled $var || log_echo "  enabling $var"
227       enable_feature $var
228     fi
229   done
230 }
231
232 # Iterates through positional parameters, checks to confirm the parameter has
233 # not been explicitly (force) enabled, and disables the setting controlled by
234 # the parameter when the setting is not enabled.
235 # Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
236 soft_disable() {
237   for var in $*; do
238     if ! enabled $var; then
239       disabled $var || log_echo "  disabling $var"
240       disable_feature $var
241     fi
242   done
243 }
244
245 #
246 # Text Processing Functions
247 #
248 toupper(){
249   echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
250 }
251
252 tolower(){
253   echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
254 }
255
256 #
257 # Temporary File Functions
258 #
259 source_path=${0%/*}
260 enable_feature source_path_used
261 if [ -z "$source_path" ] || [ "$source_path" = "." ]; then
262   source_path="`pwd`"
263   disable_feature source_path_used
264 fi
265
266 if test ! -z "$TMPDIR" ; then
267   TMPDIRx="${TMPDIR}"
268 elif test ! -z "$TEMPDIR" ; then
269   TMPDIRx="${TEMPDIR}"
270 else
271   TMPDIRx="/tmp"
272 fi
273 RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}')
274 TMP_H="${TMPDIRx}/vpx-conf-$$-${RAND}.h"
275 TMP_C="${TMPDIRx}/vpx-conf-$$-${RAND}.c"
276 TMP_CC="${TMPDIRx}/vpx-conf-$$-${RAND}.cc"
277 TMP_O="${TMPDIRx}/vpx-conf-$$-${RAND}.o"
278 TMP_X="${TMPDIRx}/vpx-conf-$$-${RAND}.x"
279 TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RAND}.asm"
280
281 clean_temp_files() {
282   rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM}
283   enabled gcov && rm -f ${TMP_C%.c}.gcno ${TMP_CC%.cc}.gcno
284 }
285
286 #
287 # Toolchain Check Functions
288 #
289 check_cmd() {
290   enabled external_build && return
291   log "$@"
292   "$@" >>${logfile} 2>&1
293 }
294
295 check_cc() {
296   log check_cc "$@"
297   cat >${TMP_C}
298   log_file ${TMP_C}
299   check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C}
300 }
301
302 check_cxx() {
303   log check_cxx "$@"
304   cat >${TMP_CC}
305   log_file ${TMP_CC}
306   check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC}
307 }
308
309 check_cpp() {
310   log check_cpp "$@"
311   cat > ${TMP_C}
312   log_file ${TMP_C}
313   check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C}
314 }
315
316 check_ld() {
317   log check_ld "$@"
318   check_cc $@ \
319     && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs}
320 }
321
322 check_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"
330 int x;
331 EOF
332 }
333
334 check_cflags() {
335  log check_cflags "$@"
336  check_cc -Werror "$@" <<EOF
337 int x;
338 EOF
339 }
340
341 check_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
348 int x;
349 EOF
350       ;;
351     *)
352       check_cxx -Werror "$@" <<EOF
353 int x;
354 EOF
355       ;;
356     esac
357 }
358
359 check_add_cflags() {
360   check_cxxflags "$@" && add_cxxflags_only "$@"
361   check_cflags "$@" && add_cflags_only "$@"
362 }
363
364 check_add_cxxflags() {
365   check_cxxflags "$@" && add_cxxflags_only "$@"
366 }
367
368 check_add_asflags() {
369   log add_asflags "$@"
370   add_asflags "$@"
371 }
372
373 check_add_ldflags() {
374   log add_ldflags "$@"
375   add_ldflags "$@"
376 }
377
378 check_asm_align() {
379   log check_asm_align "$@"
380   cat >${TMP_ASM} <<EOF
381 section .rodata
382 align 16
383 EOF
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.
394 check_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
406 write_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
418 write_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
432 write_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!
441 SRC_PATH="$source_path"
442 SRC_PATH_BARE=$source_path
443 BUILD_PFX=${BUILD_PFX}
444 TOOLCHAIN=${toolchain}
445 ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl}
446 GEN_VCPROJ=${gen_vcproj_cmd}
447 MSVS_ARCH_DIR=${msvs_arch_dir}
448
449 CC=${CC}
450 CXX=${CXX}
451 AR=${AR}
452 LD=${LD}
453 AS=${AS}
454 STRIP=${STRIP}
455 NM=${NM}
456
457 CFLAGS  = ${CFLAGS}
458 CXXFLAGS  = ${CXXFLAGS}
459 ARFLAGS = -crs\$(if \$(quiet),,v)
460 LDFLAGS = ${LDFLAGS}
461 ASFLAGS = ${ASFLAGS}
462 extralibs = ${extralibs}
463 AS_SFX    = ${AS_SFX:-.asm}
464 EXE_SFX   = ${EXE_SFX}
465 VCPROJ_SFX = ${VCPROJ_SFX}
466 RTCD_OPTIONS = ${RTCD_OPTIONS}
467 EOF
468
469   if enabled rvct; then cat >> $1 << EOF
470 fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide
471 EOF
472   else cat >> $1 << EOF
473 fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;'
474 EOF
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
488 write_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}
496 EOF
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
506 process_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
605 process_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
616 post_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
626 post_process_cmdline() {
627   true;
628 }
629
630 setup_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.)
644 show_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.
650 show_darwin_sdk_major_version() {
651   xcrun --sdk $1 --show-sdk-version 2>/dev/null | cut -d. -f1
652 }
653
654 # Print the Xcode version.
655 show_xcode_version() {
656   xcodebuild -version | head -n1 | cut -d' ' -f2
657 }
658
659 # Fails when Xcode version is less than 6.3.
660 check_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
674 process_common_toolchain() {
675   if [ -z "$toolchain" ]; then
676     gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}"
677
678     # detect tgt_isa
679     case "$gcctarget" in
680       aarch64*)
681         tgt_isa=arm64
682         ;;
683       armv6*)
684         tgt_isa=armv6
685         ;;
686       armv7*-hardfloat* | armv7*-gnueabihf | arm-*-gnueabihf)
687         tgt_isa=armv7
688         float_abi=hard
689         ;;
690       armv7*)
691         tgt_isa=armv7
692         float_abi=softfp
693         ;;
694       *x86_64*|*amd64*)
695         tgt_isa=x86_64
696         ;;
697       *i[3456]86*)
698         tgt_isa=x86
699         ;;
700       *sparc*)
701         tgt_isa=sparc
702         ;;
703     esac
704
705     # detect tgt_os
706     case "$gcctarget" in
707       *darwin10*)
708         tgt_isa=x86_64
709         tgt_os=darwin10
710         ;;
711       *darwin11*)
712         tgt_isa=x86_64
713         tgt_os=darwin11
714         ;;
715       *darwin12*)
716         tgt_isa=x86_64
717         tgt_os=darwin12
718         ;;
719       *darwin13*)
720         tgt_isa=x86_64
721         tgt_os=darwin13
722         ;;
723       *darwin14*)
724         tgt_isa=x86_64
725         tgt_os=darwin14
726         ;;
727       *darwin15*)
728         tgt_isa=x86_64
729         tgt_os=darwin15
730         ;;
731       x86_64*mingw32*)
732         tgt_os=win64
733         ;;
734       *mingw32*|*cygwin*)
735         [ -z "$tgt_isa" ] && tgt_isa=x86
736         tgt_os=win32
737         ;;
738       *linux*|*bsd*)
739         tgt_os=linux
740         ;;
741       *solaris2.10)
742         tgt_os=solaris
743         ;;
744       *os2*)
745         tgt_os=os2
746         ;;
747     esac
748
749     if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then
750       toolchain=${tgt_isa}-${tgt_os}-gcc
751     fi
752   fi
753
754   toolchain=${toolchain:-generic-gnu}
755
756   is_in ${toolchain} ${all_platforms} || enabled force_toolchain \
757     || die "Unrecognized toolchain '${toolchain}'"
758
759   enabled child || log_echo "Configuring for target '${toolchain}'"
760
761   #
762   # Set up toolchain variables
763   #
764   tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}')
765   tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}')
766   tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}')
767
768   # Mark the specific ISA requested as enabled
769   soft_enable ${tgt_isa}
770   enable_feature ${tgt_os}
771   enable_feature ${tgt_cc}
772
773   # Enable the architecture family
774   case ${tgt_isa} in
775     arm*)
776       enable_feature arm
777       ;;
778     mips*)
779       enable_feature mips
780       ;;
781   esac
782
783   # PIC is probably what we want when building shared libs
784   enabled shared && soft_enable pic
785
786   # Minimum iOS version for all target platforms (darwin and iphonesimulator).
787   # Shared library framework builds are only possible on iOS 8 and later.
788   if enabled shared; then
789     IOS_VERSION_OPTIONS="--enable-shared"
790     IOS_VERSION_MIN="8.0"
791   else
792     IOS_VERSION_OPTIONS=""
793     IOS_VERSION_MIN="6.0"
794   fi
795
796   # Handle darwin variants. Newer SDKs allow targeting older
797   # platforms, so use the newest one available.
798   case ${toolchain} in
799     arm*-darwin*)
800       add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
801       iphoneos_sdk_dir="$(show_darwin_sdk_path iphoneos)"
802       if [ -d "${iphoneos_sdk_dir}" ]; then
803         add_cflags  "-isysroot ${iphoneos_sdk_dir}"
804         add_ldflags "-isysroot ${iphoneos_sdk_dir}"
805       fi
806       ;;
807     x86*-darwin*)
808       osx_sdk_dir="$(show_darwin_sdk_path macosx)"
809       if [ -d "${osx_sdk_dir}" ]; then
810         add_cflags  "-isysroot ${osx_sdk_dir}"
811         add_ldflags "-isysroot ${osx_sdk_dir}"
812       fi
813       ;;
814   esac
815
816   case ${toolchain} in
817     *-darwin8-*)
818       add_cflags  "-mmacosx-version-min=10.4"
819       add_ldflags "-mmacosx-version-min=10.4"
820       ;;
821     *-darwin9-*)
822       add_cflags  "-mmacosx-version-min=10.5"
823       add_ldflags "-mmacosx-version-min=10.5"
824       ;;
825     *-darwin10-*)
826       add_cflags  "-mmacosx-version-min=10.6"
827       add_ldflags "-mmacosx-version-min=10.6"
828       ;;
829     *-darwin11-*)
830       add_cflags  "-mmacosx-version-min=10.7"
831       add_ldflags "-mmacosx-version-min=10.7"
832       ;;
833     *-darwin12-*)
834       add_cflags  "-mmacosx-version-min=10.8"
835       add_ldflags "-mmacosx-version-min=10.8"
836       ;;
837     *-darwin13-*)
838       add_cflags  "-mmacosx-version-min=10.9"
839       add_ldflags "-mmacosx-version-min=10.9"
840       ;;
841     *-darwin14-*)
842       add_cflags  "-mmacosx-version-min=10.10"
843       add_ldflags "-mmacosx-version-min=10.10"
844       ;;
845     *-darwin15-*)
846       add_cflags  "-mmacosx-version-min=10.11"
847       add_ldflags "-mmacosx-version-min=10.11"
848       ;;
849     *-iphonesimulator-*)
850       add_cflags  "-miphoneos-version-min=${IOS_VERSION_MIN}"
851       add_ldflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
852       iossim_sdk_dir="$(show_darwin_sdk_path iphonesimulator)"
853       if [ -d "${iossim_sdk_dir}" ]; then
854         add_cflags  "-isysroot ${iossim_sdk_dir}"
855         add_ldflags "-isysroot ${iossim_sdk_dir}"
856       fi
857       ;;
858   esac
859
860   # Handle Solaris variants. Solaris 10 needs -lposix4
861   case ${toolchain} in
862     sparc-solaris-*)
863       add_extralibs -lposix4
864       ;;
865     *-solaris-*)
866       add_extralibs -lposix4
867       ;;
868   esac
869
870   # Process ARM architecture variants
871   case ${toolchain} in
872     arm*)
873       # on arm, isa versions are supersets
874       case ${tgt_isa} in
875         arm64|armv8)
876           soft_enable neon
877           ;;
878         armv7|armv7s)
879           soft_enable neon
880           # Only enable neon_asm when neon is also enabled.
881           enabled neon && soft_enable neon_asm
882           # If someone tries to force it through, die.
883           if disabled neon && enabled neon_asm; then
884             die "Disabling neon while keeping neon-asm is not supported"
885           fi
886           case ${toolchain} in
887             # Apple iOS SDKs no longer support armv6 as of the version 9
888             # release (coincides with release of Xcode 7). Only enable media
889             # when using earlier SDK releases.
890             *-darwin*)
891               if [ "$(show_darwin_sdk_major_version iphoneos)" -lt 9 ]; then
892                 soft_enable media
893               else
894                 soft_disable media
895                 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-media "
896               fi
897               ;;
898             *)
899               soft_enable media
900               ;;
901           esac
902           ;;
903         armv6)
904           case ${toolchain} in
905             *-darwin*)
906               if [ "$(show_darwin_sdk_major_version iphoneos)" -lt 9 ]; then
907                 soft_enable media
908               else
909                 die "Your iOS SDK does not support armv6."
910               fi
911               ;;
912             *)
913               soft_enable media
914               ;;
915           esac
916           ;;
917       esac
918
919       asm_conversion_cmd="cat"
920
921       case ${tgt_cc} in
922         gcc)
923           link_with_cc=gcc
924           setup_gnu_toolchain
925           arch_int=${tgt_isa##armv}
926           arch_int=${arch_int%%te}
927           check_add_asflags --defsym ARCHITECTURE=${arch_int}
928           tune_cflags="-mtune="
929           if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then
930             if [ -z "${float_abi}" ]; then
931               check_cpp <<EOF && float_abi=hard || float_abi=softfp
932 #ifndef __ARM_PCS_VFP
933 #error "not hardfp"
934 #endif
935 EOF
936             fi
937             check_add_cflags  -march=armv7-a -mfloat-abi=${float_abi}
938             check_add_asflags -march=armv7-a -mfloat-abi=${float_abi}
939
940             if enabled neon || enabled neon_asm; then
941               check_add_cflags -mfpu=neon #-ftree-vectorize
942               check_add_asflags -mfpu=neon
943             fi
944           elif [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then
945             check_add_cflags -march=armv8-a
946             check_add_asflags -march=armv8-a
947           else
948             check_add_cflags -march=${tgt_isa}
949             check_add_asflags -march=${tgt_isa}
950           fi
951
952           enabled debug && add_asflags -g
953           asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
954           if enabled thumb; then
955             asm_conversion_cmd="$asm_conversion_cmd -thumb"
956             check_add_cflags -mthumb
957             check_add_asflags -mthumb -mimplicit-it=always
958           fi
959           ;;
960         vs*)
961           asm_conversion_cmd="${source_path}/build/make/ads2armasm_ms.pl"
962           AS_SFX=.s
963           msvs_arch_dir=arm-msvs
964           disable_feature multithread
965           disable_feature unit_tests
966           vs_version=${tgt_cc##vs}
967           if [ $vs_version -ge 12 ]; then
968             # MSVC 2013 doesn't allow doing plain .exe projects for ARM,
969             # only "AppContainerApplication" which requires an AppxManifest.
970             # Therefore disable the examples, just build the library.
971             disable_feature examples
972           fi
973           ;;
974         rvct)
975           CC=armcc
976           AR=armar
977           AS=armasm
978           LD="${source_path}/build/make/armlink_adapter.sh"
979           STRIP=arm-none-linux-gnueabi-strip
980           NM=arm-none-linux-gnueabi-nm
981           tune_cflags="--cpu="
982           tune_asflags="--cpu="
983           if [ -z "${tune_cpu}" ]; then
984             if [ ${tgt_isa} = "armv7" ]; then
985               if enabled neon || enabled neon_asm
986               then
987                 check_add_cflags --fpu=softvfp+vfpv3
988                 check_add_asflags --fpu=softvfp+vfpv3
989               fi
990               check_add_cflags --cpu=Cortex-A8
991               check_add_asflags --cpu=Cortex-A8
992             else
993               check_add_cflags --cpu=${tgt_isa##armv}
994               check_add_asflags --cpu=${tgt_isa##armv}
995             fi
996           fi
997           arch_int=${tgt_isa##armv}
998           arch_int=${arch_int%%te}
999           check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\""
1000           enabled debug && add_asflags -g
1001           add_cflags --gnu
1002           add_cflags --enum_is_int
1003           add_cflags --wchar32
1004           ;;
1005       esac
1006
1007       case ${tgt_os} in
1008         none*)
1009           disable_feature multithread
1010           disable_feature os_support
1011           ;;
1012
1013         android*)
1014           if [ -z "${sdk_path}" ]; then
1015             die "Must specify --sdk-path for Android builds."
1016           fi
1017
1018           SDK_PATH=${sdk_path}
1019           COMPILER_LOCATION=`find "${SDK_PATH}" \
1020                              -name "arm-linux-androideabi-gcc*" -print -quit`
1021           TOOLCHAIN_PATH=${COMPILER_LOCATION%/*}/arm-linux-androideabi-
1022           CC=${TOOLCHAIN_PATH}gcc
1023           CXX=${TOOLCHAIN_PATH}g++
1024           AR=${TOOLCHAIN_PATH}ar
1025           LD=${TOOLCHAIN_PATH}gcc
1026           AS=${TOOLCHAIN_PATH}as
1027           STRIP=${TOOLCHAIN_PATH}strip
1028           NM=${TOOLCHAIN_PATH}nm
1029
1030           if [ -z "${alt_libc}" ]; then
1031             alt_libc=`find "${SDK_PATH}" -name arch-arm -print | \
1032               awk '{n = split($0,a,"/"); \
1033                 split(a[n-1],b,"-"); \
1034                 print $0 " " b[2]}' | \
1035                 sort -g -k 2 | \
1036                 awk '{ print $1 }' | tail -1`
1037           fi
1038
1039           if [ -d "${alt_libc}" ]; then
1040             add_cflags "--sysroot=${alt_libc}"
1041             add_ldflags "--sysroot=${alt_libc}"
1042           fi
1043
1044           # linker flag that routes around a CPU bug in some
1045           # Cortex-A8 implementations (NDK Dev Guide)
1046           add_ldflags "-Wl,--fix-cortex-a8"
1047
1048           enable_feature pic
1049           soft_enable realtime_only
1050           if [ ${tgt_isa} = "armv7" ]; then
1051             soft_enable runtime_cpu_detect
1052           fi
1053           if enabled runtime_cpu_detect; then
1054             add_cflags "-I${SDK_PATH}/sources/android/cpufeatures"
1055           fi
1056           ;;
1057
1058         darwin*)
1059           XCRUN_FIND="xcrun --sdk iphoneos --find"
1060           CXX="$(${XCRUN_FIND} clang++)"
1061           CC="$(${XCRUN_FIND} clang)"
1062           AR="$(${XCRUN_FIND} ar)"
1063           AS="$(${XCRUN_FIND} as)"
1064           STRIP="$(${XCRUN_FIND} strip)"
1065           NM="$(${XCRUN_FIND} nm)"
1066           RANLIB="$(${XCRUN_FIND} ranlib)"
1067           AS_SFX=.s
1068           LD="${CXX:-$(${XCRUN_FIND} ld)}"
1069
1070           # ASFLAGS is written here instead of using check_add_asflags
1071           # because we need to overwrite all of ASFLAGS and purge the
1072           # options that were put in above
1073           ASFLAGS="-arch ${tgt_isa} -g"
1074
1075           add_cflags -arch ${tgt_isa}
1076           add_ldflags -arch ${tgt_isa}
1077
1078           alt_libc="$(show_darwin_sdk_path iphoneos)"
1079           if [ -d "${alt_libc}" ]; then
1080             add_cflags -isysroot ${alt_libc}
1081           fi
1082
1083           if [ "${LD}" = "${CXX}" ]; then
1084             add_ldflags -miphoneos-version-min="${IOS_VERSION_MIN}"
1085           else
1086             add_ldflags -ios_version_min "${IOS_VERSION_MIN}"
1087           fi
1088
1089           for d in lib usr/lib usr/lib/system; do
1090             try_dir="${alt_libc}/${d}"
1091             [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}"
1092           done
1093
1094           case ${tgt_isa} in
1095             armv7|armv7s|armv8|arm64)
1096               if enabled neon && ! check_xcode_minimum_version; then
1097                 soft_disable neon
1098                 log_echo "  neon disabled: upgrade Xcode (need v6.3+)."
1099                 if enabled neon_asm; then
1100                   soft_disable neon_asm
1101                   log_echo "  neon_asm disabled: upgrade Xcode (need v6.3+)."
1102                 fi
1103               fi
1104               ;;
1105           esac
1106
1107           asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl"
1108
1109           if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then
1110             check_add_cflags -fembed-bitcode
1111             check_add_asflags -fembed-bitcode
1112             check_add_ldflags -fembed-bitcode
1113           fi
1114           ;;
1115
1116         linux*)
1117           enable_feature linux
1118           if enabled rvct; then
1119             # Check if we have CodeSourcery GCC in PATH. Needed for
1120             # libraries
1121             which arm-none-linux-gnueabi-gcc 2>&- || \
1122               die "Couldn't find CodeSourcery GCC from PATH"
1123
1124             # Use armcc as a linker to enable translation of
1125             # some gcc specific options such as -lm and -lpthread.
1126             LD="armcc --translate_gcc"
1127
1128             # create configuration file (uses path to CodeSourcery GCC)
1129             armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg
1130
1131             add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1132             add_asflags --no_hide_all --apcs=/interwork
1133             add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1134             enabled pic && add_cflags --apcs=/fpic
1135             enabled pic && add_asflags --apcs=/fpic
1136             enabled shared && add_cflags --shared
1137           fi
1138           ;;
1139       esac
1140       ;;
1141     mips*)
1142       link_with_cc=gcc
1143       setup_gnu_toolchain
1144       tune_cflags="-mtune="
1145       if enabled dspr2; then
1146         check_add_cflags -mips32r2 -mdspr2
1147       fi
1148
1149       if enabled runtime_cpu_detect; then
1150         disable_feature runtime_cpu_detect
1151       fi
1152
1153       if [ -n "${tune_cpu}" ]; then
1154         case ${tune_cpu} in
1155           p5600)
1156             check_add_cflags -mips32r5 -mload-store-pairs
1157             check_add_cflags -msched-weight -mhard-float -mfp64
1158             check_add_asflags -mips32r5 -mhard-float -mfp64
1159             check_add_ldflags -mfp64
1160             ;;
1161           i6400|p6600)
1162             check_add_cflags -mips64r6 -mabi=64 -msched-weight
1163             check_add_cflags  -mload-store-pairs -mhard-float -mfp64
1164             check_add_asflags -mips64r6 -mabi=64 -mhard-float -mfp64
1165             check_add_ldflags -mips64r6 -mabi=64 -mfp64
1166             ;;
1167         esac
1168
1169         if enabled msa; then
1170           add_cflags -mmsa
1171           add_asflags -mmsa
1172           add_ldflags -mmsa
1173         fi
1174       fi
1175
1176       check_add_cflags -march=${tgt_isa}
1177       check_add_asflags -march=${tgt_isa}
1178       check_add_asflags -KPIC
1179       ;;
1180     x86*)
1181       case  ${tgt_os} in
1182         win*)
1183           enabled gcc && add_cflags -fno-common
1184           ;;
1185         solaris*)
1186           CC=${CC:-${CROSS}gcc}
1187           CXX=${CXX:-${CROSS}g++}
1188           LD=${LD:-${CROSS}gcc}
1189           CROSS=${CROSS-g}
1190           ;;
1191         os2)
1192           disable_feature pic
1193           AS=${AS:-nasm}
1194           add_ldflags -Zhigh-mem
1195           ;;
1196       esac
1197
1198       AS="${alt_as:-${AS:-auto}}"
1199       case  ${tgt_cc} in
1200         icc*)
1201           CC=${CC:-icc}
1202           LD=${LD:-icc}
1203           setup_gnu_toolchain
1204           add_cflags -use-msasm  # remove -use-msasm too?
1205           # add -no-intel-extensions to suppress warning #10237
1206           # refer to http://software.intel.com/en-us/forums/topic/280199
1207           add_ldflags -i-static -no-intel-extensions
1208           enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div
1209           enabled x86_64 && AR=xiar
1210           case ${tune_cpu} in
1211             atom*)
1212               tune_cflags="-x"
1213               tune_cpu="SSE3_ATOM"
1214               ;;
1215             *)
1216               tune_cflags="-march="
1217               ;;
1218           esac
1219           ;;
1220         gcc*)
1221           link_with_cc=gcc
1222           tune_cflags="-march="
1223           setup_gnu_toolchain
1224           #for 32 bit x86 builds, -O3 did not turn on this flag
1225           enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer
1226           ;;
1227         vs*)
1228           # When building with Microsoft Visual Studio the assembler is
1229           # invoked directly. Checking at configure time is unnecessary.
1230           # Skip the check by setting AS arbitrarily
1231           AS=msvs
1232           msvs_arch_dir=x86-msvs
1233           vc_version=${tgt_cc##vs}
1234           case $vc_version in
1235             7|8|9|10)
1236               echo "${tgt_cc} does not support avx/avx2, disabling....."
1237               RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx --disable-avx2 "
1238               soft_disable avx
1239               soft_disable avx2
1240               ;;
1241           esac
1242           case $vc_version in
1243             7|8|9)
1244               echo "${tgt_cc} omits stdint.h, disabling webm-io..."
1245               soft_disable webm_io
1246               ;;
1247           esac
1248           ;;
1249       esac
1250
1251       bits=32
1252       enabled x86_64 && bits=64
1253       check_cpp <<EOF && bits=x32
1254 #if !defined(__ILP32__) || !defined(__x86_64__)
1255 #error "not x32"
1256 #endif
1257 EOF
1258       case ${tgt_cc} in
1259         gcc*)
1260           add_cflags -m${bits}
1261           add_ldflags -m${bits}
1262           ;;
1263       esac
1264
1265       soft_enable runtime_cpu_detect
1266       # We can't use 'check_cflags' until the compiler is configured and CC is
1267       # populated.
1268       for ext in ${ARCH_EXT_LIST_X86}; do
1269         # disable higher order extensions to simplify asm dependencies
1270         if [ "$disable_exts" = "yes" ]; then
1271           if ! disabled $ext; then
1272             RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} "
1273             disable_feature $ext
1274           fi
1275         elif disabled $ext; then
1276           disable_exts="yes"
1277         else
1278           # use the shortened version for the flag: sse4_1 -> sse4
1279           check_gcc_machine_option ${ext%_*} $ext
1280         fi
1281       done
1282
1283       if enabled external_build; then
1284         log_echo "  skipping assembler detection"
1285       else
1286         case "${AS}" in
1287           auto|"")
1288             which nasm >/dev/null 2>&1 && AS=nasm
1289             which yasm >/dev/null 2>&1 && AS=yasm
1290             if [ "${AS}" = nasm ] ; then
1291               # Apple ships version 0.98 of nasm through at least Xcode 6. Revisit
1292               # this check if they start shipping a compatible version.
1293               apple=`nasm -v | grep "Apple"`
1294               [ -n "${apple}" ] \
1295                 && echo "Unsupported version of nasm: ${apple}" \
1296                 && AS=""
1297             fi
1298             [ "${AS}" = auto ] || [ -z "${AS}" ] \
1299               && die "Neither yasm nor nasm have been found." \
1300                      "See the prerequisites section in the README for more info."
1301             ;;
1302         esac
1303         log_echo "  using $AS"
1304       fi
1305       [ "${AS##*/}" = nasm ] && add_asflags -Ox
1306       AS_SFX=.asm
1307       case  ${tgt_os} in
1308         win32)
1309           add_asflags -f win32
1310           enabled debug && add_asflags -g cv8
1311           EXE_SFX=.exe
1312           ;;
1313         win64)
1314           add_asflags -f x64
1315           enabled debug && add_asflags -g cv8
1316           EXE_SFX=.exe
1317           ;;
1318         linux*|solaris*|android*)
1319           add_asflags -f elf${bits}
1320           enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
1321           enabled debug && [ "${AS}" = nasm ] && add_asflags -g
1322           [ "${AS##*/}" = nasm ] && check_asm_align
1323           ;;
1324         darwin*)
1325           add_asflags -f macho${bits}
1326           enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64"
1327           add_cflags  ${darwin_arch}
1328           add_ldflags ${darwin_arch}
1329           # -mdynamic-no-pic is still a bit of voodoo -- it was required at
1330           # one time, but does not seem to be now, and it breaks some of the
1331           # code that still relies on inline assembly.
1332           # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic
1333           enabled icc && ! enabled pic && add_cflags -fno-pic
1334           ;;
1335         iphonesimulator)
1336           add_asflags -f macho${bits}
1337           enabled x86 && sim_arch="-arch i386" || sim_arch="-arch x86_64"
1338           add_cflags  ${sim_arch}
1339           add_ldflags ${sim_arch}
1340
1341           if [ "$(show_darwin_sdk_major_version iphonesimulator)" -gt 8 ]; then
1342             # yasm v1.3.0 doesn't know what -fembed-bitcode means, so turning it
1343             # on is pointless (unless building a C-only lib). Warn the user, but
1344             # do nothing here.
1345             log "Warning: Bitcode embed disabled for simulator targets."
1346           fi
1347           ;;
1348         os2)
1349           add_asflags -f aout
1350           enabled debug && add_asflags -g
1351           EXE_SFX=.exe
1352           ;;
1353         *)
1354           log "Warning: Unknown os $tgt_os while setting up $AS flags"
1355           ;;
1356       esac
1357       ;;
1358     *-gcc|generic-gnu)
1359       link_with_cc=gcc
1360       enable_feature gcc
1361       setup_gnu_toolchain
1362       ;;
1363   esac
1364
1365   # Try to enable CPU specific tuning
1366   if [ -n "${tune_cpu}" ]; then
1367     if [ -n "${tune_cflags}" ]; then
1368       check_add_cflags ${tune_cflags}${tune_cpu} || \
1369         die "Requested CPU '${tune_cpu}' not supported by compiler"
1370     fi
1371     if [ -n "${tune_asflags}" ]; then
1372       check_add_asflags ${tune_asflags}${tune_cpu} || \
1373         die "Requested CPU '${tune_cpu}' not supported by assembler"
1374     fi
1375     if [ -z "${tune_cflags}${tune_asflags}" ]; then
1376       log_echo "Warning: CPU tuning not supported by this toolchain"
1377     fi
1378   fi
1379
1380   if enabled debug; then
1381     check_add_cflags -g && check_add_ldflags -g
1382   else
1383     check_add_cflags -DNDEBUG
1384   fi
1385
1386   enabled gprof && check_add_cflags -pg && check_add_ldflags -pg
1387   enabled gcov &&
1388     check_add_cflags -fprofile-arcs -ftest-coverage &&
1389     check_add_ldflags -fprofile-arcs -ftest-coverage
1390
1391   if enabled optimizations; then
1392     if enabled rvct; then
1393       enabled small && check_add_cflags -Ospace || check_add_cflags -Otime
1394     else
1395       enabled small && check_add_cflags -O2 ||  check_add_cflags -O3
1396     fi
1397   fi
1398
1399   if [ "${tgt_isa}" = "x86_64" ] || [ "${tgt_isa}" = "x86" ]; then
1400     soft_enable use_x86inc
1401   fi
1402
1403   # Position Independent Code (PIC) support, for building relocatable
1404   # shared objects
1405   enabled gcc && enabled pic && check_add_cflags -fPIC
1406
1407   # Work around longjmp interception on glibc >= 2.11, to improve binary
1408   # compatibility. See http://code.google.com/p/webm/issues/detail?id=166
1409   enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
1410
1411   # Check for strip utility variant
1412   ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip
1413
1414   # Try to determine target endianness
1415   check_cc <<EOF
1416 unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E';
1417 EOF
1418     [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' |
1419         grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian
1420
1421     # Try to find which inline keywords are supported
1422     check_cc <<EOF && INLINE="inline"
1423 static inline function() {}
1424 EOF
1425
1426   # Almost every platform uses pthreads.
1427   if enabled multithread; then
1428     case ${toolchain} in
1429       *-win*-vs*)
1430         ;;
1431       *-android-gcc)
1432         ;;
1433       *)
1434         check_header pthread.h && add_extralibs -lpthread
1435         ;;
1436     esac
1437   fi
1438
1439   # only for MIPS platforms
1440   case ${toolchain} in
1441     mips*)
1442       if enabled big_endian; then
1443         if enabled dspr2; then
1444           echo "dspr2 optimizations are available only for little endian platforms"
1445           disable_feature dspr2
1446         fi
1447         if enabled msa; then
1448           echo "msa optimizations are available only for little endian platforms"
1449           disable_feature msa
1450         fi
1451       fi
1452       ;;
1453   esac
1454
1455   # glibc needs these
1456   if enabled linux; then
1457     add_cflags -D_LARGEFILE_SOURCE
1458     add_cflags -D_FILE_OFFSET_BITS=64
1459   fi
1460 }
1461
1462 process_toolchain() {
1463   process_common_toolchain
1464 }
1465
1466 print_config_mk() {
1467   saved_prefix="${prefix}"
1468   prefix=$1
1469   makefile=$2
1470   shift 2
1471   for cfg; do
1472     if enabled $cfg; then
1473       upname="`toupper $cfg`"
1474       echo "${prefix}_${upname}=yes" >> $makefile
1475     fi
1476   done
1477   prefix="${saved_prefix}"
1478 }
1479
1480 print_config_h() {
1481   saved_prefix="${prefix}"
1482   prefix=$1
1483   header=$2
1484   shift 2
1485   for cfg; do
1486     upname="`toupper $cfg`"
1487     if enabled $cfg; then
1488       echo "#define ${prefix}_${upname} 1" >> $header
1489     else
1490       echo "#define ${prefix}_${upname} 0" >> $header
1491     fi
1492   done
1493   prefix="${saved_prefix}"
1494 }
1495
1496 print_config_vars_h() {
1497   header=$1
1498   shift
1499   while [ $# -gt 0 ]; do
1500     upname="`toupper $1`"
1501     echo "#define ${upname} $2" >> $header
1502     shift 2
1503   done
1504 }
1505
1506 print_webm_license() {
1507   saved_prefix="${prefix}"
1508   destination=$1
1509   prefix="$2"
1510   suffix="$3"
1511   shift 3
1512   cat <<EOF > ${destination}
1513 ${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix}
1514 ${prefix} ${suffix}
1515 ${prefix} Use of this source code is governed by a BSD-style license${suffix}
1516 ${prefix} that can be found in the LICENSE file in the root of the source${suffix}
1517 ${prefix} tree. An additional intellectual property rights grant can be found${suffix}
1518 ${prefix} in the file PATENTS.  All contributing project authors may${suffix}
1519 ${prefix} be found in the AUTHORS file in the root of the source tree.${suffix}
1520 EOF
1521   prefix="${saved_prefix}"
1522 }
1523
1524 process_targets() {
1525   true;
1526 }
1527
1528 process_detect() {
1529   true;
1530 }
1531
1532 enable_feature logging
1533 logfile="config.log"
1534 self=$0
1535 process() {
1536   cmdline_args="$@"
1537   process_cmdline "$@"
1538   if enabled child; then
1539     echo "# ${self} $@" >> ${logfile}
1540   else
1541     echo "# ${self} $@" > ${logfile}
1542   fi
1543   post_process_common_cmdline
1544   post_process_cmdline
1545   process_toolchain
1546   process_detect
1547   process_targets
1548
1549   OOT_INSTALLS="${OOT_INSTALLS}"
1550   if enabled source_path_used; then
1551   # Prepare the PWD for building.
1552   for f in ${OOT_INSTALLS}; do
1553     install -D "${source_path}/$f" "$f"
1554   done
1555   fi
1556   cp "${source_path}/build/make/Makefile" .
1557
1558   clean_temp_files
1559   true
1560 }