3c772e5aff2224754d074b5c57c7bc2bceef5cef
[profile/ivi/libvpx.git] / build / make / configure.sh
1 #!/bin/bash
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
24 die() {
25     echo "$@"
26     echo
27     echo "Configuration failed. This could reflect a misconfiguration of your"
28     echo "toolchains, improper options selected, or another problem. If you"
29     echo "don't see any useful error messages above, the next step is to look"
30     echo "at the configure error log file ($logfile) to determine what"
31     echo "configure was trying to do when it died."
32     clean_temp_files
33     exit 1
34 }
35
36
37 log(){
38     echo "$@" >>$logfile
39 }
40
41
42 log_file(){
43     log BEGIN $1
44     pr -n -t $1 >>$logfile
45     log END $1
46 }
47
48
49 log_echo() {
50     echo "$@"
51     log "$@"
52 }
53
54
55 fwrite () {
56     outfile=$1
57     shift
58     echo "$@" >> ${outfile}
59 }
60
61
62 show_help_pre(){
63     for opt in ${CMDLINE_SELECT}; do
64         opt2=`echo $opt | sed -e 's;_;-;g'`
65         if enabled $opt; then
66             eval "toggle_${opt}=\"--disable-${opt2}\""
67         else
68             eval "toggle_${opt}=\"--enable-${opt2} \""
69         fi
70     done
71
72     cat <<EOF
73 Usage: configure [options]
74 Options:
75
76 Build options:
77   --help                      print this message
78   --log=yes|no|FILE           file configure log is written to [config.err]
79   --target=TARGET             target platform tuple [generic-gnu]
80   --cpu=CPU                   optimize for a specific cpu rather than a family
81   --extra-cflags=ECFLAGS      add ECFLAGS to CFLAGS [$CFLAGS]
82   ${toggle_extra_warnings}    emit harmless warnings (always non-fatal)
83   ${toggle_werror}            treat warnings as errors, if possible
84                               (not available with all compilers)
85   ${toggle_optimizations}     turn on/off compiler optimization flags
86   ${toggle_pic}               turn on/off Position Independent Code
87   ${toggle_ccache}            turn on/off compiler cache
88   ${toggle_debug}             enable/disable debug mode
89   ${toggle_gprof}             enable/disable gprof profiling instrumentation
90   ${toggle_gcov}              enable/disable gcov coverage instrumentation
91
92 Install options:
93   ${toggle_install_docs}      control whether docs are installed
94   ${toggle_install_bins}      control whether binaries are installed
95   ${toggle_install_libs}      control whether libraries are installed
96   ${toggle_install_srcs}      control whether sources are installed
97
98
99 EOF
100 }
101
102
103 show_help_post(){
104     cat <<EOF
105
106
107 NOTES:
108     Object files are built at the place where configure is launched.
109
110     All boolean options can be negated. The default value is the opposite
111     of that shown above. If the option --disable-foo is listed, then
112     the default value for foo is enabled.
113
114 Supported targets:
115 EOF
116   show_targets ${all_platforms}
117   echo
118   exit 1
119 }
120
121
122 show_targets() {
123     while [ -n "$*" ]; do
124         if [ "${1%%-*}" = "${2%%-*}" ]; then
125             if [ "${2%%-*}" = "${3%%-*}" ]; then
126                 printf "    %-24s %-24s %-24s\n" "$1" "$2" "$3"
127                 shift; shift; shift
128             else
129                 printf "    %-24s %-24s\n" "$1" "$2"
130                 shift; shift
131             fi
132         else
133             printf "    %-24s\n" "$1"
134             shift
135         fi
136     done
137 }
138
139
140 show_help() {
141     show_help_pre
142     show_help_post
143 }
144
145 #
146 # List Processing Functions
147 #
148 set_all(){
149     value=$1
150     shift
151     for var in $*; do
152         eval $var=$value
153     done
154 }
155
156
157 is_in(){
158     value=$1
159     shift
160     for var in $*; do
161         [ $var = $value ] && return 0
162     done
163     return 1
164 }
165
166
167 add_cflags() {
168     CFLAGS="${CFLAGS} $@"
169 }
170
171
172 add_ldflags() {
173     LDFLAGS="${LDFLAGS} $@"
174 }
175
176
177 add_asflags() {
178     ASFLAGS="${ASFLAGS} $@"
179 }
180
181
182 add_extralibs() {
183     extralibs="${extralibs} $@"
184 }
185
186 #
187 # Boolean Manipulation Functions
188 #
189 enable(){
190     set_all yes $*
191 }
192
193 disable(){
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
206 soft_enable() {
207     for var in $*; do
208         if ! disabled $var; then
209             log_echo "  enabling $var"
210             enable $var
211         fi
212     done
213 }
214
215 soft_disable() {
216     for var in $*; do
217         if ! enabled $var; then
218             log_echo "  disabling $var"
219             disable $var
220         fi
221     done
222 }
223
224
225 #
226 # Text Processing Functions
227 #
228 toupper(){
229     echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
230 }
231
232
233 tolower(){
234     echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
235 }
236
237
238 #
239 # Temporary File Functions
240 #
241 source_path=${0%/*}
242 enable source_path_used
243 if test -z "$source_path" -o "$source_path" = "." ; then
244     source_path="`pwd`"
245     disable source_path_used
246 fi
247
248 if test ! -z "$TMPDIR" ; then
249     TMPDIRx="${TMPDIR}"
250 elif test ! -z "$TEMPDIR" ; then
251     TMPDIRx="${TEMPDIR}"
252 else
253     TMPDIRx="/tmp"
254 fi
255 TMP_H="${TMPDIRx}/vpx-conf-$$-${RANDOM}.h"
256 TMP_C="${TMPDIRx}/vpx-conf-$$-${RANDOM}.c"
257 TMP_O="${TMPDIRx}/vpx-conf-$$-${RANDOM}.o"
258 TMP_X="${TMPDIRx}/vpx-conf-$$-${RANDOM}.x"
259 TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RANDOM}.asm"
260
261 clean_temp_files() {
262     rm -f ${TMP_C} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM}
263 }
264
265 #
266 # Toolchain Check Functions
267 #
268 check_cmd() {
269     log "$@"
270     "$@" >>${logfile} 2>&1
271 }
272
273 check_cc() {
274     log check_cc "$@"
275     cat >${TMP_C}
276     log_file ${TMP_C}
277     check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C}
278 }
279
280 check_cpp() {
281     log check_cpp "$@"
282     cat > ${TMP_C}
283     log_file ${TMP_C}
284     check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C}
285 }
286
287 check_ld() {
288     log check_ld "$@"
289     check_cc $@ \
290         && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs}
291 }
292
293 check_header(){
294     log check_header "$@"
295     header=$1
296     shift
297     var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
298     disable $var
299     check_cpp "$@" <<EOF && enable $var
300 #include "$header"
301 int x;
302 EOF
303 }
304
305
306 check_cflags() {
307     log check_cflags "$@"
308     check_cc "$@" <<EOF
309 int x;
310 EOF
311 }
312
313 check_add_cflags() {
314     check_cflags "$@" && add_cflags "$@"
315 }
316
317 check_add_asflags() {
318     log add_asflags "$@"
319     add_asflags "$@"
320 }
321
322 check_add_ldflags() {
323     log add_ldflags "$@"
324     add_ldflags "$@"
325 }
326
327 check_asm_align() {
328     log check_asm_align "$@"
329     cat >${TMP_ASM} <<EOF
330 section .rodata
331 align 16
332 EOF
333     log_file ${TMP_ASM}
334     check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM}
335     readelf -WS ${TMP_O} >${TMP_X}
336     log_file ${TMP_X}
337     if ! grep -q '\.rodata .* 16$' ${TMP_X}; then
338         die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)"
339     fi
340 }
341
342 write_common_config_banner() {
343     print_webm_license config.mk "##" ""
344     echo '# This file automatically generated by configure. Do not edit!' >> config.mk
345     echo "TOOLCHAIN := ${toolchain}" >> config.mk
346
347     case ${toolchain} in
348         *-linux-rvct)
349             echo "ALT_LIBC := ${alt_libc}" >> config.mk
350             ;;
351     esac
352 }
353
354 write_common_config_targets() {
355     for t in ${all_targets}; do
356         if enabled ${t}; then
357             if enabled universal || enabled child; then
358                 fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}"
359             else
360                 fwrite config.mk "ALL_TARGETS += ${t}"
361             fi
362         fi
363     true;
364     done
365 true
366 }
367
368 write_common_target_config_mk() {
369     local CC=${CC}
370     enabled ccache && CC="ccache ${CC}"
371     print_webm_license $1 "##" ""
372
373     cat >> $1 << EOF
374 # This file automatically generated by configure. Do not edit!
375 SRC_PATH="$source_path"
376 SRC_PATH_BARE=$source_path
377 BUILD_PFX=${BUILD_PFX}
378 TOOLCHAIN=${toolchain}
379 ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl}
380
381 CC=${CC}
382 AR=${AR}
383 LD=${LD}
384 AS=${AS}
385 STRIP=${STRIP}
386 NM=${NM}
387
388 CFLAGS  = ${CFLAGS}
389 ARFLAGS = -rus\$(if \$(quiet),c,v)
390 LDFLAGS = ${LDFLAGS}
391 ASFLAGS = ${ASFLAGS}
392 extralibs = ${extralibs}
393 AS_SFX    = ${AS_SFX:-.asm}
394 EXE_SFX   = ${EXE_SFX}
395 RTCD_OPTIONS = ${RTCD_OPTIONS}
396 EOF
397
398     if enabled rvct; then cat >> $1 << EOF
399 fmt_deps = sed -e 's;^__image.axf;\$(dir \$@)\$(notdir \$<).o \$@;' #hide
400 EOF
401     else cat >> $1 << EOF
402 fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\$(dir \$@)\1\$(suffix \$<).o \$@;'
403 EOF
404     fi
405
406     print_config_mk ARCH   "${1}" ${ARCH_LIST}
407     print_config_mk HAVE   "${1}" ${HAVE_LIST}
408     print_config_mk CONFIG "${1}" ${CONFIG_LIST}
409     print_config_mk HAVE   "${1}" gnu_strip
410
411     enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}"
412
413 }
414
415
416 write_common_target_config_h() {
417     print_webm_license ${TMP_H} "/*" " */"
418     cat >> ${TMP_H} << EOF
419 /* This file automatically generated by configure. Do not edit! */
420 #ifndef VPX_CONFIG_H
421 #define VPX_CONFIG_H
422 #define RESTRICT    ${RESTRICT}
423 EOF
424     print_config_h ARCH   "${TMP_H}" ${ARCH_LIST}
425     print_config_h HAVE   "${TMP_H}" ${HAVE_LIST}
426     print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST}
427     echo "#endif /* VPX_CONFIG_H */" >> ${TMP_H}
428     mkdir -p `dirname "$1"`
429     cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1"
430 }
431
432 process_common_cmdline() {
433     for opt in "$@"; do
434         optval="${opt#*=}"
435         case "$opt" in
436         --child) enable child
437         ;;
438         --log*)
439         logging="$optval"
440         if ! disabled logging ; then
441             enabled logging || logfile="$logging"
442         else
443             logfile=/dev/null
444         fi
445         ;;
446         --target=*) toolchain="${toolchain:-${optval}}"
447         ;;
448         --force-target=*) toolchain="${toolchain:-${optval}}"; enable force_toolchain
449         ;;
450         --cpu)
451         ;;
452         --cpu=*) tune_cpu="$optval"
453         ;;
454         --extra-cflags=*)
455         extra_cflags="${optval}"
456         ;;
457         --enable-?*|--disable-?*)
458         eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
459         if echo "${ARCH_EXT_LIST}" | grep "^ *$option\$" >/dev/null; then
460             [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
461         elif [ $action = "disable" ] && ! disabled $option ; then
462           echo "${CMDLINE_SELECT}" | grep "^ *$option\$" >/dev/null ||
463             die_unknown $opt
464         elif [ $action = "enable" ] && ! enabled $option ; then
465           echo "${CMDLINE_SELECT}" | grep "^ *$option\$" >/dev/null ||
466             die_unknown $opt
467         fi
468         $action $option
469         ;;
470         --require-?*)
471         eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
472         if echo "${ARCH_EXT_LIST}" none | grep "^ *$option\$" >/dev/null; then
473             RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
474         else
475             die_unknown $opt
476         fi
477         ;;
478         --force-enable-?*|--force-disable-?*)
479         eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'`
480         $action $option
481         ;;
482         --libc=*)
483         [ -d "${optval}" ] || die "Not a directory: ${optval}"
484         disable builtin_libc
485         alt_libc="${optval}"
486         ;;
487         --as=*)
488         [ "${optval}" = yasm -o "${optval}" = nasm -o "${optval}" = auto ] \
489             || die "Must be yasm, nasm or auto: ${optval}"
490         alt_as="${optval}"
491         ;;
492         --prefix=*)
493         prefix="${optval}"
494         ;;
495         --libdir=*)
496         libdir="${optval}"
497         ;;
498         --sdk-path=*)
499         [ -d "${optval}" ] || die "Not a directory: ${optval}"
500         sdk_path="${optval}"
501         ;;
502         --libc|--as|--prefix|--libdir|--sdk-path)
503         die "Option ${opt} requires argument"
504         ;;
505         --help|-h) show_help
506         ;;
507         *) die_unknown $opt
508         ;;
509         esac
510     done
511 }
512
513 process_cmdline() {
514     for opt do
515         optval="${opt#*=}"
516         case "$opt" in
517         *) process_common_cmdline $opt
518         ;;
519         esac
520     done
521 }
522
523
524 post_process_common_cmdline() {
525     prefix="${prefix:-/usr/local}"
526     prefix="${prefix%/}"
527     libdir="${libdir:-${prefix}/lib}"
528     libdir="${libdir%/}"
529     if [ "${libdir#${prefix}}" = "${libdir}" ]; then
530         die "Libdir ${libdir} must be a subdirectory of ${prefix}"
531     fi
532 }
533
534
535 post_process_cmdline() {
536     true;
537 }
538
539 setup_gnu_toolchain() {
540         CC=${CC:-${CROSS}gcc}
541         AR=${AR:-${CROSS}ar}
542         LD=${LD:-${CROSS}${link_with_cc:-ld}}
543         AS=${AS:-${CROSS}as}
544     STRIP=${STRIP:-${CROSS}strip}
545     NM=${NM:-${CROSS}nm}
546         AS_SFX=.s
547         EXE_SFX=
548 }
549
550 process_common_toolchain() {
551     if [ -z "$toolchain" ]; then
552         gcctarget="$(gcc -dumpmachine 2> /dev/null)"
553
554         # detect tgt_isa
555         case "$gcctarget" in
556             *x86_64*|*amd64*)
557                 tgt_isa=x86_64
558                 ;;
559             *i[3456]86*)
560                 tgt_isa=x86
561                 ;;
562             *powerpc64*)
563                 tgt_isa=ppc64
564                 ;;
565             *powerpc*)
566                 tgt_isa=ppc32
567                 ;;
568             *sparc*)
569                 tgt_isa=sparc
570                 ;;
571         esac
572
573         # detect tgt_os
574         case "$gcctarget" in
575             *darwin8*)
576                 tgt_isa=universal
577                 tgt_os=darwin8
578                 ;;
579             *darwin9*)
580                 tgt_isa=universal
581                 tgt_os=darwin9
582                 ;;
583             *darwin10*)
584                 tgt_isa=x86_64
585                 tgt_os=darwin10
586                 ;;
587             *darwin11*)
588                 tgt_isa=x86_64
589                 tgt_os=darwin11
590                 ;;
591             *darwin12*)
592                 tgt_isa=x86_64
593                 tgt_os=darwin12
594                 ;;
595             *mingw32*|*cygwin*)
596                 [ -z "$tgt_isa" ] && tgt_isa=x86
597                 tgt_os=win32
598                 ;;
599             *linux*|*bsd*)
600                 tgt_os=linux
601                 ;;
602             *solaris2.10)
603                 tgt_os=solaris
604                 ;;
605             *os2*)
606                 tgt_os=os2
607                 ;;
608         esac
609
610         if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then
611             toolchain=${tgt_isa}-${tgt_os}-gcc
612         fi
613     fi
614
615     toolchain=${toolchain:-generic-gnu}
616
617     is_in ${toolchain} ${all_platforms} || enabled force_toolchain \
618         || die "Unrecognized toolchain '${toolchain}'"
619
620     enabled child || log_echo "Configuring for target '${toolchain}'"
621
622     #
623     # Set up toolchain variables
624     #
625     tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}')
626     tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}')
627     tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}')
628
629     # Mark the specific ISA requested as enabled
630     soft_enable ${tgt_isa}
631     enable ${tgt_os}
632     enable ${tgt_cc}
633
634     # Enable the architecture family
635     case ${tgt_isa} in
636         arm*) enable arm;;
637         mips*) enable mips;;
638     esac
639
640     # PIC is probably what we want when building shared libs
641     enabled shared && soft_enable pic
642
643     # Handle darwin variants. Newer SDKs allow targeting older
644     # platforms, so find the newest SDK available.
645     case ${toolchain} in
646         *-darwin*)
647             if [ -z "${DEVELOPER_DIR}" ]; then
648                 DEVELOPER_DIR=`xcode-select -print-path 2> /dev/null`
649                 [ $? -ne 0 ] && OSX_SKIP_DIR_CHECK=1
650             fi
651             if [ -z "${OSX_SKIP_DIR_CHECK}" ]; then
652                 OSX_SDK_ROOTS="${DEVELOPER_DIR}/SDKs"
653                 OSX_SDK_VERSIONS="MacOSX10.4u.sdk MacOSX10.5.sdk MacOSX10.6.sdk"
654                 OSX_SDK_VERSIONS="${OSX_SDK_VERSIONS} MacOSX10.7.sdk"
655                 for v in ${OSX_SDK_VERSIONS}; do
656                     if [ -d "${OSX_SDK_ROOTS}/${v}" ]; then
657                         osx_sdk_dir="${OSX_SDK_ROOTS}/${v}"
658                     fi
659                 done
660             fi
661             ;;
662     esac
663
664     if [ -d "${osx_sdk_dir}" ]; then
665         add_cflags  "-isysroot ${osx_sdk_dir}"
666         add_ldflags "-isysroot ${osx_sdk_dir}"
667     fi
668
669     case ${toolchain} in
670         *-darwin8-*)
671             add_cflags  "-mmacosx-version-min=10.4"
672             add_ldflags "-mmacosx-version-min=10.4"
673             ;;
674         *-darwin9-*)
675             add_cflags  "-mmacosx-version-min=10.5"
676             add_ldflags "-mmacosx-version-min=10.5"
677             ;;
678         *-darwin10-*)
679             add_cflags  "-mmacosx-version-min=10.6"
680             add_ldflags "-mmacosx-version-min=10.6"
681             ;;
682         *-darwin11-*)
683             add_cflags  "-mmacosx-version-min=10.7"
684             add_ldflags "-mmacosx-version-min=10.7"
685             ;;
686         *-darwin12-*)
687             add_cflags  "-mmacosx-version-min=10.8"
688             add_ldflags "-mmacosx-version-min=10.8"
689             ;;
690     esac
691
692     # Handle Solaris variants. Solaris 10 needs -lposix4
693     case ${toolchain} in
694         sparc-solaris-*)
695             add_extralibs -lposix4
696             disable fast_unaligned
697             ;;
698         *-solaris-*)
699             add_extralibs -lposix4
700             ;;
701     esac
702
703     # Process ARM architecture variants
704     case ${toolchain} in
705     arm*)
706         # on arm, isa versions are supersets
707         case ${tgt_isa} in
708         armv7)
709             soft_enable neon
710             soft_enable media
711             soft_enable edsp
712             soft_enable fast_unaligned
713             ;;
714         armv6)
715             soft_enable media
716             soft_enable edsp
717             soft_enable fast_unaligned
718             ;;
719         armv5te)
720             soft_enable edsp
721             ;;
722         esac
723
724         asm_conversion_cmd="cat"
725
726         case ${tgt_cc} in
727         gcc)
728             CROSS=${CROSS:-arm-none-linux-gnueabi-}
729             link_with_cc=gcc
730             setup_gnu_toolchain
731             arch_int=${tgt_isa##armv}
732             arch_int=${arch_int%%te}
733             check_add_asflags --defsym ARCHITECTURE=${arch_int}
734             tune_cflags="-mtune="
735             if [ ${tgt_isa} == "armv7" ]; then
736                 if enabled neon
737                 then
738                     check_add_cflags -mfpu=neon #-ftree-vectorize
739                     check_add_asflags -mfpu=neon
740                 fi
741                 check_add_cflags -march=armv7-a -mcpu=cortex-a8 -mfloat-abi=softfp
742                 check_add_asflags -mcpu=cortex-a8 -mfloat-abi=softfp  #-march=armv7-a
743             else
744                 check_add_cflags -march=${tgt_isa}
745                 check_add_asflags -march=${tgt_isa}
746             fi
747             enabled debug && add_asflags -g
748             asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
749             ;;
750         rvct)
751             CC=armcc
752             AR=armar
753             AS=armasm
754             LD=${source_path}/build/make/armlink_adapter.sh
755             STRIP=arm-none-linux-gnueabi-strip
756             NM=arm-none-linux-gnueabi-nm
757             tune_cflags="--cpu="
758             tune_asflags="--cpu="
759             if [ -z "${tune_cpu}" ]; then
760                 if [ ${tgt_isa} == "armv7" ]; then
761                     if enabled neon
762                     then
763                         check_add_cflags --fpu=softvfp+vfpv3
764                         check_add_asflags --fpu=softvfp+vfpv3
765                     fi
766                     check_add_cflags --cpu=Cortex-A8
767                     check_add_asflags --cpu=Cortex-A8
768                 else
769                     check_add_cflags --cpu=${tgt_isa##armv}
770                     check_add_asflags --cpu=${tgt_isa##armv}
771                 fi
772             fi
773             arch_int=${tgt_isa##armv}
774             arch_int=${arch_int%%te}
775             check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\""
776             enabled debug && add_asflags -g
777             add_cflags --gnu
778             add_cflags --enum_is_int
779             add_cflags --wchar32
780         ;;
781         esac
782
783         case ${tgt_os} in
784         none*)
785             disable multithread
786             disable os_support
787             ;;
788
789         android*)
790             SDK_PATH=${sdk_path}
791             COMPILER_LOCATION=`find "${SDK_PATH}" \
792                                -name "arm-linux-androideabi-gcc*" -print -quit`
793             TOOLCHAIN_PATH=${COMPILER_LOCATION%/*}/arm-linux-androideabi-
794             CC=${TOOLCHAIN_PATH}gcc
795             AR=${TOOLCHAIN_PATH}ar
796             LD=${TOOLCHAIN_PATH}gcc
797             AS=${TOOLCHAIN_PATH}as
798             STRIP=${TOOLCHAIN_PATH}strip
799             NM=${TOOLCHAIN_PATH}nm
800
801             if [ -z "${alt_libc}" ]; then
802                 alt_libc=`find "${SDK_PATH}" -name arch-arm -print | \
803                           awk '{n = split($0,a,"/"); \
804                                 split(a[n-1],b,"-"); \
805                                 print $0 " " b[2]}' | \
806                           sort -g -k 2 | \
807                           awk '{ print $1 }' | tail -1`
808             fi
809
810             add_cflags "--sysroot=${alt_libc}"
811             add_ldflags "--sysroot=${alt_libc}"
812
813             add_cflags "-I${SDK_PATH}/sources/android/cpufeatures/"
814
815             enable pic
816             soft_enable realtime_only
817             if [ ${tgt_isa} == "armv7" ]; then
818                 enable runtime_cpu_detect
819             fi
820           ;;
821
822         darwin*)
823             if [ -z "${sdk_path}" ]; then
824                 SDK_PATH=`xcode-select -print-path 2> /dev/null`
825                 SDK_PATH=${SDK_PATH}/Platforms/iPhoneOS.platform/Developer
826             else
827                 SDK_PATH=${sdk_path}
828             fi
829             TOOLCHAIN_PATH=${SDK_PATH}/usr/bin
830             CC=${TOOLCHAIN_PATH}/gcc
831             AR=${TOOLCHAIN_PATH}/ar
832             LD=${TOOLCHAIN_PATH}/arm-apple-darwin10-llvm-gcc-4.2
833             AS=${TOOLCHAIN_PATH}/as
834             STRIP=${TOOLCHAIN_PATH}/strip
835             NM=${TOOLCHAIN_PATH}/nm
836             AS_SFX=.s
837
838             # ASFLAGS is written here instead of using check_add_asflags
839             # because we need to overwrite all of ASFLAGS and purge the
840             # options that were put in above
841             ASFLAGS="-version -arch ${tgt_isa} -g"
842
843             add_cflags -arch ${tgt_isa}
844             add_ldflags -arch_only ${tgt_isa}
845
846             if [ -z "${alt_libc}" ]; then
847                 alt_libc=${SDK_PATH}/SDKs/iPhoneOS5.1.sdk
848             fi
849
850             add_cflags  "-isysroot ${alt_libc}"
851
852             # Add the paths for the alternate libc
853             for d in usr/include; do
854                 try_dir="${alt_libc}/${d}"
855                 [ -d "${try_dir}" ] && add_cflags -I"${try_dir}"
856             done
857
858             for d in lib usr/lib usr/lib/system; do
859                 try_dir="${alt_libc}/${d}"
860                 [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}"
861             done
862
863             asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl"
864          ;;
865
866         linux*)
867             enable linux
868             if enabled rvct; then
869                 # Check if we have CodeSourcery GCC in PATH. Needed for
870                 # libraries
871                 hash arm-none-linux-gnueabi-gcc 2>&- || \
872                   die "Couldn't find CodeSourcery GCC from PATH"
873
874                 # Use armcc as a linker to enable translation of
875                 # some gcc specific options such as -lm and -lpthread.
876                 LD="armcc --translate_gcc"
877
878                 # create configuration file (uses path to CodeSourcery GCC)
879                 armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg
880
881                 add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
882                 add_asflags --no_hide_all --apcs=/interwork
883                 add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
884                 enabled pic && add_cflags --apcs=/fpic
885                 enabled pic && add_asflags --apcs=/fpic
886                 enabled shared && add_cflags --shared
887             fi
888         ;;
889
890         esac
891     ;;
892     mips*)
893         CROSS=${CROSS:-mipsel-linux-uclibc-}
894         link_with_cc=gcc
895         setup_gnu_toolchain
896         tune_cflags="-mtune="
897         check_add_cflags -march=${tgt_isa}
898     check_add_asflags -march=${tgt_isa}
899     check_add_asflags -KPIC
900     ;;
901     ppc*)
902         enable ppc
903         bits=${tgt_isa##ppc}
904         link_with_cc=gcc
905         setup_gnu_toolchain
906         add_asflags -force_cpusubtype_ALL -I"\$(dir \$<)darwin"
907         soft_enable altivec
908         enabled altivec && add_cflags -maltivec
909
910         case "$tgt_os" in
911         linux*)
912             add_asflags -maltivec -mregnames -I"\$(dir \$<)linux"
913         ;;
914         darwin*)
915             darwin_arch="-arch ppc"
916             enabled ppc64 && darwin_arch="${darwin_arch}64"
917             add_cflags  ${darwin_arch} -m${bits} -fasm-blocks
918             add_asflags ${darwin_arch} -force_cpusubtype_ALL -I"\$(dir \$<)darwin"
919             add_ldflags ${darwin_arch} -m${bits}
920             enabled altivec && add_cflags -faltivec
921         ;;
922         esac
923     ;;
924     x86*)
925         bits=32
926         enabled x86_64 && bits=64
927         soft_enable runtime_cpu_detect
928         soft_enable mmx
929         soft_enable sse
930         soft_enable sse2
931         soft_enable sse3
932         soft_enable ssse3
933         soft_enable sse4_1
934
935         case  ${tgt_os} in
936             win*)
937                 enabled gcc && add_cflags -fno-common
938                 ;;
939             solaris*)
940                 CC=${CC:-${CROSS}gcc}
941                 LD=${LD:-${CROSS}gcc}
942                 CROSS=${CROSS:-g}
943                 ;;
944             os2)
945                 AS=${AS:-nasm}
946                 ;;
947         esac
948
949         AS="${alt_as:-${AS:-auto}}"
950         case  ${tgt_cc} in
951             icc*)
952                 CC=${CC:-icc}
953                 LD=${LD:-icc}
954                 setup_gnu_toolchain
955                 add_cflags -use-msasm -use-asm
956                 add_ldflags -i-static
957                 enabled x86_64 && add_cflags -ipo -no-prec-div -static -xSSE2 -axSSE2
958                 enabled x86_64 && AR=xiar
959                 case ${tune_cpu} in
960                     atom*)
961                         tune_cflags="-x"
962                         tune_cpu="SSE3_ATOM"
963                     ;;
964                     *)
965                         tune_cflags="-march="
966                     ;;
967                 esac
968                 ;;
969             gcc*)
970                 add_cflags  -m${bits}
971                 add_ldflags -m${bits}
972                 link_with_cc=gcc
973                 tune_cflags="-march="
974             setup_gnu_toolchain
975                 #for 32 bit x86 builds, -O3 did not turn on this flag
976                 enabled optimizations && check_add_cflags -fomit-frame-pointer
977                 ;;
978         esac
979
980         case "${AS}" in
981             auto|"")
982                 which nasm >/dev/null 2>&1 && AS=nasm
983                 which yasm >/dev/null 2>&1 && AS=yasm
984                 [ "${AS}" = auto -o -z "${AS}" ] \
985                     && die "Neither yasm nor nasm have been found"
986                 ;;
987         esac
988         log_echo "  using $AS"
989         [ "${AS##*/}" = nasm ] && add_asflags -Ox
990         AS_SFX=.asm
991         case  ${tgt_os} in
992             win32)
993                 add_asflags -f win32
994                 enabled debug && add_asflags -g cv8
995             ;;
996             win64)
997                 add_asflags -f x64
998                 enabled debug && add_asflags -g cv8
999             ;;
1000             linux*|solaris*)
1001                 add_asflags -f elf${bits}
1002                 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
1003                 enabled debug && [ "${AS}" = nasm ] && add_asflags -g
1004                 [ "${AS##*/}" = nasm ] && check_asm_align
1005             ;;
1006             darwin*)
1007                 add_asflags -f macho${bits}
1008                 enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64"
1009                 add_cflags  ${darwin_arch}
1010                 add_ldflags ${darwin_arch}
1011                 # -mdynamic-no-pic is still a bit of voodoo -- it was required at
1012                 # one time, but does not seem to be now, and it breaks some of the
1013                 # code that still relies on inline assembly.
1014                 # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic
1015                 enabled icc && ! enabled pic && add_cflags -fno-pic
1016             ;;
1017             os2)
1018                 add_asflags -f aout
1019                 enabled debug && add_asflags -g
1020                 EXE_SFX=.exe
1021             ;;
1022             *) log "Warning: Unknown os $tgt_os while setting up $AS flags"
1023             ;;
1024         esac
1025     ;;
1026     universal*|*-gcc|generic-gnu)
1027         link_with_cc=gcc
1028         enable gcc
1029     setup_gnu_toolchain
1030     ;;
1031     esac
1032
1033     # Try to enable CPU specific tuning
1034     if [ -n "${tune_cpu}" ]; then
1035         if [ -n "${tune_cflags}" ]; then
1036             check_add_cflags ${tune_cflags}${tune_cpu} || \
1037                 die "Requested CPU '${tune_cpu}' not supported by compiler"
1038         fi
1039     if [ -n "${tune_asflags}" ]; then
1040             check_add_asflags ${tune_asflags}${tune_cpu} || \
1041                 die "Requested CPU '${tune_cpu}' not supported by assembler"
1042         fi
1043     if [ -z "${tune_cflags}${tune_asflags}" ]; then
1044             log_echo "Warning: CPU tuning not supported by this toolchain"
1045         fi
1046     fi
1047
1048     enabled debug && check_add_cflags -g && check_add_ldflags -g
1049     enabled gprof && check_add_cflags -pg && check_add_ldflags -pg
1050     enabled gcov &&
1051         check_add_cflags -fprofile-arcs -ftest-coverage &&
1052         check_add_ldflags -fprofile-arcs -ftest-coverage
1053
1054     if enabled optimizations; then
1055         if enabled rvct; then
1056             enabled small && check_add_cflags -Ospace || check_add_cflags -Otime
1057         else
1058             enabled small && check_add_cflags -O2 ||  check_add_cflags -O3
1059         fi
1060     fi
1061
1062     # Position Independent Code (PIC) support, for building relocatable
1063     # shared objects
1064     enabled gcc && enabled pic && check_add_cflags -fPIC
1065
1066     # Work around longjmp interception on glibc >= 2.11, to improve binary
1067     # compatibility. See http://code.google.com/p/webm/issues/detail?id=166
1068     enabled linux && check_add_cflags -D_FORTIFY_SOURCE=0
1069
1070     # Check for strip utility variant
1071     ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable gnu_strip
1072
1073     # Try to determine target endianness
1074     check_cc <<EOF
1075     unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E';
1076 EOF
1077     [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' |
1078         grep '4f *32 *42 *45' >/dev/null 2>&1 && enable big_endian
1079
1080     # Almost every platform uses pthreads.
1081     if enabled multithread; then
1082         case ${toolchain} in
1083             *-win*);;
1084             *-android-gcc);;
1085             *) check_header pthread.h && add_extralibs -lpthread
1086         esac
1087     fi
1088
1089     # for sysconf(3) and friends.
1090     check_header unistd.h
1091
1092     # glibc needs these
1093     if enabled linux; then
1094         add_cflags -D_LARGEFILE_SOURCE
1095         add_cflags -D_FILE_OFFSET_BITS=64
1096     fi
1097
1098     # append any user defined extra cflags
1099     if [ -n "${extra_cflags}" ] ; then
1100         check_add_cflags ${extra_cflags} || \
1101         die "Requested extra CFLAGS '${extra_cflags}' not supported by compiler"
1102     fi
1103 }
1104
1105 process_toolchain() {
1106     process_common_toolchain
1107 }
1108
1109 print_config_mk() {
1110     local prefix=$1
1111     local makefile=$2
1112     shift 2
1113     for cfg; do
1114         upname="`toupper $cfg`"
1115         if enabled $cfg; then
1116             echo "${prefix}_${upname}=yes" >> $makefile
1117         fi
1118     done
1119 }
1120
1121 print_config_h() {
1122     local prefix=$1
1123     local header=$2
1124     shift 2
1125     for cfg; do
1126         upname="`toupper $cfg`"
1127         if enabled $cfg; then
1128             echo "#define ${prefix}_${upname} 1" >> $header
1129         else
1130             echo "#define ${prefix}_${upname} 0" >> $header
1131         fi
1132     done
1133 }
1134
1135 print_webm_license() {
1136     local destination=$1
1137     local prefix=$2
1138     local suffix=$3
1139     shift 3
1140     cat <<EOF > ${destination}
1141 ${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix}
1142 ${prefix} ${suffix}
1143 ${prefix} Use of this source code is governed by a BSD-style license${suffix}
1144 ${prefix} that can be found in the LICENSE file in the root of the source${suffix}
1145 ${prefix} tree. An additional intellectual property rights grant can be found${suffix}
1146 ${prefix} in the file PATENTS.  All contributing project authors may${suffix}
1147 ${prefix} be found in the AUTHORS file in the root of the source tree.${suffix}
1148 EOF
1149 }
1150
1151 process_targets() {
1152     true;
1153 }
1154
1155 process_detect() {
1156     true;
1157 }
1158
1159 enable logging
1160 logfile="config.err"
1161 self=$0
1162 process() {
1163     cmdline_args="$@"
1164     process_cmdline "$@"
1165     if enabled child; then
1166         echo "# ${self} $@" >> ${logfile}
1167     else
1168         echo "# ${self} $@" > ${logfile}
1169     fi
1170     post_process_common_cmdline
1171     post_process_cmdline
1172     process_toolchain
1173     process_detect
1174     process_targets
1175
1176     OOT_INSTALLS="${OOT_INSTALLS}"
1177     if enabled source_path_used; then
1178     # Prepare the PWD for building.
1179     for f in ${OOT_INSTALLS}; do
1180             install -D ${source_path}/$f $f
1181     done
1182     fi
1183     cp ${source_path}/build/make/Makefile .
1184
1185     clean_temp_files
1186     true
1187 }