Skip to content
Snippets Groups Projects
configure 118 KiB
Newer Older
# Libav configure script
Diego Biurrun's avatar
Diego Biurrun committed
# Copyright (c) 2000-2002 Fabrice Bellard
# Copyright (c) 2005-2008 Diego Biurrun
# Copyright (c) 2005-2008 Mans Rullgard
# Prevent locale nonsense from breaking basic text processing.
# make sure we are running under a compatible shell
# try to make this part work with most shells

try_exec(){
    echo "Trying shell $1"
    type "$1" > /dev/null 2>&1 && exec "$@"
unset foo
(: ${foo%%bar}) 2> /dev/null
(: ${foo?}) 2> /dev/null
E2="$?"

if test "$E1" != 0 || test "$E2" = 0; then
    echo "Broken shell detected.  Trying alternatives."
    export FF_CONF_EXEC
    if test "0$FF_CONF_EXEC" -lt 1; then
        FF_CONF_EXEC=1
        try_exec bash "$0" "$@"
    fi
    if test "0$FF_CONF_EXEC" -lt 2; then
        FF_CONF_EXEC=2
        try_exec ksh "$0" "$@"
    fi
    if test "0$FF_CONF_EXEC" -lt 3; then
        FF_CONF_EXEC=3
        try_exec /usr/xpg4/bin/sh "$0" "$@"
    fi
    echo "No compatible shell script interpreter found."
Diego Biurrun's avatar
Diego Biurrun committed
    echo "This configure script requires a POSIX-compatible shell"
    echo "THIS IS NOT A BUG IN LIBAV, DO NOT REPORT IT AS SUCH."
    echo "Instead, install a working POSIX-compatible shell."
    echo "Disabling this configure test will create a broken Libav."
    if test "$BASH_VERSION" = '2.04.0(1)-release'; then
        echo "This bash version ($BASH_VERSION) is broken on your platform."
        echo "Upgrade to a later version if available."
    fi
test -d /usr/xpg4/bin && PATH=/usr/xpg4/bin:$PATH

    cat <<EOF
Usage: configure [options]
Options: [defaults in brackets after descriptions]

Help options:
  --help                   print this message
  --list-decoders          show all available decoders
  --list-encoders          show all available encoders
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

Standard options:
  --logfile=FILE           log tests and output to FILE [config.log]
  --disable-logging        do not log configure debug information
  --prefix=PREFIX          install in PREFIX [$prefix]
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
  --datadir=DIR            install data files in DIR [PREFIX/share/avconv]
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]

Licensing options:
  --enable-gpl             allow use of GPL code, the resulting libs
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code, the resulting libs
                           and binaries will be unredistributable [no]

Configuration options:
  --disable-static         do not build static libraries [no]
  --enable-shared          build shared libraries [no]
  --enable-small           optimize for size instead of speed
  --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
  --disable-all            disable building components, libraries and programs
Program options:
  --disable-programs       do not build command line programs
  --disable-avconv         disable avconv build
Anton Khirnov's avatar
Anton Khirnov committed
  --disable-avplay         disable avplay build
  --disable-avprobe        disable avprobe build
  --disable-avserver       disable avserver build

Component options:
  --disable-doc            do not build documentation
  --disable-avdevice       disable libavdevice build
  --disable-avcodec        disable libavcodec build
  --disable-avformat       disable libavformat build
  --disable-avutil         disable libavutil build
  --disable-swscale        disable libswscale build
  --disable-avfilter       disable video filter support [no]
Justin Ruggles's avatar
Justin Ruggles committed
  --disable-avresample     disable libavresample build [no]
  --disable-pthreads       disable pthreads [auto]
  --disable-w32threads     disable Win32 threads [auto]
  --enable-x11grab         enable X11 grabbing [no]
  --disable-network        disable network support [no]
  --disable-dct            disable DCT code
  --disable-lsp            disable LSP code
  --disable-lzo            disable LZO decoder code
  --disable-mdct           disable MDCT code
  --disable-rdft           disable RDFT code
  --disable-fft            disable FFT code
  --enable-dxva2           enable DXVA2 code
  --enable-vaapi           enable VAAPI code
  --enable-vda             enable VDA code
  --enable-vdpau           enable VDPAU code

Individual component options:
  --disable-everything     disable all components listed below
  --disable-encoder=NAME   disable encoder NAME
  --enable-encoder=NAME    enable encoder NAME
  --disable-encoders       disable all encoders
  --disable-decoder=NAME   disable decoder NAME
  --enable-decoder=NAME    enable decoder NAME
  --disable-decoders       disable all decoders
  --disable-hwaccel=NAME   disable hwaccel NAME
  --enable-hwaccel=NAME    enable hwaccel NAME
  --disable-hwaccels       disable all hwaccels
  --disable-muxer=NAME     disable muxer NAME
  --enable-muxer=NAME      enable muxer NAME
  --disable-muxers         disable all muxers
  --disable-demuxer=NAME   disable demuxer NAME
  --enable-demuxer=NAME    enable demuxer NAME
  --disable-demuxers       disable all demuxers
  --enable-parser=NAME     enable parser NAME
  --disable-parser=NAME    disable parser NAME
  --disable-parsers        disable all parsers
  --enable-bsf=NAME        enable bitstream filter NAME
  --disable-bsf=NAME       disable bitstream filter NAME
  --disable-bsfs           disable all bitstream filters
  --enable-protocol=NAME   enable protocol NAME
  --disable-protocol=NAME  disable protocol NAME
  --disable-protocols      disable all protocols
  --enable-indev=NAME      enable input device NAME
  --disable-indev=NAME     disable input device NAME
  --disable-indevs         disable input devices
  --enable-outdev=NAME     enable output device NAME
  --disable-outdev=NAME    disable output device NAME
  --disable-outdevs        disable output devices
  --disable-devices        disable all devices
  --enable-filter=NAME     enable filter NAME
  --disable-filter=NAME    disable filter NAME
  --disable-filters        disable all filters

External library support:
  --enable-avisynth        enable reading of AVISynth script files [no]
  --enable-bzlib           enable bzlib [autodetect]
