configure 77.1 KB
Newer Older
1
#!/bin/sh
2
#
3 4
# FFmpeg configure script
#
diego's avatar
diego committed
5 6 7
# Copyright (c) 2000-2002 Fabrice Bellard
# Copyright (c) 2005-2008 Diego Biurrun
# Copyright (c) 2005-2008 Mans Rullgard
8
#
9

10
# Prevent locale nonsense from breaking basic text processing.
11 12
LC_ALL=C
export LC_ALL
13

14
# make sure we are running under a compatible shell
15 16 17
# try to make this part work with most shells

try_exec(){
18
    echo "Trying shell $1"
19
    type "$1" > /dev/null 2>&1 && exec "$@"
20 21
}

mru's avatar
mru committed
22
unset foo
23
(: ${foo%%bar}) 2> /dev/null
24 25
E1="$?"

26
(: ${foo?}) 2> /dev/null
27 28 29 30
E2="$?"

if test "$E1" != 0 || test "$E2" = 0; then
    echo "Broken shell detected.  Trying alternatives."
31 32 33 34 35 36 37 38 39 40 41 42
    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" "$@"
43 44
    fi
    echo "No compatible shell script interpreter found."
diego's avatar
typo  
diego committed
45
    echo "This configure script requires a POSIX-compatible shell"
46
    echo "such as bash or ksh."
diego's avatar
diego committed
47 48 49
    echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
    echo "Instead, install a working POSIX-compatible shell."
    echo "Disabling this configure test will create a broken FFmpeg."
50 51 52 53
    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
54 55 56
    exit 1
fi

57 58 59 60 61 62
show_help(){
  echo "Usage: configure [options]"
  echo "Options: [defaults in brackets after descriptions]"
  echo
  echo "Standard options:"
  echo "  --help                   print this message"
63 64
  echo "  --logfile=FILE           log tests and output to FILE [config.err]"
  echo "  --disable-logging        do not log configure debug information"
65
  echo "  --prefix=PREFIX          install in PREFIX [$prefix]"
66
  echo "  --bindir=DIR             install binaries in DIR [PREFIX/bin]"
67
  echo "  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]"
68
  echo "  --libdir=DIR             install libs in DIR [PREFIX/lib]"
69
  echo "  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]"
70
  echo "  --incdir=DIR             install includes in DIR [PREFIX/include]"
71
  echo "  --mandir=DIR             install man page in DIR [PREFIX/share/man]"
72 73
  echo
  echo "Configuration options:"
74 75
  echo "  --disable-static         do not build static libraries [no]"
  echo "  --enable-shared          build shared libraries [no]"
76 77
  echo "  --enable-gpl             allow use of GPL code, the resulting libs"
  echo "                           and binaries will be under GPL [no]"
78
  echo "  --enable-version3        upgrade (L)GPL to version 3 [no]"
79 80
  echo "  --enable-nonfree         allow use of nonfree code, the resulting libs"
  echo "                           and binaries will be unredistributable [no]"
81 82 83
  echo "  --disable-ffmpeg         disable ffmpeg build"
  echo "  --disable-ffplay         disable ffplay build"
  echo "  --disable-ffserver       disable ffserver build"
84
  echo "  --enable-postproc        enable GPLed postprocessing support [no]"
diego's avatar
diego committed
85
  echo "  --enable-avfilter        video filter support [no]"
86
  echo "  --enable-avfilter-lavf   video filters dependent on avformat [no]"
87 88 89 90 91
  echo "  --enable-beosthreads     use BeOS threads [no]"
  echo "  --enable-os2threads      use OS/2 threads [no]"
  echo "  --enable-pthreads        use pthreads [no]"
  echo "  --enable-w32threads      use Win32 threads [no]"
  echo "  --enable-x11grab         enable X11 grabbing [no]"
92 93 94 95
  echo "  --disable-network        disable network support [no]"
  echo "  --disable-ipv6           disable IPv6 support [no]"
  echo "  --disable-mpegaudio-hp   faster (but less accurate) MPEG audio decoding [no]"
  echo "  --enable-gray            enable full grayscale support (slower color)"
96
  echo "  --disable-swscale-alpha  disable alpha channel support in swscale"
mru's avatar
mru committed
97
  echo "  --disable-fastdiv        disable table-based division"
98 99 100 101 102
  echo "  --enable-small           optimize for size instead of speed"
  echo "  --disable-aandct         disable AAN DCT code"
  echo "  --disable-fft            disable FFT code"
  echo "  --disable-golomb         disable Golomb code"
  echo "  --disable-mdct           disable MDCT code"
103
  echo "  --disable-rdft           disable RDFT code"
104
  echo "  --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)"
105 106 107 108 109 110 111 112 113
  echo "  --enable-hardcoded-tables use hardcoded tables instead of runtime generation"
  echo "  --enable-memalign-hack   emulate memalign, interferes with memory debuggers"
  echo "  --enable-beos-netserver  enable BeOS netserver"
  echo "  --disable-encoder=NAME   disable encoder NAME"
  echo "  --enable-encoder=NAME    enable encoder NAME"
  echo "  --disable-encoders       disable all encoders"
  echo "  --disable-decoder=NAME   disable decoder NAME"
  echo "  --enable-decoder=NAME    enable decoder NAME"
  echo "  --disable-decoders       disable all decoders"
114 115 116
  echo "  --disable-hwaccel=NAME   disable hwaccel NAME"
  echo "  --enable-hwaccel=NAME    enable hwaccel NAME"
  echo "  --disable-hwaccels       disable all hwaccels"
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
  echo "  --disable-muxer=NAME     disable muxer NAME"
  echo "  --enable-muxer=NAME      enable muxer NAME"
  echo "  --disable-muxers         disable all muxers"
  echo "  --disable-demuxer=NAME   disable demuxer NAME"
  echo "  --enable-demuxer=NAME    enable demuxer NAME"
  echo "  --disable-demuxers       disable all demuxers"
  echo "  --enable-parser=NAME     enable parser NAME"
  echo "  --disable-parser=NAME    disable parser NAME"
  echo "  --disable-parsers        disable all parsers"
  echo "  --enable-bsf=NAME        enable bitstream filter NAME"
  echo "  --disable-bsf=NAME       disable bitstream filter NAME"
  echo "  --disable-bsfs           disable all bitstream filters"
  echo "  --enable-protocol=NAME   enable protocol NAME"
  echo "  --disable-protocol=NAME  disable protocol NAME"
  echo "  --disable-protocols      disable all protocols"
  echo "  --disable-indevs         disable input devices"
  echo "  --disable-outdevs        disable output devices"
  echo "  --disable-devices        disable all devices"
  echo "  --enable-filter=NAME     enable filter NAME"
  echo "  --disable-filter=NAME    disable filter NAME"
  echo "  --disable-filters        disable all filters"
  echo "  --list-decoders          show all available decoders"
  echo "  --list-encoders          show all available encoders"
140
  echo "  --list-hwaccels          show all available hardware accelerators"
141 142 143 144 145 146 147 148
  echo "  --list-muxers            show all available muxers"
  echo "  --list-demuxers          show all available demuxers"
  echo "  --list-parsers           show all available parsers"
  echo "  --list-protocols         show all available protocols"
  echo "  --list-bsfs              show all available bitstream filters"
  echo "  --list-indevs            show all available input devices"
  echo "  --list-outdevs           show all available output devices"
  echo "  --list-filters           show all available filters"
mru's avatar
mru committed
149 150
  echo
  echo "External library support:"
151
  echo "  --enable-avisynth        enable reading of AVISynth script files [no]"
152 153 154
  echo "  --enable-bzlib           enable bzlib [autodetect]"
  echo "  --enable-libamr-nb       enable libamr-nb floating point audio codec [no]"
  echo "  --enable-libamr-wb       enable libamr-wb floating point audio codec [no]"
155 156
  echo "  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]"
  echo "  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]"
ramiro's avatar
ramiro committed
157
  echo "  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394"
158 159 160 161 162 163 164
  echo "                           and libraw1394 [no]"
  echo "  --enable-libdirac        enable Dirac support via libdirac [no]"
  echo "  --enable-libfaac         enable FAAC support via libfaac [no]"
  echo "  --enable-libfaad         enable FAAD support via libfaad [no]"
  echo "  --enable-libfaadbin      open libfaad.so.0 at runtime [no]"
  echo "  --enable-libgsm          enable GSM support via libgsm [no]"
  echo "  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]"
165
  echo "  --enable-libnut          enable NUT (de)muxing via libnut,"
166
  echo "                           native (de)muxer exists [no]"
167
  echo "  --enable-libopenjpeg     enable JPEG 2000 decoding via OpenJPEG [no]"
168 169 170
  echo "  --enable-libschroedinger enable Dirac support via libschroedinger [no]"
  echo "  --enable-libspeex        enable Speex decoding via libspeex [no]"
  echo "  --enable-libtheora       enable Theora encoding via libtheora [no]"
171
  echo "  --enable-libvorbis       enable Vorbis encoding via libvorbis,"
172 173
  echo "                           native implementation exists [no]"
  echo "  --enable-libx264         enable H.264 encoding via x264 [no]"
174
  echo "  --enable-libxvid         enable Xvid encoding via xvidcore,"
175
  echo "                           native MPEG-4/Xvid encoder exists [no]"
diego's avatar
diego committed
176
  echo "  --enable-mlib            enable Sun medialib [no]"
177
  echo "  --enable-zlib            enable zlib [autodetect]"
178 179 180 181
  echo ""
  echo "Advanced options (experts only):"
  echo "  --source-path=PATH       path to source code [$source_path]"
  echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]"
182
  echo "  --enable-cross-compile   assume a cross-compiler is used"
183 184
  echo "  --sysroot=PATH           root of cross-build tree"
  echo "  --sysinclude=PATH        location of cross-build system headers"
185
  echo "  --target-os=OS           compiler targets OS [$target_os]"
186 187
  echo "  --target-exec=CMD        command to run executables on target"
  echo "  --target-path=DIR        path to view of build directory on target"
188
  echo "  --nm=NM                  use nm tool"
189
  echo "  --as=AS                  use assembler AS [$as_default]"
190
  echo "  --cc=CC                  use C compiler CC [$cc_default]"
191 192 193 194
  echo "  --host-cc=HOSTCC         use host C compiler HOSTCC"
  echo "  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host"
  echo "  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host"
  echo "  --host-libs=HLIBS        use libs HLIBS when linking for host"
195 196 197
  echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
  echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
  echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
198
  echo "  --extra-version=STRING   version string suffix []"
199 200 201
  echo "  --build-suffix=SUFFIX    library name suffix []"
  echo "  --arch=ARCH              select architecture [$arch]"
  echo "  --cpu=CPU                select the minimum required CPU (affects"
diego's avatar
diego committed
202
  echo "                           instruction selection, may crash on older CPUs)"
203
  echo "  --enable-powerpc-perf    enable performance report on PPC"
204
  echo "                           (requires enabling PMC)"
205
  echo "  --disable-altivec        disable AltiVec optimizations"
206
  echo "  --disable-amd3dnow       disable 3DNow! optimizations"
207
  echo "  --disable-amd3dnowext    disable 3DNow! extended optimizations"
208 209
  echo "  --disable-mmx            disable MMX optimizations"
  echo "  --disable-mmx2           disable MMX2 optimizations"
210
  echo "  --disable-sse            disable SSE optimizations"
211 212 213
  echo "  --disable-ssse3          disable SSSE3 optimizations"
  echo "  --disable-armv5te        disable armv5te optimizations"
  echo "  --disable-armv6          disable armv6 optimizations"
214
  echo "  --disable-armv6t2        disable armv6t2 optimizations"
diego's avatar
diego committed
215
  echo "  --disable-armvfp         disable ARM VFP optimizations"
216
  echo "  --disable-iwmmxt         disable iwmmxt optimizations"
217 218 219
  echo "  --disable-mmi            disable MMI optimizations"
  echo "  --disable-neon           disable neon optimizations"
  echo "  --disable-vis            disable VIS optimizations"
220
  echo "  --disable-yasm           disable use of yasm assembler"
mru's avatar
mru committed
221 222
  echo
  echo "Developer options (useful when working on FFmpeg itself):"
223
  echo "  --disable-debug          disable debugging symbols"
224
  echo "  --enable-debug=LEVEL     set the debug level [$debuglevel]"
mru's avatar
mru committed
225
  echo "  --enable-gprof           enable profiling with gprof [$gprof]"
226
  echo "  --disable-optimizations  disable compiler optimizations"
mru's avatar
mru committed
227
  echo "  --enable-extra-warnings  enable more compiler warnings"
228
  echo "  --disable-stripping      disable stripping of executables and shared libraries"
229 230
  echo ""
  echo "NOTE: Object files are built at the place where configure is launched."
stefano's avatar
stefano committed
231
  exit 0
232
}
233

234
log(){
235
    echo "$@" >> $logfile
236 237
}

238
log_file(){
mru's avatar
mru committed
239
    log BEGIN $1
240
    pr -n -t $1 >> $logfile
mru's avatar
mru committed
241 242 243
    log END $1
}

244
echolog(){
mru's avatar
mru committed
245
    log "$@"
246
    echo "$@"
247 248 249 250 251
}

