]> granicus.if.org Git - libvpx/blob - configure
Merge remote branch 'internal/upstream' into HEAD
[libvpx] / 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 EXPERIMENT_LIST="
212 "
213 CONFIG_LIST="
214     external_build
215     install_docs
216     install_bins
217     install_libs
218     install_srcs
219     debug
220     gprof
221     gcov
222     rvct
223     gcc
224     msvs
225     pic
226     big_endian
227
228     codec_srcs
229     debug_libs
230     fast_unaligned
231     mem_manager
232     mem_tracker
233     mem_checks
234     md5
235
236     dequant_tokens
237     dc_recon
238     runtime_cpu_detect
239     postproc
240     multithread
241     psnr
242     ${CODECS}
243     ${CODEC_FAMILIES}
244     encoders
245     decoders
246     static_msvcrt
247     spatial_resampling
248     realtime_only
249     shared
250     small
251     arm_asm_detok
252
253     experimental
254     ${EXPERIMENT_LIST}
255 "
256 CMDLINE_SELECT="
257     extra_warnings
258     werror
259     install_docs
260     install_bins
261     install_libs
262     install_srcs
263     debug
264     gprof
265     gcov
266     pic
267     optimizations
268     ccache
269     runtime_cpu_detect
270
271     libs
272     examples
273     libc
274     fast_unaligned
275     codec_srcs
276     debug_libs
277     md5
278
279     dequant_tokens
280     dc_recon
281     postproc
282     multithread
283     psnr
284     ${CODECS}
285     ${CODEC_FAMILIES}
286     static_msvcrt
287     mem_tracker
288     spatial_resampling
289     realtime_only
290     shared
291     small
292     arm_asm_detok
293     experimental
294 "
295
296 process_cmdline() {
297     for opt do
298         optval="${opt#*=}"
299         case "$opt" in
300         --disable-codecs) for c in ${CODECS}; do disable $c; done ;;
301         --enable-?*|--disable-?*)
302         eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
303         if echo "${EXPERIMENT_LIST}" | grep "^ *$option\$" >/dev/null; then
304             if enabled experimental; then
305                 $action $option
306             else
307                 log_echo "Ignoring $opt -- not in experimental mode."
308             fi
309         else
310             process_common_cmdline $opt
311         fi
312         ;;
313         *) process_common_cmdline $opt
314         ;;
315         esac
316     done
317 }
318
319 post_process_cmdline() {
320     local c
321
322     # If the codec family is disabled, disable all components of that family.
323     # If the codec family is enabled, enable all components of that family.
324     log_echo "Configuring selected codecs"
325     for c in ${CODECS}; do
326         disabled ${c%%_*} && disable ${c}
327         enabled ${c%%_*} && enable ${c}
328     done
329
330     # Enable all detected codecs, if they haven't been disabled
331     for c in ${CODECS}; do soft_enable $c; done
332
333     # Enable the codec family if any component of that family is enabled
334     for c in ${CODECS}; do
335         enabled $c && enable ${c%_*}
336     done
337
338     # Set the {en,de}coders variable if any algorithm in that class is enabled
339     for c in ${CODECS}; do
340         enabled ${c} && enable ${c##*_}s
341     done
342
343
344 }
345
346
347 process_targets() {
348     enabled child || write_common_config_banner
349     enabled universal || write_common_target_config_h  ${BUILD_PFX}vpx_config.h
350
351     # TODO: add host tools target (obj_int_extract, etc)
352
353     # For fat binaries, call configure recursively to configure for each
354     # binary architecture to be included.
355     if enabled universal; then
356         # Call configure (ourselves) for each subarchitecture
357         for arch in $fat_bin_archs; do
358             BUILD_PFX=${arch}/ toolchain=${arch} $self --child $cmdline_args || exit $?
359         done
360     fi
361
362     # The write_common_config (config.mk) logic is deferred until after the
363     # recursive calls to configure complete, becuase we want our universal
364     # targets to be executed last.
365     write_common_config_targets
366     enabled universal && echo "FAT_ARCHS=${fat_bin_archs}" >> config.mk
367
368     # Calculate the default distribution name, based on the enabled features
369     local cf
370     local DIST_DIR=vpx
371     for cf in $CODEC_FAMILIES; do
372         if enabled ${cf}_encoder && enabled ${cf}_decoder; then
373             DIST_DIR="${DIST_DIR}-${cf}"
374         elif enabled ${cf}_encoder; then
375             DIST_DIR="${DIST_DIR}-${cf}cx"
376         elif enabled ${cf}_decoder; then
377             DIST_DIR="${DIST_DIR}-${cf}dx"
378         fi
379     done
380     enabled debug_libs && DIST_DIR="${DIST_DIR}-debug"
381     enabled codec_srcs && DIST_DIR="${DIST_DIR}-src"
382     ! enabled postproc && DIST_DIR="${DIST_DIR}-nopost"
383     ! enabled multithread && DIST_DIR="${DIST_DIR}-nomt"
384     ! enabled install_docs && DIST_DIR="${DIST_DIR}-nodocs"
385     DIST_DIR="${DIST_DIR}-${tgt_isa}-${tgt_os}"
386     case "${tgt_os}" in
387     win*) enabled static_msvcrt && DIST_DIR="${DIST_DIR}mt" || DIST_DIR="${DIST_DIR}md"
388           DIST_DIR="${DIST_DIR}-${tgt_cc}"
389           ;;
390     esac
391     if [ -f "${source_path}/build/make/version.sh" ]; then
392         local ver=`"$source_path/build/make/version.sh" --bare $source_path`
393         DIST_DIR="${DIST_DIR}-${ver}"
394         ver=${ver%%-*}
395         VERSION_PATCH=${ver##*.}
396         ver=${ver%.*}
397         VERSION_MINOR=${ver##*.}
398         ver=${ver#v}
399         VERSION_MAJOR=${ver%.*}
400     fi
401     enabled child || cat <<EOF >> config.mk
402 ifeq (\$(MAKECMDGOALS),dist)
403 DIST_DIR?=${DIST_DIR}
404 else
405 DIST_DIR?=\$(DESTDIR)${prefix}
406 endif
407 LIBSUBDIR=${libdir##${prefix}/}
408
409 VERSION_MAJOR=${VERSION_MAJOR}
410 VERSION_MINOR=${VERSION_MINOR}
411 VERSION_PATCH=${VERSION_PATCH}
412
413 CONFIGURE_ARGS=${CONFIGURE_ARGS}
414 EOF
415     enabled child || echo "CONFIGURE_ARGS?=${CONFIGURE_ARGS}" >> config.mk
416
417     #
418     # Write makefiles for all enabled targets
419     #
420     for tgt in libs examples docs solution; do
421         local tgt_fn="$tgt-$toolchain.mk"
422
423         if enabled $tgt; then
424             echo "Creating makefiles for ${toolchain} ${tgt}"
425             write_common_target_config_mk $tgt_fn ${BUILD_PFX}vpx_config.h
426             #write_${tgt}_config
427         fi
428     done
429
430 }
431
432 process_detect() {
433     if enabled shared; then
434         # Can only build shared libs on a subset of platforms. Doing this check
435         # here rather than at option parse time because the target auto-detect
436         # magic happens after the command line has been parsed.
437         enabled linux || die "--enable-shared only supported on ELF for now"
438     fi
439     if [ -z "$CC" ]; then
440         echo "Bypassing toolchain for environment detection."
441         enable external_build
442         check_header() {
443             log fake_check_header "$@"
444             header=$1
445             shift
446             var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
447             disable $var
448             case $header in
449                 stdio.h)
450                     true;
451                 ;;
452                 *)
453                     local result=false
454                     for d in "$@"; do
455                         [ -f "${d##-I}/$header" ] && result=true && break
456                     done
457                     ${result:-true}
458             esac && enable $var
459         }
460         check_ld() {
461             true
462         }
463     fi
464     check_header stdio.h || die "Unable to invoke compiler: ${CC} ${CFLAGS}"
465     check_ld <<EOF || die "Toolchain is unable to link executables"
466 int main(void) {return 0;}
467 EOF
468     # check system headers
469     check_header stdint.h
470     check_header pthread.h
471     check_header sys/mman.h
472
473     check_header vpx/vpx_integer.h -I${source_path} && enable vpx_ports
474 }
475
476 process_toolchain() {
477     process_common_toolchain
478
479     # Handle universal binaries for this architecture
480     case $toolchain in
481         universal-darwin*)
482             local darwin_ver=${tgt_os##darwin}
483             fat_bin_archs="$fat_bin_archs ppc32-${tgt_os}-gcc"
484
485             # Intel
486             fat_bin_archs="$fat_bin_archs x86-${tgt_os}-${tgt_cc}"
487             if [ $darwin_ver -gt 8 ]; then
488                 fat_bin_archs="$fat_bin_archs x86_64-${tgt_os}-${tgt_cc}"
489             fi
490             ;;
491     esac
492
493
494     # Enable some useful compiler flags
495     if enabled gcc; then
496         enabled werror && check_add_cflags -Werror
497         check_add_cflags -Wall
498         check_add_cflags -Wdeclaration-after-statement
499         check_add_cflags -Wdisabled-optimization
500         check_add_cflags -Wpointer-arith
501         check_add_cflags -Wtype-limits
502         check_add_cflags -Wcast-qual
503         enabled extra_warnings || check_add_cflags -Wno-unused
504     fi
505
506     if enabled icc; then
507         enabled werror && check_add_cflags -Werror
508         check_add_cflags -Wall
509         check_add_cflags -Wpointer-arith
510
511         # ICC has a number of floating point optimizations that we disable
512         # in favor of deterministic output WRT to other compilers
513         add_cflags -fp-model precise
514     fi
515
516     # Enable extra, harmless warnings. These might provide additional insight
517     # to what the compiler is doing and why, but in general, but they shouldn't
518     # be treated as fatal, even if we're treating warnings as errors.
519     GCC_EXTRA_WARNINGS="
520         -Wdisabled-optimization
521         -Winline
522     "
523     enabled gcc && EXTRA_WARNINGS="${GCC_EXTRA_WARNINGS}"
524     RVCT_EXTRA_WARNINGS="
525         --remarks
526     "
527     enabled rvct && EXTRA_WARNINGS="${RVCT_EXTRA_WARNINGS}"
528     if enabled extra_warnings; then
529         for w in ${EXTRA_WARNINGS}; do
530             check_add_cflags ${w}
531             enabled gcc && enabled werror && check_add_cflags -Wno-error=${w}
532         done
533     fi
534
535     # ccache only really works on gcc toolchains
536     enabled gcc || soft_disable ccache
537     if enabled mips; then
538         enable dequant_tokens
539         enable dc_recon
540     fi
541
542     # Enable the postbuild target if building for visual studio.
543     case "$tgt_cc" in
544         vs*) enable msvs
545              enable solution
546              vs_version=${tgt_cc##vs}
547              all_targets="${all_targets} solution"
548         ;;
549     esac
550
551     # Other toolchain specific defaults
552     case $toolchain in x86*|ppc*|universal*) soft_enable postproc;; esac
553 }
554
555
556 ##
557 ## END APPLICATION SPECIFIC CONFIGURATION
558 ##
559 CONFIGURE_ARGS="$@"
560 process "$@"
561 cat <<EOF > ${BUILD_PFX}vpx_config.c
562 static const char* const cfg = "$CONFIGURE_ARGS";
563 const char *vpx_codec_build_config(void) {return cfg;}
564 EOF