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