die(){
    echolog "$@"
    cat <<EOF
252

253 254
If you think configure made a mistake, make sure you are using the latest
version from SVN.  If the latest version fails, report the problem to the
255
ffmpeg-user@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
256
EOF
257
    if disabled logging; then
258
        cat <<EOF
259 260
Rerun configure with logging enabled (do not use --disable-logging), and
include the log this produces with your report.
261 262 263
EOF
    else
cat <<EOF
264 265
Include the log file "$logfile" produced by configure as this will help
solving the problem.
266 267
EOF
    fi
268 269 270
    exit 1
}

271
# Avoid locale weirdness, besides we really just want to translate ASCII.
mru's avatar
mru committed
272
toupper(){
273
    echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
mru's avatar
mru committed
274 275
}

mru's avatar
mru committed
276
tolower(){
277
    echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
mru's avatar
mru committed
278 279
}

280 281 282 283
c_escape(){
    echo "$*" | sed 's/["\\]/\\\0/g'
}

284 285 286 287 288 289 290 291
set_all(){
    value=$1
    shift
    for var in $*; do
        eval $var=$value
    done
}

292 293 294 295 296 297 298 299
set_weak(){
    value=$1
    shift
    for var; do
        eval : \${$var:=$value}
    done
}

mru's avatar
mru committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
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
}

319 320 321 322 323 324 325 326
enable(){
    set_all yes $*
}

disable(){
    set_all no $*
}

327 328 329 330 331 332 333 334
enable_weak(){
    set_weak yes $*
}

disable_weak(){
    set_weak no $*
}

335 336 337 338 339 340 341 342
enable_safe(){
    enable $(echo "$*" | sed 's/[^A-Za-z0-9_ ]/_/g')
}

disable_safe(){
    disable $(echo "$*" | sed 's/[^A-Za-z0-9_ ]/_/g')
}

343 344 345 346
do_enable_deep(){
    for var; do
        enabled $var && continue
        eval sel="\$${var}_select"
mru's avatar
mru committed
347 348
        eval sgs="\$${var}_suggest"
        pushvar var sgs
349
        enable_deep $sel
mru's avatar
mru committed
350 351
        popvar sgs
        enable_deep_weak $sgs
352 353 354 355 356 357 358 359 360
        popvar var
    done
}

enable_deep(){
    do_enable_deep $*
    enable $*
}

361 362 363 364 365
enable_deep_weak(){
    do_enable_deep $*
    enable_weak $*
}

366
enabled(){
367 368
    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xyes"
mru's avatar
mru committed
369 370
}

371
disabled(){
372 373
    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xno"
374 375
}

mru's avatar
mru committed
376 377 378 379 380 381
enabled_all(){
    for opt; do
        enabled $opt || return 1
    done
}

382 383 384 385 386 387
disabled_all(){
    for opt; do
        disabled $opt || return 1
    done
}

mru's avatar
mru committed
388 389 390 391 392 393
enabled_any(){
    for opt; do
        enabled $opt && return 0
    done
}

394 395 396 397
disabled_any(){
    for opt; do
        disabled $opt && return 0
    done
398
    return 1
399 400
}

mru's avatar
mru committed
401 402
set_default(){
    for opt; do
403
        eval : \${$opt:=\$${opt}_default}
mru's avatar
mru committed
404 405 406
    done
}

407 408 409 410 411 412 413 414 415
is_in(){
    value=$1
    shift
    for var in $*; do
        [ $var = $value ] && return 0
    done
    return 1
}

416 417
check_deps(){
    for cfg; do
418
        cfg="${cfg#!}"
mru's avatar
mru committed
419 420 421 422
        enabled ${cfg}_checking && die "Circular dependency for $cfg."
        disabled ${cfg}_checking && continue
        enable ${cfg}_checking

423 424
        eval dep_all="\$${cfg}_deps"
        eval dep_any="\$${cfg}_deps_any"
mru's avatar
mru committed
425
        eval dep_sel="\$${cfg}_select"
mru's avatar
mru committed
426
        eval dep_sgs="\$${cfg}_suggest"
mru's avatar
mru committed
427

mru's avatar
mru committed
428 429 430
        pushvar cfg dep_all dep_any dep_sel dep_sgs
        check_deps $dep_all $dep_any $dep_sel $dep_sgs
        popvar cfg dep_all dep_any dep_sel dep_sgs
mru's avatar
mru committed
431

mru's avatar
mru committed
432 433
        enabled_all  $dep_all || disable $cfg
        enabled_any  $dep_any || disable $cfg
mru's avatar
mru committed
434
        disabled_any $dep_sel && disable $cfg
mru's avatar
mru committed
435

436 437 438
        if enabled $cfg; then
            eval dep_extralibs="\$${cfg}_extralibs"
            test -n "$dep_extralibs" && add_extralibs $dep_extralibs
439
            enable_deep $dep_sel
mru's avatar
mru committed
440
            enable_deep_weak $dep_sgs
441 442
        fi

mru's avatar
mru committed
443
        disable ${cfg}_checking
444 445 446
    done
}

mru's avatar
mru committed
447 448 449 450 451 452
print_config(){
    pfx=$1
    header=$2
    makefile=$3
    shift 3
    for cfg; do
453
        ucname="$(toupper $cfg)"
mru's avatar
mru committed
454
        if enabled $cfg; then
455 456 457
            echo "#define ${pfx}${ucname} 1" >> $header
            echo "${pfx}${ucname}=yes" >> $makefile
        else
458
            echo "#define ${pfx}${ucname} 0" >> $header
mru's avatar
mru committed
459 460
        fi
    done
461 462 463
}

flags_saved(){
464
    (: ${SAVE_CFLAGS?}) 2> /dev/null
465 466
}

467
save_flags(){
468
    flags_saved && return
469 470 471 472 473 474
    SAVE_CFLAGS="$CFLAGS"
    SAVE_LDFLAGS="$LDFLAGS"
    SAVE_extralibs="$extralibs"
}

restore_flags(){
475
    flags_saved || return
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
    CFLAGS="$SAVE_CFLAGS"
    LDFLAGS="$SAVE_LDFLAGS"
    extralibs="$SAVE_extralibs"
    unset SAVE_CFLAGS
    unset SAVE_LDFLAGS
    unset SAVE_extralibs
}

temp_cflags(){
    save_flags
    CFLAGS="$CFLAGS $*"
}

temp_ldflags(){
    save_flags
    LDFLAGS="$LDFLAGS $*"
}

temp_extralibs(){
    save_flags
    extralibs="$extralibs $*"
}

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
append(){
    var=$1
    shift
    flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
    eval "$var=\"\$$var $*\""
}

add_cflags(){
    append CFLAGS "$@"
}

add_ldflags(){
    append LDFLAGS "$@"
}

add_extralibs(){
    append extralibs "$@"
}

518
check_cmd(){
mru's avatar
mru committed
519
    log "$@"
520
    "$@" >> $logfile 2>&1
521 522
}

523
check_cc(){
524
    log check_cc "$@"
525
    cat > $TMPC
526
    log_file $TMPC
527
    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
528 529 530 531
}

check_cpp(){
    log check_cpp "$@"
532
    cat > $TMPC
533
    log_file $TMPC
534
    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
535 536
}

mru's avatar
mru committed
537 538 539 540 541 542 543
check_as(){
    log check_as "$@"
    cat > $TMPC
    log_file $TMPC
    check_cmd $as $CFLAGS "$@" -c -o $TMPO $TMPC
}

mru's avatar
mru committed
544 545 546 547 548
check_asm(){
    log check_asm "$@"
    name="$1"
    asm="$2"
    shift 2
mru's avatar
mru committed
549
    check_as "$@" <<EOF && enable $name || disable $name
550
void foo(void){ __asm__ volatile($asm); }
mru's avatar
mru committed
551 552 553
EOF
}

lorenm's avatar
lorenm committed
554 555 556 557 558 559 560 561
check_yasm(){
    log check_yasm "$@"
    echo "$1" > $TMPS
    log_file $TMPS
    shift 1
    check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
}

562
check_ld(){
563
    log check_ld "$@"
mru's avatar
mru committed
564
    check_cc || return
565 566 567 568 569 570
    flags=''
    libs=''
    for f; do
        test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
    done
    check_cmd $cc $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs
571 572 573
}

check_cflags(){
574 575
    log check_cflags "$@"
    check_cc "$@" <<EOF && add_cflags "$@"
576 577 578 579 580
int x;
EOF
}

check_ldflags(){
581 582
    log check_ldflags "$@"
    check_ld "$@" <<EOF && add_ldflags "$@"
583
int main(void){ return 0; }
584 585 586 587
EOF
}

check_header(){
588
    log check_header "$@"
589 590
    header=$1
    shift
591 592
    disable_safe $header
    check_cpp "$@" <<EOF && enable_safe $header
593 594 595 596 597 598
#include <$header>
int x;
EOF
}

check_func(){
599
    log check_func "$@"
600 601
    func=$1
    shift
mru's avatar
mru committed
602 603
    disable $func
    check_ld "$@" <<EOF && enable $func
604
extern int $func();
605
int main(void){ $func(); }
606 607 608
EOF
}

609 610
check_func_headers(){
    log check_func_headers "$@"
611 612 613 614 615 616 617 618 619
    headers=$1
    func=$2
    shift 2
    disable $func
    incs=""
    for hdr in $headers; do
        incs="$incs
#include <$hdr>"
    done
620
    check_ld "$@" <<EOF && enable $func && enable_safe $headers
621
$incs
622
int main(int argc, char **argv){
623 624 625 626 627 628
    (void) $func;
    return 0;
}
EOF
}

629 630 631 632 633 634 635 636 637 638 639 640
check_cpp_condition(){
    log check_cpp_condition "$@"
    header=$1
    condition=$2
    check_cpp <<EOF
#include <$header>
#if !($condition)
#error "unsatisfied condition: $condition"
#endif
EOF
}

641 642 643 644 645
check_lib(){
    log check_lib "$@"
    header="$1"
    func="$2"
    shift 2
646 647 648 649 650
    temp_extralibs "$@"
    check_header $header && check_func $func && add_extralibs "$@"
    err=$?
    restore_flags
    return $err
651 652
}

653 654 655 656 657 658
check_lib2(){
    log check_lib2 "$@"
    headers="$1"
    func="$2"
    shift 2
    temp_extralibs "$@"
659
    check_func_headers "$headers" $func && add_extralibs "$@"
660 661 662 663 664
    err=$?
    restore_flags
    return $err
}

665
check_exec(){
666
    check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
667 668
}

mru's avatar
mru committed
669
check_exec_crash(){
670
    code=$(cat)
mru's avatar
mru committed
671 672 673 674 675 676 677

    # 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.

678
    (check_exec "$@") >> $logfile 2>&1 <<EOF
mru's avatar
mru committed
679 680 681 682
#include <signal.h>
static void sighandler(int sig){
    raise(SIGTERM);
}
diego's avatar
diego committed
683
int main(void){
mru's avatar
mru committed
684 685 686 687 688 689 690 691 692 693 694
    signal(SIGILL, sighandler);
    signal(SIGFPE, sighandler);
    signal(SIGSEGV, sighandler);
#ifdef SIGBUS
    signal(SIGBUS, sighandler);
#endif
    { $code }
}
EOF
}

695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
check_type(){
    log check_type "$@"
    headers=$1
    type=$2
    shift 2
    disable $type
    incs=""
    for hdr in $headers; do
        incs="$incs
#include <$hdr>"
    done
    check_cc "$@" <<EOF && enable $type
$incs
$type v;
EOF
}

712 713 714 715 716 717
require(){
    name="$1"
    header="$2"
    func="$3"
    shift 3
    check_lib $header $func "$@" || die "ERROR: $name not found"
718 719
}

720 721 722 723 724 725 726 727
require2(){
    name="$1"
    headers="$2"
    func="$3"
    shift 3
    check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
}

mru's avatar
mru committed
728 729 730 731 732 733 734 735 736 737
check_foo_config(){
    cfg=$1
    pkg=$2
    header=$3
    func=$4
    shift 4
    disable $cfg
    check_cmd ${pkg}-config --version
    err=$?
    if test "$err" = 0; then
738 739
        temp_cflags $(${pkg}-config --cflags)
        temp_extralibs $(${pkg}-config --libs)
mru's avatar
mru committed
740 741 742 743 744
        check_lib "$@" $header $func && enable $cfg
    fi
    return $err
}

mru's avatar
mru committed
745 746 747 748 749 750
apply(){
    file=$1
    shift
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
}

751 752 753
# CONFIG_LIST contains configurable options, while HAVE_LIST is for
# system-dependent things.

754 755 756 757 758
COMPONENT_LIST="
    bsfs
    decoders
    demuxers
    encoders
vitor's avatar
vitor committed
759
    filters
760
    hwaccels
761
    indevs
762
    muxers
763
    outdevs
764 765 766 767 768 769
    parsers
    protocols
"

CONFIG_LIST="
    $COMPONENT_LIST
770
    aandct
771 772
    avfilter
    avfilter_lavf
773 774
    avisynth
    beos_netserver
775
    bzlib
mru's avatar
mru committed
776
    fastdiv
777 778 779
    ffmpeg
    ffplay
    ffserver
780
    fft
781
    golomb
