configure.sh 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. #!/bin/sh
  2. ##
  3. ## configure.sh
  4. ##
  5. ## This script is sourced by the main configure script and contains
  6. ## utility functions and other common bits that aren't strictly libvpx
  7. ## related.
  8. ##
  9. ## This build system is based in part on the FFmpeg configure script.
  10. ##
  11. #
  12. # Logging / Output Functions
  13. #
  14. die_unknown(){
  15. echo "Unknown option \"$1\"."
  16. echo "See $0 --help for available options."
  17. clean_temp_files
  18. exit 1
  19. }
  20. die() {
  21. echo "$@"
  22. echo
  23. echo "Configuration failed. This could reflect a misconfiguration of your"
  24. echo "toolchains, improper options selected, or another problem. If you"
  25. echo "don't see any useful error messages above, the next step is to look"
  26. echo "at the configure error log file ($logfile) to determine what"
  27. echo "configure was trying to do when it died."
  28. clean_temp_files
  29. exit 1
  30. }
  31. log(){
  32. echo "$@" >>$logfile
  33. }
  34. log_file(){
  35. log BEGIN $1
  36. cat -n $1 >>$logfile
  37. log END $1
  38. }
  39. log_echo() {
  40. echo "$@"
  41. log "$@"
  42. }
  43. fwrite () {
  44. outfile=$1
  45. shift
  46. echo "$@" >> ${outfile}
  47. }
  48. show_help_pre(){
  49. for opt in ${CMDLINE_SELECT}; do
  50. opt2=`echo $opt | sed -e 's;_;-;g'`
  51. if enabled $opt; then
  52. eval "toggle_${opt}=\"--disable-${opt2}\""
  53. else
  54. eval "toggle_${opt}=\"--enable-${opt2} \""
  55. fi
  56. done
  57. cat <<EOF
  58. Usage: configure [options]
  59. Options:
  60. Build options:
  61. --help print this message
  62. --log=yes|no|FILE file configure log is written to [config.log]
  63. --target=TARGET target platform tuple [generic-gnu]
  64. --cpu=CPU optimize for a specific cpu rather than a family
  65. --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS]
  66. --extra-cxxflags=ECXXFLAGS add ECXXFLAGS to CXXFLAGS [$CXXFLAGS]
  67. ${toggle_extra_warnings} emit harmless warnings (always non-fatal)
  68. ${toggle_werror} treat warnings as errors, if possible
  69. (not available with all compilers)
  70. ${toggle_optimizations} turn on/off compiler optimization flags
  71. ${toggle_pic} turn on/off Position Independent Code
  72. ${toggle_ccache} turn on/off compiler cache
  73. ${toggle_debug} enable/disable debug mode
  74. ${toggle_gprof} enable/disable gprof profiling instrumentation
  75. ${toggle_gcov} enable/disable gcov coverage instrumentation
  76. ${toggle_thumb} enable/disable building arm assembly in thumb mode
  77. ${toggle_dependency_tracking}
  78. disable to speed up one-time build
  79. Install options:
  80. ${toggle_install_docs} control whether docs are installed
  81. ${toggle_install_bins} control whether binaries are installed
  82. ${toggle_install_libs} control whether libraries are installed
  83. ${toggle_install_srcs} control whether sources are installed
  84. EOF
  85. }
  86. show_help_post(){
  87. cat <<EOF
  88. NOTES:
  89. Object files are built at the place where configure is launched.
  90. All boolean options can be negated. The default value is the opposite
  91. of that shown above. If the option --disable-foo is listed, then
  92. the default value for foo is enabled.
  93. Supported targets:
  94. EOF
  95. show_targets ${all_platforms}
  96. echo
  97. exit 1
  98. }
  99. show_targets() {
  100. while [ -n "$*" ]; do
  101. if [ "${1%%-*}" = "${2%%-*}" ]; then
  102. if [ "${2%%-*}" = "${3%%-*}" ]; then
  103. printf " %-24s %-24s %-24s\n" "$1" "$2" "$3"
  104. shift; shift; shift
  105. else
  106. printf " %-24s %-24s\n" "$1" "$2"
  107. shift; shift
  108. fi
  109. else
  110. printf " %-24s\n" "$1"
  111. shift
  112. fi
  113. done
  114. }
  115. show_help() {
  116. show_help_pre
  117. show_help_post
  118. }
  119. #
  120. # List Processing Functions
  121. #
  122. set_all(){
  123. value=$1
  124. shift
  125. for var in $*; do
  126. eval $var=$value
  127. done
  128. }
  129. is_in(){
  130. value=$1
  131. shift
  132. for var in $*; do
  133. [ $var = $value ] && return 0
  134. done
  135. return 1
  136. }
  137. add_cflags() {
  138. CFLAGS="${CFLAGS} $@"
  139. CXXFLAGS="${CXXFLAGS} $@"
  140. }
  141. add_cflags_only() {
  142. CFLAGS="${CFLAGS} $@"
  143. }
  144. add_cxxflags_only() {
  145. CXXFLAGS="${CXXFLAGS} $@"
  146. }
  147. add_ldflags() {
  148. LDFLAGS="${LDFLAGS} $@"
  149. }
  150. add_asflags() {
  151. ASFLAGS="${ASFLAGS} $@"
  152. }
  153. add_extralibs() {
  154. extralibs="${extralibs} $@"
  155. }
  156. #
  157. # Boolean Manipulation Functions
  158. #
  159. enable_feature(){
  160. set_all yes $*
  161. }
  162. disable_feature(){
  163. set_all no $*
  164. }
  165. enabled(){
  166. eval test "x\$$1" = "xyes"
  167. }
  168. disabled(){
  169. eval test "x\$$1" = "xno"
  170. }
  171. enable_codec(){
  172. enabled "${1}" || echo " enabling ${1}"
  173. enable_feature "${1}"
  174. is_in "${1}" vp8 vp9 && enable_feature "${1}_encoder" "${1}_decoder"
  175. }
  176. disable_codec(){
  177. disabled "${1}" || echo " disabling ${1}"
  178. disable_feature "${1}"
  179. is_in "${1}" vp8 vp9 && disable_feature "${1}_encoder" "${1}_decoder"
  180. }
  181. # Iterates through positional parameters, checks to confirm the parameter has
  182. # not been explicitly (force) disabled, and enables the setting controlled by
  183. # the parameter when the setting is not disabled.
  184. # Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
  185. soft_enable() {
  186. for var in $*; do
  187. if ! disabled $var; then
  188. enabled $var || log_echo " enabling $var"
  189. enable_feature $var
  190. fi
  191. done
  192. }
  193. # Iterates through positional parameters, checks to confirm the parameter has
  194. # not been explicitly (force) enabled, and disables the setting controlled by
  195. # the parameter when the setting is not enabled.
  196. # Note: Does NOT alter RTCD generation options ($RTCD_OPTIONS).
  197. soft_disable() {
  198. for var in $*; do
  199. if ! enabled $var; then
  200. disabled $var || log_echo " disabling $var"
  201. disable_feature $var
  202. fi
  203. done
  204. }
  205. #
  206. # Text Processing Functions
  207. #
  208. toupper(){
  209. echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
  210. }
  211. tolower(){
  212. echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
  213. }
  214. #
  215. # Temporary File Functions
  216. #
  217. source_path=${0%/*}
  218. enable_feature source_path_used
  219. if [ -z "$source_path" ] || [ "$source_path" = "." ]; then
  220. source_path="`pwd`"
  221. disable_feature source_path_used
  222. fi
  223. if test ! -z "$TMPDIR" ; then
  224. TMPDIRx="${TMPDIR}"
  225. elif test ! -z "$TEMPDIR" ; then
  226. TMPDIRx="${TEMPDIR}"
  227. else
  228. TMPDIRx="/tmp"
  229. fi
  230. RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}')
  231. TMP_H="${TMPDIRx}/vpx-conf-$$-${RAND}.h"
  232. TMP_C="${TMPDIRx}/vpx-conf-$$-${RAND}.c"
  233. TMP_CC="${TMPDIRx}/vpx-conf-$$-${RAND}.cc"
  234. TMP_O="${TMPDIRx}/vpx-conf-$$-${RAND}.o"
  235. TMP_X="${TMPDIRx}/vpx-conf-$$-${RAND}.x"
  236. TMP_ASM="${TMPDIRx}/vpx-conf-$$-${RAND}.asm"
  237. clean_temp_files() {
  238. rm -f ${TMP_C} ${TMP_CC} ${TMP_H} ${TMP_O} ${TMP_X} ${TMP_ASM}
  239. enabled gcov && rm -f ${TMP_C%.c}.gcno ${TMP_CC%.cc}.gcno
  240. }
  241. #
  242. # Toolchain Check Functions
  243. #
  244. check_cmd() {
  245. enabled external_build && return
  246. log "$@"
  247. "$@" >>${logfile} 2>&1
  248. }
  249. check_cc() {
  250. log check_cc "$@"
  251. cat >${TMP_C}
  252. log_file ${TMP_C}
  253. check_cmd ${CC} ${CFLAGS} "$@" -c -o ${TMP_O} ${TMP_C}
  254. }
  255. check_cxx() {
  256. log check_cxx "$@"
  257. cat >${TMP_CC}
  258. log_file ${TMP_CC}
  259. check_cmd ${CXX} ${CXXFLAGS} "$@" -c -o ${TMP_O} ${TMP_CC}
  260. }
  261. check_cpp() {
  262. log check_cpp "$@"
  263. cat > ${TMP_C}
  264. log_file ${TMP_C}
  265. check_cmd ${CC} ${CFLAGS} "$@" -E -o ${TMP_O} ${TMP_C}
  266. }
  267. check_ld() {
  268. log check_ld "$@"
  269. check_cc $@ \
  270. && check_cmd ${LD} ${LDFLAGS} "$@" -o ${TMP_X} ${TMP_O} ${extralibs}
  271. }
  272. check_lib() {
  273. log check_lib "$@"
  274. check_cc $@ \
  275. && check_cmd ${LD} ${LDFLAGS} -o ${TMP_X} ${TMP_O} "$@" ${extralibs}
  276. }
  277. check_header(){
  278. log check_header "$@"
  279. header=$1
  280. shift
  281. var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
  282. disable_feature $var
  283. check_cpp "$@" <<EOF && enable_feature $var
  284. #include "$header"
  285. int x;
  286. EOF
  287. }
  288. check_cflags() {
  289. log check_cflags "$@"
  290. check_cc -Werror "$@" <<EOF
  291. int x;
  292. EOF
  293. }
  294. check_cxxflags() {
  295. log check_cxxflags "$@"
  296. # Catch CFLAGS that trigger CXX warnings
  297. case "$CXX" in
  298. *c++-analyzer|*clang++|*g++*)
  299. check_cxx -Werror "$@" <<EOF
  300. int x;
  301. EOF
  302. ;;
  303. *)
  304. check_cxx -Werror "$@" <<EOF
  305. int x;
  306. EOF
  307. ;;
  308. esac
  309. }
  310. check_add_cflags() {
  311. check_cxxflags "$@" && add_cxxflags_only "$@"
  312. check_cflags "$@" && add_cflags_only "$@"
  313. }
  314. check_add_cxxflags() {
  315. check_cxxflags "$@" && add_cxxflags_only "$@"
  316. }
  317. check_add_asflags() {
  318. log add_asflags "$@"
  319. add_asflags "$@"
  320. }
  321. check_add_ldflags() {
  322. log add_ldflags "$@"
  323. add_ldflags "$@"
  324. }
  325. check_asm_align() {
  326. log check_asm_align "$@"
  327. cat >${TMP_ASM} <<EOF
  328. section .rodata
  329. align 16
  330. EOF
  331. log_file ${TMP_ASM}
  332. check_cmd ${AS} ${ASFLAGS} -o ${TMP_O} ${TMP_ASM}
  333. readelf -WS ${TMP_O} >${TMP_X}
  334. log_file ${TMP_X}
  335. if ! grep -q '\.rodata .* 16$' ${TMP_X}; then
  336. die "${AS} ${ASFLAGS} does not support section alignment (nasm <=2.08?)"
  337. fi
  338. }
  339. # tests for -m$1 toggling the feature given in $2. If $2 is empty $1 is used.
  340. check_gcc_machine_option() {
  341. opt="$1"
  342. feature="$2"
  343. [ -n "$feature" ] || feature="$opt"
  344. if enabled gcc && ! disabled "$feature" && ! check_cflags "-m$opt"; then
  345. RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature "
  346. else
  347. soft_enable "$feature"
  348. fi
  349. }
  350. # tests for -m$2, -m$3, -m$4... toggling the feature given in $1.
  351. check_gcc_machine_options() {
  352. feature="$1"
  353. shift
  354. flags="-m$1"
  355. shift
  356. for opt in $*; do
  357. flags="$flags -m$opt"
  358. done
  359. if enabled gcc && ! disabled "$feature" && ! check_cflags $flags; then
  360. RTCD_OPTIONS="${RTCD_OPTIONS}--disable-$feature "
  361. else
  362. soft_enable "$feature"
  363. fi
  364. }
  365. check_gcc_avx512_compiles() {
  366. if disabled gcc; then
  367. return
  368. fi
  369. check_cc -mavx512f <<EOF
  370. #include <immintrin.h>
  371. void f(void) {
  372. __m512i x = _mm512_set1_epi16(0);
  373. (void)x;
  374. }
  375. EOF
  376. compile_result=$?
  377. if [ ${compile_result} -ne 0 ]; then
  378. log_echo " disabling avx512: not supported by compiler"
  379. disable_feature avx512
  380. RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 "
  381. fi
  382. }
  383. write_common_config_banner() {
  384. print_webm_license config.mk "##" ""
  385. echo '# This file automatically generated by configure. Do not edit!' >> config.mk
  386. echo "TOOLCHAIN := ${toolchain}" >> config.mk
  387. case ${toolchain} in
  388. *-linux-rvct)
  389. echo "ALT_LIBC := ${alt_libc}" >> config.mk
  390. ;;
  391. esac
  392. }
  393. write_common_config_targets() {
  394. for t in ${all_targets}; do
  395. if enabled ${t}; then
  396. if enabled child; then
  397. fwrite config.mk "ALL_TARGETS += ${t}-${toolchain}"
  398. else
  399. fwrite config.mk "ALL_TARGETS += ${t}"
  400. fi
  401. fi
  402. true;
  403. done
  404. true
  405. }
  406. write_common_target_config_mk() {
  407. saved_CC="${CC}"
  408. saved_CXX="${CXX}"
  409. enabled ccache && CC="ccache ${CC}"
  410. enabled ccache && CXX="ccache ${CXX}"
  411. print_webm_license $1 "##" ""
  412. cat >> $1 << EOF
  413. # This file automatically generated by configure. Do not edit!
  414. SRC_PATH="$source_path"
  415. SRC_PATH_BARE=$source_path
  416. BUILD_PFX=${BUILD_PFX}
  417. TOOLCHAIN=${toolchain}
  418. ASM_CONVERSION=${asm_conversion_cmd:-${source_path}/build/make/ads2gas.pl}
  419. GEN_VCPROJ=${gen_vcproj_cmd}
  420. MSVS_ARCH_DIR=${msvs_arch_dir}
  421. CC=${CC}
  422. CXX=${CXX}
  423. AR=${AR}
  424. LD=${LD}
  425. AS=${AS}
  426. STRIP=${STRIP}
  427. NM=${NM}
  428. CFLAGS = ${CFLAGS}
  429. CXXFLAGS = ${CXXFLAGS}
  430. ARFLAGS = -crs\$(if \$(quiet),,v)
  431. LDFLAGS = ${LDFLAGS}
  432. ASFLAGS = ${ASFLAGS}
  433. extralibs = ${extralibs}
  434. AS_SFX = ${AS_SFX:-.asm}
  435. EXE_SFX = ${EXE_SFX}
  436. VCPROJ_SFX = ${VCPROJ_SFX}
  437. RTCD_OPTIONS = ${RTCD_OPTIONS}
  438. LIBYUV_CXXFLAGS = ${LIBYUV_CXXFLAGS}
  439. EOF
  440. if enabled rvct; then cat >> $1 << EOF
  441. fmt_deps = sed -e 's;^__image.axf;\${@:.d=.o} \$@;' #hide
  442. EOF
  443. else cat >> $1 << EOF
  444. fmt_deps = sed -e 's;^\([a-zA-Z0-9_]*\)\.o;\${@:.d=.o} \$@;'
  445. EOF
  446. fi
  447. print_config_mk ARCH "${1}" ${ARCH_LIST}
  448. print_config_mk HAVE "${1}" ${HAVE_LIST}
  449. print_config_mk CONFIG "${1}" ${CONFIG_LIST}
  450. print_config_mk HAVE "${1}" gnu_strip
  451. enabled msvs && echo "CONFIG_VS_VERSION=${vs_version}" >> "${1}"
  452. CC="${saved_CC}"
  453. CXX="${saved_CXX}"
  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. #define INLINE ${INLINE}
  463. EOF
  464. print_config_h ARCH "${TMP_H}" ${ARCH_LIST}
  465. print_config_h HAVE "${TMP_H}" ${HAVE_LIST}
  466. print_config_h CONFIG "${TMP_H}" ${CONFIG_LIST}
  467. print_config_vars_h "${TMP_H}" ${VAR_LIST}
  468. echo "#endif /* VPX_CONFIG_H */" >> ${TMP_H}
  469. mkdir -p `dirname "$1"`
  470. cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1"
  471. }
  472. write_win_arm64_neon_h_workaround() {
  473. print_webm_license ${TMP_H} "/*" " */"
  474. cat >> ${TMP_H} << EOF
  475. /* This file automatically generated by configure. Do not edit! */
  476. #ifndef VPX_WIN_ARM_NEON_H_WORKAROUND
  477. #define VPX_WIN_ARM_NEON_H_WORKAROUND
  478. /* The Windows SDK has arm_neon.h, but unlike on other platforms it is
  479. * ARM32-only. ARM64 NEON support is provided by arm64_neon.h, a proper
  480. * superset of arm_neon.h. Work around this by providing a more local
  481. * arm_neon.h that simply #includes arm64_neon.h.
  482. */
  483. #include <arm64_neon.h>
  484. #endif /* VPX_WIN_ARM_NEON_H_WORKAROUND */
  485. EOF
  486. mkdir -p `dirname "$1"`
  487. cmp "$1" ${TMP_H} >/dev/null 2>&1 || mv ${TMP_H} "$1"
  488. }
  489. process_common_cmdline() {
  490. for opt in "$@"; do
  491. optval="${opt#*=}"
  492. case "$opt" in
  493. --child)
  494. enable_feature child
  495. ;;
  496. --log*)
  497. logging="$optval"
  498. if ! disabled logging ; then
  499. enabled logging || logfile="$logging"
  500. else
  501. logfile=/dev/null
  502. fi
  503. ;;
  504. --target=*)
  505. toolchain="${toolchain:-${optval}}"
  506. ;;
  507. --force-target=*)
  508. toolchain="${toolchain:-${optval}}"
  509. enable_feature force_toolchain
  510. ;;
  511. --cpu=*)
  512. tune_cpu="$optval"
  513. ;;
  514. --extra-cflags=*)
  515. extra_cflags="${optval}"
  516. ;;
  517. --extra-cxxflags=*)
  518. extra_cxxflags="${optval}"
  519. ;;
  520. --enable-?*|--disable-?*)
  521. eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
  522. if is_in ${option} ${ARCH_EXT_LIST}; then
  523. [ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${option} "
  524. elif [ $action = "disable" ] && ! disabled $option ; then
  525. is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
  526. log_echo " disabling $option"
  527. elif [ $action = "enable" ] && ! enabled $option ; then
  528. is_in ${option} ${CMDLINE_SELECT} || die_unknown $opt
  529. log_echo " enabling $option"
  530. fi
  531. ${action}_feature $option
  532. ;;
  533. --require-?*)
  534. eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
  535. if is_in ${option} ${ARCH_EXT_LIST}; then
  536. RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
  537. else
  538. die_unknown $opt
  539. fi
  540. ;;
  541. --force-enable-?*|--force-disable-?*)
  542. eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'`
  543. ${action}_feature $option
  544. ;;
  545. --libc=*)
  546. [ -d "${optval}" ] || die "Not a directory: ${optval}"
  547. disable_feature builtin_libc
  548. alt_libc="${optval}"
  549. ;;
  550. --as=*)
  551. [ "${optval}" = yasm ] || [ "${optval}" = nasm ] \
  552. || [ "${optval}" = auto ] \
  553. || die "Must be yasm, nasm or auto: ${optval}"
  554. alt_as="${optval}"
  555. ;;
  556. --size-limit=*)
  557. w="${optval%%x*}"
  558. h="${optval##*x}"
  559. VAR_LIST="DECODE_WIDTH_LIMIT ${w} DECODE_HEIGHT_LIMIT ${h}"
  560. [ ${w} -gt 0 ] && [ ${h} -gt 0 ] || die "Invalid size-limit: too small."
  561. [ ${w} -lt 65536 ] && [ ${h} -lt 65536 ] \
  562. || die "Invalid size-limit: too big."
  563. enable_feature size_limit
  564. ;;
  565. --prefix=*)
  566. prefix="${optval}"
  567. ;;
  568. --libdir=*)
  569. libdir="${optval}"
  570. ;;
  571. --libc|--as|--prefix|--libdir)
  572. die "Option ${opt} requires argument"
  573. ;;
  574. --help|-h)
  575. show_help
  576. ;;
  577. *)
  578. die_unknown $opt
  579. ;;
  580. esac
  581. done
  582. }
  583. process_cmdline() {
  584. for opt do
  585. optval="${opt#*=}"
  586. case "$opt" in
  587. *)
  588. process_common_cmdline $opt
  589. ;;
  590. esac
  591. done
  592. }
  593. post_process_common_cmdline() {
  594. prefix="${prefix:-/usr/local}"
  595. prefix="${prefix%/}"
  596. libdir="${libdir:-${prefix}/lib}"
  597. libdir="${libdir%/}"
  598. if [ "${libdir#${prefix}}" = "${libdir}" ]; then
  599. die "Libdir ${libdir} must be a subdirectory of ${prefix}"
  600. fi
  601. }
  602. post_process_cmdline() {
  603. true;
  604. }
  605. setup_gnu_toolchain() {
  606. CC=${CC:-${CROSS}gcc}
  607. CXX=${CXX:-${CROSS}g++}
  608. AR=${AR:-${CROSS}ar}
  609. LD=${LD:-${CROSS}${link_with_cc:-ld}}
  610. AS=${AS:-${CROSS}as}
  611. STRIP=${STRIP:-${CROSS}strip}
  612. NM=${NM:-${CROSS}nm}
  613. AS_SFX=.S
  614. EXE_SFX=
  615. }
  616. # Reliably find the newest available Darwin SDKs. (Older versions of
  617. # xcrun don't support --show-sdk-path.)
  618. show_darwin_sdk_path() {
  619. xcrun --sdk $1 --show-sdk-path 2>/dev/null ||
  620. xcodebuild -sdk $1 -version Path 2>/dev/null
  621. }
  622. # Print the major version number of the Darwin SDK specified by $1.
  623. show_darwin_sdk_major_version() {
  624. xcrun --sdk $1 --show-sdk-version 2>/dev/null | cut -d. -f1
  625. }
  626. # Print the Xcode version.
  627. show_xcode_version() {
  628. xcodebuild -version | head -n1 | cut -d' ' -f2
  629. }
  630. # Fails when Xcode version is less than 6.3.
  631. check_xcode_minimum_version() {
  632. xcode_major=$(show_xcode_version | cut -f1 -d.)
  633. xcode_minor=$(show_xcode_version | cut -f2 -d.)
  634. xcode_min_major=6
  635. xcode_min_minor=3
  636. if [ ${xcode_major} -lt ${xcode_min_major} ]; then
  637. return 1
  638. fi
  639. if [ ${xcode_major} -eq ${xcode_min_major} ] \
  640. && [ ${xcode_minor} -lt ${xcode_min_minor} ]; then
  641. return 1
  642. fi
  643. }
  644. process_common_toolchain() {
  645. if [ -z "$toolchain" ]; then
  646. gcctarget="${CHOST:-$(gcc -dumpmachine 2> /dev/null)}"
  647. # detect tgt_isa
  648. case "$gcctarget" in
  649. aarch64*)
  650. tgt_isa=arm64
  651. ;;
  652. armv7*-hardfloat* | armv7*-gnueabihf | arm-*-gnueabihf)
  653. tgt_isa=armv7
  654. float_abi=hard
  655. ;;
  656. armv7*)
  657. tgt_isa=armv7
  658. float_abi=softfp
  659. ;;
  660. *x86_64*|*amd64*)
  661. tgt_isa=x86_64
  662. ;;
  663. *i[3456]86*)
  664. tgt_isa=x86
  665. ;;
  666. *sparc*)
  667. tgt_isa=sparc
  668. ;;
  669. power*64le*-*)
  670. tgt_isa=ppc64le
  671. ;;
  672. *mips64el*)
  673. tgt_isa=mips64
  674. ;;
  675. *mips32el*)
  676. tgt_isa=mips32
  677. ;;
  678. esac
  679. # detect tgt_os
  680. case "$gcctarget" in
  681. *darwin*)
  682. tgt_isa=x86_64
  683. tgt_os=darwin
  684. ;;
  685. x86_64*mingw32*)
  686. tgt_os=win64
  687. ;;
  688. x86_64*cygwin*)
  689. tgt_os=win64
  690. ;;
  691. *mingw32*|*cygwin*)
  692. [ -z "$tgt_isa" ] && tgt_isa=x86
  693. tgt_os=win32
  694. ;;
  695. *linux*|*bsd*)
  696. tgt_os=linux
  697. ;;
  698. *solaris2.10)
  699. tgt_os=solaris
  700. ;;
  701. *os2*)
  702. tgt_os=os2
  703. ;;
  704. esac
  705. if [ -n "$tgt_isa" ] && [ -n "$tgt_os" ]; then
  706. toolchain=${tgt_isa}-${tgt_os}-gcc
  707. fi
  708. fi
  709. toolchain=${toolchain:-generic-gnu}
  710. is_in ${toolchain} ${all_platforms} || enabled force_toolchain \
  711. || die "Unrecognized toolchain '${toolchain}'"
  712. enabled child || log_echo "Configuring for target '${toolchain}'"
  713. #
  714. # Set up toolchain variables
  715. #
  716. tgt_isa=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $1}')
  717. tgt_os=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $2}')
  718. tgt_cc=$(echo ${toolchain} | awk 'BEGIN{FS="-"}{print $3}')
  719. # Mark the specific ISA requested as enabled
  720. soft_enable ${tgt_isa}
  721. enable_feature ${tgt_os}
  722. enable_feature ${tgt_cc}
  723. # Enable the architecture family
  724. case ${tgt_isa} in
  725. arm*)
  726. enable_feature arm
  727. ;;
  728. mips*)
  729. enable_feature mips
  730. ;;
  731. ppc*)
  732. enable_feature ppc
  733. ;;
  734. esac
  735. # PIC is probably what we want when building shared libs
  736. enabled shared && soft_enable pic
  737. # Minimum iOS version for all target platforms (darwin and iphonesimulator).
  738. # Shared library framework builds are only possible on iOS 8 and later.
  739. if enabled shared; then
  740. IOS_VERSION_OPTIONS="--enable-shared"
  741. IOS_VERSION_MIN="8.0"
  742. else
  743. IOS_VERSION_OPTIONS=""
  744. IOS_VERSION_MIN="7.0"
  745. fi
  746. # Handle darwin variants. Newer SDKs allow targeting older
  747. # platforms, so use the newest one available.
  748. case ${toolchain} in
  749. arm*-darwin*)
  750. add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
  751. iphoneos_sdk_dir="$(show_darwin_sdk_path iphoneos)"
  752. if [ -d "${iphoneos_sdk_dir}" ]; then
  753. add_cflags "-isysroot ${iphoneos_sdk_dir}"
  754. add_ldflags "-isysroot ${iphoneos_sdk_dir}"
  755. fi
  756. ;;
  757. x86*-darwin*)
  758. osx_sdk_dir="$(show_darwin_sdk_path macosx)"
  759. if [ -d "${osx_sdk_dir}" ]; then
  760. add_cflags "-isysroot ${osx_sdk_dir}"
  761. add_ldflags "-isysroot ${osx_sdk_dir}"
  762. fi
  763. ;;
  764. esac
  765. case ${toolchain} in
  766. *-darwin-*)
  767. mvmin=$(sw_vers -productVersion)
  768. if [[ $mvmin == 10.* ]]; then
  769. mvmin="-mmacosx-version-min=""${mvmin%.*}"
  770. else
  771. mvmin="-mmacosx-version-min=""${mvmin%%.*}"
  772. fi
  773. add_cflags $mvmin
  774. add_ldflags $mvmin
  775. ;;
  776. *-iphonesimulator-*)
  777. add_cflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
  778. add_ldflags "-miphoneos-version-min=${IOS_VERSION_MIN}"
  779. iossim_sdk_dir="$(show_darwin_sdk_path iphonesimulator)"
  780. if [ -d "${iossim_sdk_dir}" ]; then
  781. add_cflags "-isysroot ${iossim_sdk_dir}"
  782. add_ldflags "-isysroot ${iossim_sdk_dir}"
  783. fi
  784. ;;
  785. esac
  786. # Handle Solaris variants. Solaris 10 needs -lposix4
  787. case ${toolchain} in
  788. sparc-solaris-*)
  789. add_extralibs -lposix4
  790. ;;
  791. *-solaris-*)
  792. add_extralibs -lposix4
  793. ;;
  794. esac
  795. # Process ARM architecture variants
  796. case ${toolchain} in
  797. arm*)
  798. # on arm, isa versions are supersets
  799. case ${tgt_isa} in
  800. arm64|armv8)
  801. soft_enable neon
  802. ;;
  803. armv7|armv7s)
  804. soft_enable neon
  805. # Only enable neon_asm when neon is also enabled.
  806. enabled neon && soft_enable neon_asm
  807. # If someone tries to force it through, die.
  808. if disabled neon && enabled neon_asm; then
  809. die "Disabling neon while keeping neon-asm is not supported"
  810. fi
  811. ;;
  812. esac
  813. asm_conversion_cmd="cat"
  814. case ${tgt_cc} in
  815. gcc)
  816. link_with_cc=gcc
  817. setup_gnu_toolchain
  818. arch_int=${tgt_isa##armv}
  819. arch_int=${arch_int%%te}
  820. tune_cflags="-mtune="
  821. if [ ${tgt_isa} = "armv7" ] || [ ${tgt_isa} = "armv7s" ]; then
  822. if [ -z "${float_abi}" ]; then
  823. check_cpp <<EOF && float_abi=hard || float_abi=softfp
  824. #ifndef __ARM_PCS_VFP
  825. #error "not hardfp"
  826. #endif
  827. EOF
  828. fi
  829. check_add_cflags -march=armv7-a -mfloat-abi=${float_abi}
  830. check_add_asflags -march=armv7-a -mfloat-abi=${float_abi}
  831. if enabled neon || enabled neon_asm; then
  832. check_add_cflags -mfpu=neon #-ftree-vectorize
  833. check_add_asflags -mfpu=neon
  834. fi
  835. elif [ ${tgt_isa} = "arm64" ] || [ ${tgt_isa} = "armv8" ]; then
  836. check_add_cflags -march=armv8-a
  837. check_add_asflags -march=armv8-a
  838. else
  839. check_add_cflags -march=${tgt_isa}
  840. check_add_asflags -march=${tgt_isa}
  841. fi
  842. enabled debug && add_asflags -g
  843. asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
  844. case ${tgt_os} in
  845. win*)
  846. asm_conversion_cmd="$asm_conversion_cmd -noelf"
  847. AS="$CC -c"
  848. EXE_SFX=.exe
  849. enable_feature thumb
  850. ;;
  851. esac
  852. if enabled thumb; then
  853. asm_conversion_cmd="$asm_conversion_cmd -thumb"
  854. check_add_cflags -mthumb
  855. check_add_asflags -mthumb -mimplicit-it=always
  856. fi
  857. ;;
  858. vs*)
  859. # A number of ARM-based Windows platforms are constrained by their
  860. # respective SDKs' limitations. Fortunately, these are all 32-bit ABIs
  861. # and so can be selected as 'win32'.
  862. if [ ${tgt_os} = "win32" ]; then
  863. asm_conversion_cmd="${source_path}/build/make/ads2armasm_ms.pl"
  864. AS_SFX=.S
  865. msvs_arch_dir=arm-msvs
  866. disable_feature multithread
  867. disable_feature unit_tests
  868. if [ ${tgt_cc##vs} -ge 12 ]; then
  869. # MSVC 2013 doesn't allow doing plain .exe projects for ARM32,
  870. # only "AppContainerApplication" which requires an AppxManifest.
  871. # Therefore disable the examples, just build the library.
  872. disable_feature examples
  873. disable_feature tools
  874. fi
  875. else
  876. # Windows 10 on ARM, on the other hand, has full Windows SDK support
  877. # for building Win32 ARM64 applications in addition to ARM64
  878. # Windows Store apps. It is the only 64-bit ARM ABI that
  879. # Windows supports, so it is the default definition of 'win64'.
  880. # ARM64 build support officially shipped in Visual Studio 15.9.0.
  881. # Because the ARM64 Windows SDK's arm_neon.h is ARM32-specific
  882. # while LLVM's is not, probe its validity.
  883. if enabled neon; then
  884. if [ -n "${CC}" ]; then
  885. check_header arm_neon.h || check_header arm64_neon.h && \
  886. enable_feature win_arm64_neon_h_workaround
  887. else
  888. # If a probe is not possible, assume this is the pure Windows
  889. # SDK and so the workaround is necessary.
  890. enable_feature win_arm64_neon_h_workaround
  891. fi
  892. fi
  893. fi
  894. ;;
  895. rvct)
  896. CC=armcc
  897. AR=armar
  898. AS=armasm
  899. LD="${source_path}/build/make/armlink_adapter.sh"
  900. STRIP=arm-none-linux-gnueabi-strip
  901. NM=arm-none-linux-gnueabi-nm
  902. tune_cflags="--cpu="
  903. tune_asflags="--cpu="
  904. if [ -z "${tune_cpu}" ]; then
  905. if [ ${tgt_isa} = "armv7" ]; then
  906. if enabled neon || enabled neon_asm
  907. then
  908. check_add_cflags --fpu=softvfp+vfpv3
  909. check_add_asflags --fpu=softvfp+vfpv3
  910. fi
  911. check_add_cflags --cpu=Cortex-A8
  912. check_add_asflags --cpu=Cortex-A8
  913. else
  914. check_add_cflags --cpu=${tgt_isa##armv}
  915. check_add_asflags --cpu=${tgt_isa##armv}
  916. fi
  917. fi
  918. arch_int=${tgt_isa##armv}
  919. arch_int=${arch_int%%te}
  920. enabled debug && add_asflags -g
  921. add_cflags --gnu
  922. add_cflags --enum_is_int
  923. add_cflags --wchar32
  924. ;;
  925. esac
  926. case ${tgt_os} in
  927. none*)
  928. disable_feature multithread
  929. disable_feature os_support
  930. ;;
  931. android*)
  932. echo "Assuming standalone build with NDK toolchain."
  933. echo "See build/make/Android.mk for details."
  934. check_add_ldflags -static
  935. soft_enable unit_tests
  936. ;;
  937. darwin*)
  938. XCRUN_FIND="xcrun --sdk iphoneos --find"
  939. CXX="$(${XCRUN_FIND} clang++)"
  940. CC="$(${XCRUN_FIND} clang)"
  941. AR="$(${XCRUN_FIND} ar)"
  942. AS="$(${XCRUN_FIND} as)"
  943. STRIP="$(${XCRUN_FIND} strip)"
  944. NM="$(${XCRUN_FIND} nm)"
  945. RANLIB="$(${XCRUN_FIND} ranlib)"
  946. AS_SFX=.S
  947. LD="${CXX:-$(${XCRUN_FIND} ld)}"
  948. # ASFLAGS is written here instead of using check_add_asflags
  949. # because we need to overwrite all of ASFLAGS and purge the
  950. # options that were put in above
  951. ASFLAGS="-arch ${tgt_isa} -g"
  952. add_cflags -arch ${tgt_isa}
  953. add_ldflags -arch ${tgt_isa}
  954. alt_libc="$(show_darwin_sdk_path iphoneos)"
  955. if [ -d "${alt_libc}" ]; then
  956. add_cflags -isysroot ${alt_libc}
  957. fi
  958. if [ "${LD}" = "${CXX}" ]; then
  959. add_ldflags -miphoneos-version-min="${IOS_VERSION_MIN}"
  960. else
  961. add_ldflags -ios_version_min "${IOS_VERSION_MIN}"
  962. fi
  963. for d in lib usr/lib usr/lib/system; do
  964. try_dir="${alt_libc}/${d}"
  965. [ -d "${try_dir}" ] && add_ldflags -L"${try_dir}"
  966. done
  967. case ${tgt_isa} in
  968. armv7|armv7s|armv8|arm64)
  969. if enabled neon && ! check_xcode_minimum_version; then
  970. soft_disable neon
  971. log_echo " neon disabled: upgrade Xcode (need v6.3+)."
  972. if enabled neon_asm; then
  973. soft_disable neon_asm
  974. log_echo " neon_asm disabled: upgrade Xcode (need v6.3+)."
  975. fi
  976. fi
  977. ;;
  978. esac
  979. asm_conversion_cmd="${source_path}/build/make/ads2gas_apple.pl"
  980. if [ "$(show_darwin_sdk_major_version iphoneos)" -gt 8 ]; then
  981. check_add_cflags -fembed-bitcode
  982. check_add_asflags -fembed-bitcode
  983. check_add_ldflags -fembed-bitcode
  984. fi
  985. ;;
  986. linux*)
  987. enable_feature linux
  988. if enabled rvct; then
  989. # Check if we have CodeSourcery GCC in PATH. Needed for
  990. # libraries
  991. which arm-none-linux-gnueabi-gcc 2>&- || \
  992. die "Couldn't find CodeSourcery GCC from PATH"
  993. # Use armcc as a linker to enable translation of
  994. # some gcc specific options such as -lm and -lpthread.
  995. LD="armcc --translate_gcc"
  996. # create configuration file (uses path to CodeSourcery GCC)
  997. armcc --arm_linux_configure --arm_linux_config_file=arm_linux.cfg
  998. add_cflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
  999. add_asflags --no_hide_all --apcs=/interwork
  1000. add_ldflags --arm_linux_paths --arm_linux_config_file=arm_linux.cfg
  1001. enabled pic && add_cflags --apcs=/fpic
  1002. enabled pic && add_asflags --apcs=/fpic
  1003. enabled shared && add_cflags --shared
  1004. fi
  1005. ;;
  1006. esac
  1007. ;;
  1008. mips*)
  1009. link_with_cc=gcc
  1010. setup_gnu_toolchain
  1011. tune_cflags="-mtune="
  1012. if enabled dspr2; then
  1013. check_add_cflags -mips32r2 -mdspr2
  1014. fi
  1015. if enabled runtime_cpu_detect; then
  1016. disable_feature runtime_cpu_detect
  1017. fi
  1018. if [ -n "${tune_cpu}" ]; then
  1019. case ${tune_cpu} in
  1020. p5600)
  1021. check_add_cflags -mips32r5 -mload-store-pairs
  1022. check_add_cflags -msched-weight -mhard-float -mfp64
  1023. check_add_asflags -mips32r5 -mhard-float -mfp64
  1024. check_add_ldflags -mfp64
  1025. ;;
  1026. i6400|p6600)
  1027. check_add_cflags -mips64r6 -mabi=64 -msched-weight
  1028. check_add_cflags -mload-store-pairs -mhard-float -mfp64
  1029. check_add_asflags -mips64r6 -mabi=64 -mhard-float -mfp64
  1030. check_add_ldflags -mips64r6 -mabi=64 -mfp64
  1031. ;;
  1032. esac
  1033. if enabled msa; then
  1034. # TODO(libyuv:793)
  1035. # The new mips functions in libyuv do not build
  1036. # with the toolchains we currently use for testing.
  1037. soft_disable libyuv
  1038. add_cflags -mmsa
  1039. add_asflags -mmsa
  1040. add_ldflags -mmsa
  1041. fi
  1042. fi
  1043. if enabled mmi; then
  1044. tgt_isa=loongson3a
  1045. check_add_ldflags -march=loongson3a
  1046. fi
  1047. check_add_cflags -march=${tgt_isa}
  1048. check_add_asflags -march=${tgt_isa}
  1049. check_add_asflags -KPIC
  1050. ;;
  1051. ppc64le*)
  1052. link_with_cc=gcc
  1053. setup_gnu_toolchain
  1054. # Do not enable vsx by default.
  1055. # https://bugs.chromium.org/p/webm/issues/detail?id=1522
  1056. enabled vsx || RTCD_OPTIONS="${RTCD_OPTIONS}--disable-vsx "
  1057. if [ -n "${tune_cpu}" ]; then
  1058. case ${tune_cpu} in
  1059. power?)
  1060. tune_cflags="-mcpu="
  1061. ;;
  1062. esac
  1063. fi
  1064. ;;
  1065. x86*)
  1066. case ${tgt_os} in
  1067. android)
  1068. soft_enable realtime_only
  1069. ;;
  1070. win*)
  1071. enabled gcc && add_cflags -fno-common
  1072. ;;
  1073. solaris*)
  1074. CC=${CC:-${CROSS}gcc}
  1075. CXX=${CXX:-${CROSS}g++}
  1076. LD=${LD:-${CROSS}gcc}
  1077. CROSS=${CROSS-g}
  1078. ;;
  1079. os2)
  1080. disable_feature pic
  1081. AS=${AS:-nasm}
  1082. add_ldflags -Zhigh-mem
  1083. ;;
  1084. esac
  1085. AS="${alt_as:-${AS:-auto}}"
  1086. case ${tgt_cc} in
  1087. icc*)
  1088. CC=${CC:-icc}
  1089. LD=${LD:-icc}
  1090. setup_gnu_toolchain
  1091. add_cflags -use-msasm # remove -use-msasm too?
  1092. # add -no-intel-extensions to suppress warning #10237
  1093. # refer to http://software.intel.com/en-us/forums/topic/280199
  1094. add_ldflags -i-static -no-intel-extensions
  1095. enabled x86_64 && add_cflags -ipo -static -O3 -no-prec-div
  1096. enabled x86_64 && AR=xiar
  1097. case ${tune_cpu} in
  1098. atom*)
  1099. tune_cflags="-x"
  1100. tune_cpu="SSE3_ATOM"
  1101. ;;
  1102. *)
  1103. tune_cflags="-march="
  1104. ;;
  1105. esac
  1106. ;;
  1107. gcc*)
  1108. link_with_cc=gcc
  1109. tune_cflags="-march="
  1110. setup_gnu_toolchain
  1111. #for 32 bit x86 builds, -O3 did not turn on this flag
  1112. enabled optimizations && disabled gprof && check_add_cflags -fomit-frame-pointer
  1113. ;;
  1114. vs*)
  1115. # When building with Microsoft Visual Studio the assembler is
  1116. # invoked directly. Checking at configure time is unnecessary.
  1117. # Skip the check by setting AS arbitrarily
  1118. AS=msvs
  1119. msvs_arch_dir=x86-msvs
  1120. case ${tgt_cc##vs} in
  1121. 14)
  1122. echo "${tgt_cc} does not support avx512, disabling....."
  1123. RTCD_OPTIONS="${RTCD_OPTIONS}--disable-avx512 "
  1124. soft_disable avx512
  1125. ;;
  1126. esac
  1127. ;;
  1128. esac
  1129. bits=32
  1130. enabled x86_64 && bits=64
  1131. check_cpp <<EOF && bits=x32
  1132. #if !defined(__ILP32__) || !defined(__x86_64__)
  1133. #error "not x32"
  1134. #endif
  1135. EOF
  1136. case ${tgt_cc} in
  1137. gcc*)
  1138. add_cflags -m${bits}
  1139. add_ldflags -m${bits}
  1140. ;;
  1141. esac
  1142. soft_enable runtime_cpu_detect
  1143. # We can't use 'check_cflags' until the compiler is configured and CC is
  1144. # populated.
  1145. for ext in ${ARCH_EXT_LIST_X86}; do
  1146. # disable higher order extensions to simplify asm dependencies
  1147. if [ "$disable_exts" = "yes" ]; then
  1148. if ! disabled $ext; then
  1149. RTCD_OPTIONS="${RTCD_OPTIONS}--disable-${ext} "
  1150. disable_feature $ext
  1151. fi
  1152. elif disabled $ext; then
  1153. disable_exts="yes"
  1154. else
  1155. if [ "$ext" = "avx512" ]; then
  1156. check_gcc_machine_options $ext avx512f avx512cd avx512bw avx512dq avx512vl
  1157. check_gcc_avx512_compiles
  1158. else
  1159. # use the shortened version for the flag: sse4_1 -> sse4
  1160. check_gcc_machine_option ${ext%_*} $ext
  1161. fi
  1162. fi
  1163. done
  1164. if enabled external_build; then
  1165. log_echo " skipping assembler detection"
  1166. else
  1167. case "${AS}" in
  1168. auto|"")
  1169. which nasm >/dev/null 2>&1 && AS=nasm
  1170. which yasm >/dev/null 2>&1 && AS=yasm
  1171. if [ "${AS}" = nasm ] ; then
  1172. # Apple ships version 0.98 of nasm through at least Xcode 6. Revisit
  1173. # this check if they start shipping a compatible version.
  1174. apple=`nasm -v | grep "Apple"`
  1175. [ -n "${apple}" ] \
  1176. && echo "Unsupported version of nasm: ${apple}" \
  1177. && AS=""
  1178. fi
  1179. [ "${AS}" = auto ] || [ -z "${AS}" ] \
  1180. && die "Neither yasm nor nasm have been found." \
  1181. "See the prerequisites section in the README for more info."
  1182. ;;
  1183. esac
  1184. log_echo " using $AS"
  1185. fi
  1186. AS_SFX=.asm
  1187. case ${tgt_os} in
  1188. win32)
  1189. add_asflags -f win32
  1190. enabled debug && add_asflags -g cv8
  1191. EXE_SFX=.exe
  1192. ;;
  1193. win64)
  1194. add_asflags -f win64
  1195. enabled debug && add_asflags -g cv8
  1196. EXE_SFX=.exe
  1197. ;;
  1198. linux*|solaris*|android*)
  1199. add_asflags -f elf${bits}
  1200. enabled debug && [ "${AS}" = yasm ] && add_asflags -g dwarf2
  1201. enabled debug && [ "${AS}" = nasm ] && add_asflags -g
  1202. [ "${AS##*/}" = nasm ] && check_asm_align
  1203. ;;
  1204. darwin*)
  1205. add_asflags -f macho${bits}
  1206. enabled x86 && darwin_arch="-arch i386" || darwin_arch="-arch x86_64"
  1207. add_cflags ${darwin_arch}
  1208. add_ldflags ${darwin_arch}
  1209. # -mdynamic-no-pic is still a bit of voodoo -- it was required at
  1210. # one time, but does not seem to be now, and it breaks some of the
  1211. # code that still relies on inline assembly.
  1212. # enabled icc && ! enabled pic && add_cflags -fno-pic -mdynamic-no-pic
  1213. enabled icc && ! enabled pic && add_cflags -fno-pic
  1214. ;;
  1215. iphonesimulator)
  1216. add_asflags -f macho${bits}
  1217. enabled x86 && sim_arch="-arch i386" || sim_arch="-arch x86_64"
  1218. add_cflags ${sim_arch}
  1219. add_ldflags ${sim_arch}
  1220. if [ "$(disabled external_build)" ] &&
  1221. [ "$(show_darwin_sdk_major_version iphonesimulator)" -gt 8 ]; then
  1222. # yasm v1.3.0 doesn't know what -fembed-bitcode means, so turning it
  1223. # on is pointless (unless building a C-only lib). Warn the user, but
  1224. # do nothing here.
  1225. log "Warning: Bitcode embed disabled for simulator targets."
  1226. fi
  1227. ;;
  1228. os2)
  1229. add_asflags -f aout
  1230. enabled debug && add_asflags -g
  1231. EXE_SFX=.exe
  1232. ;;
  1233. *)
  1234. log "Warning: Unknown os $tgt_os while setting up $AS flags"
  1235. ;;
  1236. esac
  1237. ;;
  1238. *-gcc|generic-gnu)
  1239. link_with_cc=gcc
  1240. enable_feature gcc
  1241. setup_gnu_toolchain
  1242. ;;
  1243. esac
  1244. # Try to enable CPU specific tuning
  1245. if [ -n "${tune_cpu}" ]; then
  1246. if [ -n "${tune_cflags}" ]; then
  1247. check_add_cflags ${tune_cflags}${tune_cpu} || \
  1248. die "Requested CPU '${tune_cpu}' not supported by compiler"
  1249. fi
  1250. if [ -n "${tune_asflags}" ]; then
  1251. check_add_asflags ${tune_asflags}${tune_cpu} || \
  1252. die "Requested CPU '${tune_cpu}' not supported by assembler"
  1253. fi
  1254. if [ -z "${tune_cflags}${tune_asflags}" ]; then
  1255. log_echo "Warning: CPU tuning not supported by this toolchain"
  1256. fi
  1257. fi
  1258. if enabled debug; then
  1259. check_add_cflags -g && check_add_ldflags -g
  1260. else
  1261. check_add_cflags -DNDEBUG
  1262. fi
  1263. enabled gprof && check_add_cflags -pg && check_add_ldflags -pg
  1264. enabled gcov &&
  1265. check_add_cflags -fprofile-arcs -ftest-coverage &&
  1266. check_add_ldflags -fprofile-arcs -ftest-coverage
  1267. if enabled optimizations; then
  1268. if enabled rvct; then
  1269. enabled small && check_add_cflags -Ospace || check_add_cflags -Otime
  1270. else
  1271. enabled small && check_add_cflags -O2 || check_add_cflags -O3
  1272. fi
  1273. fi
  1274. # Position Independent Code (PIC) support, for building relocatable
  1275. # shared objects
  1276. enabled gcc && enabled pic && check_add_cflags -fPIC
  1277. # Work around longjmp interception on glibc >= 2.11, to improve binary
  1278. # compatibility. See http://code.google.com/p/webm/issues/detail?id=166
  1279. enabled linux && check_add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
  1280. # Check for strip utility variant
  1281. ${STRIP} -V 2>/dev/null | grep GNU >/dev/null && enable_feature gnu_strip
  1282. # Try to determine target endianness
  1283. check_cc <<EOF
  1284. unsigned int e = 'O'<<24 | '2'<<16 | 'B'<<8 | 'E';
  1285. EOF
  1286. [ -f "${TMP_O}" ] && od -A n -t x1 "${TMP_O}" | tr -d '\n' |
  1287. grep '4f *32 *42 *45' >/dev/null 2>&1 && enable_feature big_endian
  1288. # Try to find which inline keywords are supported
  1289. check_cc <<EOF && INLINE="inline"
  1290. static inline function() {}
  1291. EOF
  1292. # Almost every platform uses pthreads.
  1293. if enabled multithread; then
  1294. case ${toolchain} in
  1295. *-win*-vs*)
  1296. ;;
  1297. *-android-gcc)
  1298. # bionic includes basic pthread functionality, obviating -lpthread.
  1299. ;;
  1300. *)
  1301. check_header pthread.h && check_lib -lpthread <<EOF && add_extralibs -lpthread || disable_feature pthread_h
  1302. #include <pthread.h>
  1303. #include <stddef.h>
  1304. void *thread_check (void *);
  1305. void *thread_check (void *obj){ return obj;};
  1306. int main(void) { pthread_t thread_id; return pthread_create(&thread_id, NULL, thread_check, NULL); }
  1307. EOF
  1308. ;;
  1309. esac
  1310. fi
  1311. # only for MIPS platforms
  1312. case ${toolchain} in
  1313. mips*)
  1314. if enabled big_endian; then
  1315. if enabled dspr2; then
  1316. echo "dspr2 optimizations are available only for little endian platforms"
  1317. disable_feature dspr2
  1318. fi
  1319. if enabled msa; then
  1320. echo "msa optimizations are available only for little endian platforms"
  1321. disable_feature msa
  1322. fi
  1323. if enabled mmi; then
  1324. echo "mmi optimizations are available only for little endian platforms"
  1325. disable_feature mmi
  1326. fi
  1327. fi
  1328. ;;
  1329. esac
  1330. # glibc needs these
  1331. if enabled linux; then
  1332. add_cflags -D_LARGEFILE_SOURCE
  1333. add_cflags -D_FILE_OFFSET_BITS=64
  1334. fi
  1335. }
  1336. process_toolchain() {
  1337. process_common_toolchain
  1338. }
  1339. print_config_mk() {
  1340. saved_prefix="${prefix}"
  1341. prefix=$1
  1342. makefile=$2
  1343. shift 2
  1344. for cfg; do
  1345. if enabled $cfg; then
  1346. upname="`toupper $cfg`"
  1347. echo "${prefix}_${upname}=yes" >> $makefile
  1348. fi
  1349. done
  1350. prefix="${saved_prefix}"
  1351. }
  1352. print_config_h() {
  1353. saved_prefix="${prefix}"
  1354. prefix=$1
  1355. header=$2
  1356. shift 2
  1357. for cfg; do
  1358. upname="`toupper $cfg`"
  1359. if enabled $cfg; then
  1360. echo "#define ${prefix}_${upname} 1" >> $header
  1361. else
  1362. echo "#define ${prefix}_${upname} 0" >> $header
  1363. fi
  1364. done
  1365. prefix="${saved_prefix}"
  1366. }
  1367. print_config_vars_h() {
  1368. header=$1
  1369. shift
  1370. while [ $# -gt 0 ]; do
  1371. upname="`toupper $1`"
  1372. echo "#define ${upname} $2" >> $header
  1373. shift 2
  1374. done
  1375. }
  1376. print_webm_license() {
  1377. saved_prefix="${prefix}"
  1378. destination=$1
  1379. prefix="$2"
  1380. suffix="$3"
  1381. shift 3
  1382. cat <<EOF > ${destination}
  1383. ${prefix} Copyright (c) 2011 The WebM project authors. All Rights Reserved.${suffix}
  1384. ${prefix} ${suffix}
  1385. ${prefix} Use of this source code is governed by a BSD-style license${suffix}
  1386. ${prefix} that can be found in the LICENSE file in the root of the source${suffix}
  1387. ${prefix} tree. An additional intellectual property rights grant can be found${suffix}
  1388. ${prefix} in the file PATENTS. All contributing project authors may${suffix}
  1389. ${prefix} be found in the AUTHORS file in the root of the source tree.${suffix}
  1390. EOF
  1391. prefix="${saved_prefix}"
  1392. }
  1393. process_targets() {
  1394. true;
  1395. }
  1396. process_detect() {
  1397. true;
  1398. }
  1399. enable_feature logging
  1400. logfile="config.log"
  1401. self=$0
  1402. process() {
  1403. cmdline_args="$@"
  1404. process_cmdline "$@"
  1405. if enabled child; then
  1406. echo "# ${self} $@" >> ${logfile}
  1407. else
  1408. echo "# ${self} $@" > ${logfile}
  1409. fi
  1410. post_process_common_cmdline
  1411. post_process_cmdline
  1412. process_toolchain
  1413. process_detect
  1414. process_targets
  1415. OOT_INSTALLS="${OOT_INSTALLS}"
  1416. if enabled source_path_used; then
  1417. # Prepare the PWD for building.
  1418. for f in ${OOT_INSTALLS}; do
  1419. install -D "${source_path}/$f" "$f"
  1420. done
  1421. fi
  1422. cp "${source_path}/build/make/Makefile" .
  1423. clean_temp_files
  1424. true
  1425. }