Stefano Sabatini's avatar
Stefano Sabatini committed
  --enable-frei0r          enable frei0r video filtering
  --enable-gnutls          enable gnutls [no]
  --enable-libcdio         enable audio CD grabbing with libcdio
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                           and libraw1394 [no]
  --enable-libfaac         enable AAC encoding via libfaac [no]
  --enable-libfdk-aac      enable AAC encoding via libfdk-aac [no]
  --enable-libfreetype     enable libfreetype [no]
  --enable-libgsm          enable GSM de/encoding via libgsm [no]
  --enable-libilbc         enable iLBC de/encoding via libilbc [no]
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
  --enable-libopencv       enable video filtering via libopencv [no]
  --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
  --enable-libopus         enable Opus decoding via libopus [no]
  --enable-libpulse        enable Pulseaudio input via libpulse [no]
  --enable-librtmp         enable RTMP[E] support via librtmp [no]
  --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
  --enable-libspeex        enable Speex de/encoding via libspeex [no]
  --enable-libtheora       enable Theora encoding via libtheora [no]
  --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
  --enable-libvorbis       enable Vorbis encoding via libvorbis [no]
  --enable-libvpx          enable VP8 de/encoding via libvpx [no]
  --enable-libx264         enable H.264 encoding via x264 [no]
  --enable-libxavs         enable AVS encoding via xavs [no]
  --enable-libxvid         enable Xvid encoding via xvidcore,
                           native MPEG-4/Xvid encoder exists [no]
  --enable-openssl         enable openssl [no]
  --enable-zlib            enable zlib [autodetect]

Advanced options (experts only):
  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
  --enable-cross-compile   assume a cross-compiler is used
  --sysroot=PATH           root of cross-build tree
  --sysinclude=PATH        location of cross-build system headers
  --target-os=OS           compiler targets OS [$target_os]
  --target-exec=CMD        command to run executables on target
  --target-path=DIR        path to view of build directory on target
  --toolchain=NAME         set tool defaults according to NAME
  --nm=NM                  use nm tool
  --ar=AR                  use archive tool AR [$ar_default]
  --as=AS                  use assembler AS [$as_default]
  --cc=CC                  use C compiler CC [$cc_default]
  --dep-cc=DEPCC           use dependency generator DEPCC [$cc_default]
  --ld=LD                  use linker LD
  --host-cc=HOSTCC         use host C compiler HOSTCC
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
  --host-ld=HOSTLD         use host linker HOSTLD
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
  --host-libs=HLIBS        use libs HLIBS when linking for host
  --host-os=OS             compiler host OS [$target_os]
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
  --extra-libs=ELIBS       add ELIBS [$ELIBS]
  --extra-version=STRING   version string suffix []
  --optflags=OPTFLAGS      override optimization-related compiler flags
  --build-suffix=SUFFIX    library name suffix []
  --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
  --arch=ARCH              select architecture [$arch]
  --cpu=CPU                select the minimum required CPU (affects
                           instruction selection, may crash on older CPUs)
  --enable-pic             build position-independent code
  --enable-sram            allow use of on-chip SRAM
  --enable-thumb           compile for Thumb instruction set
  --disable-symver         disable symbol versioning
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
  --disable-safe-bitstream-reader
                           disable buffer boundary checking in bitreaders
                           (faster, but may crash)
  --enable-memalign-hack   emulate memalign, interferes with memory debuggers
  --enable-lto             use link-time optimization

Optimization options (experts only):
  --disable-asm            disable all assembler optimizations
  --disable-altivec        disable AltiVec optimizations
  --disable-amd3dnow       disable 3DNow! optimizations
  --disable-amd3dnowext    disable 3DNow! extended optimizations
  --disable-mmx            disable MMX optimizations
  --disable-mmxext         disable MMXEXT optimizations
  --disable-sse            disable SSE optimizations
  --disable-sse2           disable SSE2 optimizations
  --disable-sse3           disable SSE3 optimizations
  --disable-ssse3          disable SSSE3 optimizations
  --disable-sse4           disable SSE4 optimizations
  --disable-sse42          disable SSE4.2 optimizations
  --disable-avx            disable AVX optimizations
  --disable-fma4           disable FMA4 optimizations
  --disable-armv5te        disable armv5te optimizations
  --disable-armv6          disable armv6 optimizations
  --disable-armv6t2        disable armv6t2 optimizations
  --disable-vfp            disable VFP optimizations
  --disable-neon           disable NEON optimizations
  --disable-vis            disable VIS optimizations
  --disable-inline-asm     disable use of inline assembler
  --disable-yasm           disable use of yasm assembler

Developer options (useful when working on Libav itself):
  --disable-debug          disable debugging symbols
  --enable-debug=LEVEL     set the debug level [$debuglevel]
  --disable-optimizations  disable compiler optimizations
  --enable-extra-warnings  enable more compiler warnings
  --samples=PATH           location of test samples for FATE, if not set use
                           \$LIBAV_SAMPLES at make invocation time.
  --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
                           should be used only for debugging purposes)
  --enable-random          randomly enable/disable components
  --disable-random
  --enable-random=LIST     randomly enable/disable specific components or
  --disable-random=LIST    component groups. LIST is a comma-separated list
                           of NAME[:PROB] entries where NAME is a component
                           (group) and PROB the probability associated with
                           NAME (default 0.5).
  --random-seed=VALUE      seed value for --enable/disable-random

NOTE: Object files are built at the place where configure is launched.
EOF
Måns Rullgård's avatar
Måns Rullgård committed
    log BEGIN $1
    pr -n -t $1 >> $logfile
Måns Rullgård's avatar
Måns Rullgård committed
    log END $1
}

Måns Rullgård's avatar
Måns Rullgård committed
    log "$@"
warn(){
    log "WARNING: $*"
    WARNINGS="${WARNINGS}WARNING: $*\n"
}

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
libav-user@libav.org mailing list or IRC #libav on irc.freenode.net.
Rerun configure with logging enabled (do not use --disable-logging), and
include the log this produces with your report.
        cat <<EOF
Include the log file "$logfile" produced by configure as this will help
solving the problem.
# Avoid locale weirdness, besides we really just want to translate ASCII.
    echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