782
    gpl
mru's avatar
mru committed
783
    gprof
784
    gray
aurel's avatar
aurel committed
785
    hardcoded_tables
786
    ipv6
787 788
    libamr_nb
    libamr_wb
ramiro's avatar
ramiro committed
789
    libdc1394
790
    libdirac
791 792 793
    libfaac
    libfaad
    libfaadbin
794
    libgsm
795
    libmp3lame
796
    libnut
797 798
    libopencore_amrnb
    libopencore_amrwb
799
    libopenjpeg
800
    libschroedinger
conrad's avatar
conrad committed
801
    libspeex
diego's avatar
diego committed
802
    libtheora
803
    libvorbis
804 805
    libx264
    libxvid
mru's avatar
mru committed
806
    mdct
807
    memalign_hack
808
    mlib
809 810
    mpegaudio_hp
    network
811
    nonfree
812
    postproc
813
    powerpc_perf
814
    rdft
815
    runtime_cpudetect
mru's avatar
mru committed
816
    shared
817
    small
mru's avatar
mru committed
818
    static
819
    swscale_alpha
820
    version3
821
    x11grab
822
    zlib
823
"
824

825 826
THREADS_LIST='
    beosthreads
827
    os2threads
828 829 830 831
    pthreads
    w32threads
'

832 833
ARCH_LIST='
    alpha
mru's avatar
mru committed
834
    arm
835 836 837 838
    bfin
    ia64
    m68k
    mips
839
    mips64
840
    parisc
841
    ppc
reimar's avatar
reimar committed
842
    ppc64
843 844 845 846 847 848 849 850 851 852
    s390
    sh4
    sparc
    sparc64
    x86
    x86_32
    x86_64
'

ARCH_EXT_LIST='
mru's avatar
mru committed
853
    altivec
854
    amd3dnow
855
    amd3dnowext
mru's avatar
mru committed
856
    armv5te
857
    armv6
mru's avatar
mru committed
858
    armv6t2
mru's avatar
mru committed
859
    armvfp
860 861 862
    iwmmxt
    mmi
    mmx
863
    mmx2
mru's avatar
mru committed
864
    neon
865
    ppc4xx
866
    sse
mru's avatar
mru committed
867
    ssse3
868
    vis
869 870 871 872 873
'

HAVE_LIST="
    $ARCH_EXT_LIST
    $THREADS_LIST
benoit's avatar
benoit committed
874
    alsa_asoundlib_h
875
    altivec_h
876
    arpa_inet_h
877
    bigendian
mru's avatar
mru committed
878
    bswap
alex's avatar
alex committed
879
    closesocket
mru's avatar
mru committed
880
    cmov
881
    conio_h
882
    dcbzl
883 884 885 886 887
    dev_bktr_ioctl_bt848_h
    dev_bktr_ioctl_meteor_h
    dev_ic_bt8xx_h
    dev_video_meteor_ioctl_meteor_h
    dev_video_bktr_ioctl_bt848_h
mru's avatar
mru committed
888
    dlfcn_h
889
    dlopen
890
    dos_paths
891 892
    ebp_available
    ebx_available
893
    fast_64bit
894
    fast_cmov
benoit's avatar
 
benoit committed
895
    fast_unaligned
mru's avatar
mru committed
896
    fork
897
    gethrtime
898
    GetProcessTimes
ramiro's avatar
ramiro committed
899
    getrusage
mru's avatar
mru committed
900
    inet_aton
mru's avatar
mru committed
901
    inline_asm
mru's avatar
mru committed
902
    ldbrx
903 904
    libdc1394_1
    libdc1394_2
905
    llrint
906
    loongson
907
    lrint
908
    lrintf
909
    lzo1x_999_compress
910 911
    machine_ioctl_bt848_h
    machine_ioctl_meteor_h
912 913
    malloc_h
    memalign
ramiro's avatar
ramiro committed
914
    mkstemp
915
    pld
ramiro's avatar
ramiro committed
916
    posix_memalign
917 918
    round
    roundf
919 920
    sdl
    sdl_video_size
921
    setmode
922
    socklen_t
mru's avatar
mru committed
923
    soundcard_h
924
    poll_h
925
    sys_mman_h
926
    sys_resource_h
927
    sys_select_h
mru's avatar
mru committed
928
    sys_soundcard_h
929
    sys_videoio_h
930
    ten_operands
931
    termios_h
mru's avatar
mru committed
932
    threads
ramiro's avatar
ramiro committed
933
    truncf
934
    VirtualAlloc
935
    winsock2_h
936
    xform_asm
lorenm's avatar
lorenm committed
937
    yasm
938
"
mru's avatar
mru committed
939

940 941
# options emitted with CONFIG_ prefix but not available on command line
CONFIG_EXTRA="
942 943
    gplv3
    lgplv3
944 945
"

946
CMDLINE_SELECT="
947
    $ARCH_EXT_LIST
948
    $CONFIG_LIST
949
    $THREADS_LIST
950
    cross_compile
951 952
    debug
    extra_warnings
953
    logging
954
    optimizations
955
    stripping
956
    yasm
957
"
958 959

PATHS_LIST='
960
    bindir
961
    datadir
962 963 964 965 966
    incdir
    libdir
    mandir
    prefix
    shlibdir
967 968 969 970 971
'

CMDLINE_SET="
    $PATHS_LIST
    arch
972
    as
973 974 975 976
    build_suffix
    cc
    cpu
    cross_prefix
977
    extra_version
978 979 980 981
    host_cc
    host_cflags
    host_ldflags
    host_libs
982
    host_os
983
    logfile
984
    nm
985
    source_path
986 987
    sysinclude
    sysroot
988
    target_exec
989
    target_os
990
    target_path
991
"
992

diego's avatar
diego committed
993 994
# code dependency declarations

mru's avatar
mru committed
995
# architecture extensions
996
altivec_deps="ppc"
997
amd3dnow_deps="mmx"
998
amd3dnowext_deps="amd3dnow"
mru's avatar
mru committed
999 1000
armv5te_deps="arm"
armv6_deps="arm"
mru's avatar
mru committed
1001
armv6t2_deps="arm"
mru's avatar
mru committed
1002 1003
armvfp_deps="arm"
iwmmxt_deps="arm"
1004
mmi_deps="mips"
mru's avatar
mru committed
1005
mmx_deps="x86"
1006
mmx2_deps="mmx"
mru's avatar
mru committed
1007
neon_deps="arm"
1008
ppc4xx_deps="ppc"
1009 1010
sse_deps="mmx"
ssse3_deps="sse"
1011
vis_deps="sparc"
mru's avatar
mru committed
1012

1013
# decoders / encoders / hardware accelerators
mru's avatar
mru committed
1014 1015 1016
aac_decoder_select="fft mdct"
ac3_decoder_select="fft mdct"
atrac3_decoder_select="fft mdct"
1017
cavs_decoder_select="golomb"
mru's avatar
mru committed
1018
cook_decoder_select="fft mdct"
1019
cscd_decoder_suggest="zlib"
mru's avatar
mru committed
1020
dca_decoder_select="fft mdct"
1021
dnxhd_encoder_select="aandct"
1022
dxa_decoder_select="zlib"
mru's avatar
mru committed
1023
eac3_decoder_select="fft mdct"
1024
eatgq_decoder_select="aandct"
aurel's avatar
aurel committed
1025
eatqi_decoder_select="aandct"
1026 1027 1028
ffv1_decoder_select="golomb"
flac_decoder_select="golomb"
flac_encoder_select="golomb"
1029 1030
flashsv_decoder_select="zlib"
flashsv_encoder_select="zlib"
1031 1032 1033
flv_encoder_select="aandct"
h261_encoder_select="aandct"
h263_encoder_select="aandct"
gb's avatar
gb committed
1034
h263_vaapi_hwaccel_deps="va_va_h"
1035
h263p_encoder_select="aandct"
1036
h264_decoder_select="golomb"
gb's avatar
gb committed
1037
h264_vaapi_hwaccel_deps="va_va_h"
1038
h264_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
mru's avatar
mru committed
1039
imc_decoder_select="fft mdct"
1040 1041
jpegls_decoder_select="golomb"
jpegls_encoder_select="golomb"
1042
ljpeg_encoder_select="aandct"
1043
loco_decoder_select="golomb"
1044 1045 1046 1047
mjpeg_encoder_select="aandct"
mpeg1video_encoder_select="aandct"
mpeg2video_encoder_select="aandct"
mpeg4_encoder_select="aandct"
1048 1049
mpeg_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
mpeg1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
gb's avatar
gb committed
1050 1051
mpeg2_vaapi_hwaccel_deps="va_va_h"
mpeg4_vaapi_hwaccel_deps="va_va_h"
1052
mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
1053 1054 1055
msmpeg4v1_encoder_select="aandct"
msmpeg4v2_encoder_select="aandct"
msmpeg4v3_encoder_select="aandct"
mru's avatar
mru committed
1056 1057
nellymoser_decoder_select="fft mdct"
nellymoser_encoder_select="fft mdct"
1058 1059
png_decoder_select="zlib"
png_encoder_select="zlib"
1060
qdm2_decoder_select="fft mdct rdft"
1061 1062
rv10_encoder_select="aandct"
rv20_encoder_select="aandct"
aurel's avatar
aurel committed
1063 1064
rv30_decoder_select="golomb"
rv40_decoder_select="golomb"
1065 1066 1067 1068 1069
shorten_decoder_select="golomb"
sonic_decoder_select="golomb"
sonic_encoder_select="golomb"
sonic_ls_encoder_select="golomb"
svq3_decoder_select="golomb"
bcoudurier's avatar
bcoudurier committed
1070
svq3_decoder_suggest="zlib"
1071 1072 1073
tiff_decoder_suggest="zlib"
tiff_encoder_suggest="zlib"
tscc_decoder_select="zlib"
gb's avatar
gb committed
1074
vc1_vaapi_hwaccel_deps="va_va_h"
1075
vc1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
mru's avatar
mru committed
1076 1077 1078 1079 1080 1081
vorbis_decoder_select="fft mdct"
vorbis_encoder_select="fft mdct"
wmav1_decoder_select="fft mdct"
wmav1_encoder_select="fft mdct"
wmav2_decoder_select="fft mdct"
wmav2_encoder_select="fft mdct"
1082 1083
wmv1_encoder_select="aandct"
wmv2_encoder_select="aandct"
gb's avatar
gb committed
1084
wmv3_vaapi_hwaccel_deps="va_va_h"
1085
wmv3_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1086 1087 1088 1089
zlib_decoder_select="zlib"
zlib_encoder_select="zlib"
zmbv_decoder_select="zlib"
zmbv_encoder_select="zlib"
1090

diego's avatar
diego committed
1091
# external libraries
1092 1093 1094 1095
libamr_nb_decoder_deps="libamr_nb"
libamr_nb_encoder_deps="libamr_nb"
libamr_wb_decoder_deps="libamr_wb"
libamr_wb_encoder_deps="libamr_wb"
1096
libdirac_decoder_deps="libdirac !libschroedinger"
1097
libdirac_encoder_deps="libdirac"
1098
libfaac_encoder_deps="libfaac"
1099
libfaad_decoder_deps="libfaad"
1100
libfaadbin_decoder_extralibs='$ldl'
mru's avatar
mru committed
1101 1102
libgsm_decoder_deps="libgsm"
libgsm_encoder_deps="libgsm"
mru's avatar
mru committed
1103 1104
libgsm_ms_decoder_deps="libgsm"
libgsm_ms_encoder_deps="libgsm"
1105
libmp3lame_encoder_deps="libmp3lame"
1106 1107 1108
libopencore_amrnb_decoder_deps="libopencore_amrnb"
libopencore_amrnb_encoder_deps="libopencore_amrnb"
libopencore_amrwb_decoder_deps="libopencore_amrwb"
1109
libopenjpeg_decoder_deps="libopenjpeg"
1110 1111
libschroedinger_decoder_deps="libschroedinger"
libschroedinger_encoder_deps="libschroedinger"
conrad's avatar
conrad committed
1112
libspeex_decoder_deps="libspeex"
diego's avatar
diego committed
1113
libtheora_encoder_deps="libtheora"
1114
libvorbis_encoder_deps="libvorbis"
1115 1116
libx264_encoder_deps="libx264"
libxvid_encoder_deps="libxvid"
1117

