blob: 44c706fcfbd34c8b752ba30b7680ff2a7dddaa59 [file] [log] [blame]
Guillaume Martres3526f1c2013-08-13 18:46:58 -07001#!/bin/sh
John Koleszar0ea50ce2010-05-18 11:58:33 -04002##
John Koleszar0d719652010-05-28 10:11:58 -04003## configure.sh
John Koleszar0ea50ce2010-05-18 11:58:33 -04004##
John Koleszar0d719652010-05-28 10:11:58 -04005## This script is sourced by the main configure script and contains
Yaowu Xuc27fc142016-08-22 16:08:15 -07006## utility functions and other common bits that aren't strictly libaom
John Koleszar0d719652010-05-28 10:11:58 -04007## related.
John Koleszar0ea50ce2010-05-18 11:58:33 -04008##
John Koleszar0d719652010-05-28 10:11:58 -04009## This build system is based in part on the FFmpeg configure script.
10##
John Koleszar0ea50ce2010-05-18 11:58:33 -040011
12
13#
14# Logging / Output Functions
15#
16die_unknown(){
Johann7efb3022014-11-20 18:20:06 -080017 echo "Unknown option \"$1\"."
18 echo "See $0 --help for available options."
19 clean_temp_files
20 exit 1
John Koleszar0ea50ce2010-05-18 11:58:33 -040021}
22
John Koleszar0ea50ce2010-05-18 11:58:33 -040023die() {
Johann7efb3022014-11-20 18:20:06 -080024 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
John Koleszar0ea50ce2010-05-18 11:58:33 -040033}
34
John Koleszar0ea50ce2010-05-18 11:58:33 -040035log(){
Johann7efb3022014-11-20 18:20:06 -080036 echo "$@" >>$logfile
John Koleszar0ea50ce2010-05-18 11:58:33 -040037}
38
John Koleszar0ea50ce2010-05-18 11:58:33 -040039log_file(){
Johann7efb3022014-11-20 18:20:06 -080040 log BEGIN $1
41 cat -n $1 >>$logfile
42 log END $1
John Koleszar0ea50ce2010-05-18 11:58:33 -040043}
44
John Koleszar0ea50ce2010-05-18 11:58:33 -040045log_echo() {
Johann7efb3022014-11-20 18:20:06 -080046 echo "$@"
47 log "$@"
John Koleszar0ea50ce2010-05-18 11:58:33 -040048}
49
John Koleszar0ea50ce2010-05-18 11:58:33 -040050fwrite () {
Johann7efb3022014-11-20 18:20:06 -080051 outfile=$1
52 shift
53 echo "$@" >> ${outfile}
John Koleszar0ea50ce2010-05-18 11:58:33 -040054}
55
John Koleszar0ea50ce2010-05-18 11:58:33 -040056show_help_pre(){
Johann7efb3022014-11-20 18:20:06 -080057 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
John Koleszar0ea50ce2010-05-18 11:58:33 -040065
Johann7efb3022014-11-20 18:20:06 -080066 cat <<EOF
John Koleszar0ea50ce2010-05-18 11:58:33 -040067Usage: configure [options]
68Options:
69
70Build options:
71 --help print this message
James Zerne636af12013-07-18 14:17:00 -070072 --log=yes|no|FILE file configure log is written to [config.log]
John Koleszar0ea50ce2010-05-18 11:58:33 -040073 --target=TARGET target platform tuple [generic-gnu]
74 --cpu=CPU optimize for a specific cpu rather than a family
Attila Nagy41955322011-01-20 14:46:57 +020075 --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS]
James Zern12355c42015-09-12 10:25:28 -070076 --extra-cxxflags=ECXXFLAGS add ECXXFLAGS to CXXFLAGS [$CXXFLAGS]
John Koleszar0ea50ce2010-05-18 11:58:33 -040077 ${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
Gaute Strokkenes6795e252011-03-15 12:20:54 +000081 ${toggle_pic} turn on/off Position Independent Code
John Koleszar0ea50ce2010-05-18 11:58:33 -040082 ${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
Martin Storsjo132422d2013-05-13 01:16:09 +030086 ${toggle_thumb} enable/disable building arm assembly in thumb mode
James Zernaaccf652015-02-05 19:31:38 -080087 ${toggle_dependency_tracking}
88 disable to speed up one-time build
John Koleszar0ea50ce2010-05-18 11:58:33 -040089
90Install options:
91 ${toggle_install_docs} control whether docs are installed
92 ${toggle_install_bins} control whether binaries are installed
93 ${toggle_install_libs} control whether libraries are installed
94 ${toggle_install_srcs} control whether sources are installed
95
96
97EOF
98}
99
John Koleszar0ea50ce2010-05-18 11:58:33 -0400100show_help_post(){
Johann7efb3022014-11-20 18:20:06 -0800101 cat <<EOF
John Koleszar0ea50ce2010-05-18 11:58:33 -0400102
103
104NOTES:
105 Object files are built at the place where configure is launched.
106
107 All boolean options can be negated. The default value is the opposite
108 of that shown above. If the option --disable-foo is listed, then
109 the default value for foo is enabled.
110
111Supported targets:
112EOF
113 show_targets ${all_platforms}
114 echo
115 exit 1
116}
117
John Koleszar0ea50ce2010-05-18 11:58:33 -0400118show_targets() {
Johann7efb3022014-11-20 18:20:06 -0800119 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
John Koleszar0ea50ce2010-05-18 11:58:33 -0400133}
134
John Koleszar0ea50ce2010-05-18 11:58:33 -0400135show_help() {
Johann7efb3022014-11-20 18:20:06 -0800136 show_help_pre
137 show_help_post
John Koleszar0ea50ce2010-05-18 11:58:33 -0400138}
139
140#
141# List Processing Functions
142#
143set_all(){
Johann7efb3022014-11-20 18:20:06 -0800144 value=$1
145 shift
146 for var in $*; do
147 eval $var=$value
148 done
John Koleszar0ea50ce2010-05-18 11:58:33 -0400149}
150
John Koleszar0ea50ce2010-05-18 11:58:33 -0400151is_in(){
Johann7efb3022014-11-20 18:20:06 -0800152 value=$1
153 shift
154 for var in $*; do
155 [ $var = $value ] && return 0
156 done
157 return 1
John Koleszar0ea50ce2010-05-18 11:58:33 -0400158}
159
John Koleszar0ea50ce2010-05-18 11:58:33 -0400160add_cflags() {
Johann7efb3022014-11-20 18:20:06 -0800161 CFLAGS="${CFLAGS} $@"
162 CXXFLAGS="${CXXFLAGS} $@"
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700163}
164
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700165add_cflags_only() {
Johann7efb3022014-11-20 18:20:06 -0800166 CFLAGS="${CFLAGS} $@"
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700167}
168
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700169add_cxxflags_only() {
Johann7efb3022014-11-20 18:20:06 -0800170 CXXFLAGS="${CXXFLAGS} $@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400171}
172
John Koleszar0ea50ce2010-05-18 11:58:33 -0400173add_ldflags() {
Johann7efb3022014-11-20 18:20:06 -0800174 LDFLAGS="${LDFLAGS} $@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400175}
176
John Koleszar0ea50ce2010-05-18 11:58:33 -0400177add_asflags() {
Johann7efb3022014-11-20 18:20:06 -0800178 ASFLAGS="${ASFLAGS} $@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400179}
180
John Koleszar0ea50ce2010-05-18 11:58:33 -0400181add_extralibs() {
Johann7efb3022014-11-20 18:20:06 -0800182 extralibs="${extralibs} $@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400183}
184
185#
186# Boolean Manipulation Functions
187#
Johann0146fa92016-06-10 14:59:26 -0700188
James Zern42ab4012013-08-21 18:11:45 -0700189enable_feature(){
Johann7efb3022014-11-20 18:20:06 -0800190 set_all yes $*
John Koleszar0ea50ce2010-05-18 11:58:33 -0400191}
192
James Zern42ab4012013-08-21 18:11:45 -0700193disable_feature(){
Johann7efb3022014-11-20 18:20:06 -0800194 set_all no $*
John Koleszar0ea50ce2010-05-18 11:58:33 -0400195}
196
197enabled(){
Johann7efb3022014-11-20 18:20:06 -0800198 eval test "x\$$1" = "xyes"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400199}
200
201disabled(){
Johann7efb3022014-11-20 18:20:06 -0800202 eval test "x\$$1" = "xno"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400203}
204
Johann2967bf32016-06-22 16:08:10 -0700205enable_codec(){
206 enabled "${1}" || echo " enabling ${1}"
207 enable_feature "${1}"
208
Yaowu Xuf883b422016-08-30 14:01:10 -0700209 is_in "${1}" av1 && enable_feature "${1}_encoder" "${1}_decoder"
Johann2967bf32016-06-22 16:08:10 -0700210}
211
212disable_codec(){
213 disabled "${1}" || echo " disabling ${1}"
214 disable_feature "${1}"
215
Yaowu Xuf883b422016-08-30 14:01:10 -0700216 is_in "${1}" av1 && disable_feature "${1}_encoder" "${1}_decoder"
Johann2967bf32016-06-22 16:08:10 -0700217}
218
Tom Finegan60022122015-09-23 11:42:37 -0700219# Iterates through positional parameters, checks to confirm the parameter has
220# not been explicitly (force) disabled, and enables the setting controlled by
221# the parameter when the setting is not disabled.
222# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
John Koleszar0ea50ce2010-05-18 11:58:33 -0400223soft_enable() {
Johann7efb3022014-11-20 18:20:06 -0800224 for var in $*; do
225 if ! disabled $var; then
James Zernef7f33b2015-01-28 20:30:51 -0800226 enabled $var || log_echo " enabling $var"
Johann7efb3022014-11-20 18:20:06 -0800227 enable_feature $var
228 fi
229 done
John Koleszar0ea50ce2010-05-18 11:58:33 -0400230}
231
Tom Finegan60022122015-09-23 11:42:37 -0700232# Iterates through positional parameters, checks to confirm the parameter has
233# not been explicitly (force) enabled, and disables the setting controlled by
234# the parameter when the setting is not enabled.
235# Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
John Koleszar0ea50ce2010-05-18 11:58:33 -0400236soft_disable() {
Johann7efb3022014-11-20 18:20:06 -0800237 for var in $*; do
238 if ! enabled $var; then
James Zernef7f33b2015-01-28 20:30:51 -0800239 disabled $var || log_echo " disabling $var"
Johann7efb3022014-11-20 18:20:06 -0800240 disable_feature $var
241 fi
242 done
John Koleszar0ea50ce2010-05-18 11:58:33 -0400243}
244
John Koleszar0ea50ce2010-05-18 11:58:33 -0400245#
246# Text Processing Functions
247#
248toupper(){
Johann7efb3022014-11-20 18:20:06 -0800249 echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
John Koleszar0ea50ce2010-05-18 11:58:33 -0400250}
251
John Koleszar0ea50ce2010-05-18 11:58:33 -0400252tolower(){
Johann7efb3022014-11-20 18:20:06 -0800253 echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
John Koleszar0ea50ce2010-05-18 11:58:33 -0400254}
255
John Koleszar0ea50ce2010-05-18 11:58:33 -0400256#
257# Temporary File Functions
258#
259source_path=${0%/*}
James Zern42ab4012013-08-21 18:11:45 -0700260enable_feature source_path_used
James Zern8753f9c2014-07-29 23:25:15 -0700261if [ -z "$source_path" ] || [ "$source_path" = "." ]; then
Johann7efb3022014-11-20 18:20:06 -0800262 source_path="`pwd`"
263 disable_feature source_path_used
John Koleszar0ea50ce2010-05-18 11:58:33 -0400264fi
265
266if test ! -z "$TMPDIR" ; then
Johann7efb3022014-11-20 18:20:06 -0800267 TMPDIRx="${TMPDIR}"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400268elif test ! -z "$TEMPDIR" ; then
Johann7efb3022014-11-20 18:20:06 -0800269 TMPDIRx="${TEMPDIR}"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400270else
Johann7efb3022014-11-20 18:20:06 -0800271 TMPDIRx="/tmp"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400272fi
Guillaume Martres3526f1c2013-08-13 18:46:58 -0700273RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}')
Yaowu Xuf883b422016-08-30 14:01:10 -0700274TMP_H="${TMPDIRx}/aom-conf-$$-${RAND}.h"
275TMP_C="${TMPDIRx}/aom-conf-$$-${RAND}.c"
276TMP_CC="${TMPDIRx}/aom-conf-$$-${RAND}.cc"
277TMP_O="${TMPDIRx}/aom-conf-$$-${RAND}.o"
278TMP_X="${TMPDIRx}/aom-conf-$$-${RAND}.x"
279TMP_ASM="${TMPDIRx}/aom-conf-$$-${RAND}.asm"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400280
281clean_temp_files() {
Johann7efb3022014-11-20 18:20:06 -0800282 rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM}
283 enabled gcov && rm -f ${TMP_C%.c}.gcno ${TMP_CC%.cc}.gcno
John Koleszar0ea50ce2010-05-18 11:58:33 -0400284}
285
286#
287# Toolchain Check Functions
288#
289check_cmd() {
Johann7efb3022014-11-20 18:20:06 -0800290 enabled external_build && return
291 log "$@"
292 "$@" >>${logfile} 2>&1
John Koleszar0ea50ce2010-05-18 11:58:33 -0400293}
294
295check_cc() {
Johann7efb3022014-11-20 18:20:06 -0800296 log check_cc "$@"
297 cat >${TMP_C}
298 log_file ${TMP_C}
299 check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400300}
301
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700302check_cxx() {
Johann7efb3022014-11-20 18:20:06 -0800303 log check_cxx "$@"
304 cat >${TMP_CC}
305 log_file ${TMP_CC}
306 check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC}
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700307}
308
John Koleszar0ea50ce2010-05-18 11:58:33 -0400309check_cpp() {
Johann7efb3022014-11-20 18:20:06 -0800310 log check_cpp "$@"
311 cat > ${TMP_C}
312 log_file ${TMP_C}
313 check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400314}
315
316check_ld() {
Johann7efb3022014-11-20 18:20:06 -0800317 log check_ld "$@"
318 check_cc $@ \
319 && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400320}
321
322check_header(){
Johann7efb3022014-11-20 18:20:06 -0800323 log check_header "$@"
324 header=$1
325 shift
326 var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
327 disable_feature $var
328 check_cpp "$@" <<EOF && enable_feature $var
John Koleszar0ea50ce2010-05-18 11:58:33 -0400329#include "$header"
330int x;
331EOF
332}
333
John Koleszar0ea50ce2010-05-18 11:58:33 -0400334check_cflags() {
Johann7efb3022014-11-20 18:20:06 -0800335 log check_cflags "$@"
336 check_cc -Werror "$@" <<EOF
John Koleszar0ea50ce2010-05-18 11:58:33 -0400337int x;
338EOF
339}
340
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700341check_cxxflags() {
Johann7efb3022014-11-20 18:20:06 -0800342 log check_cxxflags "$@"
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700343
Johann7efb3022014-11-20 18:20:06 -0800344 # Catch CFLAGS that trigger CXX warnings
345 case "$CXX" in
346 *c++-analyzer|*clang++|*g++*)
347 check_cxx -Werror "$@" <<EOF
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700348int x;
349EOF
350 ;;
Johann7efb3022014-11-20 18:20:06 -0800351 *)
352 check_cxx -Werror "$@" <<EOF
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700353int x;
354EOF
355 ;;
356 esac
357}
358
John Koleszar0ea50ce2010-05-18 11:58:33 -0400359check_add_cflags() {
Johann7efb3022014-11-20 18:20:06 -0800360 check_cxxflags "$@" && add_cxxflags_only "$@"
361 check_cflags "$@" && add_cflags_only "$@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400362}
363
James Zern12355c42015-09-12 10:25:28 -0700364check_add_cxxflags() {
365 check_cxxflags "$@" && add_cxxflags_only "$@"
366}
367
John Koleszar0ea50ce2010-05-18 11:58:33 -0400368check_add_asflags() {
Johann7efb3022014-11-20 18:20:06 -0800369 log add_asflags "$@"
370 add_asflags "$@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400371}
372
373check_add_ldflags() {
Johann7efb3022014-11-20 18:20:06 -0800374 log add_ldflags "$@"
375 add_ldflags "$@"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400376}
377
Jan Kratochvil7be093e2010-10-05 19:15:08 +0200378check_asm_align() {
Johann7efb3022014-11-20 18:20:06 -0800379 log check_asm_align "$@"
380 cat >${TMP_ASM} <<EOF
Jan Kratochvil7be093e2010-10-05 19:15:08 +0200381section .rodata
382align 16
383EOF
Johann7efb3022014-11-20 18:20:06 -0800384 log_file ${TMP_ASM}
385 check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM}
386 readelf -WS ${TMP_O} >${TMP_X}
387 log_file ${TMP_X}
388 if ! grep -q '\.rodata .* 16$' ${TMP_X}; then
389 die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)"
390 fi
Jan Kratochvil7be093e2010-10-05 19:15:08 +0200391}
392
James Zernc37ecba2014-03-18 17:22:35 -0700393# tests for -m$1 toggling the feature given in $2. If $2 is empty $1 is used.
394check_gcc_machine_option() {
Johann7efb3022014-11-20 18:20:06 -0800395 opt="$1"
396 feature="$2"
397 [ -n "$feature" ] || feature="$opt"
James Zernc37ecba2014-03-18 17:22:35 -0700398
Johann7efb3022014-11-20 18:20:06 -0800399 if enabled gcc && ! disabled "$feature" && ! check_cflags "-m$opt"; then
400 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature "
401 else
402 soft_enable "$feature"
403 fi
James Zernc37ecba2014-03-18 17:22:35 -0700404}
405
John Koleszar0ea50ce2010-05-18 11:58:33 -0400406write_common_config_banner() {
Johann7efb3022014-11-20 18:20:06 -0800407 print_webm_license config.mk "##" ""
408 echo '# This file automatically generated by configure. Do not edit!' >> config.mk
409 echo "TOOLCHAIN := ${toolchain}" >> config.mk
John Koleszar0ea50ce2010-05-18 11:58:33 -0400410
Johann7efb3022014-11-20 18:20:06 -0800411 case ${toolchain} in
412 *-linux-rvct)
413 echo "ALT_LIBC := ${alt_libc}" >> config.mk
414 ;;
415 esac
John Koleszar0ea50ce2010-05-18 11:58:33 -0400416}
417
418write_common_config_targets() {
Johann7efb3022014-11-20 18:20:06 -0800419 for t in ${all_targets}; do
420 if enabled ${t}; then
Tom Finegan3d7063d2015-05-12 15:33:40 -0700421 if enabled child; then
Johann7efb3022014-11-20 18:20:06 -0800422 fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}"
423 else
424 fwrite config.mk "ALL_TARGETS += ${t}"
425 fi
426 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -0400427 true;
Johann7efb3022014-11-20 18:20:06 -0800428 done
429 true
John Koleszar0ea50ce2010-05-18 11:58:33 -0400430}
431
432write_common_target_config_mk() {
Johann7efb3022014-11-20 18:20:06 -0800433 saved_CC="${CC}"
434 saved_CXX="${CXX}"
435 enabled ccache && CC="ccache ${CC}"
436 enabled ccache && CXX="ccache ${CXX}"
437 print_webm_license $1 "##" ""
John Koleszar0ea50ce2010-05-18 11:58:33 -0400438
Johann7efb3022014-11-20 18:20:06 -0800439 cat >> $1 << EOF
John Koleszar0ea50ce2010-05-18 11:58:33 -0400440# This file automatically generated by configure. Do not edit!
441SRC_PATH="$source_path"
442SRC_PATH_BARE=$source_path
443BUILD_PFX=${BUILD_PFX}
444TOOLCHAIN=${toolchain}
445ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl}
Martin Storsjobd91beb2013-05-17 00:57:57 +0300446GEN_VCPROJ=${gen_vcproj_cmd}
Martin Storsjoad484fc2013-05-18 23:32:49 +0300447MSVS_ARCH_DIR=${msvs_arch_dir}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400448
449CC=${CC}
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700450CXX=${CXX}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400451AR=${AR}
452LD=${LD}
453AS=${AS}
454STRIP=${STRIP}
455NM=${NM}
456
John Koleszar1df03142010-05-20 14:44:18 -0400457CFLAGS = ${CFLAGS}
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700458CXXFLAGS = ${CXXFLAGS}
Michael Bebenitaf4f27fe2017-03-02 17:40:44 -0800459ARFLAGS = crs\$(if \$(quiet),,v)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400460LDFLAGS = ${LDFLAGS}
461ASFLAGS = ${ASFLAGS}
462extralibs = ${extralibs}
463AS_SFX = ${AS_SFX:-.asm}
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700464EXE_SFX = ${EXE_SFX}
Martin Storsjobd91beb2013-05-17 00:57:57 +0300465VCPROJ_SFX = ${VCPROJ_SFX}
Christian Duvivier707b65b2012-08-08 15:47:36 -0700466RTCD_OPTIONS = ${RTCD_OPTIONS}
Alex Conversed5f51b32016-10-11 12:26:24 -0700467WX_CXXFLAGS = ${WX_CXXFLAGS}
468WX_LDFLAGS = ${WX_LDFLAGS}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400469EOF
470
Johann7efb3022014-11-20 18:20:06 -0800471 if enabled rvct; then cat >> $1 << EOF
John Koleszarde529482012-12-19 13:44:32 -0800472fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide
John Koleszar0ea50ce2010-05-18 11:58:33 -0400473EOF
Johann7efb3022014-11-20 18:20:06 -0800474 else cat >> $1 << EOF
John Koleszarde529482012-12-19 13:44:32 -0800475fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;'
John Koleszar0ea50ce2010-05-18 11:58:33 -0400476EOF
Johann7efb3022014-11-20 18:20:06 -0800477 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -0400478
Johann7efb3022014-11-20 18:20:06 -0800479 print_config_mk ARCH "${1}" ${ARCH_LIST}
480 print_config_mk HAVE "${1}" ${HAVE_LIST}
481 print_config_mk CONFIG "${1}" ${CONFIG_LIST}
482 print_config_mk HAVE "${1}" gnu_strip
John Koleszar0ea50ce2010-05-18 11:58:33 -0400483
Johann7efb3022014-11-20 18:20:06 -0800484 enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400485
Johann7efb3022014-11-20 18:20:06 -0800486 CC="${saved_CC}"
487 CXX="${saved_CXX}"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400488}
489
John Koleszar0ea50ce2010-05-18 11:58:33 -0400490write_common_target_config_h() {
Johann7efb3022014-11-20 18:20:06 -0800491 print_webm_license ${TMP_H} "/*" " */"
492 cat >> ${TMP_H} << EOF
John Koleszar0ea50ce2010-05-18 11:58:33 -0400493/* This file automatically generated by configure. Do not edit! */
Yaowu Xuf883b422016-08-30 14:01:10 -0700494#ifndef AOM_CONFIG_H
495#define AOM_CONFIG_H
John Koleszar0ea50ce2010-05-18 11:58:33 -0400496#define RESTRICT ${RESTRICT}
Ronald S. Bultjeaac73df2013-02-06 12:45:28 -0800497#define INLINE ${INLINE}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400498EOF
Johann7efb3022014-11-20 18:20:06 -0800499 print_config_h ARCH "${TMP_H}" ${ARCH_LIST}
500 print_config_h HAVE "${TMP_H}" ${HAVE_LIST}
501 print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST}
502 print_config_vars_h "${TMP_H}" ${VAR_LIST}
Yaowu Xuf883b422016-08-30 14:01:10 -0700503 echo "#endif /* AOM_CONFIG_H */" >> ${TMP_H}
Johann7efb3022014-11-20 18:20:06 -0800504 mkdir -p `dirname "$1"`
505 cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400506}
507
508process_common_cmdline() {
Johann7efb3022014-11-20 18:20:06 -0800509 for opt in "$@"; do
510 optval="${opt#*=}"
511 case "$opt" in
512 --child)
513 enable_feature child
John Koleszar0ea50ce2010-05-18 11:58:33 -0400514 ;;
Johann7efb3022014-11-20 18:20:06 -0800515 --log*)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400516 logging="$optval"
517 if ! disabled logging ; then
Johann7efb3022014-11-20 18:20:06 -0800518 enabled logging || logfile="$logging"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400519 else
Johann7efb3022014-11-20 18:20:06 -0800520 logfile=/dev/null
John Koleszar0ea50ce2010-05-18 11:58:33 -0400521 fi
522 ;;
Johann7efb3022014-11-20 18:20:06 -0800523 --target=*)
524 toolchain="${toolchain:-${optval}}"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400525 ;;
Johann7efb3022014-11-20 18:20:06 -0800526 --force-target=*)
527 toolchain="${toolchain:-${optval}}"
528 enable_feature force_toolchain
John Koleszar0ea50ce2010-05-18 11:58:33 -0400529 ;;
Johann7efb3022014-11-20 18:20:06 -0800530 --cpu=*)
531 tune_cpu="$optval"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400532 ;;
Johann7efb3022014-11-20 18:20:06 -0800533 --extra-cflags=*)
Attila Nagy41955322011-01-20 14:46:57 +0200534 extra_cflags="${optval}"
535 ;;
James Zern12355c42015-09-12 10:25:28 -0700536 --extra-cxxflags=*)
537 extra_cxxflags="${optval}"
538 ;;
Johann7efb3022014-11-20 18:20:06 -0800539 --enable-?*|--disable-?*)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400540 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
Johann1de5ba72016-06-17 14:25:23 -0700541 if is_in ${option} ${ARCH_EXT_LIST}; then
Johann7efb3022014-11-20 18:20:06 -0800542 [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${option} "
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700543 elif [ $action = "disable" ] && ! disabled $option ; then
Johann1de5ba72016-06-17 14:25:23 -0700544 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
James Zernef7f33b2015-01-28 20:30:51 -0800545 log_echo " disabling $option"
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700546 elif [ $action = "enable" ] && ! enabled $option ; then
Johann1de5ba72016-06-17 14:25:23 -0700547 is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
James Zernef7f33b2015-01-28 20:30:51 -0800548 log_echo " enabling $option"
Christian Duvivier26c41302012-08-08 17:20:23 -0700549 fi
James Zernccb6bdc2013-08-21 19:00:08 -0700550 ${action}_feature $option
Christian Duvivier707b65b2012-08-08 15:47:36 -0700551 ;;
Johann7efb3022014-11-20 18:20:06 -0800552 --require-?*)
Christian Duvivier707b65b2012-08-08 15:47:36 -0700553 eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
Johann1de5ba72016-06-17 14:25:23 -0700554 if is_in ${option} ${ARCH_EXT_LIST}; then
Christian Duvivier707b65b2012-08-08 15:47:36 -0700555 RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
556 else
557 die_unknown $opt
558 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -0400559 ;;
Johann7efb3022014-11-20 18:20:06 -0800560 --force-enable-?*|--force-disable-?*)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400561 eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'`
James Zernccb6bdc2013-08-21 19:00:08 -0700562 ${action}_feature $option
John Koleszar0ea50ce2010-05-18 11:58:33 -0400563 ;;
Johann7efb3022014-11-20 18:20:06 -0800564 --libc=*)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400565 [ -d "${optval}" ] || die "Not a directory: ${optval}"
James Zern42ab4012013-08-21 18:11:45 -0700566 disable_feature builtin_libc
John Koleszar0ea50ce2010-05-18 11:58:33 -0400567 alt_libc="${optval}"
568 ;;
Johann7efb3022014-11-20 18:20:06 -0800569 --as=*)
James Zern8753f9c2014-07-29 23:25:15 -0700570 [ "${optval}" = yasm ] || [ "${optval}" = nasm ] \
Johann7efb3022014-11-20 18:20:06 -0800571 || [ "${optval}" = auto ] \
572 || die "Must be yasm, nasm or auto: ${optval}"
Jan Kratochvil7be093e2010-10-05 19:15:08 +0200573 alt_as="${optval}"
574 ;;
Johann7efb3022014-11-20 18:20:06 -0800575 --size-limit=*)
Jim Bankoski943e4322014-07-17 06:31:50 -0700576 w="${optval%%x*}"
577 h="${optval##*x}"
578 VAR_LIST="DECODE_WIDTH_LIMIT ${w} DECODE_HEIGHT_LIMIT ${h}"
James Zern8753f9c2014-07-29 23:25:15 -0700579 [ ${w} -gt 0 ] && [ ${h} -gt 0 ] || die "Invalid size-limit: too small."
580 [ ${w} -lt 65536 ] && [ ${h} -lt 65536 ] \
Jim Bankoski943e4322014-07-17 06:31:50 -0700581 || die "Invalid size-limit: too big."
582 enable_feature size_limit
583 ;;
Johann7efb3022014-11-20 18:20:06 -0800584 --prefix=*)
John Koleszar670af3a2010-05-26 15:57:42 -0400585 prefix="${optval}"
586 ;;
Johann7efb3022014-11-20 18:20:06 -0800587 --libdir=*)
John Koleszar670af3a2010-05-26 15:57:42 -0400588 libdir="${optval}"
589 ;;
Johann7efb3022014-11-20 18:20:06 -0800590 --sdk-path=*)
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700591 [ -d "${optval}" ] || die "Not a directory: ${optval}"
592 sdk_path="${optval}"
593 ;;
Johann7efb3022014-11-20 18:20:06 -0800594 --libc|--as|--prefix|--libdir|--sdk-path)
John Koleszar0ea50ce2010-05-18 11:58:33 -0400595 die "Option ${opt} requires argument"
596 ;;
Johann7efb3022014-11-20 18:20:06 -0800597 --help|-h)
598 show_help
John Koleszar0ea50ce2010-05-18 11:58:33 -0400599 ;;
Johann7efb3022014-11-20 18:20:06 -0800600 *)
601 die_unknown $opt
John Koleszar0ea50ce2010-05-18 11:58:33 -0400602 ;;
Johann7efb3022014-11-20 18:20:06 -0800603 esac
604 done
John Koleszar0ea50ce2010-05-18 11:58:33 -0400605}
606
607process_cmdline() {
Johann7efb3022014-11-20 18:20:06 -0800608 for opt do
609 optval="${opt#*=}"
610 case "$opt" in
611 *)
612 process_common_cmdline $opt
John Koleszar0ea50ce2010-05-18 11:58:33 -0400613 ;;
Johann7efb3022014-11-20 18:20:06 -0800614 esac
615 done
John Koleszar0ea50ce2010-05-18 11:58:33 -0400616}
617
John Koleszar670af3a2010-05-26 15:57:42 -0400618post_process_common_cmdline() {
Johann7efb3022014-11-20 18:20:06 -0800619 prefix="${prefix:-/usr/local}"
620 prefix="${prefix%/}"
621 libdir="${libdir:-${prefix}/lib}"
622 libdir="${libdir%/}"
623 if [ "${libdir#${prefix}}" = "${libdir}" ]; then
624 die "Libdir ${libdir} must be a subdirectory of ${prefix}"
625 fi
John Koleszar670af3a2010-05-26 15:57:42 -0400626}
627
John Koleszar0ea50ce2010-05-18 11:58:33 -0400628post_process_cmdline() {
Johann7efb3022014-11-20 18:20:06 -0800629 true;
John Koleszar0ea50ce2010-05-18 11:58:33 -0400630}
631
632setup_gnu_toolchain() {
Johann7efb3022014-11-20 18:20:06 -0800633 CC=${CC:-${CROSS}gcc}
634 CXX=${CXX:-${CROSS}g++}
635 AR=${AR:-${CROSS}ar}
636 LD=${LD:-${CROSS}${link_with_cc:-ld}}
637 AS=${AS:-${CROSS}as}
638 STRIP=${STRIP:-${CROSS}strip}
639 NM=${NM:-${CROSS}nm}
640 AS_SFX=.s
641 EXE_SFX=
John Koleszar0ea50ce2010-05-18 11:58:33 -0400642}
643
Lawrence Velázquezad314c12015-01-23 22:30:23 -0500644# Reliably find the newest available Darwin SDKs. (Older versions of
645# xcrun don't support --show-sdk-path.)
646show_darwin_sdk_path() {
647 xcrun --sdk $1 --show-sdk-path 2>/dev/null ||
648 xcodebuild -sdk $1 -version Path 2>/dev/null
649}
650
Tom Finegan6cf994b2015-09-18 15:58:41 -0700651# Print the major version number of the Darwin SDK specified by $1.
652show_darwin_sdk_major_version() {
653 xcrun --sdk $1 --show-sdk-version 2>/dev/null | cut -d. -f1
654}
655
Tom Fineganbfc75f72016-06-15 14:34:34 -0700656# Print the Xcode version.
657show_xcode_version() {
658 xcodebuild -version | head -n1 | cut -d' ' -f2
659}
660
661# Fails when Xcode version is less than 6.3.
662check_xcode_minimum_version() {
663 xcode_major=$(show_xcode_version | cut -f1 -d.)
664 xcode_minor=$(show_xcode_version | cut -f2 -d.)
665 xcode_min_major=6
666 xcode_min_minor=3
667 if [ ${xcode_major} -lt ${xcode_min_major} ]; then
668 return 1
669 fi
670 if [ ${xcode_major} -eq ${xcode_min_major} ] \
671 && [ ${xcode_minor} -lt ${xcode_min_minor} ]; then
672 return 1
673 fi
674}
675
John Koleszar0ea50ce2010-05-18 11:58:33 -0400676process_common_toolchain() {
James Zern25d9a142017-01-25 18:19:08 -0800677 case "$toolchain" in
678 *-vs*) ;;
679 *) add_cflags_only -std=c99 ;;
680 esac
James Zern8770f082016-12-12 18:48:05 -0800681
Johann7efb3022014-11-20 18:20:06 -0800682 if [ -z "$toolchain" ]; then
683 gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}"
John Koleszar98058bc2010-05-24 12:50:43 -0400684
Johann7efb3022014-11-20 18:20:06 -0800685 # detect tgt_isa
686 case "$gcctarget" in
Martin Storsjo819f3c82016-03-03 12:00:06 +0200687 aarch64*)
688 tgt_isa=arm64
689 ;;
James Zernb524cca2016-01-13 23:16:10 -0800690 armv7*-hardfloat* | armv7*-gnueabihf | arm-*-gnueabihf)
Johann7efb3022014-11-20 18:20:06 -0800691 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 ;;
Johann7efb3022014-11-20 18:20:06 -0800704 *sparc*)
705 tgt_isa=sparc
706 ;;
707 esac
John Koleszar98058bc2010-05-24 12:50:43 -0400708
Johann7efb3022014-11-20 18:20:06 -0800709 # detect tgt_os
710 case "$gcctarget" in
Johann7efb3022014-11-20 18:20:06 -0800711 *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 ;;
Lawrence Velázquez4fe4c282015-01-22 16:46:02 -0500727 *darwin14*)
728 tgt_isa=x86_64
729 tgt_os=darwin14
730 ;;
Alex Converse080ad912015-11-02 14:05:37 -0800731 *darwin15*)
732 tgt_isa=x86_64
733 tgt_os=darwin15
734 ;;
Tom Finegan9d3076c2017-02-03 08:42:34 -0800735 *darwin16*)
736 tgt_isa=x86_64
737 tgt_os=darwin16
738 ;;
Johann7efb3022014-11-20 18:20:06 -0800739 x86_64*mingw32*)
740 tgt_os=win64
741 ;;
742 *mingw32*|*cygwin*)
743 [ -z "$tgt_isa" ] && tgt_isa=x86
744 tgt_os=win32
745 ;;
746 *linux*|*bsd*)
747 tgt_os=linux
748 ;;
749 *solaris2.10)
750 tgt_os=solaris
751 ;;
752 *os2*)
753 tgt_os=os2
754 ;;
755 esac
John Koleszar98058bc2010-05-24 12:50:43 -0400756
Johann7efb3022014-11-20 18:20:06 -0800757 if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then
758 toolchain=${tgt_isa}-${tgt_os}-gcc
John Koleszar98058bc2010-05-24 12:50:43 -0400759 fi
Johann7efb3022014-11-20 18:20:06 -0800760 fi
John Koleszar98058bc2010-05-24 12:50:43 -0400761
Johann7efb3022014-11-20 18:20:06 -0800762 toolchain=${toolchain:-generic-gnu}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400763
Johann7efb3022014-11-20 18:20:06 -0800764 is_in ${toolchain} ${all_platforms} || enabled force_toolchain \
765 || die "Unrecognized toolchain '${toolchain}'"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400766
Johann7efb3022014-11-20 18:20:06 -0800767 enabled child || log_echo "Configuring for target '${toolchain}'"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400768
Johann7efb3022014-11-20 18:20:06 -0800769 #
770 # Set up toolchain variables
771 #
772 tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}')
773 tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}')
774 tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}')
John Koleszar0ea50ce2010-05-18 11:58:33 -0400775
Johann7efb3022014-11-20 18:20:06 -0800776 # Mark the specific ISA requested as enabled
777 soft_enable ${tgt_isa}
778 enable_feature ${tgt_os}
779 enable_feature ${tgt_cc}
John Koleszar0ea50ce2010-05-18 11:58:33 -0400780
Johann7efb3022014-11-20 18:20:06 -0800781 # Enable the architecture family
782 case ${tgt_isa} in
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700783 arm*)
Johann7efb3022014-11-20 18:20:06 -0800784 enable_feature arm
785 ;;
786 mips*)
787 enable_feature mips
788 ;;
789 esac
790
791 # PIC is probably what we want when building shared libs
792 enabled shared && soft_enable pic
793
794 # Minimum iOS version for all target platforms (darwin and iphonesimulator).
Johannb29ebfe2016-06-16 16:35:45 -0700795 # Shared library framework builds are only possible on iOS 8 and later.
Brion Vibber992e4b72016-05-02 12:41:59 -0400796 if enabled shared; then
797 IOS_VERSION_OPTIONS="--enable-shared"
Johannb29ebfe2016-06-16 16:35:45 -0700798 IOS_VERSION_MIN="8.0"
Brion Vibber992e4b72016-05-02 12:41:59 -0400799 else
800 IOS_VERSION_OPTIONS=""
Johannb29ebfe2016-06-16 16:35:45 -0700801 IOS_VERSION_MIN="6.0"
Brion Vibber992e4b72016-05-02 12:41:59 -0400802 fi
Johann7efb3022014-11-20 18:20:06 -0800803
804 # Handle darwin variants. Newer SDKs allow targeting older
Lawrence Velázquezad314c12015-01-23 22:30:23 -0500805 # platforms, so use the newest one available.
Johann7efb3022014-11-20 18:20:06 -0800806 case ${toolchain} in
Tom Finegan6cf994b2015-09-18 15:58:41 -0700807 arm*-darwin*)
Tom Finegan324bcbf2015-09-18 16:01:32 -0700808 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
Tom Finegan6cf994b2015-09-18 15:58:41 -0700809 iphoneos_sdk_dir="$(show_darwin_sdk_path iphoneos)"
810 if [ -d "${iphoneos_sdk_dir}" ]; then
811 add_cflags "-isysroot ${iphoneos_sdk_dir}"
812 add_ldflags "-isysroot ${iphoneos_sdk_dir}"
813 fi
814 ;;
815 x86*-darwin*)
Lawrence Velázquezad314c12015-01-23 22:30:23 -0500816 osx_sdk_dir="$(show_darwin_sdk_path macosx)"
817 if [ -d "${osx_sdk_dir}" ]; then
818 add_cflags "-isysroot ${osx_sdk_dir}"
819 add_ldflags "-isysroot ${osx_sdk_dir}"
Johann7efb3022014-11-20 18:20:06 -0800820 fi
821 ;;
822 esac
823
Johann7efb3022014-11-20 18:20:06 -0800824 case ${toolchain} in
825 *-darwin8-*)
826 add_cflags "-mmacosx-version-min=10.4"
827 add_ldflags "-mmacosx-version-min=10.4"
828 ;;
829 *-darwin9-*)
830 add_cflags "-mmacosx-version-min=10.5"
831 add_ldflags "-mmacosx-version-min=10.5"
832 ;;
833 *-darwin10-*)
834 add_cflags "-mmacosx-version-min=10.6"
835 add_ldflags "-mmacosx-version-min=10.6"
836 ;;
837 *-darwin11-*)
838 add_cflags "-mmacosx-version-min=10.7"
839 add_ldflags "-mmacosx-version-min=10.7"
840 ;;
841 *-darwin12-*)
842 add_cflags "-mmacosx-version-min=10.8"
843 add_ldflags "-mmacosx-version-min=10.8"
844 ;;
845 *-darwin13-*)
846 add_cflags "-mmacosx-version-min=10.9"
847 add_ldflags "-mmacosx-version-min=10.9"
848 ;;
Lawrence Velázquez4fe4c282015-01-22 16:46:02 -0500849 *-darwin14-*)
850 add_cflags "-mmacosx-version-min=10.10"
851 add_ldflags "-mmacosx-version-min=10.10"
852 ;;
Alex Converse080ad912015-11-02 14:05:37 -0800853 *-darwin15-*)
854 add_cflags "-mmacosx-version-min=10.11"
855 add_ldflags "-mmacosx-version-min=10.11"
856 ;;
Tom Finegan9d3076c2017-02-03 08:42:34 -0800857 *-darwin16-*)
858 add_cflags "-mmacosx-version-min=10.12"
859 add_ldflags "-mmacosx-version-min=10.12"
860 ;;
Johann7efb3022014-11-20 18:20:06 -0800861 *-iphonesimulator-*)
862 add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
863 add_ldflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
Lawrence Velázquezad314c12015-01-23 22:30:23 -0500864 iossim_sdk_dir="$(show_darwin_sdk_path iphonesimulator)"
865 if [ -d "${iossim_sdk_dir}" ]; then
866 add_cflags "-isysroot ${iossim_sdk_dir}"
867 add_ldflags "-isysroot ${iossim_sdk_dir}"
868 fi
Johann7efb3022014-11-20 18:20:06 -0800869 ;;
870 esac
871
872 # Handle Solaris variants. Solaris 10 needs -lposix4
873 case ${toolchain} in
874 sparc-solaris-*)
875 add_extralibs -lposix4
Johann7efb3022014-11-20 18:20:06 -0800876 ;;
877 *-solaris-*)
878 add_extralibs -lposix4
879 ;;
880 esac
881
882 # Process ARM architecture variants
883 case ${toolchain} in
884 arm*)
885 # on arm, isa versions are supersets
886 case ${tgt_isa} in
Tom Finegane87d6812014-06-25 18:32:16 -0700887 arm64|armv8)
Johann7efb3022014-11-20 18:20:06 -0800888 soft_enable neon
889 ;;
Tom Finegancd2088b2014-06-10 18:52:58 -0700890 armv7|armv7s)
Johann7efb3022014-11-20 18:20:06 -0800891 soft_enable neon
Johanne5770982014-12-08 15:13:37 -0800892 # Only enable neon_asm when neon is also enabled.
893 enabled neon && soft_enable neon_asm
894 # If someone tries to force it through, die.
895 if disabled neon && enabled neon_asm; then
896 die "Disabling neon while keeping neon-asm is not supported"
897 fi
Johann7efb3022014-11-20 18:20:06 -0800898 esac
John Koleszar0ea50ce2010-05-18 11:58:33 -0400899
Johann7efb3022014-11-20 18:20:06 -0800900 asm_conversion_cmd="cat"
John Koleszar0ea50ce2010-05-18 11:58:33 -0400901
Johann7efb3022014-11-20 18:20:06 -0800902 case ${tgt_cc} in
John Koleszar0ea50ce2010-05-18 11:58:33 -0400903 gcc)
Johann7efb3022014-11-20 18:20:06 -0800904 link_with_cc=gcc
905 setup_gnu_toolchain
906 arch_int=${tgt_isa##armv}
907 arch_int=${arch_int%%te}
908 check_add_asflags --defsym ARCHITECTURE=${arch_int}
909 tune_cflags="-mtune="
910 if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then
911 if [ -z "${float_abi}" ]; then
912 check_cpp <<EOF && float_abi=hard || float_abi=softfp
Martin Storsjo2ce47832013-05-01 23:05:54 +0300913#ifndef __ARM_PCS_VFP
914#error "not hardfp"
915#endif
916EOF
Johann7efb3022014-11-20 18:20:06 -0800917 fi
918 check_add_cflags -march=armv7-a -mfloat-abi=${float_abi}
919 check_add_asflags -march=armv7-a -mfloat-abi=${float_abi}
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700920
Johann7efb3022014-11-20 18:20:06 -0800921 if enabled neon || enabled neon_asm; then
922 check_add_cflags -mfpu=neon #-ftree-vectorize
923 check_add_asflags -mfpu=neon
John Koleszar0ea50ce2010-05-18 11:58:33 -0400924 fi
Johann2967bf32016-06-22 16:08:10 -0700925 elif [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then
926 check_add_cflags -march=armv8-a
927 check_add_asflags -march=armv8-a
Johann7efb3022014-11-20 18:20:06 -0800928 else
929 check_add_cflags -march=${tgt_isa}
930 check_add_asflags -march=${tgt_isa}
931 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -0400932
Johann7efb3022014-11-20 18:20:06 -0800933 enabled debug && add_asflags -g
934 asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
935 if enabled thumb; then
936 asm_conversion_cmd="$asm_conversion_cmd -thumb"
937 check_add_cflags -mthumb
938 check_add_asflags -mthumb -mimplicit-it=always
939 fi
940 ;;
941 vs*)
942 asm_conversion_cmd="${source_path}/build/make/ads2armasm_ms.pl"
943 AS_SFX=.s
944 msvs_arch_dir=arm-msvs
945 disable_feature multithread
946 disable_feature unit_tests
947 vs_version=${tgt_cc##vs}
James Zern56bf1a92016-12-15 17:59:17 -0800948 # MSVC 2013 doesn't allow doing plain .exe projects for ARM,
949 # only "AppContainerApplication" which requires an AppxManifest.
950 # Therefore disable the examples, just build the library.
951 disable_feature examples
Johann7efb3022014-11-20 18:20:06 -0800952 ;;
953 rvct)
954 CC=armcc
955 AR=armar
956 AS=armasm
957 LD="${source_path}/build/make/armlink_adapter.sh"
958 STRIP=arm-none-linux-gnueabi-strip
959 NM=arm-none-linux-gnueabi-nm
960 tune_cflags="--cpu="
961 tune_asflags="--cpu="
962 if [ -z "${tune_cpu}" ]; then
963 if [ ${tgt_isa} = "armv7" ]; then
964 if enabled neon || enabled neon_asm
965 then
966 check_add_cflags --fpu=softvfp+vfpv3
967 check_add_asflags --fpu=softvfp+vfpv3
968 fi
969 check_add_cflags --cpu=Cortex-A8
970 check_add_asflags --cpu=Cortex-A8
971 else
972 check_add_cflags --cpu=${tgt_isa##armv}
973 check_add_asflags --cpu=${tgt_isa##armv}
974 fi
975 fi
976 arch_int=${tgt_isa##armv}
977 arch_int=${arch_int%%te}
978 check_add_asflags --pd "\"ARCHITECTURE SETA ${arch_int}\""
979 enabled debug && add_asflags -g
980 add_cflags --gnu
981 add_cflags --enum_is_int
982 add_cflags --wchar32
983 ;;
984 esac
985
986 case ${tgt_os} in
Tero Rintaluoma11a222f2011-01-24 11:21:40 +0200987 none*)
Johann7efb3022014-11-20 18:20:06 -0800988 disable_feature multithread
989 disable_feature os_support
990 ;;
John Koleszar1d0dc7c2012-11-02 15:17:36 -0700991
992 android*)
Johann2967bf32016-06-22 16:08:10 -0700993 if [ -z "${sdk_path}" ]; then
994 die "Must specify --sdk-path for Android builds."
995 fi
996
Johann7efb3022014-11-20 18:20:06 -0800997 SDK_PATH=${sdk_path}
998 COMPILER_LOCATION=`find "${SDK_PATH}" \
999 -name "arm-linux-androideabi-gcc*" -print -quit`
1000 TOOLCHAIN_PATH=${COMPILER_LOCATION%/*}/arm-linux-androideabi-
1001 CC=${TOOLCHAIN_PATH}gcc
1002 CXX=${TOOLCHAIN_PATH}g++
1003 AR=${TOOLCHAIN_PATH}ar
1004 LD=${TOOLCHAIN_PATH}gcc
1005 AS=${TOOLCHAIN_PATH}as
1006 STRIP=${TOOLCHAIN_PATH}strip
1007 NM=${TOOLCHAIN_PATH}nm
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001008
Johann7efb3022014-11-20 18:20:06 -08001009 if [ -z "${alt_libc}" ]; then
1010 alt_libc=`find "${SDK_PATH}" -name arch-arm -print | \
1011 awk '{n = split($0,a,"/"); \
1012 split(a[n-1],b,"-"); \
1013 print $0 " " b[2]}' | \
1014 sort -g -k 2 | \
1015 awk '{ print $1 }' | tail -1`
1016 fi
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001017
Johanna6f70b42015-10-27 15:38:47 -07001018 if [ -d "${alt_libc}" ]; then
1019 add_cflags "--sysroot=${alt_libc}"
1020 add_ldflags "--sysroot=${alt_libc}"
1021 fi
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001022
Johann7efb3022014-11-20 18:20:06 -08001023 # linker flag that routes around a CPU bug in some
1024 # Cortex-A8 implementations (NDK Dev Guide)
1025 add_ldflags "-Wl,--fix-cortex-a8"
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001026
Johann7efb3022014-11-20 18:20:06 -08001027 enable_feature pic
1028 soft_enable realtime_only
1029 if [ ${tgt_isa} = "armv7" ]; then
1030 soft_enable runtime_cpu_detect
1031 fi
1032 if enabled runtime_cpu_detect; then
1033 add_cflags "-I${SDK_PATH}/sources/android/cpufeatures"
1034 fi
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001035 ;;
1036
John Koleszar0ea50ce2010-05-18 11:58:33 -04001037 darwin*)
Lawrence Velázquezad314c12015-01-23 22:30:23 -05001038 XCRUN_FIND="xcrun --sdk iphoneos --find"
Johann7efb3022014-11-20 18:20:06 -08001039 CXX="$(${XCRUN_FIND} clang++)"
1040 CC="$(${XCRUN_FIND} clang)"
1041 AR="$(${XCRUN_FIND} ar)"
1042 AS="$(${XCRUN_FIND} as)"
1043 STRIP="$(${XCRUN_FIND} strip)"
1044 NM="$(${XCRUN_FIND} nm)"
1045 RANLIB="$(${XCRUN_FIND} ranlib)"
1046 AS_SFX=.s
Tom Fineganb05158d2016-05-02 10:42:00 -07001047 LD="${CXX:-$(${XCRUN_FIND} ld)}"
Tom Finegana5fb9f22014-10-01 13:33:34 -07001048
Johann7efb3022014-11-20 18:20:06 -08001049 # ASFLAGS is written here instead of using check_add_asflags
1050 # because we need to overwrite all of ASFLAGS and purge the
1051 # options that were put in above
1052 ASFLAGS="-arch ${tgt_isa} -g"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001053
Lawrence Velázquezad314c12015-01-23 22:30:23 -05001054 add_cflags -arch ${tgt_isa}
Johann7efb3022014-11-20 18:20:06 -08001055 add_ldflags -arch ${tgt_isa}
Tom Fineganbd2a9bd2014-09-30 20:12:56 -07001056
Lawrence Velázquezad314c12015-01-23 22:30:23 -05001057 alt_libc="$(show_darwin_sdk_path iphoneos)"
1058 if [ -d "${alt_libc}" ]; then
1059 add_cflags -isysroot ${alt_libc}
1060 fi
1061
Johann7efb3022014-11-20 18:20:06 -08001062 if [ "${LD}" = "${CXX}" ]; then
1063 add_ldflags -miphoneos-version-min="${IOS_VERSION_MIN}"
1064 else
1065 add_ldflags -ios_version_min "${IOS_VERSION_MIN}"
1066 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -04001067
Johann7efb3022014-11-20 18:20:06 -08001068 for d in lib usr/lib usr/lib/system; do
1069 try_dir="${alt_libc}/${d}"
1070 [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}"
1071 done
John Koleszar0ea50ce2010-05-18 11:58:33 -04001072
Tom Fineganbfc75f72016-06-15 14:34:34 -07001073 case ${tgt_isa} in
1074 armv7|armv7s|armv8|arm64)
1075 if enabled neon && ! check_xcode_minimum_version; then
1076 soft_disable neon
1077 log_echo " neon disabled: upgrade Xcode (need v6.3+)."
1078 if enabled neon_asm; then
1079 soft_disable neon_asm
1080 log_echo " neon_asm disabled: upgrade Xcode (need v6.3+)."
1081 fi
1082 fi
1083 ;;
1084 esac
1085
Johann7efb3022014-11-20 18:20:06 -08001086 asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl"
Tom Finegan9194f3c2015-09-24 14:55:51 -07001087
1088 if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then
1089 check_add_cflags -fembed-bitcode
1090 check_add_asflags -fembed-bitcode
1091 check_add_ldflags -fembed-bitcode
1092 fi
Johann7efb3022014-11-20 18:20:06 -08001093 ;;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001094
1095 linux*)
Johann7efb3022014-11-20 18:20:06 -08001096 enable_feature linux
1097 if enabled rvct; then
1098 # Check if we have CodeSourcery GCC in PATH. Needed for
1099 # libraries
James Zernbe660f82016-04-29 19:48:51 -07001100 which arm-none-linux-gnueabi-gcc 2>&- || \
Johann7efb3022014-11-20 18:20:06 -08001101 die "Couldn't find CodeSourcery GCC from PATH"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001102
Johann7efb3022014-11-20 18:20:06 -08001103 # Use armcc as a linker to enable translation of
1104 # some gcc specific options such as -lm and -lpthread.
1105 LD="armcc --translate_gcc"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001106
Johann7efb3022014-11-20 18:20:06 -08001107 # create configuration file (uses path to CodeSourcery GCC)
1108 armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg
John Koleszar0ea50ce2010-05-18 11:58:33 -04001109
Johann7efb3022014-11-20 18:20:06 -08001110 add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1111 add_asflags --no_hide_all --apcs=/interwork
1112 add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
1113 enabled pic && add_cflags --apcs=/fpic
1114 enabled pic && add_asflags --apcs=/fpic
1115 enabled shared && add_cflags --shared
1116 fi
1117 ;;
1118 esac
1119 ;;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001120 mips*)
Johann7efb3022014-11-20 18:20:06 -08001121 link_with_cc=gcc
1122 setup_gnu_toolchain
1123 tune_cflags="-mtune="
1124 if enabled dspr2; then
1125 check_add_cflags -mips32r2 -mdspr2
Johann7efb3022014-11-20 18:20:06 -08001126 fi
Parag Salasakar84ec68d2015-03-16 12:36:59 +05301127
Parag Salasakar4009b632015-04-13 14:13:07 +05301128 if enabled runtime_cpu_detect; then
1129 disable_feature runtime_cpu_detect
1130 fi
1131
Parag Salasakar84ec68d2015-03-16 12:36:59 +05301132 if [ -n "${tune_cpu}" ]; then
1133 case ${tune_cpu} in
1134 p5600)
Johann2967bf32016-06-22 16:08:10 -07001135 check_add_cflags -mips32r5 -mload-store-pairs
Parag Salasakar4009b632015-04-13 14:13:07 +05301136 check_add_cflags -msched-weight -mhard-float -mfp64
1137 check_add_asflags -mips32r5 -mhard-float -mfp64
1138 check_add_ldflags -mfp64
Parag Salasakar84ec68d2015-03-16 12:36:59 +05301139 ;;
Johann2967bf32016-06-22 16:08:10 -07001140 i6400|p6600)
1141 check_add_cflags -mips64r6 -mabi=64 -msched-weight
Parag Salasakar4009b632015-04-13 14:13:07 +05301142 check_add_cflags -mload-store-pairs -mhard-float -mfp64
1143 check_add_asflags -mips64r6 -mabi=64 -mhard-float -mfp64
1144 check_add_ldflags -mips64r6 -mabi=64 -mfp64
Parag Salasakar84ec68d2015-03-16 12:36:59 +05301145 ;;
1146 esac
1147
1148 if enabled msa; then
Parag Salasakar4009b632015-04-13 14:13:07 +05301149 add_cflags -mmsa
1150 add_asflags -mmsa
1151 add_ldflags -mmsa
Parag Salasakar84ec68d2015-03-16 12:36:59 +05301152 fi
1153 fi
1154
Johann7efb3022014-11-20 18:20:06 -08001155 check_add_cflags -march=${tgt_isa}
1156 check_add_asflags -march=${tgt_isa}
1157 check_add_asflags -KPIC
1158 ;;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001159 x86*)
Johann7efb3022014-11-20 18:20:06 -08001160 case ${tgt_os} in
1161 win*)
1162 enabled gcc && add_cflags -fno-common
1163 ;;
1164 solaris*)
1165 CC=${CC:-${CROSS}gcc}
1166 CXX=${CXX:-${CROSS}g++}
1167 LD=${LD:-${CROSS}gcc}
James Zern47a17182015-12-21 22:09:52 -08001168 CROSS=${CROSS-g}
Johann7efb3022014-11-20 18:20:06 -08001169 ;;
1170 os2)
KO Myung-Hun8a6f0552015-08-30 15:17:40 +09001171 disable_feature pic
Johann7efb3022014-11-20 18:20:06 -08001172 AS=${AS:-nasm}
KO Myung-Hune909da82015-08-30 16:27:58 +09001173 add_ldflags -Zhigh-mem
Johann7efb3022014-11-20 18:20:06 -08001174 ;;
1175 esac
John Koleszar0ea50ce2010-05-18 11:58:33 -04001176
Johann7efb3022014-11-20 18:20:06 -08001177 AS="${alt_as:-${AS:-auto}}"
1178 case ${tgt_cc} in
1179 icc*)
1180 CC=${CC:-icc}
1181 LD=${LD:-icc}
1182 setup_gnu_toolchain
1183 add_cflags -use-msasm # remove -use-msasm too?
1184 # add -no-intel-extensions to suppress warning #10237
1185 # refer to http://software.intel.com/en-us/forums/topic/280199
1186 add_ldflags -i-static -no-intel-extensions
1187 enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div
1188 enabled x86_64 && AR=xiar
1189 case ${tune_cpu} in
1190 atom*)
1191 tune_cflags="-x"
1192 tune_cpu="SSE3_ATOM"
1193 ;;
1194 *)
1195 tune_cflags="-march="
1196 ;;
1197 esac
1198 ;;
1199 gcc*)
1200 link_with_cc=gcc
1201 tune_cflags="-march="
1202 setup_gnu_toolchain
1203 #for 32 bit x86 builds, -O3 did not turn on this flag
1204 enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer
1205 ;;
1206 vs*)
1207 # When building with Microsoft Visual Studio the assembler is
1208 # invoked directly. Checking at configure time is unnecessary.
1209 # Skip the check by setting AS arbitrarily
1210 AS=msvs
1211 msvs_arch_dir=x86-msvs
1212 vc_version=${tgt_cc##vs}
Johann7efb3022014-11-20 18:20:06 -08001213 ;;
1214 esac
John Koleszar0ea50ce2010-05-18 11:58:33 -04001215
Johann7efb3022014-11-20 18:20:06 -08001216 bits=32
1217 enabled x86_64 && bits=64
1218 check_cpp <<EOF && bits=x32
Dim Temp134384d2014-12-03 22:06:46 +01001219#if !defined(__ILP32__) || !defined(__x86_64__)
James Zern8bf4c432014-06-27 15:33:39 -07001220#error "not x32"
1221#endif
1222EOF
Johann7efb3022014-11-20 18:20:06 -08001223 case ${tgt_cc} in
1224 gcc*)
1225 add_cflags -m${bits}
1226 add_ldflags -m${bits}
1227 ;;
1228 esac
James Zern8bf4c432014-06-27 15:33:39 -07001229
Johann7efb3022014-11-20 18:20:06 -08001230 soft_enable runtime_cpu_detect
1231 # We can't use 'check_cflags' until the compiler is configured and CC is
1232 # populated.
James Zern6e6dbbc2015-11-17 16:14:05 -08001233 for ext in ${ARCH_EXT_LIST_X86}; do
1234 # disable higher order extensions to simplify asm dependencies
1235 if [ "$disable_exts" = "yes" ]; then
1236 if ! disabled $ext; then
1237 RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} "
1238 disable_feature $ext
1239 fi
1240 elif disabled $ext; then
1241 disable_exts="yes"
1242 else
1243 # use the shortened version for the flag: sse4_1 -> sse4
1244 check_gcc_machine_option ${ext%_*} $ext
1245 fi
1246 done
Erik Niemeyere6863ef2013-10-29 09:48:12 -06001247
Johann12f26bf2015-10-26 16:40:17 -07001248 if enabled external_build; then
1249 log_echo " skipping assembler detection"
1250 else
1251 case "${AS}" in
1252 auto|"")
1253 which nasm >/dev/null 2>&1 && AS=nasm
1254 which yasm >/dev/null 2>&1 && AS=yasm
1255 if [ "${AS}" = nasm ] ; then
1256 # Apple ships version 0.98 of nasm through at least Xcode 6. Revisit
1257 # this check if they start shipping a compatible version.
1258 apple=`nasm -v | grep "Apple"`
1259 [ -n "${apple}" ] \
1260 && echo "Unsupported version of nasm: ${apple}" \
1261 && AS=""
1262 fi
1263 [ "${AS}" = auto ] || [ -z "${AS}" ] \
1264 && die "Neither yasm nor nasm have been found." \
1265 "See the prerequisites section in the README for more info."
1266 ;;
1267 esac
1268 log_echo " using $AS"
1269 fi
Johann7efb3022014-11-20 18:20:06 -08001270 AS_SFX=.asm
1271 case ${tgt_os} in
1272 win32)
1273 add_asflags -f win32
1274 enabled debug && add_asflags -g cv8
1275 EXE_SFX=.exe
1276 ;;
1277 win64)
Johann02869c22017-12-04 08:50:09 -08001278 add_asflags -f win64
Johann7efb3022014-11-20 18:20:06 -08001279 enabled debug && add_asflags -g cv8
1280 EXE_SFX=.exe
1281 ;;
1282 linux*|solaris*|android*)
1283 add_asflags -f elf${bits}
1284 enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
1285 enabled debug && [ "${AS}" = nasm ] && add_asflags -g
1286 [ "${AS##*/}" = nasm ] && check_asm_align
1287 ;;
1288 darwin*)
1289 add_asflags -f macho${bits}
1290 enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64"
1291 add_cflags ${darwin_arch}
1292 add_ldflags ${darwin_arch}
1293 # -mdynamic-no-pic is still a bit of voodoo -- it was required at
1294 # one time, but does not seem to be now, and it breaks some of the
1295 # code that still relies on inline assembly.
1296 # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic
1297 enabled icc && ! enabled pic && add_cflags -fno-pic
1298 ;;
1299 iphonesimulator)
1300 add_asflags -f macho${bits}
1301 enabled x86 && sim_arch="-arch i386" || sim_arch="-arch x86_64"
1302 add_cflags ${sim_arch}
1303 add_ldflags ${sim_arch}
Tom Finegan9194f3c2015-09-24 14:55:51 -07001304
1305 if [ "$(show_darwin_sdk_major_version iphonesimulator)" -gt 8 ]; then
1306 # yasm v1.3.0 doesn't know what -fembed-bitcode means, so turning it
1307 # on is pointless (unless building a C-only lib). Warn the user, but
1308 # do nothing here.
1309 log "Warning: Bitcode embed disabled for simulator targets."
1310 fi
Johann7efb3022014-11-20 18:20:06 -08001311 ;;
1312 os2)
1313 add_asflags -f aout
1314 enabled debug && add_asflags -g
1315 EXE_SFX=.exe
1316 ;;
1317 *)
1318 log "Warning: Unknown os $tgt_os while setting up $AS flags"
1319 ;;
1320 esac
1321 ;;
Tom Finegan3d7063d2015-05-12 15:33:40 -07001322 *-gcc|generic-gnu)
Johann7efb3022014-11-20 18:20:06 -08001323 link_with_cc=gcc
1324 enable_feature gcc
1325 setup_gnu_toolchain
1326 ;;
1327 esac
John Koleszar0ea50ce2010-05-18 11:58:33 -04001328
Johann7efb3022014-11-20 18:20:06 -08001329 # Try to enable CPU specific tuning
1330 if [ -n "${tune_cpu}" ]; then
1331 if [ -n "${tune_cflags}" ]; then
1332 check_add_cflags ${tune_cflags}${tune_cpu} || \
1333 die "Requested CPU '${tune_cpu}' not supported by compiler"
1334 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -04001335 if [ -n "${tune_asflags}" ]; then
Johann7efb3022014-11-20 18:20:06 -08001336 check_add_asflags ${tune_asflags}${tune_cpu} || \
1337 die "Requested CPU '${tune_cpu}' not supported by assembler"
1338 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -04001339 if [ -z "${tune_cflags}${tune_asflags}" ]; then
Johann7efb3022014-11-20 18:20:06 -08001340 log_echo "Warning: CPU tuning not supported by this toolchain"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001341 fi
Johann7efb3022014-11-20 18:20:06 -08001342 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -04001343
Johann7efb3022014-11-20 18:20:06 -08001344 if enabled debug; then
1345 check_add_cflags -g && check_add_ldflags -g
1346 else
1347 check_add_cflags -DNDEBUG
1348 fi
1349
1350 enabled gprof && check_add_cflags -pg && check_add_ldflags -pg
1351 enabled gcov &&
1352 check_add_cflags -fprofile-arcs -ftest-coverage &&
1353 check_add_ldflags -fprofile-arcs -ftest-coverage
1354
1355 if enabled optimizations; then
1356 if enabled rvct; then
1357 enabled small && check_add_cflags -Ospace || check_add_cflags -Otime
Yunqing Wang765485c2014-07-15 16:18:34 -07001358 else
Johann7efb3022014-11-20 18:20:06 -08001359 enabled small && check_add_cflags -O2 || check_add_cflags -O3
Yunqing Wang765485c2014-07-15 16:18:34 -07001360 fi
Johann7efb3022014-11-20 18:20:06 -08001361 fi
Yunqing Wang765485c2014-07-15 16:18:34 -07001362
Johann7efb3022014-11-20 18:20:06 -08001363 # Position Independent Code (PIC) support, for building relocatable
1364 # shared objects
1365 enabled gcc && enabled pic && check_add_cflags -fPIC
John Koleszar0ea50ce2010-05-18 11:58:33 -04001366
Johann7efb3022014-11-20 18:20:06 -08001367 # Work around longjmp interception on glibc >= 2.11, to improve binary
1368 # compatibility. See http://code.google.com/p/webm/issues/detail?id=166
1369 enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
Jim Bankoskia93b1152013-08-05 17:28:52 -07001370
Johann7efb3022014-11-20 18:20:06 -08001371 # Check for strip utility variant
1372 ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip
John Koleszar0ea50ce2010-05-18 11:58:33 -04001373
Johann7efb3022014-11-20 18:20:06 -08001374 # Try to determine target endianness
1375 check_cc <<EOF
1376unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E';
John Koleszar0ea50ce2010-05-18 11:58:33 -04001377EOF
1378 [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' |
James Zern42ab4012013-08-21 18:11:45 -07001379 grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian
John Koleszar0ea50ce2010-05-18 11:58:33 -04001380
Ronald S. Bultjeaac73df2013-02-06 12:45:28 -08001381 # Try to find which inline keywords are supported
1382 check_cc <<EOF && INLINE="inline"
Johann7efb3022014-11-20 18:20:06 -08001383static inline function() {}
Ronald S. Bultjeaac73df2013-02-06 12:45:28 -08001384EOF
Ronald S. Bultjeaac73df2013-02-06 12:45:28 -08001385
Johann7efb3022014-11-20 18:20:06 -08001386 # Almost every platform uses pthreads.
1387 if enabled multithread; then
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001388 case ${toolchain} in
Johann7efb3022014-11-20 18:20:06 -08001389 *-win*-vs*)
1390 ;;
1391 *-android-gcc)
1392 ;;
1393 *)
1394 check_header pthread.h && add_extralibs -lpthread
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001395 ;;
1396 esac
Johann7efb3022014-11-20 18:20:06 -08001397 fi
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001398
Johann7efb3022014-11-20 18:20:06 -08001399 # only for MIPS platforms
1400 case ${toolchain} in
1401 mips*)
Parag Salasakar4009b632015-04-13 14:13:07 +05301402 if enabled big_endian; then
1403 if enabled dspr2; then
Johann7efb3022014-11-20 18:20:06 -08001404 echo "dspr2 optimizations are available only for little endian platforms"
1405 disable_feature dspr2
1406 fi
Parag Salasakar4009b632015-04-13 14:13:07 +05301407 if enabled msa; then
1408 echo "msa optimizations are available only for little endian platforms"
1409 disable_feature msa
1410 fi
Johann7efb3022014-11-20 18:20:06 -08001411 fi
1412 ;;
1413 esac
Attila Nagy41955322011-01-20 14:46:57 +02001414
Johann7efb3022014-11-20 18:20:06 -08001415 # glibc needs these
James Zernb6430362017-01-14 14:18:01 -08001416 if enabled linux || [ "$toolchain" = "generic-gnu" ]; then
Johann7efb3022014-11-20 18:20:06 -08001417 add_cflags -D_LARGEFILE_SOURCE
1418 add_cflags -D_FILE_OFFSET_BITS=64
1419 fi
John Koleszar0ea50ce2010-05-18 11:58:33 -04001420}
1421
1422process_toolchain() {
Johann7efb3022014-11-20 18:20:06 -08001423 process_common_toolchain
John Koleszar0ea50ce2010-05-18 11:58:33 -04001424}
1425
1426print_config_mk() {
Johann7efb3022014-11-20 18:20:06 -08001427 saved_prefix="${prefix}"
1428 prefix=$1
1429 makefile=$2
1430 shift 2
1431 for cfg; do
1432 if enabled $cfg; then
1433 upname="`toupper $cfg`"
1434 echo "${prefix}_${upname}=yes" >> $makefile
1435 fi
1436 done
1437 prefix="${saved_prefix}"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001438}
1439
1440print_config_h() {
Johann7efb3022014-11-20 18:20:06 -08001441 saved_prefix="${prefix}"
1442 prefix=$1
1443 header=$2
1444 shift 2
1445 for cfg; do
1446 upname="`toupper $cfg`"
1447 if enabled $cfg; then
1448 echo "#define ${prefix}_${upname} 1" >> $header
1449 else
1450 echo "#define ${prefix}_${upname} 0" >> $header
1451 fi
1452 done
1453 prefix="${saved_prefix}"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001454}
1455
Jim Bankoski943e4322014-07-17 06:31:50 -07001456print_config_vars_h() {
Johann7efb3022014-11-20 18:20:06 -08001457 header=$1
1458 shift
1459 while [ $# -gt 0 ]; do
1460 upname="`toupper $1`"
1461 echo "#define ${upname} $2" >> $header
1462 shift 2
1463 done
Jim Bankoski943e4322014-07-17 06:31:50 -07001464}
1465
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001466print_webm_license() {
Johann7efb3022014-11-20 18:20:06 -08001467 saved_prefix="${prefix}"
1468 destination=$1
1469 prefix="$2"
1470 suffix="$3"
1471 shift 3
1472 cat <<EOF > ${destination}
Yaowu Xu42c58342016-11-28 16:04:57 -08001473${prefix} Copyright (c) 2016, Alliance for Open Media. All rights reserved.${suffix}
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001474${prefix} ${suffix}
Yaowu Xu42c58342016-11-28 16:04:57 -08001475${prefix} This source code is subject to the terms of the BSD 2 Clause License and${suffix}
1476${prefix} the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License${suffix}
1477${prefix} was not distributed with this source code in the LICENSE file, you can${suffix}
1478${prefix} obtain it at www.aomedia.org/license/software. If the Alliance for Open${suffix}
1479${prefix} Media Patent License 1.0 was not distributed with this source code in the${suffix}
1480${prefix} PATENTS file, you can obtain it at www.aomedia.org/license/patent.${suffix}
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001481EOF
Johann7efb3022014-11-20 18:20:06 -08001482 prefix="${saved_prefix}"
John Koleszar1d0dc7c2012-11-02 15:17:36 -07001483}
1484
John Koleszar0ea50ce2010-05-18 11:58:33 -04001485process_targets() {
Johann7efb3022014-11-20 18:20:06 -08001486 true;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001487}
1488
1489process_detect() {
Johann7efb3022014-11-20 18:20:06 -08001490 true;
John Koleszar0ea50ce2010-05-18 11:58:33 -04001491}
1492
James Zern42ab4012013-08-21 18:11:45 -07001493enable_feature logging
James Zerne636af12013-07-18 14:17:00 -07001494logfile="config.log"
John Koleszar0ea50ce2010-05-18 11:58:33 -04001495self=$0
1496process() {
Johann7efb3022014-11-20 18:20:06 -08001497 cmdline_args="$@"
1498 process_cmdline "$@"
1499 if enabled child; then
1500 echo "# ${self} $@" >> ${logfile}
1501 else
1502 echo "# ${self} $@" > ${logfile}
1503 fi
1504 post_process_common_cmdline
1505 post_process_cmdline
1506 process_toolchain
1507 process_detect
1508 process_targets
John Koleszar0ea50ce2010-05-18 11:58:33 -04001509
Johann7efb3022014-11-20 18:20:06 -08001510 OOT_INSTALLS="${OOT_INSTALLS}"
1511 if enabled source_path_used; then
1512 # Prepare the PWD for building.
1513 for f in ${OOT_INSTALLS}; do
1514 install -D "${source_path}/$f" "$f"
1515 done
1516 fi
1517 cp "${source_path}/build/make/Makefile" .
John Koleszar0ea50ce2010-05-18 11:58:33 -04001518
Johann7efb3022014-11-20 18:20:06 -08001519 clean_temp_files
1520 true
John Koleszar0ea50ce2010-05-18 11:58:33 -04001521}