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