diego's avatar
diego committed
1118
# demuxers / muxers
1119
ac3_demuxer_deps="ac3_parser"
benoit's avatar
benoit committed
1120 1121 1122 1123
alsa_demuxer_deps="alsa_asoundlib_h snd_pcm_htimestamp"
alsa_demuxer_extralibs="-lasound"
alsa_muxer_deps="alsa_asoundlib_h"
alsa_muxer_extralibs="-lasound"
1124
audio_beos_demuxer_deps="audio_beos"
1125
audio_beos_demuxer_extralibs="-lmedia -lbe"
1126
audio_beos_muxer_deps="audio_beos"
1127
audio_beos_muxer_extralibs="-lmedia -lbe"
1128
avisynth_demuxer_deps="avisynth"
1129
bktr_demuxer_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
1130
dirac_demuxer_deps="dirac_parser"
1131
dv1394_demuxer_deps="dv1394 dv_demuxer"
stefano's avatar
stefano committed
1132 1133
jack_demuxer_deps="jack_jack_h"
jack_demuxer_extralibs="-ljack"
ramiro's avatar
ramiro committed
1134
libdc1394_demuxer_deps="libdc1394"
1135 1136
libnut_demuxer_deps="libnut"
libnut_muxer_deps="libnut"
1137 1138
matroska_demuxer_suggest="zlib bzlib"
mov_demuxer_suggest="zlib"
1139
mp3_demuxer_deps="mpegaudio_parser"
1140 1141
oss_demuxer_deps_any="soundcard_h sys_soundcard_h"
oss_muxer_deps_any="soundcard_h sys_soundcard_h"
1142
redir_demuxer_deps="network"
1143
rtp_muxer_deps="network rtp_protocol"
1144 1145
rtsp_demuxer_deps="sdp_demuxer"
sdp_demuxer_deps="rtp_protocol mpegts_demuxer"
1146
v4l_demuxer_deps="linux_videodev_h"
1147
v4l2_demuxer_deps_any="linux_videodev2_h sys_videoio_h"
ramiro's avatar
ramiro committed
1148 1149
vfwcap_demuxer_deps="capCreateCaptureWindow"
vfwcap_demuxer_extralibs="-lvfw32"
1150
x11_grab_device_demuxer_deps="x11grab XShmCreateImage"
1151
x11_grab_device_demuxer_extralibs="-lX11 -lXext"
1152

diego's avatar
diego committed
1153
# protocols
1154
gopher_protocol_deps="network"
1155 1156 1157 1158 1159
http_protocol_deps="network"
rtp_protocol_deps="udp_protocol"
tcp_protocol_deps="network"
udp_protocol_deps="network"

1160
# filters
1161
movie_filter_deps="avfilter_lavf"
1162

diego's avatar
diego committed
1163
# programs
mru's avatar
mru committed
1164
ffplay_deps="sdl"
1165
ffserver_deps="ffm_muxer rtp_protocol rtsp_demuxer"
1166
ffserver_extralibs='$ldl'
mru's avatar
mru committed
1167

diego's avatar
diego committed
1168

glantau's avatar
glantau committed
1169
# default parameters
1170

1171
logfile="config.err"
1172 1173

# installation paths
mru's avatar
mru committed
1174 1175
prefix_default="/usr/local"
bindir_default='${prefix}/bin'
1176
datadir_default='${prefix}/share/ffmpeg'
mru's avatar
mru committed
1177 1178 1179 1180
incdir_default='${prefix}/include'
libdir_default='${prefix}/lib'
mandir_default='${prefix}/share/man'
shlibdir_default="$libdir_default"
1181 1182

# toolchain
diego's avatar
diego committed
1183
ar="ar"
1184
cc_default="gcc"
1185
host_cc_default="gcc"
diego's avatar
diego committed
1186
ln_s="ln -sf"
1187
nm_default="nm"
diego's avatar
diego committed
1188
objformat="elf"
michaelni's avatar
michaelni committed
1189
ranlib="ranlib"
1190
strip="strip"
diego's avatar
diego committed
1191
yasmexe="yasm"
1192 1193

# machine
1194
arch=$(uname -m)
1195
cpu="generic"
1196 1197

# OS
1198
target_os=$(tolower $(uname -s))
1199
host_os=$target_os
1200 1201

# configurable options
1202
enable debug
mru's avatar
mru committed
1203
enable fastdiv
1204 1205 1206 1207 1208 1209
enable ffmpeg
enable ffplay
enable ffserver
enable ipv6
enable mpegaudio_hp
enable network
1210
enable optimizations
1211
enable protocols
diego's avatar
diego committed
1212
enable static
1213
enable stripping
1214
enable swscale_alpha
1215 1216

# build settings
1217
add_cflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112
mru's avatar
mru committed
1218
SHFLAGS='-shared -Wl,-soname,$$(@F)'
1219
FFSERVERLDFLAGS=-Wl,-E
1220 1221
LIBPREF="lib"
LIBSUF=".a"
1222 1223
FULLNAME='$(NAME)$(BUILDSUF)'
LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)'
1224 1225
SLIBPREF="lib"
SLIBSUF=".so"
1226
SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
1227 1228
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
1229
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
1230

1231 1232 1233
host_cflags='-O3 -g -Wall'
host_libs='-lm'

1234 1235
target_path='.'

1236 1237
# gcc stupidly only outputs the basename of targets with -MM, but we need the
# full relative path for objects in subdirectories for non-recursive Make.
1238
DEPEND_CMD='$(CC) $(CFLAGS) -MM $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o,"'
1239

1240
# find source path
1241
source_path="$(dirname "$0")"
1242
enable source_path_used
1243
if test -z "$source_path" -o "$source_path" = "." ; then
1244
    source_path="$(pwd)"
1245
    disable source_path_used
1246
else
1247
    source_path="$(cd "$source_path"; pwd)"
1248
    echo "$source_path" | grep -q '[[:blank:]]' &&
1249
        die "Out of tree builds are impossible with whitespace in source path."
1250 1251
    test -e "$source_path/config.h" &&
        die "Out of tree builds are impossible with config.h in source dir."
1252 1253
fi

1254 1255 1256 1257 1258 1259
for v in "$@"; do
    r="${v#*=}"
    l="${v%$r}"
    test "$r" = "${r#* }" || r="'$r'"
    FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
done
1260

1261 1262 1263 1264
find_things(){
    thing=$1
    pattern=$2
    file=$source_path/$3
mru's avatar
mru committed
1265
    sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file"
1266 1267 1268 1269
}

ENCODER_LIST=$(find_things  encoder  ENC      libavcodec/allcodecs.c)
DECODER_LIST=$(find_things  decoder  DEC      libavcodec/allcodecs.c)
1270
HWACCEL_LIST=$(find_things  hwaccel  HWACCEL  libavcodec/allcodecs.c)
1271 1272 1273 1274 1275 1276 1277
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   muxer    _MUX     libavdevice/alldevices.c)
INDEV_LIST=$(find_things    demuxer  DEMUX    libavdevice/alldevices.c)
PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c)
1278
FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
1279

1280 1281 1282
enable $ARCH_EXT_LIST \
       $DECODER_LIST \
       $ENCODER_LIST \
1283
       $HWACCEL_LIST \
1284 1285 1286 1287
       $PARSER_LIST \
       $BSF_LIST \
       $DEMUXER_LIST \
       $MUXER_LIST \
1288
       $FILTER_LIST \
1289 1290 1291
       $PROTOCOL_LIST \
       $INDEV_LIST \
       $OUTDEV_LIST \
1292 1293 1294 1295 1296 1297 1298

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

1299
show_list() {
Ramiro's avatar
Ramiro committed
1300 1301 1302
    suffix=_$1
    shift
    echo $* | sed s/$suffix//g | tr ' ' '\n' | sort
1303 1304 1305
    exit 0
}

1306
for opt do
1307 1308
    optval="${opt#*=}"
    case "$opt" in
diego's avatar
diego committed
1309
    --extra-cflags=*) add_cflags $optval
1310
    ;;
diego's avatar
diego committed
1311
    --extra-ldflags=*) add_ldflags $optval
1312
    ;;
diego's avatar
diego committed
1313
    --extra-libs=*) add_extralibs $optval
1314
    ;;
diego's avatar
diego committed
1315
    --disable-devices) disable $INDEV_LIST $OUTDEV_LIST
1316
    ;;
1317 1318
    --enable-debug=*) debuglevel="$optval"
    ;;
1319
    --enable-*=*|--disable-*=*)
1320
    eval $(echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/')
1321
    case "$thing" in
1322
        encoder|decoder|hwaccel|muxer|demuxer|parser|bsf|protocol|filter) $action ${optval}_${thing} ;;
1323 1324 1325 1326
        *) die_unknown "$opt" ;;
    esac
    ;;
    --enable-?*|--disable-?*)
1327
    eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
1328 1329 1330 1331 1332 1333 1334
    if is_in $option $COMPONENT_LIST; then
        eval $action \$$(toupper ${option%s})_LIST
    elif is_in $option $CMDLINE_SELECT; then
        $action $option
    else
        die_unknown $opt
    fi
1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
    ;;
    --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
    ;;
    *)
1345
    optname="${opt%%=*}"
1346 1347 1348 1349
    optname="${optname#--}"
    optname=$(echo "$optname" | sed 's/-/_/g')
    is_in $optname $CMDLINE_SET || die_unknown $opt
    eval $optname='$optval'
1350 1351
    ;;
    esac
1352 1353
done

mru's avatar
mru committed
1354 1355
disabled logging && logfile=/dev/null

1356
echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
mru's avatar
mru committed
1357 1358
set >> $logfile

1359 1360
test -n "$cross_prefix" && enable cross_compile

1361
ar="${cross_prefix}${ar}"
diego's avatar
diego committed
1362
cc_default="${cross_prefix}${cc_default}"
mru's avatar
mru committed
1363
nm_default="${cross_prefix}${nm_default}"
1364 1365 1366
ranlib="${cross_prefix}${ranlib}"
strip="${cross_prefix}${strip}"

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

1369 1370
set_default cc nm sysinclude
as_default=$cc
1371 1372
enabled cross_compile || host_cc_default=$cc
set_default host_cc
1373

1374 1375 1376 1377 1378 1379 1380 1381
exesuf() {
    case $1 in
        mingw32*|cygwin*|*-dos|freedos|opendos|os/2*) echo .exe ;;
    esac
}

EXESUF=$(exesuf $target_os)
HOSTEXESUF=$(exesuf $host_os)
1382

1383
# set temporary file name
mru's avatar
mru committed
1384
: ${TMPDIR:=$TEMPDIR}
1385
: ${TMPDIR:=$TMP}
mru's avatar
mru committed
1386
: ${TMPDIR:=/tmp}
1387

1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
if ! check_cmd type mktemp; 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 temoporary file in $TMPDIR."
    append TMPFILES $tmp
    eval $1=$tmp
}

trap 'rm -f -- $TMPFILES' EXIT
trap exit HUP INT TERM

tmpfile TMPC  .c
tmpfile TMPE  $EXESUF
tmpfile TMPH  .h
tmpfile TMPO  .o
tmpfile TMPS  .S
tmpfile TMPSH .sh

unset -f mktemp
1415

1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
# 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

1429
if   $cc --version 2>/dev/null | grep -qi gcc; then
1430 1431 1432 1433 1434
    cc_type=gcc
elif $cc --version 2>/dev/null | grep -q Intel; then
    cc_type=icc
elif $cc -v 2>&1 | grep -q xlc; then
    cc_type=xlc
1435 1436 1437
elif $cc -V 2>/dev/null | grep -q Compaq; then
    cc_type=ccc
    DEPEND_CMD='$(CC) $(CFLAGS) -M $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o,"'
1438
    debuglevel=3
1439
    add_ldflags -Wl,-z,now # calls to libots crash without this
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
elif $cc --vsn 2>/dev/null | grep -q RVCT; then
    test -d "$sysroot" || die "No valid sysroot specified."
    cc_type=armcc
    armcc_conf="$PWD/armcc.conf"
    $cc --arm_linux_configure                 \
        --arm_linux_config_file="$armcc_conf" \
        --configure_sysroot="$sysroot"        \
        --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
        die "Error creating armcc configuration file."
    cc="$cc --arm_linux_config_file=$armcc_conf --translate_gcc"
1450
    as_default="${cross_prefix}gcc"
1451 1452 1453 1454
fi

test -n "$cc_type" && enable $cc_type || echolog "Unknown C compiler $cc"

1455 1456
set_default as

mru's avatar
mru committed
1457 1458 1459 1460 1461 1462 1463 1464 1465
if test -n "$sysroot"; then
    case "$cc_type" in
        gcc)
            add_cflags  --sysroot="$sysroot"
            add_ldflags --sysroot="$sysroot"
        ;;
    esac
fi

1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478
# compiler sanity check
check_exec <<EOF
int main(void){ return 0; }
EOF
if test "$?" != 0; then
    echo "$cc is unable to create an executable file."
    if test -z "$cross_prefix" && ! enabled cross_compile ; then
        echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
        echo "Only do this if you know what cross compiling means."
    fi
    die "C compiler test failed."
fi

1479
check_cflags -std=c99
1480 1481 1482 1483 1484 1485
check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cflags -D_FILE_OFFSET_BITS=64
#include <stdlib.h>
EOF
check_cc -D_LARGEFILE_SOURCE <<EOF && add_cflags -D_LARGEFILE_SOURCE
#include <stdlib.h>
EOF
1486

ramiro's avatar
ramiro committed
1487 1488 1489 1490
case "$arch" in
    alpha)
        arch="alpha"
        enable fast_64bit
mru's avatar
mru committed
1491
        check_cflags -mieee
ramiro's avatar
ramiro committed
1492
    ;;
mru's avatar
mru committed
1493 1494
    arm|armv[4567]*l)
        arch="arm"
ramiro's avatar
ramiro committed
1495
    ;;
mru's avatar
mru committed
1496 1497
    avr32)
    ;;
mru's avatar
mru committed
1498 1499 1500 1501 1502
    bfin)
        arch="bfin"
    ;;
    ia64)
        arch="ia64"
ramiro's avatar
ramiro committed
1503
        enable fast_64bit