tolower(){
    echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
c_escape(){
    echo "$*" | sed 's/["\\]/\\\0/g'
}

sh_quote(){
    v=$(echo "$1" | sed "s/'/'\\\\''/g")
    test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'"
cleanws(){
    echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//'
}

        eval "case $v in $pat) echo $v ;; esac"
filter_out(){
    pat=$1
    shift
    for v; do
        eval "case $v in $pat) ;; *) echo $v ;; esac"
    done
}

    for v; do eval $m; done
add_suffix(){
    suffix=$1
    shift
    for v; do echo ${v}${suffix}; done
}

set_all(){
    value=$1
    shift
    for var in $*; do
        eval $var=$value
    done
}

set_weak(){
    value=$1
    shift
    for var; do
        eval : \${$var:=$value}
    done
}

set_safe(){
    var=$1
    shift
    eval $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')='$*'
}

get_safe(){
    eval echo \$$(echo "$1" | sed 's/[^A-Za-z0-9_]/_/g')
}

pushvar(){
    for var in $*; do
        eval level=\${${var}_level:=0}
        eval ${var}_${level}="\$$var"
        eval ${var}_level=$(($level+1))
    done
}

popvar(){
    for var in $*; do
        eval level=\${${var}_level:-0}
        test $level = 0 && continue
        eval level=$(($level-1))
        eval $var="\${${var}_${level}}"
        eval ${var}_level=$level
        eval unset ${var}_${level}
    done
}

enable(){
    set_all yes $*
}

disable(){
    set_all no $*
}

enable_weak(){
    set_weak yes $*
}

disable_weak(){
    set_weak no $*
}

    for var; do
        enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
    done
    for var; do
        disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
    done
do_enable_deep(){
    for var; do
        enabled $var && continue
        eval sel="\$${var}_select"
        eval sgs="\$${var}_suggest"
        pushvar var sgs
        popvar sgs
        enable_deep_weak $sgs
        popvar var
    done
}

enable_deep(){
    do_enable_deep $*
    enable $*
}

enable_deep_weak(){
    do_enable_deep $*
    enable_weak $*
}

    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xyes"
    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xno"
enabled_all(){
    for opt; do
        enabled $opt || return 1
    done
}

disabled_all(){
    for opt; do
        disabled $opt || return 1
    done
}

enabled_any(){
    for opt; do
        enabled $opt && return 0
    done
}

disabled_any(){
    for opt; do
        disabled $opt && return 0
    done
set_default(){
    for opt; do
        eval : \${$opt:=\$${opt}_default}
is_in(){
    value=$1
    shift
    for var in $*; do
        [ $var = $value ] && return 0
    done
    return 1
}

        enabled ${cfg}_checking && die "Circular dependency for $cfg."
        disabled ${cfg}_checking && continue
        enable ${cfg}_checking
        eval dep_all="\$${cfg}_deps"
        eval dep_any="\$${cfg}_deps_any"
        eval dep_sel="\$${cfg}_select"
        eval dep_sgs="\$${cfg}_suggest"
        eval dep_ifa="\$${cfg}_if"
        eval dep_ifn="\$${cfg}_if_any"
        pushvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
        do_check_deps $dep_all $dep_any $dep_sel $dep_sgs $dep_ifa $dep_ifn
        popvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
        [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
        [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
Måns Rullgård's avatar
Måns Rullgård committed
        enabled_all  $dep_all || disable $cfg
        enabled_any  $dep_any || disable $cfg
        disabled_any $dep_sel && disable $cfg
        if enabled $cfg; then
            enable_deep $dep_sel
            enable_deep_weak $dep_sgs
        disable ${cfg}_checking
check_deps(){
    unset allopts

    do_check_deps "$@"

    for cfg in $allopts; do
        enabled $cfg || continue
        eval dep_extralibs="\$${cfg}_extralibs"
        test -n "$dep_extralibs" && add_extralibs $dep_extralibs
    done
}

print_config(){
    pfx=$1
    map 'eval echo "$v \${$v:-no}"' "$@" |
    awk "BEGIN { split(\"$files\", files) }
        {
            c = \"$pfx\" toupper(\$1);
            v = \$2;
            sub(/yes/, 1, v);
            sub(/no/,  0, v);
            for (f in files) {
                file = files[f];
                if (file ~ /\\.h\$/) {
                    printf(\"#define %s %d\\n\", c, v) >>file;
                } else if (file ~ /\\.asm\$/) {
                    printf(\"%%define %s %d\\n\", c, v) >>file;
                } else if (file ~ /\\.mak\$/) {
                    n = -v ? \"\" : \"!\";
                    printf(\"%s%s=yes\\n\", n, c) >>file;
                }
            }
        }"
print_enabled(){
    suf=$1
    shift
    for v; do
        enabled $v && printf "%s\n" ${v%$suf};
prepend(){
    var=$1
    shift
    eval "$var=\"$* \$$var\""
}

    append CPPFLAGS "$@"
    append CFLAGS $($cflags_filter "$@")
    append ASFLAGS $($asflags_filter "$@")
    append LDFLAGS $($ldflags_filter "$@")
    prepend extralibs $($ldflags_filter "$@")
add_host_cflags(){
    append host_cflags $($host_cflags_filter "$@")
}

add_host_ldflags(){
    append host_ldflags $($host_ldflags_filter "$@")
}

add_compat(){
    append compat_objs $1
    shift
    map 'add_cppflags -D$v' "$@"
}

    log "$@"
cc_o(){
    eval printf '%s\\n' $CC_O
}

cc_e(){
    eval printf '%s\\n' $CC_E
}

    check_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC
    check_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC
as_o(){
    eval printf '%s\\n' $AS_O
}

check_as(){
    log check_as "$@"
    cat > $TMPS
    log_file $TMPS
    check_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $(as_o $TMPO) $TMPS
check_inline_asm(){
    log check_inline_asm "$@"
    check_cc "$@" <<EOF && enable $name
void foo(void){ __asm__ volatile($code); }
check_insn(){
    log check_insn "$@"
    check_inline_asm ${1}_inline "\"$2\""
    echo "$2" | check_as && enable ${1}_external || disable ${1}_external
}

Loren Merritt's avatar
Loren Merritt committed
check_yasm(){
    log check_yasm "$@"
    echo "$1" > $TMPS
    log_file $TMPS
    shift 1
    check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
}

ld_o(){
    eval printf '%s\\n' $LD_O
}

    flags=$(filter_out '-l*' "$@")
    libs=$(filter '-l*' "$@")
    check_cc $($cflags_filter $flags) || return
    flags=$($ldflags_filter $flags)
    libs=$($ldflags_filter $libs)
    check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
check_code(){
    log check_code "$@"
    check=$1
    headers=$2
    code=$3
    shift 3
    {
        for hdr in $headers; do
            echo "#include <$hdr>"
        done
        echo "int main(void) { $code; return 0; }"
    } | check_$check "$@"
}

check_cppflags(){
    log check_cppflags "$@"
    check_cc "$@" <<EOF && append CPPFLAGS "$@"
check_cflags(){
    set -- $($cflags_filter "$@")
    check_cc "$@" <<EOF && append CFLAGS "$@"
test_ldflags(){
    log test_ldflags "$@"
    check_ld "$@" <<EOF
check_ldflags(){
    log check_ldflags "$@"
    test_ldflags "$@" && add_ldflags "$@"
}

check_header(){
    disable_safe $header
    check_cpp "$@" <<EOF && enable_safe $header
#include <$header>
int x;
EOF
}

check_func(){
Måns Rullgård's avatar
Måns Rullgård committed
    disable $func
    check_ld "$@" <<EOF && enable $func
extern int $func();
check_mathfunc(){
    log check_mathfunc "$@"
    narg=$2
    shift 2
    test $narg = 2 && args="f, g" || args="f"
    disable $func
    check_ld "$@" <<EOF && enable $func
#include <math.h>
float foo(float f, float g) { return $func($args); }
int main(void){ return 0; }
check_func_headers(){
    log check_func_headers "$@"
    {
        for hdr in $headers; do
            echo "#include <$hdr>"
        done
        for func in $funcs; do
            echo "long check_$func(void) { return (long) $func; }"
        done
        echo "int main(void) { return 0; }"
    } | check_ld "$@" && enable $funcs && enable_safe $headers
check_cpp_condition(){
    log check_cpp_condition "$@"
    header=$1
    condition=$2
    check_cpp "$@" <<EOF
#include <$header>
#if !($condition)
#error "unsatisfied condition: $condition"
#endif
EOF
}

check_lib(){
    log check_lib "$@"
    header="$1"
    func="$2"
    shift 2
    check_header $header && check_func $func "$@" && add_extralibs "$@"
check_lib2(){
    log check_lib2 "$@"
    headers="$1"
    check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
check_pkg_config(){
    log check_pkg_config "$@"
    pkg="$1"
    headers="$2"
    funcs="$3"
    shift 3
    $pkg_config --exists $pkg || return
    pkg_cflags=$($pkg_config --cflags $pkg)
    pkg_libs=$($pkg_config --libs $pkg)
    check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
        set_safe ${pkg}_cflags $pkg_cflags   &&
        set_safe ${pkg}_libs   $pkg_libs
}

    check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
check_exec_crash(){

    # exit() is not async signal safe.  _Exit (C99) and _exit (POSIX)
    # are safe but may not be available everywhere.  Thus we use
    # raise(SIGTERM) instead.  The check is run in a subshell so we
    # can redirect the "Terminated" message from the shell.  SIGBUS
    # is not defined by standard C so it is used conditionally.

    (check_exec "$@") >> $logfile 2>&1 <<EOF
#include <signal.h>
static void sighandler(int sig){
    raise(SIGTERM);
}
Diego Biurrun's avatar
Diego Biurrun committed
int main(void){
    signal(SIGILL, sighandler);
    signal(SIGFPE, sighandler);
    signal(SIGSEGV, sighandler);
#ifdef SIGBUS
    signal(SIGBUS, sighandler);
#endif
check_type(){
    log check_type "$@"
    headers=$1
    type=$2
    shift 2
    check_code cc "$headers" "$type v" "$@" && enable_safe "$type"
check_struct(){
    log check_type "$@"
    headers=$1
    struct=$2
    member=$3
    shift 3
    disable_safe "${struct}_${member}"
    check_code cc "$headers" "const void *p = &(($struct *)0)->$member" "$@" &&
        enable_safe "${struct}_${member}"
require(){
    name="$1"
    header="$2"
    func="$3"
    shift 3
    check_lib $header $func "$@" || die "ERROR: $name not found"
require2(){
    name="$1"
    headers="$2"
    func="$3"
    shift 3
    check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
}

require_pkg_config(){
    pkg="$1"
    check_pkg_config "$@" || die "ERROR: $pkg not found"
    add_cflags    $(get_safe ${pkg}_cflags)
    add_extralibs $(get_safe ${pkg}_libs)
}

hostcc_o(){
    eval printf '%s\\n' $HOSTCC_O
}

check_host_cc(){
    log check_host_cc "$@"
    cat > $TMPC
    log_file $TMPC
    check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC
}

check_host_cflags(){
    log check_host_cflags "$@"
    set -- $($host_cflags_filter "$@")
    check_host_cc "$@" <<EOF && append host_cflags "$@"
int x;
EOF
}

apply(){
    file=$1
    shift
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
}

    cmp -s "$1" "$2" && echo "$2 is unchanged" && return
    mkdir -p "$(dirname $2)"
Mans Rullgard's avatar
Mans Rullgard committed
    $cp_f "$1" "$2"
# CONFIG_LIST contains configurable options, while HAVE_LIST is for
# system-dependent things.

COMPONENT_LIST="
    bsfs
    decoders
    demuxers
    encoders
Vitor Sessak's avatar
Vitor Sessak committed
    filters
Laurent Aimar's avatar
Laurent Aimar committed
    dxva2
Stefano Sabatini's avatar
Stefano Sabatini committed
    frei0r
Aurelien Jacobs's avatar
Aurelien Jacobs committed
    hardcoded_tables
Ramiro Polla's avatar
Ramiro Polla committed
    libdc1394
    libopenjpeg
    libopus
    libspeex
    libtheora
James Zern's avatar
James Zern committed
    libvpx
    runtime_cpudetect
Måns Rullgård's avatar
Måns Rullgård committed
    tomi
ARCH_EXT_LIST_ARM='
    armv5te
    armv6
    armv6t2
    neon
HAVE_LIST_PUB='
    bigendian
    fast_unaligned
    $(add_suffix _external $ARCH_EXT_LIST)
    $(add_suffix _inline   $ARCH_EXT_LIST)
    aligned_stack
    alsa_asoundlib_h
    attribute_may_alias
    attribute_packed
Alex Beregszaszi's avatar
Alex Beregszaszi committed
    closesocket
    dev_bktr_ioctl_bt848_h
    dev_bktr_ioctl_meteor_h
    dev_ic_bt8xx_h
    dev_video_bktr_ioctl_bt848_h
    dev_video_meteor_ioctl_meteor_h
Måns Rullgård's avatar
Måns Rullgård committed
    fcntl
Måns Rullgård's avatar
Måns Rullgård committed
    fork
    GetProcessAffinityMask
    GetSystemTimeAsFileTime
Ramiro Polla's avatar
Ramiro Polla committed
    getrusage
Måns Rullgård's avatar
Måns Rullgård committed
    ldbrx
    machine_ioctl_bt848_h
    machine_ioctl_meteor_h
    MapViewOfFile
    mkstemp
    mprotect
    nanosleep
    posix_memalign
    sndio_h
Måns Rullgård's avatar
Måns Rullgård committed
    soundcard_h
    strerror_r
    strptime
Stefano Sabatini's avatar
Stefano Sabatini committed
    strtok_r
    struct_group_source_req
    struct_ip_mreq_source
    struct_pollfd
    struct_v4l2_frmivalenum_discrete
Måns Rullgård's avatar
Måns Rullgård committed
    sys_soundcard_h
    sys_time_h
    unistd_h
    windows_h
Diego Biurrun's avatar
Diego Biurrun committed
# options emitted with CONFIG_ prefix but not available on the command line
    host_ldflags
    host_libs
Måns Rullgård's avatar
Måns Rullgård committed
    samples
    toolchain
# code dependency declarations

# architecture extensions
armv5te_deps="arm"
armv6_deps="arm"
armv6t2_deps="arm"
vfp_deps="arm"
vfpv3_deps="vfp"
map 'eval ${v}_inline_deps=inline_asm' $ARCH_EXT_LIST_ARM

altivec_deps="ppc"
ppc4xx_deps="ppc"

vis_deps="sparc"

x86_64_suggest="cmov fast_cmov"
amd3dnow_deps="mmx"
amd3dnowext_deps="amd3dnow"
mmx_deps="x86"
mmxext_deps="mmx"
sse_deps="mmxext"
sse2_deps="sse"
sse3_deps="sse2"
ssse3_deps="sse3"
sse4_deps="ssse3"
sse42_deps="sse4"
avx_deps="sse42"
mmx_external_deps="yasm"
mmx_inline_deps="inline_asm"
mmx_suggest="mmx_external mmx_inline"

for ext in $(filter_out mmx $ARCH_EXT_LIST_X86); do
    eval dep=\$${ext}_deps
    eval ${ext}_external_deps='"${dep}_external"'
    eval ${ext}_inline_deps='"${dep}_inline"'
    eval ${ext}_suggest='"${ext}_external ${ext}_inline"'
done

aligned_stack_if_any="ppc x86"
fast_64bit_if_any="alpha ia64 mips64 parisc64 ppc64 sparc64 x86_64"
fast_clz_if_any="alpha avr32 mips ppc x86"
fast_unaligned_if_any="ppc x86"
inline_asm_deps="!tms470"
need_memalign="altivec neon sse"
symver_if_any="symver_asm_label symver_gnu_asm"

dct_select="rdft"
mdct_select="fft"
rdft_select="fft"
mpegaudio_select="mpegaudiodsp"
aac_decoder_select="mdct sinewin"
aac_encoder_select="mdct sinewin"
aac_latm_decoder_select="aac_decoder aac_latm_parser"
ac3_decoder_select="mdct ac3dsp ac3_parser"
ac3_encoder_select="mdct ac3dsp"
ac3_fixed_encoder_select="mdct ac3dsp"
atrac1_decoder_select="mdct sinewin"
binkaudio_dct_decoder_select="mdct rdft dct sinewin"
binkaudio_rdft_decoder_select="mdct rdft sinewin"
cavs_decoder_select="golomb mpegvideo"
comfortnoise_encoder_select="lpc"
cook_decoder_select="mdct sinewin"
cscd_decoder_select="lzo"
cscd_decoder_suggest="zlib"
dnxhd_encoder_select="aandcttables mpegvideoenc"
dxa_decoder_select="zlib"
eac3_decoder_select="ac3_decoder"
eac3_encoder_select="ac3_encoder"
eamad_decoder_select="aandcttables error_resilience mpegvideo"
eatgq_decoder_select="aandcttables"
eatqi_decoder_select="aandcttables error_resilience mpegvideo"
ffv1_decoder_select="golomb rangecoder"
ffv1_encoder_select="rangecoder"
ffvhuff_encoder_select="huffman"
flac_decoder_select="golomb"
flashsv_decoder_select="zlib"
flashsv_encoder_select="zlib"
flashsv2_decoder_select="zlib"
flv_decoder_select="h263_decoder"
flv_encoder_select="h263_encoder"
fraps_decoder_select="huffman"
h261_decoder_select="error_resilience mpegvideo"
h261_encoder_select="aandcttables mpegvideoenc"
h263_decoder_select="error_resilience h263_parser mpegvideo"
h263_encoder_select="aandcttables error_resilience mpegvideoenc"
h263i_decoder_select="h263_decoder"
h263p_encoder_select="h263_encoder"
h264_decoder_select="error_resilience golomb h264chroma h264dsp h264pred h264qpel mpegvideo"
huffyuv_encoder_select="huffman"
iac_decoder_select="fft mdct sinewin"
imc_decoder_select="fft mdct sinewin"
jpegls_decoder_select="golomb"
jpegls_encoder_select="golomb"
ljpeg_encoder_select="aandcttables mpegvideoenc"
loco_decoder_select="golomb"
mdec_decoder_select="error_resilience mpegvideo"
mjpeg_encoder_select="aandcttables mpegvideoenc"
mlp_decoder_select="mlp_parser"
mp1_decoder_select="mpegaudio"
mp1float_decoder_select="mpegaudio"
mp2_decoder_select="mpegaudio"
mp2float_decoder_select="mpegaudio"
mp3_decoder_select="mpegaudio"
mp3adu_decoder_select="mpegaudio"
mp3adufloat_decoder_select="mpegaudio"
mp3float_decoder_select="mpegaudio"
mp3on4_decoder_select="mpegaudio"
mp3on4float_decoder_select="mpegaudio"
mpc7_decoder_select="mpegaudiodsp"
mpc8_decoder_select="mpegaudiodsp"
mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
mpeg_xvmc_decoder_select="mpegvideo_decoder"
mpeg1video_decoder_select="error_resilience mpegvideo"
mpeg1video_encoder_select="aandcttables error_resilience mpegvideoenc"
mpeg2video_decoder_select="error_resilience mpegvideo"
mpeg2video_encoder_select="aandcttables error_resilience mpegvideoenc"
mpeg4_decoder_select="h263_decoder mpeg4video_parser"
mpeg4_encoder_select="h263_encoder"
msmpeg4v1_decoder_select="h263_decoder"
msmpeg4v1_encoder_select="h263_encoder"
msmpeg4v2_decoder_select="h263_decoder"
msmpeg4v2_encoder_select="h263_encoder"
msmpeg4v3_decoder_select="h263_decoder"
msmpeg4v3_encoder_select="h263_encoder"
Alberto Delmás's avatar
Alberto Delmás committed
mss2_decoder_select="vc1_decoder"
nellymoser_decoder_select="mdct sinewin"
nellymoser_encoder_select="mdct sinewin"
nuv_decoder_select="lzo"
png_decoder_select="zlib"
png_encoder_select="zlib"
qdm2_decoder_select="mdct rdft mpegaudiodsp"
ra_144_encoder_select="lpc"
rv30_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo"
rv40_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo"
shorten_decoder_select="golomb"
svq1_decoder_select="error_resilience mpegvideo"
svq1_encoder_select="aandcttables error_resilience mpegvideoenc"
svq3_decoder_select="error_resilience golomb h264chroma h264dsp h264pred h264qpel mpegvideo"
svq3_decoder_suggest="zlib"
theora_decoder_select="vp3_decoder"
tiff_decoder_suggest="zlib"
tiff_encoder_suggest="zlib"
truehd_decoder_select="mlp_decoder"
tscc_decoder_select="zlib"
twinvq_decoder_select="mdct lsp sinewin"
utvideo_encoder_select="huffman"
vc1_decoder_select="h263_decoder h264chroma h264qpel"
vc1image_decoder_select="vc1_decoder"
vorbis_decoder_select="mdct"
vorbis_encoder_select="mdct"
vp3_decoder_select="vp3dsp videodsp"
vp5_decoder_select="vp3dsp videodsp"
vp6_decoder_select="huffman vp3dsp videodsp"
vp6a_decoder_select="vp6_decoder"
vp6f_decoder_select="vp6_decoder"
vp8_decoder_select="h264pred videodsp"
wmapro_decoder_select="mdct sinewin"
wmav1_decoder_select="mdct sinewin"
wmav1_encoder_select="mdct sinewin"
wmav2_decoder_select="mdct sinewin"
wmav2_encoder_select="mdct sinewin"
wmavoice_decoder_select="lsp rdft dct mdct sinewin"
wmv1_encoder_select="h263_encoder"
wmv2_encoder_select="h263_encoder"
wmv3_decoder_select="vc1_decoder"
wmv3image_decoder_select="wmv3_decoder"
Derek Buitenhuis's avatar
Derek Buitenhuis committed
zerocodec_decoder_select="zlib"
zlib_decoder_select="zlib"
zlib_encoder_select="zlib"
zmbv_decoder_select="zlib"
zmbv_encoder_select="zlib"
vaapi_deps="va_va_h"
vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"

h263_vaapi_hwaccel_select="vaapi h263_decoder"
h263_vdpau_hwaccel_select="vdpau h263_decoder"
h264_dxva2_hwaccel_deps="dxva2api_h"
h264_dxva2_hwaccel_select="dxva2 h264_decoder"
h264_vaapi_hwaccel_select="vaapi h264_decoder"
h264_vda_hwaccel_select="vda h264_decoder"
h264_vdpau_decoder_select="vdpau h264_decoder"
h264_vdpau_hwaccel_select="vdpau h264_decoder"
mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
mpeg2_dxva2_hwaccel_deps="dxva2api_h"
mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
mpeg4_vdpau_hwaccel_select="vdpau mpeg4_decoder"
vc1_dxva2_hwaccel_deps="dxva2api_h"
vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
vc1_vdpau_decoder_select="vdpau vc1_decoder"
vc1_vdpau_hwaccel_select="vdpau vc1_decoder"
wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
h264_parser_select="error_resilience golomb h264dsp h264pred mpegvideo"
mpeg4video_parser_select="error_resilience mpegvideo"
mpegvideo_parser_select="error_resilience mpegvideo"
vc1_parser_select="error_resilience mpegvideo"
# external libraries
libfdk_aac_encoder_deps="libfdk_aac"
libgsm_decoder_deps="libgsm"
libgsm_encoder_deps="libgsm"
libgsm_ms_decoder_deps="libgsm"
libgsm_ms_encoder_deps="libgsm"
libilbc_decoder_deps="libilbc"
libilbc_encoder_deps="libilbc"
libopencore_amrnb_decoder_deps="libopencore_amrnb"
libopencore_amrnb_encoder_deps="libopencore_amrnb"
libopencore_amrwb_decoder_deps="libopencore_amrwb"
libopenjpeg_decoder_deps="libopenjpeg"
libopenjpeg_encoder_deps="libopenjpeg"
libopus_decoder_deps="libopus"
libopus_encoder_deps="libopus"
libschroedinger_decoder_deps="libschroedinger"
libschroedinger_encoder_deps="libschroedinger"
libspeex_decoder_deps="libspeex"
libspeex_encoder_deps="libspeex"
libtheora_encoder_deps="libtheora"
libvo_aacenc_encoder_deps="libvo_aacenc"
libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
libvorbis_encoder_deps="libvorbis"
James Zern's avatar
James Zern committed
libvpx_decoder_deps="libvpx"
James Zern's avatar
James Zern committed
libvpx_encoder_deps="libvpx"
libxavs_encoder_deps="libxavs"
# demuxers / muxers
ac3_demuxer_select="ac3_parser"
asf_stream_muxer_select="asf_muxer"
avisynth_demuxer_deps="avisynth"
dirac_demuxer_select="dirac_parser"
flac_demuxer_select="flac_parser"
ismv_muxer_select="mov_muxer"
matroska_audio_muxer_select="matroska_muxer"
matroska_demuxer_suggest="bzlib lzo zlib"
mov_demuxer_suggest="zlib"
mov_muxer_select="rtpenc_chain"
mp3_demuxer_select="mpegaudio_parser"
mpegts_muxer_select="adts_muxer latm_muxer mpegvideo"
mpegtsraw_demuxer_select="mpegts_demuxer"
mxf_d10_muxer_select="mxf_muxer"
ogg_demuxer_select="golomb"
rtpdec_select="asf_demuxer rm_demuxer rtp_protocol mpegts_demuxer mov_demuxer"
rtsp_demuxer_select="http_protocol rtpdec"
rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol rtpenc_chain"
Martin Storsjö's avatar
Martin Storsjö committed
sap_demuxer_select="sdp_demuxer"
sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"
smoothstreaming_muxer_select="ismv_muxer"
spdif_muxer_select="aac_parser"
tak_demuxer_select="tak_parser"
tg2_muxer_select="mov_muxer"
tgp_muxer_select="mov_muxer"
w64_demuxer_deps="wav_demuxer"
alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
alsa_outdev_deps="alsa_asoundlib_h"
bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
dv1394_indev_deps="dv1394 dv_demuxer"
fbdev_indev_deps="linux_fb_h"
libcdio_indev_deps="libcdio"
libdc1394_indev_deps="libdc1394"
oss_indev_deps_any="soundcard_h sys_soundcard_h"
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
pulse_indev_deps="libpulse"
sndio_indev_deps="sndio_h"
sndio_outdev_deps="sndio_h"
v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
vfwcap_indev_extralibs="-lavicap32"
x11grab_indev_deps="x11grab XShmCreateImage"
# protocols
Samuel Pitoiset's avatar
Samuel Pitoiset committed
ffrtmpcrypt_protocol_deps="!librtmp_protocol"
ffrtmpcrypt_protocol_deps_any="gcrypt nettle openssl"
ffrtmpcrypt_protocol_select="tcp_protocol"
ffrtmphttp_protocol_deps="!librtmp_protocol"
ffrtmphttp_protocol_select="http_protocol"
httpproxy_protocol_select="tcp_protocol"
http_protocol_select="tcp_protocol"
https_protocol_select="tls_protocol"
librtmp_protocol_deps="librtmp"
librtmpe_protocol_deps="librtmp"
librtmps_protocol_deps="librtmp"
librtmpt_protocol_deps="librtmp"
librtmpte_protocol_deps="librtmp"
Måns Rullgård's avatar
Måns Rullgård committed
mmsh_protocol_select="http_protocol"
rtmp_protocol_deps="!librtmp_protocol"
rtmp_protocol_select="tcp_protocol"
Samuel Pitoiset's avatar
Samuel Pitoiset committed
rtmpe_protocol_select="ffrtmpcrypt_protocol"
Samuel Pitoiset's avatar
Samuel Pitoiset committed
rtmps_protocol_deps="!librtmp_protocol"
rtmps_protocol_select="tls_protocol"
rtmpt_protocol_select="ffrtmphttp_protocol"
Samuel Pitoiset's avatar
Samuel Pitoiset committed
rtmpte_protocol_select="ffrtmpcrypt_protocol ffrtmphttp_protocol"
rtmpts_protocol_select="ffrtmphttp_protocol https_protocol"
rtp_protocol_select="udp_protocol"
sctp_protocol_deps="struct_sctp_event_subscribe"
sctp_protocol_select="network"
tcp_protocol_select="network"
tls_protocol_deps_any="openssl gnutls"
tls_protocol_select="tcp_protocol"
blackframe_filter_deps="gpl"
boxblur_filter_deps="gpl"
cropdetect_filter_deps="gpl"
delogo_filter_deps="gpl"
frei0r_filter_deps="frei0r dlopen strtok_r"
frei0r_filter_extralibs='$ldl'
frei0r_src_filter_deps="frei0r dlopen strtok_r"
frei0r_src_filter_extralibs='$ldl'
hqdn3d_filter_deps="gpl"
resample_filter_deps="avresample"
scale_filter_deps="swscale"
avcodec_deps="avutil"
avdevice_deps="avutil avcodec avformat"
avfilter_deps="avutil"
avformat_deps="avutil avcodec"
avresample_deps="avutil"
swscale_deps="avutil"
# programs
avconv_deps="avcodec avfilter avformat avresample swscale"
avconv_select="aformat_filter anull_filter asyncts_filter format_filter
               fps_filter null_filter resample_filter scale_filter
               setpts_filter"
avplay_deps="avcodec avformat avresample swscale sdl"
Anton Khirnov's avatar
Anton Khirnov committed
avplay_select="rdft"
avprobe_deps="avcodec avformat"
avserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer !shared"
avserver_extralibs='$ldl'
Fabrice Bellard's avatar
Fabrice Bellard committed
# default parameters

# installation paths
prefix_default="/usr/local"
bindir_default='${prefix}/bin'
datadir_default='${prefix}/share/avconv'
incdir_default='${prefix}/include'
libdir_default='${prefix}/lib'
mandir_default='${prefix}/share/man'
shlibdir_default="$libdir_default"
ar_default="ar"
host_cc_default="gcc"
Mans Rullgard's avatar
Mans Rullgard committed
cp_f="cp -f"
ln_s="ln -sf"
nm_default="nm -g"
objformat="elf"
pkg_config_default=pkg-config
Michael Niedermayer's avatar
Michael Niedermayer committed
ranlib="ranlib"
yasmexe="yasm"
target_os_default=$(tolower $(uname -s))
host_os=$target_os_default

# configurable options
enable $LIBRARY_LIST $PROGRAM_LIST
enable safe_bitstream_reader
enable static
SHFLAGS='-shared -Wl,-soname,$$(@F)'
AVSERVERLDFLAGS=-Wl,-E
FULLNAME='$(NAME)$(BUILDSUF)'
LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)'
SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
Måns Rullgård's avatar
Måns Rullgård committed
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
asflags_filter=echo
cflags_filter=echo
ldflags_filter=echo

HOSTLD_O='-o $@'
host_cflags='-D_ISOC99_SOURCE -D_XOPEN_SOURCE=600 -O3 -g'
host_libs='-lm'
host_cflags_filter=echo
host_ldflags_filter=echo
target_path='$(CURDIR)'
# since the object filename is not given with the -MM flag, the compiler
# is only able to print the basename, and we must add the path ourselves
DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
DEPFLAGS='-MM'
if test -f configure; then
    source_path=.
    source_path=$(cd $(dirname "$0"); pwd)
    echo "$source_path" | grep -q '[[:blank:]]' &&
        die "Out of tree builds are impossible with whitespace in source path."
    test -e "$source_path/config.h" &&
        die "Out of tree builds are impossible with config.h in source dir."
    r=${v#*=}
    l=${v%"$r"}
    r=$(sh_quote "$r")
    LIBAV_CONFIGURATION="${LIBAV_CONFIGURATION# } ${l}${r}"
find_things(){
    thing=$1
    pattern=$2
    file=$source_path/$3
    sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file"
}

ENCODER_LIST=$(find_things  encoder  ENC      libavcodec/allcodecs.c)
DECODER_LIST=$(find_things  decoder  DEC      libavcodec/allcodecs.c)
HWACCEL_LIST=$(find_things  hwaccel  HWACCEL  libavcodec/allcodecs.c)
PARSER_LIST=$(find_things   parser   PARSER   libavcodec/allcodecs.c)
BSF_LIST=$(find_things      bsf      BSF      libavcodec/allcodecs.c)
MUXER_LIST=$(find_things    muxer    _MUX     libavformat/allformats.c)
DEMUXER_LIST=$(find_things  demuxer  DEMUX    libavformat/allformats.c)
OUTDEV_LIST=$(find_things   outdev   OUTDEV   libavdevice/alldevices.c)
INDEV_LIST=$(find_things    indev    _IN      libavdevice/alldevices.c)
PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c)
FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
ALL_COMPONENTS="
    $BSF_LIST
    $DECODER_LIST
    $DEMUXER_LIST
    $ENCODER_LIST
    $FILTER_LIST
    $HWACCEL_LIST
    $INDEV_LIST
    $MUXER_LIST
    $OUTDEV_LIST
    $PARSER_LIST
    $PROTOCOL_LIST
"

for n in $COMPONENT_LIST; do
    v=$(toupper ${n%s})_LIST
    eval enable \$$v
    eval ${n}_if_any="\$$v"
done

enable $ARCH_EXT_LIST

die_unknown(){
    echo "Unknown option \"$1\"."
    echo "See $0 --help for available options."
    exit 1
}

Ramiro Polla's avatar
Ramiro Polla committed
    suffix=_$1
    shift
    echo $* | sed s/$suffix//g | tr ' ' '\n' | sort | pr -3 -t
rand_list(){
    IFS=', '
    set -- $*
    unset IFS
    for thing; do
        comp=${thing%:*}
        prob=${thing#$comp}
        prob=${prob#:}
        is_in ${comp} $COMPONENT_LIST && eval comp=\$$(toupper ${comp%s})_LIST
        echo "prob ${prob:-0.5}"
        printf '%s\n' $comp
    done
}

do_random(){
    action=$1
    shift
    random_seed=$(awk "BEGIN { srand($random_seed); print srand() }")
    $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == \"prob\" { prob = \$2; next } rand() < prob { print }")
}

        --extra-ldflags=*)
            add_ldflags $optval
        --extra-libs=*)
            add_extralibs $optval
        --disable-devices)
            disable $INDEV_LIST $OUTDEV_LIST
        --enable-debug=*)
            debuglevel="$optval"
        ;;
        --disable-programs)
            disable $PROGRAM_LIST
        ;;
        --disable-everything)
            map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST
        ;;
        --disable-all)
            map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST
            disable $LIBRARY_LIST $PROGRAM_LIST doc
        ;;
        --enable-random|--disable-random)
            action=${opt%%-random}
            do_random ${action#--} $COMPONENT_LIST
        ;;
        --enable-random=*|--disable-random=*)
            action=${opt%%-random=*}
            do_random ${action#--} $optval
        ;;
        --enable-*=*|--disable-*=*)
            eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/')
            is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
            eval list=\$$(toupper $thing)_LIST
            name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
            $action $(filter "$name" $list)
        ;;
        --enable-?*|--disable-?*)
            eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
            if is_in $option $COMPONENT_LIST; then
                test $action = disable && action=unset
                eval $action \$$(toupper ${option%s})_LIST
            elif is_in $option $CMDLINE_SELECT; then
                $action $option
            else
                die_unknown $opt
            fi
        ;;
        --list-*)
            NAME="${opt#--list-}"
            is_in $NAME $COMPONENT_LIST || die_unknown $opt
            NAME=${NAME%s}
            eval show_list $NAME \$$(toupper $NAME)_LIST
        ;;
        --help|-h) show_help
        ;;
        *)
            optname="${opt%%=*}"
            optname="${optname#--}"
            optname=$(echo "$optname" | sed 's/-/_/g')
            if is_in $optname $CMDLINE_SET; then
                eval $optname='$optval'
            elif is_in $optname $CMDLINE_APPEND; then
                append $optname "$optval"
            else
                die_unknown $opt
            fi
        ;;
Måns Rullgård's avatar
Måns Rullgård committed
disabled logging && logfile=/dev/null

echo "# $0 $LIBAV_CONFIGURATION" > $logfile
Måns Rullgård's avatar
Måns Rullgård committed
set >> $logfile

test -n "$cross_prefix" && enable cross_compile

if enabled cross_compile; then
    test -n "$arch" && test -n "$target_os" ||
        die "Must specify target arch and OS when cross-compiling"
fi

ar_default="${cross_prefix}${ar_default}"
cc_default="${cross_prefix}${cc_default}"
Måns Rullgård's avatar
Måns Rullgård committed
nm_default="${cross_prefix}${nm_default}"
pkg_config_default="${cross_prefix}${pkg_config_default}"
ranlib="${cross_prefix}${ranlib}"

sysinclude_default="${sysroot}/usr/include"

case "$toolchain" in
    clang-asan)
        cc_default="clang"
        add_cflags  -faddress-sanitizer
        add_ldflags -faddress-sanitizer
    ;;
    clang-tsan)
        cc_default="clang"
        add_cflags  -fthread-sanitizer
        add_ldflags -fthread-sanitizer
    ;;
    msvc)
        cc_default="c99wrap cl"
        ld_default="c99wrap link"
        nm_default="dumpbin -symbols"
        target_os_default="win32"
    ;;
    ?*)
        die "Unknown toolchain $toolchain"
    ;;
esac

set_default arch cc pkg_config sysinclude target_os
enabled cross_compile || host_cc_default=$cc
set_default host_cc
if ! $pkg_config --version >/dev/null 2>&1; then
    warn "$pkg_config not found, library detection may fail."
    pkg_config=false
fi

        mingw32*|win32|win64|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;;
    esac
}

EXESUF=$(exesuf $target_os)
HOSTEXESUF=$(exesuf $host_os)
# set temporary file name
: ${TMPDIR:=$TEMPDIR}
: ${TMPDIR:=/tmp}
if ! check_cmd mktemp -u XXXXXX; then
    # simple replacement for missing mktemp
    # NOT SAFE FOR GENERAL USE
    mktemp(){
        echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$"
    }
fi

tmpfile(){
    tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 &&
        (set -C; exec > $tmp) 2>/dev/null ||
        die "Unable to create temporary file in $TMPDIR."
    append TMPFILES $tmp
    eval $1=$tmp
}

trap 'rm -f -- $TMPFILES' EXIT

tmpfile TMPASM .asm
tmpfile TMPC   .c
tmpfile TMPE   $EXESUF
tmpfile TMPH   .h
tmpfile TMPO   .o
tmpfile TMPS   .S
tmpfile TMPSH  .sh
tmpfile TMPV   .ver
chmod +x $TMPE

# make sure we can execute files in $TMPDIR
cat > $TMPSH 2>> $logfile <<EOF
#! /bin/sh
EOF
chmod +x $TMPSH >> $logfile 2>&1
if ! $TMPSH >> $logfile 2>&1; then
    cat <<EOF
Unable to create and execute files in $TMPDIR.  Set the TMPDIR environment
variable to another directory and make sure that it is not mounted noexec.
EOF
    die "Sanity test failed."
fi

ccc_flags(){
    for flag; do
        case $flag in
            -std=c99)           echo -c99                       ;;
            -mcpu=*)            echo -arch ${flag#*=}           ;;
            -mieee)             echo -ieee                      ;;
            -O*|-fast)          echo $flag                      ;;
            -fno-math-errno)    echo -assume nomath_errno       ;;
            -g)                 echo -g3                        ;;
            -Wall)              echo -msg_enable level2         ;;
            -Wno-pointer-sign)  echo -msg_disable ptrmismatch1  ;;
            -Wl,*)              echo $flag                      ;;
            -f*|-W*)                                            ;;
            *)                  echo $flag                      ;;
        esac
   done
}

msvc_flags(){
    for flag; do
        case $flag in
            -fomit-frame-pointer) echo -Oy ;;
            -g)                   echo -Z7 ;;
            -Wall)                echo -W4 -wd4244 -wd4127 -wd4018 -wd4389 \
                                       -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \
                                       -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \
            -std=c99)             ;;
            -fno-math-errno)      ;;
            -fno-common)          ;;
            -fno-signed-zeros)    ;;
            -lz)                  echo zlib.lib ;;
            -lavifil32)           echo vfw32.lib ;;
            -lavicap32)           echo vfw32.lib user32.lib ;;
            -l*)                  echo ${flag#-l}.lib ;;
            *)                    echo $flag ;;
        esac
    done
}

Loading
Loading full blame...