Merge remote branch 'internal/upstream' into HEAD
[platform/upstream/libvpx.git] / configure
1 #!/bin/bash
2 ##
3 ##  configure
4 ##
5 ##  This script is the front-end to the build system. It provides a similar
6 ##  interface to standard configure scripts with some extra bits for dealing
7 ##  with toolchains that differ from the standard POSIX interface and
8 ##  for extracting subsets of the source tree. In theory, reusable parts
9 ##  of this script were intended to live in build/make/configure.sh,
10 ##  but in practice, the line is pretty blurry.
11 ##
12 ##  This build system is based in part on the FFmpeg configure script.
13 ##
14
15 #source_path="`dirname \"$0\"`"
16 source_path=${0%/*}
17 . "${source_path}/build/make/configure.sh"
18
19 show_help(){
20     show_help_pre
21     cat << EOF
22 Advanced options:
23   ${toggle_libs}                  don't build libraries
24   ${toggle_examples}              don't build examples
25   --libc=PATH                     path to alternate libc
26   ${toggle_fast_unaligned}        don't use unaligned accesses, even when
27                                   supported by hardware [auto]
28   ${toggle_codec_srcs}            in/exclude codec library source code
29   ${toggle_debug_libs}            in/exclude debug version of libraries
30   ${toggle_md5}                   support for output of checksum data
31   ${toggle_static_msvcrt}         use static MSVCRT (VS builds only)
32   ${toggle_vp8}                   VP8 codec support
33   ${toggle_psnr}                  output of PSNR data, if supported (encoders)
34   ${toggle_mem_tracker}           track memory usage
35   ${toggle_postproc}              postprocessing
36   ${toggle_multithread}           multithreaded encoding and decoding.
37   ${toggle_spatial_resampling}    spatial sampling (scaling) support
38   ${toggle_realtime_only}         enable this option while building for real-time encoding
39   ${toggle_runtime_cpu_detect}    runtime cpu detection
40   ${toggle_shared}                shared library support
41   ${toggle_arm_asm_detok}         assembly version of the detokenizer (ARM platforms only)
42
43 Codecs:
44   Codecs can be selectively enabled or disabled individually, or by family:
45       --disable-<codec>
46   is equivalent to:
47       --disable-<codec>-encoder
48       --disable-<codec>-decoder
49
50   Codecs available in this distribution:
51 EOF
52 #restore editor state '
53
54     local family;
55     local last_family;
56     local c;
57     local str;
58     for c in ${CODECS}; do
59         family=${c%_*}
60         if [ "${family}" != "${last_family}" ]; then
61             [ -z "${str}" ] || echo "${str}"
62             str="$(printf '    %10s:' ${family})"
63         fi
64         str="${str} $(printf '%10s' ${c#*_})"
65         last_family=${family}
66     done
67     echo "${str}"
68     show_help_post
69 }
70
71 ##
72 ## BEGIN APPLICATION SPECIFIC CONFIGURATION
73 ##
74
75 # all_platforms is a list of all supported target platforms. Maintain
76 # alphabetically by architecture, generic-gnu last.
77 all_platforms="${all_platforms} armv5te-linux-rvct"
78 all_platforms="${all_platforms} armv5te-linux-gcc"
79 all_platforms="${all_platforms} armv5te-symbian-gcc"
80 all_platforms="${all_platforms} armv5te-wince-vs8"
81 all_platforms="${all_platforms} armv6-darwin-gcc"
82 all_platforms="${all_platforms} armv6-linux-rvct"
83 all_platforms="${all_platforms} armv6-linux-gcc"
84 all_platforms="${all_platforms} armv6-symbian-gcc"
85 all_platforms="${all_platforms} armv6-wince-vs8"
86 all_platforms="${all_platforms} iwmmxt-linux-rvct"
87 all_platforms="${all_platforms} iwmmxt-linux-gcc"
88 all_platforms="${all_platforms} iwmmxt-wince-vs8"
89 all_platforms="${all_platforms} iwmmxt2-linux-rvct"
90 all_platforms="${all_platforms} iwmmxt2-linux-gcc"
91 all_platforms="${all_platforms} iwmmxt2-wince-vs8"
92 all_platforms="${all_platforms} armv7-darwin-gcc"    #neon Cortex-A8
93 all_platforms="${all_platforms} armv7-linux-rvct"    #neon Cortex-A8
94 all_platforms="${all_platforms} armv7-linux-gcc"     #neon Cortex-A8
95 all_platforms="${all_platforms} mips32-linux-gcc"
96 all_platforms="${all_platforms} ppc32-darwin8-gcc"
97 all_platforms="${all_platforms} ppc32-darwin9-gcc"
98 all_platforms="${all_platforms} ppc64-darwin8-gcc"
99 all_platforms="${all_platforms} ppc64-darwin9-gcc"
100 all_platforms="${all_platforms} ppc64-linux-gcc"
101 all_platforms="${all_platforms} x86-darwin8-gcc"
102 all_platforms="${all_platforms} x86-darwin8-icc"
103 all_platforms="${all_platforms} x86-darwin9-gcc"
104 all_platforms="${all_platforms} x86-darwin9-icc"
105 all_platforms="${all_platforms} x86-linux-gcc"
106 all_platforms="${all_platforms} x86-linux-icc"
107 all_platforms="${all_platforms} x86-solaris-gcc"
108 all_platforms="${all_platforms} x86-win32-gcc"
109 all_platforms="${all_platforms} x86-win32-vs7"
110 all_platforms="${all_platforms} x86-win32-vs8"
111 all_platforms="${all_platforms} x86-win32-vs9"
112 all_platforms="${all_platforms} x86_64-darwin9-gcc"
113 all_platforms="${all_platforms} x86_64-linux-gcc"
114 all_platforms="${all_platforms} x86_64-linux-icc"
115 all_platforms="${all_platforms} x86_64-solaris-gcc"
116 all_platforms="${all_platforms} x86_64-win64-vs8"
117 all_platforms="${all_platforms} x86_64-win64-vs9"
118 all_platforms="${all_platforms} universal-darwin8-gcc"
119 all_platforms="${all_platforms} universal-darwin9-gcc"
120 all_platforms="${all_platforms} generic-gnu"
121
122 # all_targets is a list of all targets that can be configured
123 # note that these should be in dependency order for now.
124 all_targets="libs examples docs"
125
126 # all targets available are enabled, by default.
127 for t in ${all_targets}; do
128     [ -f ${source_path}/${t}.mk ] && enable ${t}
129 done
130
131 # check installed doxygen version
132 doxy_version=$(doxygen --version 2>/dev/null)
133 doxy_major=${doxy_version%%.*}
134 if [ ${doxy_major:-0} -ge 1 ]; then
135     doxy_version=${doxy_version#*.}
136     doxy_minor=${doxy_version%%.*}
137     doxy_patch=${doxy_version##*.}
138
139     [ $doxy_major -gt 1 ] && enable doxygen
140     [ $doxy_minor -gt 5 ] && enable doxygen
141     [ $doxy_minor -eq 5 ] && [ $doxy_patch -ge 3 ] && enable doxygen
142 fi
143
144 # install everything except the sources, by default. sources will have
145 # to be enabled when doing dist builds, since that's no longer a common
146 # case.
147 enabled doxygen && php -v >/dev/null 2>&1 && enable install_docs
148 enable install_bins
149 enable install_libs
150
151 enable optimizations
152 enable fast_unaligned #allow unaligned accesses, if supported by hw
153 enable md5
154 enable spatial_resampling
155 enable multithread
156
157 [ -d ${source_path}/../include ] && enable alt_tree_layout
158 for d in vp8; do
159     [ -d ${source_path}/${d} ] && disable alt_tree_layout;
160 done
161
162 if ! enabled alt_tree_layout; then
163 # development environment
164 [ -d ${source_path}/vp8 ] && CODECS="${CODECS} vp8_encoder vp8_decoder"
165 else
166 # customer environment
167 [ -f ${source_path}/../include/vpx/vp8cx.h ] && CODECS="${CODECS} vp8_encoder"
168 [ -f ${source_path}/../include/vpx/vp8dx.h ] && CODECS="${CODECS} vp8_decoder"
169
170 [ -f ${source_path}/../lib/*/*mt.lib ] && soft_enable static_msvcrt
171 fi
172
173 CODECS="$(echo ${CODECS} | tr ' ' '\n')"
174 CODEC_FAMILIES="$(for c in ${CODECS}; do echo ${c%_*}; done | sort | uniq)"
175
176 ARCH_LIST="
177     arm
178     mips
179     x86
180     x86_64
181     ppc32
182     ppc64
183 "
184 ARCH_EXT_LIST="
185     armv5te
186     armv6
187     armv7
188     iwmmxt
189     iwmmxt2
190
191     mips32
192
193     mmx
194     sse
195     sse2
196     sse3
197     ssse3
198
199     altivec
200 "
201 HAVE_LIST="
202     ${ARCH_EXT_LIST}
203     vpx_ports
204     stdint_h
205     alt_tree_layout
206     pthread_h
207     sys_mman_h
208 "
209 EXPERIMENT_LIST="
210 "
211 CONFIG_LIST="
212     external_build
213     install_docs
214     install_bins
215     install_libs
216     install_srcs
217     debug
218     gprof
219     gcov
220     rvct
221     gcc
222     msvs
223     pic
224     big_endian
225
226     codec_srcs
227     debug_libs
228     fast_unaligned
229     mem_manager
230     mem_tracker
231     mem_checks
232     md5
233
234     dequant_tokens
235     dc_recon
236     runtime_cpu_detect
237     postproc
238     multithread
239     psnr
240     ${CODECS}
241     ${CODEC_FAMILIES}
242     encoders
243     decoders
244     static_msvcrt
245     spatial_resampling
246     realtime_only
247     shared
248     arm_asm_detok
249
250     experimental
251     ${EXPERIMENT_LIST}
252 "
253 CMDLINE_SELECT="
254     extra_warnings
255     werror
256     install_docs
257     install_bins
258     install_libs
259     install_srcs
260     debug
261     gprof
262     gcov
263     pic
264     optimizations
265     ccache
266     runtime_cpu_detect
267
268     libs
269     examples
270     libc
271     fast_unaligned
272     codec_srcs
273     debug_libs
274     md5
275
276     dequant_tokens
277     dc_recon
278     postproc
279     multithread
280     psnr
281     ${CODECS}
282     ${CODEC_FAMILIES}
283     static_msvcrt
284     mem_tracker
285     spatial_resampling
286     realtime_only
287     shared
288     arm_asm_detok
289     experimental
290 "
291
292 process_cmdline() {
293     for opt do
294         optval="${opt#*=}"
295         case "$opt" in
296         --disable-codecs) for c in ${CODECS}; do disable $c; done ;;
297         --enable-?*|--disable-?*)
298         eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
299         if echo "${EXPERIMENT_LIST}" | grep "^ *$option\$" >/dev/null; then
300             if enabled experimental; then
301                 $action $option
302             else
303                 log_echo "Ignoring $opt -- not in experimental mode."
304             fi
305         else
306             process_common_cmdline $opt
307         fi
308         ;;
309         *) process_common_cmdline $opt
310         ;;
311         esac
312     done
313 }
314
315 post_process_cmdline() {
316     local c
317
318     # If the codec family is disabled, disable all components of that family.
319     # If the codec family is enabled, enable all components of that family.
320     log_echo "Configuring selected codecs"
321     for c in ${CODECS}; do
322         disabled ${c%%_*} && disable ${c}
323         enabled ${c%%_*} && enable ${c}
324     done
325
326     # Enable all detected codecs, if they haven't been disabled
327     for c in ${CODECS}; do soft_enable $c; done
328
329     # Enable the codec family if any component of that family is enabled
330     for c in ${CODECS}; do
331         enabled $c && enable ${c%_*}
332     done
333
334     # Set the {en,de}coders variable if any algorithm in that class is enabled
335     for c in ${CODECS}; do
336         enabled ${c} && enable ${c##*_}s
337     done
338
339
340 }
341
342
343 process_targets() {
344     enabled child || write_common_config_banner
345     enabled universal || write_common_target_config_h  ${BUILD_PFX}vpx_config.h
346
347     # TODO: add host tools target (obj_int_extract, etc)
348
349     # For fat binaries, call configure recursively to configure for each
350     # binary architecture to be included.
351     if enabled universal; then
352         # Call configure (ourselves) for each subarchitecture
353         for arch in $fat_bin_archs; do
354             BUILD_PFX=${arch}/ toolchain=${arch} $self --child $cmdline_args || exit $?
355         done
356     fi
357
358     # The write_common_config (config.mk) logic is deferred until after the
359     # recursive calls to configure complete, becuase we want our universal
360     # targets to be executed last.
361     write_common_config_targets
362     enabled universal && echo "FAT_ARCHS=${fat_bin_archs}" >> config.mk
363
364     # Calculate the default distribution name, based on the enabled features
365     local cf
366     local DIST_DIR=vpx
367     for cf in $CODEC_FAMILIES; do
368         if enabled ${cf}_encoder && enabled ${cf}_decoder; then
369             DIST_DIR="${DIST_DIR}-${cf}"
370         elif enabled ${cf}_encoder; then
371             DIST_DIR="${DIST_DIR}-${cf}cx"
372         elif enabled ${cf}_decoder; then
373             DIST_DIR="${DIST_DIR}-${cf}dx"
374         fi
375     done
376     enabled debug_libs && DIST_DIR="${DIST_DIR}-debug"
377     enabled codec_srcs && DIST_DIR="${DIST_DIR}-src"
378     ! enabled postproc && DIST_DIR="${DIST_DIR}-nopost"
379     ! enabled multithread && DIST_DIR="${DIST_DIR}-nomt"
380     ! enabled install_docs && DIST_DIR="${DIST_DIR}-nodocs"
381     DIST_DIR="${DIST_DIR}-${tgt_isa}-${tgt_os}"
382     case "${tgt_os}" in
383     win*) enabled static_msvcrt && DIST_DIR="${DIST_DIR}mt" || DIST_DIR="${DIST_DIR}md"
384           DIST_DIR="${DIST_DIR}-${tgt_cc}"
385           ;;
386     esac
387     if [ -f "${source_path}/build/make/version.sh" ]; then
388         local ver=`"$source_path/build/make/version.sh" --bare $source_path`
389         DIST_DIR="${DIST_DIR}-${ver}"
390         ver=${ver%%-*}
391         VERSION_PATCH=${ver##*.}
392         ver=${ver%.*}
393         VERSION_MINOR=${ver##*.}
394         ver=${ver#v}
395         VERSION_MAJOR=${ver%.*}
396     fi
397     enabled child || cat <<EOF >> config.mk
398 ifeq (\$(MAKECMDGOALS),dist)
399 DIST_DIR?=${DIST_DIR}
400 else
401 DIST_DIR?=\$(DESTDIR)${prefix}
402 endif
403 LIBSUBDIR=${libdir##${prefix}/}
404
405 VERSION_MAJOR=${VERSION_MAJOR}
406 VERSION_MINOR=${VERSION_MINOR}
407 VERSION_PATCH=${VERSION_PATCH}
408
409 CONFIGURE_ARGS=${CONFIGURE_ARGS}
410 EOF
411     enabled child || echo "CONFIGURE_ARGS?=${CONFIGURE_ARGS}" >> config.mk
412
413     #
414     # Write makefiles for all enabled targets
415     #
416     for tgt in libs examples docs solution; do
417         local tgt_fn="$tgt-$toolchain.mk"
418
419         if enabled $tgt; then
420             echo "Creating makefiles for ${toolchain} ${tgt}"
421             write_common_target_config_mk $tgt_fn ${BUILD_PFX}vpx_config.h
422             #write_${tgt}_config
423         fi
424     done
425
426 }
427
428 process_detect() {
429     if enabled shared; then
430         # Can only build shared libs on a subset of platforms. Doing this check
431         # here rather than at option parse time because the target auto-detect
432         # magic happens after the command line has been parsed.
433         enabled linux || die "--enable-shared only supported on ELF for now"
434     fi
435     if [ -z "$CC" ]; then
436         echo "Bypassing toolchain for environment detection."
437         enable external_build
438         check_header() {
439             log fake_check_header "$@"
440             header=$1
441             shift
442             var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
443             disable $var
444             case $header in
445                 stdio.h)
446                     true;
447                 ;;
448                 *)
449                     local result=false
450                     for d in "$@"; do
451                         [ -f "${d##-I}/$header" ] && result=true && break
452                     done
453                     ${result:-true}
454             esac && enable $var
455         }
456         check_ld() {
457             true
458         }
459     fi
460     check_header stdio.h || die "Unable to invoke compiler: ${CC} ${CFLAGS}"
461     check_ld <<EOF || die "Toolchain is unable to link executables"
462 int main(void) {return 0;}
463 EOF
464     # check system headers
465     check_header stdint.h
466     check_header pthread.h
467     check_header sys/mman.h
468
469     check_header vpx/vpx_integer.h -I${source_path} && enable vpx_ports
470 }
471
472 process_toolchain() {
473     process_common_toolchain
474
475     # Handle universal binaries for this architecture
476     case $toolchain in
477         universal-darwin*)
478             local darwin_ver=${tgt_os##darwin}
479             fat_bin_archs="$fat_bin_archs ppc32-${tgt_os}-gcc"
480
481             # Intel
482             fat_bin_archs="$fat_bin_archs x86-${tgt_os}-${tgt_cc}"
483             if [ $darwin_ver -gt 8 ]; then
484                 fat_bin_archs="$fat_bin_archs x86_64-${tgt_os}-${tgt_cc}"
485             fi
486             ;;
487     esac
488
489
490     # Enable some useful compiler flags
491     if enabled gcc; then
492         enabled werror && check_add_cflags -Werror
493         check_add_cflags -Wall
494         check_add_cflags -Wdeclaration-after-statement
495         check_add_cflags -Wdisabled-optimization
496         check_add_cflags -Wpointer-arith
497         check_add_cflags -Wtype-limits
498         check_add_cflags -Wcast-qual
499         enabled extra_warnings || check_add_cflags -Wno-unused
500     fi
501
502     if enabled icc; then
503         enabled werror && check_add_cflags -Werror
504         check_add_cflags -Wall
505         check_add_cflags -Wpointer-arith
506
507         # ICC has a number of floating point optimizations that we disable
508         # in favor of deterministic output WRT to other compilers
509         add_cflags -fp-model precise
510     fi
511
512     # Enable extra, harmless warnings. These might provide additional insight
513     # to what the compiler is doing and why, but in general, but they shouldn't
514     # be treated as fatal, even if we're treating warnings as errors.
515     GCC_EXTRA_WARNINGS="
516         -Wdisabled-optimization
517         -Winline
518     "
519     enabled gcc && EXTRA_WARNINGS="${GCC_EXTRA_WARNINGS}"
520     RVCT_EXTRA_WARNINGS="
521         --remarks
522     "
523     enabled rvct && EXTRA_WARNINGS="${RVCT_EXTRA_WARNINGS}"
524     if enabled extra_warnings; then
525         for w in ${EXTRA_WARNINGS}; do
526             check_add_cflags ${w}
527             enabled gcc && enabled werror && check_add_cflags -Wno-error=${w}
528         done
529     fi
530
531     # ccache only really works on gcc toolchains
532     enabled gcc || soft_disable ccache
533     if enabled mips; then
534         enable dequant_tokens
535         enable dc_recon
536     fi
537
538     # Enable the postbuild target if building for visual studio.
539     case "$tgt_cc" in
540         vs*) enable msvs
541              enable solution
542              vs_version=${tgt_cc##vs}
543              all_targets="${all_targets} solution"
544         ;;
545     esac
546
547     # Other toolchain specific defaults
548     case $toolchain in x86*|ppc*|universal*) soft_enable postproc;; esac
549 }
550
551
552 ##
553 ## END APPLICATION SPECIFIC CONFIGURATION
554 ##
555 CONFIGURE_ARGS="$@"
556 process "$@"
557 cat <<EOF > ${BUILD_PFX}vpx_config.c
558 static const char* const cfg = "$CONFIGURE_ARGS";
559 const char *vpx_codec_build_config(void) {return cfg;}
560 EOF