mru's avatar
mru committed
1504 1505 1506
    ;;
    m68k)
        arch="m68k"
ramiro's avatar
ramiro committed
1507
    ;;
1508
    mips|mipsel|IP*)
ramiro's avatar
ramiro committed
1509 1510
        arch="mips"
    ;;
1511 1512
    mips64)
        arch="mips"
1513
        subarch="mips64"
1514 1515
        enable fast_64bit
    ;;
1516
    parisc|hppa)
ramiro's avatar
ramiro committed
1517 1518
        arch="parisc"
    ;;
1519
    parisc64|hppa64)
ramiro's avatar
ramiro committed
1520 1521 1522
        arch="parisc"
        enable fast_64bit
    ;;
mru's avatar
mru committed
1523 1524 1525 1526 1527 1528
    "Power Macintosh"|ppc|powerpc)
        arch="ppc"
        enable fast_unaligned
    ;;
    ppc64)
        arch="ppc"
reimar's avatar
reimar committed
1529
        subarch="ppc64"
mru's avatar
mru committed
1530 1531 1532
        enable fast_64bit
        enable fast_unaligned
    ;;
ramiro's avatar
ramiro committed
1533 1534 1535
    s390|s390x)
        arch="s390"
    ;;
mru's avatar
mru committed
1536 1537
    sh4|sh)
        arch="sh4"
ramiro's avatar
ramiro committed
1538
    ;;
mru's avatar
mru committed
1539 1540 1541 1542 1543 1544
    sparc)
        arch="sparc"
    ;;
    sun4u|sparc64)
        arch="sparc"
        subarch="sparc64"
ramiro's avatar
ramiro committed
1545 1546
        enable fast_64bit
    ;;
mru's avatar
mru committed
1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
    i386|i486|i586|i686|i86pc|BePC)
        arch="x86"
        subarch="x86_32"
        enable fast_unaligned
    ;;
    x86_64|amd64)
        arch="x86"
        subarch="x86_32"
        enable cmov
        enable fast_cmov
        enable fast_unaligned
        check_cc <<EOF && enable fast_64bit && subarch="x86_64"
        int test[sizeof(char*) - 7];
EOF
ramiro's avatar
ramiro committed
1561 1562 1563 1564 1565 1566
    ;;
    *)
        arch="unknown"
    ;;
esac

1567
enable $arch $subarch
ramiro's avatar
ramiro committed
1568

1569
# OS specific
1570
case $target_os in
1571
    beos|haiku|zeta)
mru's avatar
mru committed
1572
        prefix_default="$HOME/config"
1573
        # helps building libavcodec
diego's avatar
diego committed
1574
        add_cflags -DPIC -fomit-frame-pointer
1575
        # 3 gcc releases known for BeOS, each with ugly bugs
1576
        gcc_version="$($cc -v 2>&1 | grep version | cut -d ' ' -f3-)"
1577 1578 1579 1580 1581
        case "$gcc_version" in
          2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
            disable mmx
            ;;
          *20010315*) echo "BeBits gcc"
diego's avatar
diego committed
1582
            add_cflags -fno-expensive-optimizations
1583 1584 1585 1586 1587 1588 1589 1590
            ;;
        esac
        SHFLAGS=-nostart
        # enable BeOS things
        enable audio_beos
        # no need for libm, but the inet stuff
        # Check for BONE
        # XXX: actually should check for NOT net_server
1591
        if echo $BEINCLUDES | grep -q 'headers/be/bone'; then
1592 1593 1594 1595 1596 1597 1598
            network_extralibs="-lbind -lsocket"
        else
            enable beos_netserver
            network_extralibs="-lnet"
        fi ;;
    sunos)
        FFSERVERLDFLAGS=""
mru's avatar
mru committed
1599
        SHFLAGS='-shared -Wl,-h,$$(@F)'
1600
        network_extralibs="-lsocket -lnsl"
1601
        add_cflags -D__EXTENSIONS__
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622
        ;;
    netbsd)
        oss_demuxer_extralibs="-lossaudio"
        oss_muxer_extralibs="-lossaudio"
        ;;
    openbsd)
        disable need_memalign
        LIBOBJFLAGS='$(PIC)'
        SHFLAGS='-shared'
        oss_demuxer_extralibs="-lossaudio"
        oss_muxer_extralibs="-lossaudio"
        ;;
    freebsd)
        disable need_memalign
        ;;
    bsd/os)
        osextralibs="-lpoll -lgnugetopt"
        strip="strip -d"
        ;;
    darwin)
        disable need_memalign
1623
        SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR) -Wl,-read_only_relocs,suppress'
1624 1625 1626 1627 1628 1629
        strip="strip -x"
        FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
        SLIBSUF=".dylib"
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
        FFSERVERLDFLAGS=-Wl,-bind_at_load
lorenm's avatar
lorenm committed
1630
        objformat="macho"
1631
        enabled x86_64 && objformat="macho64"
1632 1633
        ;;
    mingw32*)
1634
        target_os=mingw32
ramiro's avatar
ramiro committed
1635
        LIBTARGET=i386
1636
        if enabled x86_64; then
ramiro's avatar
ramiro committed
1637 1638 1639
            disable need_memalign
            LIBTARGET=x64
        fi
1640
        shlibdir_default="$bindir_default"
1641 1642 1643 1644 1645
        disable ffserver
        SLIBPREF=""
        SLIBSUF=".dll"
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
1646
        SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)'
1647 1648
        SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \
            install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"'
1649
        SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"'
1650
        SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
lorenm's avatar
lorenm committed
1651
        objformat="win32"
1652
        enable dos_paths
1653
        check_cflags -fno-common
1654
        if ! enabled x86_64; then
ramiro's avatar
ramiro committed
1655 1656 1657 1658 1659 1660
            check_cpp_condition _mingw.h "(__MINGW32_MAJOR_VERSION > 3) || (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
                die "ERROR: MinGW runtime version must be >= 3.15."
            enabled_any avisynth vfwcap_demuxer &&
                { check_cpp_condition w32api.h "(__W32API_MAJOR_VERSION > 3) || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION >= 13)" ||
                  die "ERROR: avisynth and vfwcap_demuxer require w32api version 3.13 or later."; }
            fi
1661 1662
        ;;
    cygwin*)
1663
        target_os=cygwin
1664
        shlibdir_default="$bindir_default"
1665 1666 1667 1668 1669
        SLIBPREF="cyg"
        SLIBSUF=".dll"
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
        SHFLAGS='-shared -Wl,--enable-auto-image-base'
lorenm's avatar
lorenm committed
1670
        objformat="win32"
1671
        enable dos_paths
1672
        check_cflags -fno-common
1673
        ;;
diego's avatar
diego committed
1674
    *-dos|freedos|opendos)
diego's avatar
diego committed
1675
        disable ffplay ffserver
diego's avatar
diego committed
1676 1677
        disable $INDEV_LIST $OUTDEV_LIST
        network_extralibs="-lsocket"
ramiro's avatar
ramiro committed
1678
        objformat="coff"
1679
        enable dos_paths
diego's avatar
diego committed
1680
        ;;
1681 1682 1683 1684
    linux)
        enable dv1394
        ;;
    irix*)
1685
        target_os=irix
1686 1687
        ranlib="echo ignoring ranlib"
        ;;
1688 1689 1690 1691
    os/2*)
        strip="lxlite"
        ln_s="cp -f"
        FFLDFLAGS="-Zomf -Zbin-files -Zargs-wild -Zmap"
mru's avatar
mru committed
1692
        SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
1693
        FFSERVERLDFLAGS=""
1694
        LIBSUF="_s.a"
1695 1696 1697 1698
        SLIBPREF=""
        SLIBSUF=".dll"
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)'
mru's avatar
mru committed
1699 1700 1701 1702 1703 1704 1705 1706 1707
        SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(NAME).def; \
          echo PROTMODE >> $(SUBDIR)$(NAME).def; \
          echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(NAME).def; \
          echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(NAME).def; \
          echo EXPORTS >> $(SUBDIR)$(NAME).def; \
          emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def'
        SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \
          emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
        SLIB_INSTALL_EXTRA_CMD='install -m 644 $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"'
1708
        SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib'
1709
        enable dos_paths
1710
        ;;
1711 1712
    gnu/kfreebsd)
        ;;
1713 1714
    gnu)
        ;;
1715

1716
    *)
1717
        die "Unknown OS '$target_os'."
1718 1719 1720
        ;;
esac

mru's avatar
mru committed
1721 1722
set_default $PATHS_LIST

1723
add_extralibs $osextralibs
glantau's avatar
glantau committed
1724

1725 1726
# Combine FFLDFLAGS and the LDFLAGS environment variable.
LDFLAGS="$FFLDFLAGS $LDFLAGS"
1727

1728
# we need to build at least one lib type
1729
if ! enabled_any static shared; then
1730 1731 1732 1733 1734 1735 1736 1737 1738
    cat <<EOF
At least one library type must be built.
Specify --enable-static to build the static libraries or --enable-shared to
build the shared libraries as well. To only build the shared libraries specify
--disable-static in addition to --enable-shared.
EOF
    exit 1;
fi

diego's avatar
diego committed
1739
disabled static && LIBNAME=""
ramiro's avatar
ramiro committed
1740

1741 1742
if enabled_any libfaad libfaadbin ; then
    if check_header faad.h; then
diego's avatar
diego committed
1743
        check_cc <<EOF
1744 1745 1746 1747
#include <faad.h>
#ifndef FAAD2_VERSION
ok faad1
#endif
diego's avatar
diego committed
1748
int main(void) { return 0; }
1749 1750 1751
EOF
        test $? = 0 && enable libfaad2
    else
diego's avatar
diego committed
1752
        die "FAAD test failed."
1753 1754 1755 1756
    fi
fi


1757
die_license_disabled() {
mru's avatar
mru committed
1758
    enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768
}

die_license_disabled gpl libfaad2
die_license_disabled gpl libx264
die_license_disabled gpl libxvid
die_license_disabled gpl postproc
die_license_disabled gpl x11grab

die_license_disabled nonfree libamr_nb
die_license_disabled nonfree libamr_wb
1769
die_license_disabled nonfree libfaac
1770

1771 1772 1773
die_license_disabled version3 libopencore_amrnb
die_license_disabled version3 libopencore_amrwb

1774
enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
1775

mru's avatar
mru committed
1776
check_deps $ARCH_EXT_LIST
1777

1778 1779
test -z "$need_memalign" && need_memalign="$mmx"

1780
#Darwin CC versions
1781
if test $target_os = darwin; then
1782
    if enabled xlc; then
diego's avatar
diego committed
1783
        add_cflags -qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto
1784
    else
diego's avatar
diego committed
1785 1786 1787
        add_cflags -pipe
        check_cflags -force_cpusubtype_ALL
        check_cflags -Wno-sign-compare
1788
        enabled shared || check_cflags -mdynamic-no-pic
1789
    fi
1790 1791
fi

1792
disabled optimizations || check_cflags -fomit-frame-pointer
1793

1794
# Add processor-specific flags
1795
if test $cpu != "generic"; then
mru's avatar
mru committed
1796 1797
    warn_altivec(){
        $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1.";
1798
    }
1799
    case $cpu in
1800
        601|ppc601|PowerPC601)
diego's avatar
diego committed
1801
            add_cflags -mcpu=601
mru's avatar
mru committed
1802
            warn_altivec enabled PPC601
1803 1804
        ;;
        603*|ppc603*|PowerPC603*)
diego's avatar
diego committed
1805
            add_cflags -mcpu=603
mru's avatar
mru committed
1806
            warn_altivec enabled PPC603
1807 1808
        ;;
        604*|ppc604*|PowerPC604*)
diego's avatar
diego committed
1809
            add_cflags -mcpu=604
mru's avatar
mru committed
1810
            warn_altivec enabled PPC604
1811 1812
        ;;
        G3|g3|75*|ppc75*|PowerPC75*)
diego's avatar
diego committed
1813
            add_cflags -mcpu=750 -mpowerpc-gfxopt
mru's avatar
mru committed
1814
            warn_altivec enabled PPC75x
1815 1816
        ;;
        G4|g4|745*|ppc745*|PowerPC745*)
diego's avatar
diego committed
1817
            add_cflags -mcpu=7450 -mpowerpc-gfxopt
mru's avatar
mru committed
1818
            warn_altivec disabled PPC745x
1819 1820
        ;;
        74*|ppc74*|PowerPC74*)
diego's avatar
diego committed
1821
            add_cflags -mcpu=7400 -mpowerpc-gfxopt
mru's avatar
mru committed
1822
            warn_altivec disabled PPC74xx
1823 1824
        ;;
        G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
diego's avatar
diego committed
1825
            add_cflags -mcpu=970 -mpowerpc-gfxopt -mpowerpc64
mru's avatar
mru committed
1826
            warn_altivec disabled PPC970
1827
        ;;
1828
        Cell|CELL|cell)
diego's avatar
diego committed
1829
            add_cflags -mcpu=cell
1830
            warn_altivec disabled Cell
reimar's avatar
reimar committed
1831
            enable ldbrx
1832
        ;;
1833 1834
        # targets that do NOT support conditional mov (cmov)
        i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
