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