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