diego's avatar
diego committed
1835
            add_cflags -march=$cpu
1836
            disable cmov
1837 1838
        ;;
        # targets that do support conditional mov (cmov)
1839
        i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2)
diego's avatar
diego committed
1840
            add_cflags -march=$cpu
1841 1842
            enable cmov
            enable fast_cmov
1843 1844
        ;;
        # targets that do support conditional mov but on which it's slow
1845
        pentium4|pentium4m|prescott|nocona)
diego's avatar
diego committed
1846
            add_cflags -march=$cpu
1847 1848
            enable cmov
            disable fast_cmov
1849
        ;;
1850
        sparc64)
diego's avatar
diego committed
1851
            add_cflags -mcpu=v9
1852
        ;;
1853
        arm11*|cortex*)
diego's avatar
diego committed
1854
            add_cflags -mcpu=$cpu
1855 1856
            enable fast_unaligned
        ;;
mru's avatar
mru committed
1857
        armv*)
diego's avatar
diego committed
1858
            add_cflags -march=$cpu
mru's avatar
mru committed
1859
        ;;
1860
        arm*)
diego's avatar
diego committed
1861
            add_cflags -mcpu=$cpu
mru's avatar
mru committed
1862
        ;;
mru's avatar
mru committed
1863
        ev4|ev45|ev5|ev56|pca56|ev6|ev67)
1864
            enabled ccc && add_cflags -arch $cpu || add_cflags -mcpu=$cpu
mru's avatar
mru committed
1865
        ;;
1866 1867 1868
        bf*)
            add_cflags -mcpu=$cpu
        ;;
mru's avatar
mru committed
1869 1870 1871
        mips*|[45]k*|[237]4k*|m4k|r*000|loongson2[ef])
            add_cflags -march=$cpu
        ;;
1872
        *)
1873
            echo "WARNING: Unknown CPU \"$cpu\", ignored."
1874
        ;;
1875 1876 1877
    esac
fi

1878 1879 1880
check_cc <<EOF || die "Symbol mangling check failed."
int ff_extern;
EOF
1881
sym=$($nm -P -g $TMPO | grep ff_extern)
1882 1883
extern_prefix=${sym%%ff_extern*}

mru's avatar
mru committed
1884 1885 1886
check_cc <<EOF && enable inline_asm
void foo(void) { __asm__ volatile ("" ::); }
EOF
mru's avatar
mru committed
1887

mru's avatar
mru committed
1888
if enabled x86; then
1889 1890 1891 1892
    # check whether EBP is available on x86
    # As 'i' is stored on the stack, this program will crash
    # if the base pointer is used to access it because the
    # base pointer is cleared in the inline assembly code.
mru's avatar
mru committed
1893
    check_exec_crash <<EOF && enable ebp_available
1894
    volatile int i=0;
1895
    __asm__ volatile (
1896 1897 1898 1899 1900 1901
        "xorl %%ebp, %%ebp"
    ::: "%ebp");
    return i;
EOF

    # check wether EBX is available on x86
mru's avatar
mru committed
1902
    check_asm ebx_available '"":::"%ebx"'
1903

1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915
    # check whether more than 10 operands are supported
    check_cc <<EOF && enable ten_operands
int main(void) {
    int x=0;
    __asm__ volatile(
        ""
        :"+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x)
    );
    return 0;
}
EOF

1916
    # check whether binutils is new enough to compile SSSE3/MMX2
mru's avatar
mru committed
1917
    enabled ssse3 && check_asm ssse3 '"pabsw %xmm0, %xmm0"'
1918
    enabled mmx2  && check_asm mmx2  '"pmaxub %mm0, %mm1"'
mru's avatar
mru committed
1919 1920

    check_asm bswap '"bswap %%eax" ::: "%eax"'
lorenm's avatar
lorenm committed
1921

1922
    YASMFLAGS="-f $objformat -DARCH_$(toupper $subarch)"
lorenm's avatar
lorenm committed
1923 1924 1925 1926
    enabled     x86_64        && append YASMFLAGS "-m amd64"
    enabled_all x86_64 shared && append YASMFLAGS "-DPIC"
    case "$objformat" in
        elf) enabled debug && append YASMFLAGS "-g dwarf2" ;;
1927
        macho64)              append YASMFLAGS "-DPIC -DPREFIX" ;;
lorenm's avatar
lorenm committed
1928 1929
        *)                    append YASMFLAGS "-DPREFIX"  ;;
    esac
1930
    disabled yasm || { check_yasm "pabsw xmm0, xmm0" && enable yasm; }
1931 1932
fi

1933 1934
# check for assembler specific support

1935 1936
enabled mips && check_asm loongson '"dmult.g $1, $2, $3"'

1937
enabled ppc && check_asm dcbzl '"dcbzl 0, 1"'
1938
enabled ppc && check_asm ppc4xx '"maclhw r10, r11, r12"'
1939
enabled ppc && check_asm xform_asm '"lwzx 0, %y0" :: "Z"(*(int*)0)'
1940

1941 1942
# check for SIMD availability

1943
# AltiVec flags: The FSF version of GCC differs from the Apple version
mru's avatar
mru committed
1944
if enabled altivec; then
1945 1946
    check_cflags -maltivec -mabi=altivec &&
        { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
1947
        check_cflags -faltivec
1948

mru's avatar
mru committed
1949
    # check if our compiler supports Motorola AltiVec C API
1950
    check_cc <<EOF || disable altivec
1951
$inc_altivec_h
1952 1953 1954 1955 1956
int main(void) {
    vector signed int v1, v2, v3;
    v1 = vec_add(v2,v3);
    return 0;
}
1957 1958 1959
EOF

    # check if our compiler supports braces for vector declarations
1960
    check_cc <<EOF || die "You need a compiler that supports {} in AltiVec vector declarations."
1961
$inc_altivec_h
1962
int main (void) { (vector int) {1}; return 0; }
1963 1964
EOF
fi
1965

1966
# We have to check if pld is a nop and disable it.
mru's avatar
mru committed
1967
enabled arm     && check_asm pld     '"pld [r0]"'
mru's avatar
mru committed
1968 1969
enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"'
enabled armv6   && check_asm armv6   '"sadd16 r0, r0, r0"'
mru's avatar
mru committed
1970
enabled armv6t2 && check_asm armv6t2 '"movt r0, #0"'
mru's avatar
mru committed
1971
enabled armvfp  && check_asm armvfp  '"fadds s0, s0, s0"'
mru's avatar
mru committed
1972 1973
enabled iwmmxt  && check_asm iwmmxt  '"wunpckelub wr6, wr4"'
enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
mru's avatar
mru committed
1974
enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
mru's avatar
mru committed
1975
enabled vis     && check_asm vis     '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc
1976

diego's avatar
diego committed
1977
enabled vis && add_cflags -mcpu=ultrasparc -mtune=ultrasparc
1978

1979 1980
# ---
# big/little-endian test
mru's avatar
mru committed
1981 1982
check_cc <<EOF || die "endian test failed"
unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
michaelni's avatar
michaelni committed
1983
EOF
mru's avatar
mru committed
1984
od -A n -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
bellard's avatar
bellard committed
1985

nickols_k's avatar
nickols_k committed
1986 1987 1988
# ---
# check availability of some header files

1989 1990 1991 1992
if check_func dlopen; then
    ldl=
elif check_func dlopen -ldl; then
    ldl=-ldl
1993 1994
fi

1995 1996 1997
# Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; }

1998 1999 2000
check_func  fork
check_func  gethrtime
check_func  getrusage
2001
check_func  inet_aton $network_extralibs
2002 2003
check_func  memalign
check_func  mkstemp
ramiro's avatar
ramiro committed
2004
check_func  posix_memalign
2005
check_func_headers io.h setmode
2006
check_func_headers lzo/lzo1x.h lzo1x_999_compress
2007
check_func_headers windows.h GetProcessTimes
2008
check_func_headers windows.h VirtualAlloc
ramiro's avatar
ramiro committed
2009

2010
check_header conio.h
2011 2012
check_header dlfcn.h
check_header malloc.h
2013
check_header poll.h
2014
check_header sys/mman.h
2015
check_header sys/resource.h
2016
check_header sys/select.h
2017
check_header termios.h
2018 2019
check_header vdpau/vdpau.h
check_header vdpau/vdpau_x11.h
diego's avatar
diego committed
2020
check_header X11/extensions/XvMClib.h
2021

ramiro's avatar
ramiro committed
2022 2023
if ! enabled_any memalign memalign_hack posix_memalign && enabled need_memalign ; then
    die "Error, no aligned memory allocator but SSE enabled, disable it or use --enable-memalign-hack."
2024
fi
2025

2026
disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable  zlib
2027
disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
2028 2029 2030 2031

# check for some common methods of building with pthread support
# do this before the optional library checks as some of them require pthreads
if enabled pthreads; then
mru's avatar
mru committed
2032 2033 2034 2035
    if check_func pthread_create; then
        :
    elif check_func pthread_create -pthread; then
        add_cflags -pthread
2036
        add_extralibs -pthread
mru's avatar
mru committed
2037 2038
    elif check_func pthread_create -pthreads; then
        add_cflags -pthreads
2039
        add_extralibs -pthreads
ramiro's avatar
ramiro committed
2040 2041
    elif check_func pthread_create -lpthreadGC2; then
        add_extralibs -lpthreadGC2
mru's avatar
mru committed
2042 2043 2044
    elif ! check_lib pthread.h pthread_create -lpthread; then
        die "ERROR: can't find pthreads library"
    fi
2045 2046
fi

2047
for thread in $THREADS_LIST; do
2048
    if enabled $thread; then
ramiro's avatar
ramiro committed
2049 2050
        test -n "$thread_type" &&
            die "ERROR: Only one thread type must be selected." ||
2051 2052 2053 2054
            thread_type="$thread"
    fi
done

mru's avatar
mru committed
2055
check_lib math.h sin -lm
gb's avatar
gb committed
2056
check_lib va/va.h vaInitialize -lva
mru's avatar
mru committed
2057

2058
# test for C99 functions in math.h
ramiro's avatar
ramiro committed
2059
for func in llrint lrint lrintf round roundf truncf; do
2060
    check_exec <<EOF && enable $func || disable $func
2061
#include <math.h>
2062
int main(void) { return ($func(3.999f) > 0)?0:1; }
2063
EOF
2064
done
2065

2066
# these are off by default, so fail if requested and not available
2067
enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
2068
enabled libamr_nb  && require  libamrnb amrnb/interf_dec.h Decoder_Interface_init -lamrnb -lm
2069
enabled libamr_wb  && require  libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
2070
enabled libdirac   && add_cflags $(pkg-config --cflags dirac) &&
diego's avatar
diego committed
2071 2072
                      require  libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init -ldirac_decoder &&
                      require  libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init -ldirac_encoder
2073 2074
enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
enabled libfaad    && require2 libfaad faad.h faacDecOpen -lfaad
2075
enabled libgsm     && require  libgsm gsm.h gsm_create -lgsm
2076
enabled libmp3lame && require  libmp3lame lame/lame.h lame_init -lmp3lame -lm
2077
enabled libnut     && require  libnut libnut.h nut_demuxer_init -lnut
2078 2079
enabled libopencore_amrnb  && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb -lm
enabled libopencore_amrwb  && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb -lm
2080
enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg
diego's avatar
diego committed
2081 2082
enabled libschroedinger && add_cflags $(pkg-config --cflags schroedinger-1.0) &&
                           require libschroedinger schroedinger/schro.h schro_init $(pkg-config --libs schroedinger-1.0)
conrad's avatar
conrad committed
2083
enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
2084 2085
enabled libtheora  && require  libtheora theora/theora.h theora_info_init -ltheora -logg
enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
2086
enabled libx264    && require  libx264 x264.h x264_encoder_open -lx264 -lm &&
mru's avatar
mru committed
2087 2088
                      { check_cpp_condition x264.h "X264_BUILD >= 65" ||
                        die "ERROR: libx264 version must be >= 0.65."; }
2089
enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore
2090
enabled mlib       && require  mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
2091

2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
# libdc1394 check
if enabled libdc1394; then
    { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 &&
        enable libdc1394_2; } ||
    { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 &&
        enable libdc1394_1; } ||
    die "ERROR: No version of libdc1394 found "
fi


mellum's avatar
mellum committed
2102 2103
_restrict=
for restrict_keyword in restrict __restrict__ __restrict; do
2104
    check_cc <<EOF && _restrict=$restrict_keyword && break
2105 2106
void foo(char * $restrict_keyword p);
EOF
mellum's avatar
mellum committed
2107 2108
done

bellard's avatar
bellard committed
2109
##########################################
diego's avatar
diego committed
2110
# SDL check
bellard's avatar
bellard committed
2111

2112 2113
disable sdl_too_old
disable sdl
mru's avatar
mru committed
2114
SDL_CONFIG="${cross_prefix}sdl-config"
2115
if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
2116
    sdl_cflags=$("${SDL_CONFIG}" --cflags)
mru's avatar
mru committed
2117
    temp_cflags $sdl_cflags
2118
    temp_extralibs $("${SDL_CONFIG}" --libs)
2119
    if check_lib2 SDL.h SDL_Init; then
2120
        _sdlversion=$("${SDL_CONFIG}" --version | sed 's/[^0-9]//g')
2121
        if test "$_sdlversion" -lt 121 ; then
2122
            enable sdl_too_old
2123
        else
2124
            enable sdl
mru's avatar
mru committed
2125
            check_cc $sdl_cflags <<EOF && enable sdl_video_size
2126
#include <SDL.h>
2127
int main(int argc, char **argv){
2128 2129 2130 2131 2132
    const SDL_VideoInfo *vi = SDL_GetVideoInfo();
    int w = vi->current_w;
    return 0;
}
EOF
2133 2134
        fi
    fi
2135
    restore_flags
michael's avatar
michael committed
2136
fi
2137

2138
texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
2139

ramiro's avatar
ramiro committed
2140 2141 2142 2143
##########################################
# Network check

if enabled network; then
2144
    check_type "sys/types.h sys/socket.h" socklen_t
ramiro's avatar
ramiro committed
2145 2146 2147 2148
    # Prefer arpa/inet.h over winsock2
    if check_header arpa/inet.h ; then
        check_func closesocket
    elif check_header winsock2.h ; then
2149
        network_extralibs="-lws2_32"
2150
        check_type ws2tcpip.h socklen_t
2151
        check_func_headers winsock2.h closesocket
ramiro's avatar
ramiro committed
2152 2153 2154
    fi
fi

2155
##########################################
diego's avatar
diego committed
2156
# IPv6 check
2157

2158
enabled network && enabled ipv6 && check_ld <<EOF && enable ipv6 || disable ipv6
2159 2160 2161 2162
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
diego's avatar
diego committed
2163
int main(void) {
2164 2165 2166 2167 2168
    struct sockaddr_storage saddr;
    struct ipv6_mreq mreq6;
    getaddrinfo(0,0,0,0);
    getnameinfo(0,0,0,0,0,0,0);
    IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
2169 2170 2171
}
EOF

2172 2173
check_header linux/videodev.h
check_header linux/videodev2.h
2174
check_header sys/videoio.h
2175

2176
check_func_headers "windows.h vfw.h" capCreateCaptureWindow -lvfw32
ramiro's avatar
ramiro committed
2177

2178
# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
ramiro's avatar
ramiro committed
2179 2180 2181 2182 2183 2184 2185
{ check_header dev/bktr/ioctl_meteor.h &&
  check_header dev/bktr/ioctl_bt848.h; } ||
{ check_header machine/ioctl_meteor.h &&
  check_header machine/ioctl_bt848.h; } ||
{ check_header dev/video/meteor/ioctl_meteor.h &&
  check_header dev/video/bktr/ioctl_bt848.h; } ||
check_header dev/ic/bt8xx.h
2186

2187 2188
check_header sys/soundcard.h
check_header soundcard.h
mru's avatar
mru committed
2189

benoit's avatar
benoit committed
2190 2191
check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound

stefano's avatar
stefano committed
2192 2193
check_lib2 jack/jack.h jack_client_open -ljack

2194
# deal with the X11 frame grabber
2195
enabled x11grab                         &&
2196 2197 2198
check_header X11/Xlib.h                 &&
check_header X11/extensions/XShm.h      &&
check_func XOpenDisplay -lX11           &&
2199
check_func XShmCreateImage -lX11 -lXext
2200

2201
enabled debug && add_cflags -g"$debuglevel"
2202 2203 2204

# add some useful compiler flags if supported
check_cflags -Wdeclaration-after-statement
2205 2206
check_cflags -Wall
check_cflags -Wno-switch
michael's avatar
michael committed
2207 2208 2209
check_cflags -Wdisabled-optimization
check_cflags -Wpointer-arith
check_cflags -Wredundant-decls
mru's avatar
mru committed
2210
check_cflags -Wno-pointer-sign
2211
check_cflags -Wcast-qual
2212
check_cflags -Wwrite-strings
2213
check_cflags -Wtype-limits
2214
check_cflags -Wundef
2215
enabled extra_warnings && check_cflags -Winline
2216

2217
# add some linker flags
2218
check_ldflags -Wl,--warn-common
2219 2220
check_ldflags -Wl,--as-needed
check_ldflags '-Wl,-rpath-link,\$(BUILD_ROOT)/libpostproc -Wl,-rpath-link,\$(BUILD_ROOT)/libswscale -Wl,-rpath-link,\$(BUILD_ROOT)/libavfilter -Wl,-rpath-link,\$(BUILD_ROOT)/libavdevice -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil'
2221
check_ldflags -Wl,-Bsymbolic
bellard's avatar
bellard committed
2222

2223 2224
if enabled small; then
    check_cflags -Os            # not all compilers support -Os
2225 2226
    optimizations="small"
elif enabled optimizations; then
2227
    if enabled xlc; then
diego's avatar
diego committed
2228 2229
        add_cflags  -O5
        add_ldflags -O5
2230 2231
    elif enabled ccc; then
        add_cflags -fast
2232
    else
diego's avatar
diego committed
2233
        add_cflags -O3
2234
    fi
2235
fi
2236
check_cflags -fno-math-errno
2237
check_cflags -fno-signed-zeros
2238

cehoyos's avatar
cehoyos committed
2239
# add some flags for Intel C Compiler
2240
if enabled icc; then
mru's avatar
mru committed
2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252
    # Just warnings, no remarks
    check_cflags -w1
    # -wd: Disable following warnings
    # 144, 167, 556: -Wno-pointer-sign
    # 10006: ignoring unknown option -fno-signed-zeros
    # 10156: ignoring option '-W'; no argument required
    check_cflags -wd144,167,556,10006,10156
    # 11030: Warning unknown option --as-needed
    # 10156: ignoring option '-export'; no argument required
    check_ldflags -wd10156,11030
    # Allow to compile with optimizations
    check_ldflags -march=$cpu
cehoyos's avatar
cehoyos committed
2253 2254
    # icc 11.0 and 11.1 work with ebp_available, but don't pass the test
    enable ebp_available
2255 2256 2257 2258 2259 2260 2261 2262
elif enabled ccc; then
    # disable some annoying warnings
    add_cflags -msg_disable cvtu32to64
    add_cflags -msg_disable embedcomment
    add_cflags -msg_disable needconstext
    add_cflags -msg_disable nomainieee
    add_cflags -msg_disable ptrmismatch1
    add_cflags -msg_disable unreachcode
cehoyos's avatar
cehoyos committed
2263 2264
fi

2265
# PIC flags for shared library objects where they are needed
2266
if enabled shared; then
2267 2268
    # LIBOBJFLAGS may have already been set in the OS configuration
    if test -z "$LIBOBJFLAGS" ; then
2269
        case "${subarch-$arch}" in
2270
            x86_64|ia64|alpha|sparc*|power*|parisc*|mips*) LIBOBJFLAGS='$(PIC)' ;;
