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