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