2271 2272
        esac
    fi
2273 2274
fi

2275
if enabled gprof; then
diego's avatar
diego committed
2276 2277
    add_cflags  -p
    add_ldflags -p
2278 2279
fi

diego's avatar
diego committed
2280
# Find out if the .align argument is a power of two or not.
mru's avatar
mru committed
2281
check_asm asmalign_pot '".align 3"'
2282

2283 2284
enabled_any $DECODER_LIST      && enable decoders
enabled_any $ENCODER_LIST      && enable encoders
2285
enabled_any $HWACCEL_LIST      && enable hwaccels
2286 2287 2288
enabled_any $BSF_LIST          && enable bsfs
enabled_any $DEMUXER_LIST      && enable demuxers
enabled_any $MUXER_LIST        && enable muxers
2289
enabled_any $FILTER_LIST       && enable filters
2290 2291 2292 2293 2294 2295 2296
enabled_any $INDEV_LIST        && enable demuxers
enabled_any $OUTDEV_LIST       && enable muxers
enabled_any $PROTOCOL_LIST     && enable protocols

enabled_any $THREADS_LIST      && enable threads

check_deps $CONFIG_LIST       \
2297
           $CONFIG_EXTRA      \
2298 2299 2300
           $HAVE_LIST         \
           $DECODER_LIST      \
           $ENCODER_LIST      \
2301
           $HWACCEL_LIST      \
2302 2303 2304 2305
           $PARSER_LIST       \
           $BSF_LIST          \
           $DEMUXER_LIST      \
           $MUXER_LIST        \
2306
           $FILTER_LIST       \
2307 2308 2309
           $INDEV_LIST        \
           $OUTDEV_LIST       \
           $PROTOCOL_LIST     \
2310

2311
echo "install prefix            $prefix"
diego's avatar
diego committed
2312 2313
echo "source path               $source_path"
echo "C compiler                $cc"
diego's avatar
diego committed
2314
echo ".align is power-of-two    $asmalign_pot"
diego's avatar
diego committed
2315
echo "ARCH                      $arch ($cpu)"
2316 2317
if test "$build_suffix" != ""; then
    echo "build suffix              $build_suffix"
2318
fi
2319 2320 2321
if test "$extra_version" != ""; then
    echo "version string suffix     $extra_version"
fi
mru's avatar
mru committed
2322
echo "big-endian                ${bigendian-no}"
2323
echo "runtime cpu detection     ${runtime_cpudetect-no}"
2324
if enabled x86; then
cehoyos's avatar
cehoyos committed
2325
    echo "yasm                      ${yasm-no}"
mru's avatar
mru committed
2326
    echo "MMX enabled               ${mmx-no}"
2327
    echo "MMX2 enabled              ${mmx2-no}"
2328
    echo "3DNow! enabled            ${amd3dnow-no}"
2329
    echo "3DNow! extended enabled   ${amd3dnowext-no}"
2330
    echo "SSE enabled               ${sse-no}"
2331
    echo "SSSE3 enabled             ${ssse3-no}"
mru's avatar
mru committed
2332 2333
    echo "CMOV enabled              ${cmov-no}"
    echo "CMOV is fast              ${fast_cmov-no}"
michael's avatar
michael committed
2334 2335
    echo "EBX available             ${ebx_available-no}"
    echo "EBP available             ${ebp_available-no}"
2336
    echo "10 operands supported     ${ten_operands-no}"
bellard's avatar
bellard committed
2337
fi
2338
if enabled arm; then
mru's avatar
mru committed
2339 2340
    echo "ARMv5TE enabled           ${armv5te-no}"
    echo "ARMv6 enabled             ${armv6-no}"
mru's avatar
mru committed
2341
    echo "ARMv6T2 enabled           ${armv6t2-no}"
mru's avatar
mru committed
2342
    echo "ARM VFP enabled           ${armvfp-no}"
mru's avatar
mru committed
2343
    echo "IWMMXT enabled            ${iwmmxt-no}"
mru's avatar
mru committed
2344
    echo "NEON enabled              ${neon-no}"
2345
fi
2346
if enabled mips; then
mru's avatar
mru committed
2347
    echo "MMI enabled               ${mmi-no}"
bellard's avatar
bellard committed
2348
fi
2349
if enabled ppc; then
mru's avatar
mru committed
2350
    echo "AltiVec enabled           ${altivec-no}"
2351
    echo "PPC 4xx optimizations     ${ppc4xx-no}"
mru's avatar
mru committed
2352
    echo "dcbzl available           ${dcbzl-no}"
2353 2354 2355 2356
    echo "performance report        ${powerpc_perf-no}"
fi
if enabled sparc; then
    echo "VIS enabled               ${vis-no}"
bellard's avatar
bellard committed
2357
fi
mru's avatar
mru committed
2358 2359
echo "gprof enabled             ${gprof-no}"
echo "debug symbols             ${debug-no}"
2360
echo "strip symbols             ${stripping-no}"
2361
echo "optimizations             ${optimizations-no}"
mru's avatar
mru committed
2362 2363
echo "static                    ${static-no}"
echo "shared                    ${shared-no}"
2364
echo "postprocessing support    ${postproc-no}"
2365
echo "new filter support        ${avfilter-no}"
2366
echo "filters using lavformat   ${avfilter_lavf-no}"
mru's avatar
mru committed
2367
echo "network support           ${network-no}"
2368
if enabled network; then
mru's avatar
mru committed
2369
    echo "IPv6 support              ${ipv6-no}"
diego's avatar
diego committed
2370
fi
mru's avatar
mru committed
2371 2372
echo "threading support         ${thread_type-no}"
echo "SDL support               ${sdl-no}"
2373
if enabled sdl_too_old; then
diego's avatar
diego committed
2374 2375
    echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
