1#!/bin/sh
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\"`"
16source_path=${0%/*}
17. "${source_path}/build/make/configure.sh"
18
19show_help(){
20    show_help_pre
21    cat << EOF
22Advanced options:
23  ${toggle_libs}                  libraries
24  ${toggle_examples}              examples
25  ${toggle_analyzer}              analyzer
26  ${toggle_docs}                  documentation
27  ${toggle_unit_tests}            unit tests
28  ${toggle_tools}                 tools
29  ${toggle_decode_perf_tests}     build decoder perf tests with unit tests
30  ${toggle_encode_perf_tests}     build encoder perf tests with unit tests
31  --cpu=CPU                       tune for the specified CPU (ARM: cortex-a8, X86: sse3)
32  --libc=PATH                     path to alternate libc
33  --size-limit=WxH                max size to allow in the decoder
34  --as={yasm|nasm|auto}           use specified assembler [auto, yasm preferred]
35  --sdk-path=PATH                 path to root of sdk (android builds only)
36  ${toggle_codec_srcs}            in/exclude codec library source code
37  ${toggle_debug_libs}            in/exclude debug version of libraries
38  ${toggle_static_msvcrt}         use static MSVCRT (VS builds only)
39  ${toggle_highbitdepth}          enable 16-bit generic pixel pipeline (used by high bitdepth profiles)
40  ${toggle_lowbitdepth}           enable 8-bit optimized pixel pipeline
41  ${toggle_av1}                  AV1 codec support
42  ${toggle_internal_stats}        output of encoder internal stats for debug, if supported (encoders)
43  ${toggle_postproc}              postprocessing
44  ${toggle_multithread}           multithreaded encoding and decoding
45  ${toggle_spatial_resampling}    spatial sampling (scaling) support
46  ${toggle_realtime_only}         enable this option while building for real-time encoding
47  ${toggle_coefficient_range_checking}
48                                  enable decoder to check if intermediate
49                                  transform coefficients are in valid range
50  ${toggle_runtime_cpu_detect}    runtime cpu detection
51  ${toggle_shared}                shared library support
52  ${toggle_static}                static library support
53  ${toggle_small}                 favor smaller size over speed
54  ${toggle_postproc_visualizer}   macro block / block level visualizers
55  ${toggle_webm_io}               enable input from and output to WebM container
56  ${toggle_libyuv}                enable libyuv
57  ${toggle_accounting}            enable bit accounting
58  ${toggle_inspection}            enable bitstream inspection
59
60Codecs:
61  Codecs can be selectively enabled or disabled individually, or by family:
62      --disable-<codec>
63  is equivalent to:
64      --disable-<codec>-encoder
65      --disable-<codec>-decoder
66
67  Codecs available in this distribution:
68EOF
69#restore editor state '
70
71    family="";
72    last_family="";
73    c="";
74    str="";
75    for c in ${CODECS}; do
76        family=${c%_*}
77        if [ "${family}" != "${last_family}" ]; then
78            [ -z "${str}" ] || echo "${str}"
79            str="$(printf '    %10s:' ${family})"
80        fi
81        str="${str} $(printf '%10s' ${c#*_})"
82        last_family=${family}
83    done
84    echo "${str}"
85    show_help_post
86}
87
88##
89## BEGIN APPLICATION SPECIFIC CONFIGURATION
90##
91
92# all_platforms is a list of all supported target platforms. Maintain
93# alphabetically by architecture, generic-gnu last.
94all_platforms="${all_platforms} arm64-darwin-gcc"
95all_platforms="${all_platforms} arm64-linux-gcc"
96all_platforms="${all_platforms} armv7-android-gcc"   #neon Cortex-A8
97all_platforms="${all_platforms} armv7-darwin-gcc"    #neon Cortex-A8
98all_platforms="${all_platforms} armv7-linux-rvct"    #neon Cortex-A8
99all_platforms="${all_platforms} armv7-linux-gcc"     #neon Cortex-A8
100all_platforms="${all_platforms} armv7-none-rvct"     #neon Cortex-A8
101all_platforms="${all_platforms} armv7-win32-vs12"
102all_platforms="${all_platforms} armv7-win32-vs14"
103all_platforms="${all_platforms} armv7-win32-vs15"
104all_platforms="${all_platforms} armv7s-darwin-gcc"
105all_platforms="${all_platforms} armv8-linux-gcc"
106all_platforms="${all_platforms} mips32-linux-gcc"
107all_platforms="${all_platforms} mips64-linux-gcc"
108all_platforms="${all_platforms} sparc-solaris-gcc"
109all_platforms="${all_platforms} x86-android-gcc"
110all_platforms="${all_platforms} x86-darwin8-gcc"
111all_platforms="${all_platforms} x86-darwin8-icc"
112all_platforms="${all_platforms} x86-darwin9-gcc"
113all_platforms="${all_platforms} x86-darwin9-icc"
114all_platforms="${all_platforms} x86-darwin10-gcc"
115all_platforms="${all_platforms} x86-darwin11-gcc"
116all_platforms="${all_platforms} x86-darwin12-gcc"
117all_platforms="${all_platforms} x86-darwin13-gcc"
118all_platforms="${all_platforms} x86-darwin14-gcc"
119all_platforms="${all_platforms} x86-darwin15-gcc"
120all_platforms="${all_platforms} x86-darwin16-gcc"
121all_platforms="${all_platforms} x86-iphonesimulator-gcc"
122all_platforms="${all_platforms} x86-linux-gcc"
123all_platforms="${all_platforms} x86-linux-icc"
124all_platforms="${all_platforms} x86-os2-gcc"
125all_platforms="${all_platforms} x86-solaris-gcc"
126all_platforms="${all_platforms} x86-win32-gcc"
127all_platforms="${all_platforms} x86-win32-vs12"
128all_platforms="${all_platforms} x86-win32-vs14"
129all_platforms="${all_platforms} x86-win32-vs15"
130all_platforms="${all_platforms} x86_64-android-gcc"
131all_platforms="${all_platforms} x86_64-darwin9-gcc"
132all_platforms="${all_platforms} x86_64-darwin10-gcc"
133all_platforms="${all_platforms} x86_64-darwin11-gcc"
134all_platforms="${all_platforms} x86_64-darwin12-gcc"
135all_platforms="${all_platforms} x86_64-darwin13-gcc"
136all_platforms="${all_platforms} x86_64-darwin14-gcc"
137all_platforms="${all_platforms} x86_64-darwin15-gcc"
138all_platforms="${all_platforms} x86_64-darwin16-gcc"
139all_platforms="${all_platforms} x86_64-iphonesimulator-gcc"
140all_platforms="${all_platforms} x86_64-linux-gcc"
141all_platforms="${all_platforms} x86_64-linux-icc"
142all_platforms="${all_platforms} x86_64-solaris-gcc"
143all_platforms="${all_platforms} x86_64-win64-gcc"
144all_platforms="${all_platforms} x86_64-win64-vs12"
145all_platforms="${all_platforms} x86_64-win64-vs14"
146all_platforms="${all_platforms} x86_64-win64-vs15"
147all_platforms="${all_platforms} generic-gnu"
148
149# all_targets is a list of all targets that can be configured
150# note that these should be in dependency order for now.
151all_targets="libs examples docs tools"
152
153# all targets available are enabled, by default.
154for t in ${all_targets}; do
155    [ -f "${source_path}/${t}.mk" ] && enable_feature ${t}
156done
157
158if ! diff --version >/dev/null; then
159  die "diff missing: Try installing diffutils via your package manager."
160fi
161
162if ! perl --version >/dev/null; then
163    die "Perl is required to build"
164fi
165
166
167if [ "`cd \"${source_path}\" && pwd`" != "`pwd`" ]; then
168  # test to see if source_path already configured
169  if [ -f "${source_path}/aom_config.h" ]; then
170    die "source directory already configured; run 'make distclean' there first"
171  fi
172fi
173
174# check installed doxygen version
175doxy_version=$(doxygen --version 2>/dev/null)
176doxy_major=${doxy_version%%.*}
177if [ ${doxy_major:-0} -ge 1 ]; then
178    doxy_version=${doxy_version#*.}
179    doxy_minor=${doxy_version%%.*}
180    doxy_patch=${doxy_version##*.}
181
182    [ $doxy_major -gt 1 ] && enable_feature doxygen
183    [ $doxy_minor -gt 5 ] && enable_feature doxygen
184    [ $doxy_minor -eq 5 ] && [ $doxy_patch -ge 3 ] && enable_feature doxygen
185fi
186
187# disable codecs when their source directory does not exist
188[ -d "${source_path}/av1" ] || disable_codec av1
189
190# install everything except the sources, by default. sources will have
191# to be enabled when doing dist builds, since that's no longer a common
192# case.
193enabled doxygen && enable_feature install_docs
194enable_feature install_bins
195enable_feature install_libs
196
197enable_feature static
198enable_feature optimizations
199enable_feature dependency_tracking
200enable_feature spatial_resampling
201enable_feature multithread
202enable_feature os_support
203enable_feature highbitdepth
204
205CODECS="
206    av1_encoder
207    av1_decoder
208"
209CODEC_FAMILIES="
210    av1
211"
212
213ARCH_LIST="
214    arm
215    mips
216    x86
217    x86_64
218"
219ARCH_EXT_LIST_X86="
220    mmx
221    sse
222    sse2
223    sse3
224    ssse3
225    sse4_1
226    avx
227    avx2
228"
229ARCH_EXT_LIST="
230    neon
231    neon_asm
232
233    mips32
234    dspr2
235    msa
236    mips64
237
238    ${ARCH_EXT_LIST_X86}
239"
240HAVE_LIST="
241    ${ARCH_EXT_LIST}
242    aom_ports
243    fexcept
244    pthread_h
245    unistd_h
246    wxwidgets
247"
248EXPERIMENT_LIST="
249    fp_mb_stats
250    cdef
251    cdef_singlepass
252    var_tx
253    rect_tx
254    rect_tx_ext
255    tpl_mv
256    dual_filter
257    convolve_round
258    compound_round
259    ext_tx
260    tx64x64
261    ext_intra
262    intra_interp
263    filter_intra
264    intra_edge
265    intrabc
266    interintra
267    wedge
268    compound_segment
269    ext_refs
270    global_motion
271    new_quant
272    supertx
273    ans
274    loop_restoration
275    striped_loop_restoration
276    ext_partition
277    ext_partition_types
278    ext_partition_types_ab
279    unpoison_partition_ctx
280    ext_tile
281    motion_var
282    ncobmc
283    warped_motion
284    q_adapt_probs
285    inter_stats_only
286    palette_delta_encoding
287    rawbits
288    kf_ctx
289    pvq
290    cfl
291    xiphrc
292    dct_only
293    daala_tx
294    daala_dct4
295    daala_dct8
296    daala_dct16
297    daala_dct32
298    daala_dct64
299    cb4x4
300    chroma_2x2
301    chroma_sub8x8
302    frame_size
303    ext_delta_q
304    adapt_scan
305    parallel_deblocking
306    deblock_13tap
307    loopfiltering_across_tiles
308    tempmv_signaling
309    rd_debug
310    reference_buffer
311    coef_interleave
312    entropy_stats
313    masked_tx
314    dependent_horztiles
315    dist_8x8
316    palette_throughput
317    ref_adapt
318    lv_map
319    ctx1d
320    txk_sel
321    mv_compress
322    segment_zeromv
323    frame_superres
324    new_multisymbol
325    compound_singleref
326    aom_qm
327    one_sided_compound
328    ext_comp_refs
329    smooth_hv
330    var_refs
331    lgt
332    lgt_from_pred
333    sbl_symbol
334    ncobmc_adapt_weight
335    bgsprite
336    var_tx_no_tx_mode
337    mrc_tx
338    lpf_direct
339    loopfilter_level
340    no_frame_context_signaling
341    txmg
342    max_tile
343    hash_me
344    colorspace_headers
345    mfmv
346    frame_marker
347    jnt_comp
348    frame_sign_bias
349    ext_skip
350    obu
351    amvr
352    lpf_sb
353    opt_ref_mv
354    tmv
355    restrict_compressed_hdr
356    horzonly_frame_superres
357"
358CONFIG_LIST="
359    dependency_tracking
360    external_build
361    install_docs
362    install_bins
363    install_libs
364    install_srcs
365    debug
366    gprof
367    gcov
368    rvct
369    gcc
370    msvs
371    pic
372    big_endian
373
374    codec_srcs
375    debug_libs
376
377    runtime_cpu_detect
378    postproc
379    multithread
380    internal_stats
381    ${CODECS}
382    ${CODEC_FAMILIES}
383    static_msvcrt
384    spatial_resampling
385    realtime_only
386    shared
387    static
388    small
389    postproc_visualizer
390    os_support
391    unit_tests
392    webm_io
393    libyuv
394    accounting
395    inspection
396    decode_perf_tests
397    encode_perf_tests
398    bitstream_debug
399    symbolrate
400    coefficient_range_checking
401    lowbitdepth
402    highbitdepth
403    experimental
404    size_limit
405    ${EXPERIMENT_LIST}
406    analyzer
407"
408CMDLINE_SELECT="
409    dependency_tracking
410    external_build
411    extra_warnings
412    werror
413    install_docs
414    install_bins
415    install_libs
416    install_srcs
417    debug
418    gprof
419    gcov
420    pic
421    optimizations
422    ccache
423    runtime_cpu_detect
424    thumb
425
426    libs
427    examples
428    analyzer
429    docs
430    tools
431    libc
432    as
433    size_limit
434    codec_srcs
435    debug_libs
436
437    postproc
438    multithread
439    internal_stats
440    ${CODECS}
441    ${CODEC_FAMILIES}
442    static_msvcrt
443    spatial_resampling
444    realtime_only
445    shared
446    static
447    small
448    postproc_visualizer
449    unit_tests
450    webm_io
451    libyuv
452    accounting
453    inspection
454    decode_perf_tests
455    encode_perf_tests
456    coefficient_range_checking
457    bitstream_debug
458    symbolrate
459    lowbitdepth
460    highbitdepth
461    experimental
462    adopted_experiments
463    colorspace_headers
464"
465
466process_cmdline() {
467    for opt do
468        optval="${opt#*=}"
469        case "$opt" in
470        --disable-codecs)
471          for c in ${CODEC_FAMILIES}; do disable_codec $c; done
472          ;;
473        --enable-?*|--disable-?*)
474        eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
475        if is_in ${option} ${EXPERIMENT_LIST}; then
476            if enabled experimental; then
477                ${action}_feature $option
478            else
479                log_echo "Ignoring $opt -- not in experimental mode."
480            fi
481        elif is_in ${option} "${CODECS} ${CODEC_FAMILIES}"; then
482            ${action}_codec ${option}
483        else
484            process_common_cmdline $opt
485        fi
486        ;;
487        *) process_common_cmdline "$opt"
488        ;;
489        esac
490    done
491}
492
493post_process_cmdline() {
494    c=""
495
496    # Enable all detected codecs, if they haven't been disabled
497    for c in ${CODECS}; do soft_enable $c; done
498
499    # Enable the codec family if any component of that family is enabled
500    for c in ${CODECS}; do
501        enabled $c && enable_feature ${c%_*}
502    done
503
504    # Set the {en,de}coders variable if any algorithm in that class is enabled
505    for c in ${CODECS}; do
506        enabled ${c} && enable_feature ${c##*_}s
507    done
508
509    enable_feature cb4x4
510
511    # Enable adopted experiments by default
512    soft_enable adopted_experiments
513    if enabled adopted_experiments; then
514      soft_enable chroma_sub8x8
515      soft_enable rect_tx
516      soft_enable global_motion
517      soft_enable ext_tx
518      soft_enable cdef
519      soft_enable ext_intra
520      soft_enable intra_edge
521      soft_enable mv_compress
522      soft_enable ext_refs
523      soft_enable dual_filter
524      soft_enable motion_var
525      soft_enable warped_motion
526      soft_enable var_tx
527      soft_enable wedge
528      soft_enable compound_segment
529      soft_enable interintra
530      soft_enable one_sided_compound
531      soft_enable convolve_round
532      soft_enable aom_qm
533      soft_enable dist_8x8
534      soft_enable cdef_singlepass
535      soft_enable loop_restoration
536
537      # Provisional adopted
538      soft_enable reference_buffer
539      soft_enable loopfiltering_across_tiles
540      soft_enable palette_throughput
541      soft_enable smooth_hv
542      soft_enable tempmv_signaling
543      soft_enable ext_comp_refs
544      soft_enable ext_delta_q
545      soft_enable parallel_deblocking
546    fi
547
548    # Enable low-bitdepth pixel pipeline by default
549    soft_enable lowbitdepth
550
551    # Enable LBD/HBD txfm consistency tool
552    soft_enable txmg
553
554    # Fix up experiment dependencies
555    enabled pvq && disable_feature chroma_2x2
556    enabled pvq && disable_feature rect_tx
557    enabled pvq && disable_feature ext_tx
558    enabled pvq && disable_feature var_tx
559    enabled pvq && disable_feature highbitdepth
560    enabled pvq && disable_feature lgt
561    enabled pvq && disable_feature mrc_tx
562    enabled lv_map && disable_feature mrc_tx
563    enabled supertx && disable_feature mrc_tx
564    enabled coef_interleave && disable_feature mrc_tx
565    enabled pvq && disable_feature palette_throughput
566    enabled mrc_tx && enable_feature ext_tx
567    enabled mrc_tx && enable_feature var_tx
568    enabled txk_sel && soft_enable lv_map
569    enabled ctx1d && soft_enable lv_map
570    enabled ctx1d && soft_enable ext_tx
571    enabled compound_round && soft_enable convolve_round
572    enabled intra_edge && enable_feature ext_intra
573    enabled chroma_2x2 && disable_feature chroma_sub8x8
574    enabled chroma_sub8x8 && enable_feature cb4x4
575    enabled ncobmc_adapt_weight && enable_feature motion_var
576    enabled bgsprite && enable_feature global_motion
577    enabled ext_comp_refs && enable_feature ext_refs
578    enabled ext_comp_refs && enable_feature one_sided_compound
579    enabled rect_tx_ext && enable_feature rect_tx
580    enabled lgt_from_pred && enable_feature ext_tx
581    enabled lgt_from_pred && disable_feature mrc_tx
582    enabled cfl && enable_feature smooth_hv
583    enabled cdef_singlepass && enable_feature cdef
584    enabled new_multisymbol && enable_feature restrict_compressed_hdr
585    enabled mfmv && enable_feature frame_marker
586    enabled jnt_comp && enable_feature frame_marker
587    enabled frame_sign_bias && enable_feature frame_marker
588    enabled txmg && enable_feature highbitdepth
589    enabled ext_skip && enable_feature frame_marker
590    enabled ext_skip && enable_feature ext_refs
591    enabled horzonly_frame_superres && enable_feature frame_superres
592
593    if enabled rawbits && enabled ans; then
594      log_echo "rawbits requires not ans, so disabling rawbits"
595      disable_feature rawbits
596    fi
597    if enabled daala_tx; then
598      enable_feature daala_dct4
599      enable_feature daala_dct8
600      enable_feature daala_dct16
601      enable_feature daala_dct32
602      enable_feature daala_dct64
603    fi
604    if enabled daala_dct64 && ! enabled tx64x64; then
605      log_echo "daala_dct64 requires tx64x64, so disabling daala_dct64"
606      disable_feature daala_dct64
607    fi
608    if enabled daala_dct4 || enabled daala_dct8 || enabled daala_dct16 ||
609        enabled daala_dct32 || enabled daala_dct64; then
610      disable_feature lgt
611      enable_feature lowbitdepth
612    fi
613    if enabled var_tx_no_tx_mode && ! enabled var_tx; then
614      log_echo "var_tx_no_tx_mode requires var_tx, so disabling var_tx_no_tx_mode"
615      disable_feature var_tx_no_tx_mode
616    fi
617    if enabled ext_partition_types; then
618      if enabled fp_mb_stats; then
619        log_echo "ext_partition_types not compatible with fp_mb_stats;"
620        log_echo "disabling fp_mb_stats"
621        disable_feature fp_mb_stats
622      fi
623      if enabled supertx; then
624        log_echo "ext_partition_types not compatible with supertx;"
625        log_echo "disabling supertx"
626        disable_feature supertx
627      fi
628      if ! enabled rect_tx; then
629        log_echo "ext_partition_types requires rect_tx;"
630        log_echo "enabling rect_tx;"
631        enable_feature rect_tx
632      fi
633    fi
634    # Enable accounting and inspection when building the analyzer
635    if enabled analyzer; then
636      soft_enable accounting
637      soft_enable inspection
638    fi
639    # Enable hash_me if amvr is enabled
640    if enabled amvr; then
641      log_echo "amvr requires hash_me"
642      enable_feature hash_me
643    fi
644
645    if enabled striped_loop_restoration && ! enabled loop_restoration ; then
646      log_echo "striped_loop_restoration requires loop_restoration"
647      log_echo "enable loop_restoration"
648      enable_feature loop_restoration
649    fi
650    if enabled striped_loop_restoration && enabled frame_superres ; then
651      log_echo "striped_loop_restoration not compatible with frame_superres"
652      log_echo "disabling striped_loop_restoration"
653      disable_feature striped_loop_restoration
654    fi
655}
656
657process_targets() {
658    enabled child || write_common_config_banner
659    write_common_target_config_h ${BUILD_PFX}aom_config.h
660    write_common_config_targets
661
662    # Calculate the default distribution name, based on the enabled features
663    cf=""
664    DIST_DIR=aom
665    for cf in $CODEC_FAMILIES; do
666        if enabled ${cf}_encoder && enabled ${cf}_decoder; then
667            DIST_DIR="${DIST_DIR}-${cf}"
668        elif enabled ${cf}_encoder; then
669            DIST_DIR="${DIST_DIR}-${cf}cx"
670        elif enabled ${cf}_decoder; then
671            DIST_DIR="${DIST_DIR}-${cf}dx"
672        fi
673    done
674    enabled debug_libs && DIST_DIR="${DIST_DIR}-debug"
675    enabled codec_srcs && DIST_DIR="${DIST_DIR}-src"
676    ! enabled postproc && DIST_DIR="${DIST_DIR}-nopost"
677    ! enabled multithread && DIST_DIR="${DIST_DIR}-nomt"
678    ! enabled install_docs && DIST_DIR="${DIST_DIR}-nodocs"
679    DIST_DIR="${DIST_DIR}-${tgt_isa}-${tgt_os}"
680    case "${tgt_os}" in
681    win*) enabled static_msvcrt && DIST_DIR="${DIST_DIR}mt" || DIST_DIR="${DIST_DIR}md"
682          DIST_DIR="${DIST_DIR}-${tgt_cc}"
683          ;;
684    esac
685    if [ -f "${source_path}/build/make/version.sh" ]; then
686        ver=`"$source_path/build/make/version.sh" --bare "$source_path"`
687        DIST_DIR="${DIST_DIR}-${ver}"
688        VERSION_STRING=${ver}
689        ver=${ver%%-*}
690        VERSION_PATCH=${ver##*.}
691        ver=${ver%.*}
692        VERSION_MINOR=${ver##*.}
693        ver=${ver#v}
694        VERSION_MAJOR=${ver%.*}
695    fi
696    enabled child || cat <<EOF >> config.mk
697
698PREFIX=${prefix}
699ifeq (\$(MAKECMDGOALS),dist)
700DIST_DIR?=${DIST_DIR}
701else
702DIST_DIR?=\$(DESTDIR)${prefix}
703endif
704LIBSUBDIR=${libdir##${prefix}/}
705
706VERSION_STRING=${VERSION_STRING}
707
708VERSION_MAJOR=${VERSION_MAJOR}
709VERSION_MINOR=${VERSION_MINOR}
710VERSION_PATCH=${VERSION_PATCH}
711
712CONFIGURE_ARGS=${CONFIGURE_ARGS}
713EOF
714    enabled child || echo "CONFIGURE_ARGS?=${CONFIGURE_ARGS}" >> config.mk
715
716    #
717    # Write makefiles for all enabled targets
718    #
719    for tgt in libs examples docs tools solution; do
720        tgt_fn="$tgt-$toolchain.mk"
721
722        if enabled $tgt; then
723            echo "Creating makefiles for ${toolchain} ${tgt}"
724            write_common_target_config_mk $tgt_fn ${BUILD_PFX}aom_config.h
725            #write_${tgt}_config
726        fi
727    done
728
729}
730
731process_detect() {
732    if enabled shared; then
733        # Can only build shared libs on a subset of platforms. Doing this check
734        # here rather than at option parse time because the target auto-detect
735        # magic happens after the command line has been parsed.
736        case "${tgt_os}" in
737        linux|os2|darwin*|iphonesimulator*)
738            # Supported platforms
739            ;;
740        *)
741            if enabled gnu; then
742                echo "--enable-shared is only supported on ELF; assuming this is OK"
743            else
744                die "--enable-shared only supported on ELF, OS/2, and Darwin for now"
745            fi
746            ;;
747        esac
748    fi
749    if [ -z "$CC" ] || enabled external_build; then
750        echo "Bypassing toolchain for environment detection."
751        enable_feature external_build
752        check_header() {
753            log fake_check_header "$@"
754            header=$1
755            shift
756            var=`echo $header | sed 's/[^A-Za-z0-9_]/_/g'`
757            disable_feature $var
758            # Headers common to all environments
759            case $header in
760                stdio.h)
761                    true;
762                ;;
763                *)
764                    result=false
765                    for d in "$@"; do
766                        [ -f "${d##-I}/$header" ] && result=true && break
767                    done
768                    ${result:-true}
769            esac && enable_feature $var
770
771            # Specialize windows and POSIX environments.
772            case $toolchain in
773                *-win*-*)
774                    # Don't check for any headers in Windows builds.
775                    false
776                ;;
777                *)
778                    case $header in
779                        pthread.h) true;;
780                        unistd.h) true;;
781                        *) false;;
782                    esac && enable_feature $var
783            esac
784            enabled $var
785        }
786        check_ld() {
787            true
788        }
789    fi
790    check_header stdio.h || die "Unable to invoke compiler: ${CC} ${CFLAGS}"
791    check_ld <<EOF || die "Toolchain is unable to link executables"
792int main(void) {return 0;}
793EOF
794    # check system headers
795    check_header pthread.h
796    check_header unistd.h # for sysconf(3) and friends.
797
798    check_header aom/aom_integer.h -I${source_path} && enable_feature aom_ports
799
800    check_ld <<EOF && enable_feature fexcept
801#define _GNU_SOURCE
802#include <fenv.h>
803int main(void) { (void)feenableexcept(FE_DIVBYZERO | FE_INVALID); return 0; }
804EOF
805}
806
807process_toolchain() {
808    process_common_toolchain
809
810    # Enable some useful compiler flags
811    if enabled gcc; then
812        enabled werror && check_add_cflags -Werror
813        check_add_cflags -Wall
814        check_add_cflags -Wdisabled-optimization
815        check_add_cflags -Wfloat-conversion
816        check_add_cflags -Wpointer-arith
817        check_add_cflags -Wtype-limits
818        check_add_cflags -Wvla
819        check_add_cflags -Wimplicit-function-declaration
820        check_add_cflags -Wuninitialized
821        check_add_cflags -Wunused
822        check_add_cflags -Wsign-compare
823        check_add_cflags -Wstring-conversion
824        check_add_cflags -Wlogical-op
825        check_add_cflags -Wstack-usage=320000
826        # Enabling the following warning (in combination with -Wunused above)
827        # for C++ generates errors in third_party code including googletest and
828        # libyuv. So enable it only for C code.
829        check_cflags "-Wextra" && add_cflags_only "-Wextra"
830        # Enabling the following warning for C++ generates some useless warnings
831        # about some function parameters shadowing class member function names.
832        # So, only enable this warning for C code.
833        check_cflags "-Wshadow" && add_cflags_only "-Wshadow"
834        if enabled mips || [ -z "${INLINE}" ]; then
835          enabled extra_warnings || check_add_cflags -Wno-unused-function
836        fi
837        # gtest makes heavy use of undefined pre-processor symbols
838        check_cflags "-Wundef" && add_cflags_only "-Wundef"
839        # Avoid this warning for third_party C++ sources. Some reorganization
840        # would be needed to apply this only to test/*.cc.
841        check_cflags -Wshorten-64-to-32 && add_cflags_only -Wshorten-64-to-32
842    fi
843
844    if enabled icc; then
845        enabled werror && check_add_cflags -Werror
846        check_add_cflags -Wall
847        check_add_cflags -Wpointer-arith
848
849        # ICC has a number of floating point optimizations that we disable
850        # in favor of deterministic output WRT to other compilers
851        add_cflags -fp-model precise
852    fi
853
854    if enabled analyzer; then
855      soft_enable wxwidgets
856      if ! wx-config --version > /dev/null; then
857        die "Couldn't find wx-config"
858      fi
859
860      add_cxxflags_only $(wx-config --cppflags)
861      add_extralibs $(wx-config --libs)
862    fi
863
864    # Enable extra, harmless warnings. These might provide additional insight
865    # to what the compiler is doing and why, but in general, but they shouldn't
866    # be treated as fatal, even if we're treating warnings as errors.
867    GCC_EXTRA_WARNINGS="
868        -Wdisabled-optimization
869        -Winline
870    "
871    enabled gcc && EXTRA_WARNINGS="${GCC_EXTRA_WARNINGS}"
872    RVCT_EXTRA_WARNINGS="
873        --remarks
874    "
875    enabled rvct && EXTRA_WARNINGS="${RVCT_EXTRA_WARNINGS}"
876    if enabled extra_warnings; then
877        for w in ${EXTRA_WARNINGS}; do
878            check_add_cflags ${w}
879            enabled gcc && enabled werror && check_add_cflags -Wno-error=${w}
880        done
881    fi
882
883    # ccache only really works on gcc toolchains
884    enabled gcc || soft_disable ccache
885
886    # Enable the postbuild target if building for visual studio.
887    case "$tgt_cc" in
888        vs*) enable_feature msvs
889             enable_feature solution
890             vs_version=${tgt_cc##vs}
891             VCPROJ_SFX=vcxproj
892             gen_vcproj_cmd=${source_path}/build/make/gen_msvs_vcxproj.sh
893             enabled werror && gen_vcproj_cmd="${gen_vcproj_cmd} --enable-werror"
894             all_targets="${all_targets} solution"
895             INLINE="__inline"
896        ;;
897    esac
898
899    # Other toolchain specific defaults
900    case $toolchain in x86*) soft_enable postproc;; esac
901
902    if enabled postproc_visualizer; then
903        enabled postproc || die "postproc_visualizer requires postproc to be enabled"
904    fi
905
906    # Enable unit tests by default if we have a working C++ compiler.
907    case "$toolchain" in
908        *-vs*)
909            soft_enable unit_tests
910            soft_enable webm_io
911            soft_enable libyuv
912        ;;
913        *-android-*)
914            soft_enable webm_io
915            soft_enable libyuv
916            # GTestLog must be modified to use Android logging utilities.
917        ;;
918        *-darwin-*)
919            # iOS/ARM builds do not work with gtest. This does not match
920            # x86 targets.
921        ;;
922        *-iphonesimulator-*)
923            soft_enable webm_io
924            soft_enable libyuv
925        ;;
926        *-win*)
927            # Some mingw toolchains don't have pthread available by default.
928            # Treat these more like visual studio where threading in gtest
929            # would be disabled for the same reason.
930            check_cxx "$@" <<EOF && soft_enable unit_tests
931int z;
932EOF
933            check_cxx "$@" <<EOF && soft_enable webm_io
934int z;
935EOF
936            check_cxx "$@" <<EOF && soft_enable libyuv
937int z;
938EOF
939        ;;
940        *)
941            enabled pthread_h && check_cxx "$@" <<EOF && soft_enable unit_tests
942int z;
943EOF
944            check_cxx "$@" <<EOF && soft_enable webm_io
945int z;
946EOF
947            check_cxx "$@" <<EOF && soft_enable libyuv
948int z;
949EOF
950        ;;
951    esac
952    # libwebm needs to be linked with C++ standard library
953    enabled webm_io && LD=${CXX}
954
955    # append any user defined extra cflags
956    if [ -n "${extra_cflags}" ] ; then
957        check_add_cflags ${extra_cflags} || \
958        die "Requested extra CFLAGS '${extra_cflags}' not supported by compiler"
959    fi
960    if [ -n "${extra_cxxflags}" ]; then
961        check_add_cxxflags ${extra_cxxflags} || \
962        die "Requested extra CXXFLAGS '${extra_cxxflags}' not supported by compiler"
963    fi
964}
965
966
967##
968## END APPLICATION SPECIFIC CONFIGURATION
969##
970CONFIGURE_ARGS="$@"
971process "$@"
972print_webm_license ${BUILD_PFX}aom_config.c "/*" " */"
973cat <<EOF >> ${BUILD_PFX}aom_config.c
974#include "aom/aom_codec.h"
975static const char* const cfg = "$CONFIGURE_ARGS";
976const char *aom_codec_build_config(void) {return cfg;}
977EOF
978