fi
mru's avatar
mru committed
2376 2377 2378 2379
echo "Sun medialib support      ${mlib-no}"
echo "AVISynth enabled          ${avisynth-no}"
echo "libamr-nb support         ${libamr_nb-no}"
echo "libamr-wb support         ${libamr_wb-no}"
ramiro's avatar
ramiro committed
2380
echo "libdc1394 support         ${libdc1394-no}"
2381
echo "libdirac enabled          ${libdirac-no}"
mru's avatar
mru committed
2382 2383
echo "libfaac enabled           ${libfaac-no}"
echo "libfaad enabled           ${libfaad-no}"
2384
echo "libfaad dlopened          ${libfaadbin-no}"
mru's avatar
mru committed
2385 2386 2387
echo "libgsm enabled            ${libgsm-no}"
echo "libmp3lame enabled        ${libmp3lame-no}"
echo "libnut enabled            ${libnut-no}"
2388 2389
echo "libopencore-amrnb support ${libopencore_amrnb-no}"
echo "libopencore-amrwb support ${libopencore_amrwb-no}"
2390
echo "libopenjpeg enabled       ${libopenjpeg-no}"
2391
echo "libschroedinger enabled   ${libschroedinger-no}"
conrad's avatar
conrad committed
2392
echo "libspeex enabled          ${libspeex-no}"
mru's avatar
mru committed
2393 2394
echo "libtheora enabled         ${libtheora-no}"
echo "libvorbis enabled         ${libvorbis-no}"
2395 2396
echo "libx264 enabled           ${libx264-no}"
echo "libxvid enabled           ${libxvid-no}"
mru's avatar
mru committed
2397
echo "zlib enabled              ${zlib-no}"
2398
echo "bzlib enabled             ${bzlib-no}"
2399
echo
glantau's avatar
glantau committed
2400

2401
for type in decoder encoder hwaccel parser demuxer muxer protocol filter bsf indev outdev; do
2402
    echo "Enabled ${type}s:"
mru's avatar
mru committed
2403
    eval list=\$$(toupper $type)_LIST
2404
    for part in $list; do
mru's avatar
mru committed
2405 2406 2407
        enabled $part && echo ${part%_*}
    done | sort | pr -3 -t
    echo
2408 2409
done

2410
license="LGPL version 2.1 or later"
2411
if enabled nonfree; then
2412
    license="nonfree and unredistributable"
2413 2414 2415 2416
elif enabled gplv3; then
    license="GPL version 3 or later"
elif enabled lgplv3; then
    license="LGPL version 3 or later"
2417
elif enabled gpl; then
2418
    license="GPL version 2 or later"
2419 2420 2421
fi

echo "License: $license"
2422

2423 2424
echo "Creating config.mak and config.h..."

diego's avatar
diego committed
2425 2426
echo "# Automatically generated by configure - do not modify!" > config.mak
echo "/* Automatically generated by configure - do not modify! */" > $TMPH
2427 2428
echo "#ifndef FFMPEG_CONFIG_H" >> $TMPH
echo "#define FFMPEG_CONFIG_H" >> $TMPH
diego's avatar
diego committed
2429
echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH
2430
echo "#define FFMPEG_DATADIR \"$(eval c_escape $datadir)\"" >> $TMPH
glantau's avatar
glantau committed
2431

2432
echo "FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION" >> config.mak
mru's avatar
mru committed
2433
echo "prefix=$prefix" >> config.mak
2434 2435 2436 2437
echo "LIBDIR=\$(DESTDIR)$libdir" >> config.mak
echo "SHLIBDIR=\$(DESTDIR)$shlibdir" >> config.mak
echo "INCDIR=\$(DESTDIR)$incdir" >> config.mak
echo "BINDIR=\$(DESTDIR)$bindir" >> config.mak
2438
echo "DATADIR=\$(DESTDIR)$datadir" >> config.mak
2439
echo "MANDIR=\$(DESTDIR)$mandir" >> config.mak
2440 2441 2442
echo "SRC_PATH=\"$source_path\"" >> config.mak
echo "SRC_PATH_BARE=$source_path" >> config.mak
echo "BUILD_ROOT=\"$PWD\"" >> config.mak
2443
echo "CC=$cc" >> config.mak
2444
echo "AS=$as" >> config.mak
lorenm's avatar
lorenm committed
2445
echo "YASM=$yasmexe" >> config.mak
2446
echo "AR=$ar" >> config.mak
michaelni's avatar
michaelni committed
2447
echo "RANLIB=$ranlib" >> config.mak
2448
echo "LN_S=$ln_s" >> config.mak
2449
enabled stripping &&
ramiro's avatar
ramiro committed
2450
    echo "STRIP=$strip" >> config.mak ||
mru's avatar
mru committed
2451
    echo "STRIP=echo ignoring strip" >> config.mak
2452

nickols_k's avatar
nickols_k committed
2453
echo "OPTFLAGS=$CFLAGS" >> config.mak
2454
echo "LDFLAGS=$LDFLAGS" >> config.mak
2455
echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak
2456
echo "SHFLAGS=$SHFLAGS" >> config.mak
lorenm's avatar
lorenm committed
2457
echo "YASMFLAGS=$YASMFLAGS" >> config.mak
2458
echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
2459
echo "BUILD_STATIC=$static" >> config.mak
2460
echo "BUILDSUF=$build_suffix" >> config.mak
2461
echo "FULLNAME=$FULLNAME" >> config.mak
2462
echo "LIBPREF=$LIBPREF" >> config.mak
2463
echo "LIBSUF=$LIBSUF" >> config.mak
2464
echo "LIBNAME=$LIBNAME" >> config.mak
2465
echo "SLIBPREF=$SLIBPREF" >> config.mak
2466 2467
echo "SLIBSUF=$SLIBSUF" >> config.mak
echo "EXESUF=$EXESUF" >> config.mak
2468
echo "EXTRA_VERSION=$extra_version" >> config.mak
2469
echo "DEPEND_CMD=$DEPEND_CMD" >> config.mak
2470 2471
echo "HOSTCC=$host_cc" >> config.mak
echo "HOSTCFLAGS=$host_cflags" >> config.mak
2472
echo "HOSTEXESUF=$HOSTEXESUF" >> config.mak
2473 2474
echo "HOSTLDFLAGS=$host_ldflags" >> config.mak
echo "HOSTLIBS=$host_libs" >> config.mak
2475 2476
echo "TARGET_EXEC=$target_exec" >> config.mak
echo "TARGET_PATH=$target_path" >> config.mak
mru's avatar
mru committed
2477

2478
if enabled bigendian; then
2479 2480
    echo "WORDS_BIGENDIAN=yes" >> config.mak
    echo "#define WORDS_BIGENDIAN 1" >> $TMPH
2481
fi
mru's avatar
mru committed
2482

2483
if enabled sdl; then
2484 2485
    echo "SDL_LIBS=$("${SDL_CONFIG}" --libs)" >> config.mak
    echo "SDL_CFLAGS=$("${SDL_CONFIG}" --cflags)" >> config.mak
bellard's avatar
bellard committed
2486
fi
2487
if enabled texi2html; then
2488
    echo "BUILD_DOC=yes" >> config.mak
2489
fi
diego's avatar
diego committed
2490

2491 2492 2493
get_version(){
    name=$1
    file=$source_path/$2
mru's avatar
mru committed
2494 2495
    eval $(grep "#define ${name}_VERSION_M" "$file" | awk '{ print $2"="$3 }')
    eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO
mru's avatar
mru committed
2496 2497 2498
    lcname=$(tolower $name)
    eval echo "${lcname}_VERSION=\$${name}_VERSION" >> config.mak
    eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> config.mak
2499 2500
}

mru's avatar
mru committed
2501 2502 2503 2504 2505 2506
get_version LIBSWSCALE  libswscale/swscale.h
get_version LIBPOSTPROC libpostproc/postprocess.h
get_version LIBAVCODEC  libavcodec/avcodec.h
get_version LIBAVDEVICE libavdevice/avdevice.h
get_version LIBAVFORMAT libavformat/avformat.h
get_version LIBAVUTIL   libavutil/avutil.h
mru's avatar
mru committed
2507
get_version LIBAVFILTER libavfilter/avfilter.h
diego's avatar
diego committed
2508

2509
if enabled shared; then
2510 2511
    echo "BUILD_SHARED=yes" >> config.mak
    echo "PIC=-fPIC -DPIC" >> config.mak
ramiro's avatar
ramiro committed
2512
    echo "LIBTARGET=${LIBTARGET}" >> config.mak
2513 2514 2515
    echo "SLIBNAME=${SLIBNAME}" >> config.mak
    echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak
    echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak
2516
    echo "SLIB_CREATE_DEF_CMD=${SLIB_CREATE_DEF_CMD}" >> config.mak
2517 2518 2519
    echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak
    echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak
    echo "SLIB_UNINSTALL_EXTRA_CMD=${SLIB_UNINSTALL_EXTRA_CMD}" >> config.mak
nickols_k's avatar
nickols_k committed
2520
fi
2521
echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
2522
echo "EXTRALIBS=$extralibs" >> config.mak
2523

2524 2525
echo "ARCH=$arch" >> config.mak

2526 2527
print_config ARCH_   $TMPH config.mak $ARCH_LIST
print_config HAVE_   $TMPH config.mak $HAVE_LIST
2528
print_config CONFIG_ $TMPH config.mak $CONFIG_LIST       \
2529
                                      $CONFIG_EXTRA      \
2530 2531
                                      $DECODER_LIST      \
                                      $ENCODER_LIST      \
2532
                                      $HWACCEL_LIST      \
2533 2534 2535 2536
                                      $PARSER_LIST       \
                                      $BSF_LIST          \
                                      $DEMUXER_LIST      \
                                      $MUXER_LIST        \
2537
                                      $FILTER_LIST       \
2538 2539 2540
                                      $PROTOCOL_LIST     \
                                      $INDEV_LIST        \
                                      $OUTDEV_LIST       \
2541

mellum's avatar
mellum committed
2542 2543
echo "#define restrict $_restrict" >> $TMPH

2544
if enabled small; then
2545
    echo "#define av_always_inline"  >> $TMPH
michael's avatar
michael committed
2546 2547
fi

2548

2549
# Apparently it's not possible to portably echo a backslash.
ramiro's avatar
ramiro committed
2550
enabled asmalign_pot &&
2551
    printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH ||
diego's avatar
diego committed
2552
    printf '#define ASMALIGN(ZEROBITS) ".align 1 << " #ZEROBITS "\\n\\t"\n' >> $TMPH
2553

2554
echo "#define EXTERN_PREFIX \"${extern_prefix}\"" >> $TMPH
kabi's avatar
kabi committed
2555

2556 2557
echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH

diego's avatar
diego committed
2558
# Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
ramiro's avatar
ramiro committed
2559 2560 2561
cmp -s $TMPH config.h &&
    echo "config.h is unchanged" ||
    mv -f $TMPH config.h
nickols_k's avatar
nickols_k committed
2562

2563
# build tree in object directory if source path is different from current one
2564
if enabled source_path_used; then
2565
    DIRS="\
2566 2567 2568
        doc               \
        libavcodec        \
        libavcodec/alpha  \
mru's avatar
mru committed
2569
        libavcodec/arm    \
2570 2571 2572 2573 2574
        libavcodec/bfin   \
        libavcodec/mlib   \
        libavcodec/ppc    \
        libavcodec/sh4    \
        libavcodec/sparc  \
2575
        libavcodec/x86    \
2576
        libavdevice       \
2577
        libavfilter       \
2578 2579 2580 2581
        libavformat       \
        libavutil         \
        libpostproc       \
        libswscale        \
2582 2583 2584 2585 2586
        libswscale/bfin   \
        libswscale/mlib   \
        libswscale/ppc    \
        libswscale/sparc  \
        libswscale/x86    \
2587 2588 2589
        tests             \
        tools             \
        "
2590
    FILES="\
2591 2592
        Makefile             \
        common.mak           \
mru's avatar
mru committed
2593
        subdir.mak           \
2594 2595
        doc/texi2pod.pl      \
        libavcodec/Makefile  \
2596
        libavdevice/Makefile \
2597
        libavfilter/Makefile \
2598 2599 2600 2601 2602
        libavformat/Makefile \
        libavutil/Makefile   \
        libpostproc/Makefile \
        libswscale/Makefile  \
        "
2603
    for dir in $DIRS ; do
2604
        mkdir -p $dir
2605 2606
    done
    for f in $FILES ; do
2607
        $ln_s "$source_path/$f" $f
2608 2609
    done
fi
2610 2611


2612
# build pkg-config files
2613

2614 2615
pkgconfig_generate(){
name=$1
2616
shortname=${name#lib}${build_suffix}
2617 2618 2619 2620
comment=$2
version=$3
libs=$4
requires=$5
2621
cat <<EOF > $name/$name.pc
2622
prefix=$prefix
2623
exec_prefix=\${prefix}
2624
libdir=$libdir
2625
includedir=$incdir
2626

2627 2628 2629
Name: $name
Description: $comment
Version: $version
2630 2631
Requires: $(disabled shared && echo $requires)
Requires.private: $(enabled shared && echo $requires)
2632
Conflicts:
2633 2634
Libs: -L\${libdir} -l${shortname} $(disabled shared && echo $libs)
Libs.private: $(enabled shared && echo $libs)
2635
Cflags: -I\${includedir}
2636
EOF
2637
cat <<EOF > $name/$name-uninstalled.pc
2638 2639
prefix=
exec_prefix=
aurel's avatar
aurel committed
2640
libdir=\${pcfiledir}
2641
includedir=${source_path}
2642

2643 2644 2645 2646
Name: $name
Description: $comment
Version: $version
Requires: $requires
2647
Conflicts:
2648
Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
2649 2650
Cflags: -I\${includedir}
EOF
2651
}
2652

2653
pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION"
2654 2655 2656
pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
2657
enabled avfilter &&
2658
    pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
2659
enabled postproc &&
2660
    pkgconfig_generate libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION"
diego's avatar
diego committed
2661
pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"