configure 138 KB
Newer Older
1
#!/bin/sh
2
#
3
# FFmpeg configure script
4
#
Diego Biurrun's avatar
Diego Biurrun 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
}

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 Biurrun's avatar
Diego Biurrun committed
45
    echo "This configure script requires a POSIX-compatible shell"
46
    echo "such as bash or ksh."
47
    echo "THIS IS NOT A BUG IN FFMPEG, DO NOT REPORT IT AS SUCH."
48
    echo "Instead, install a working POSIX-compatible shell."
49
    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
test -d /usr/xpg4/bin && PATH=/usr/xpg4/bin:$PATH

59
show_help(){
60
    cat <<EOF
61 62 63
Usage: configure [options]
Options: [defaults in brackets after descriptions]

64
Help options:
65
  --help                   print this message
66 67 68 69 70 71 72 73 74 75 76 77 78
  --list-decoders          show all available decoders
  --list-encoders          show all available encoders
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

Standard options:
79
  --logfile=FILE           log tests and output to FILE [config.log]
80
  --disable-logging        do not log configure debug information
81
  --fatal-warnings         fail if any configure warning is generated
82 83
  --prefix=PREFIX          install in PREFIX [$prefix]
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
84
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
85 86 87 88 89
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]

90
Licensing options:
91 92 93 94 95
  --enable-gpl             allow use of GPL code, the resulting libs
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code, the resulting libs
                           and binaries will be unredistributable [no]
96 97 98 99 100

Configuration options:
  --disable-static         do not build static libraries [no]
  --enable-shared          build shared libraries [no]
  --enable-small           optimize for size instead of speed
101
  --disable-runtime-cpudetect disable detecting cpu capabilities at runtime (smaller binary)
102 103
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
104
  --disable-all            disable building components, libraries and programs
105

106 107
Program options:
  --disable-programs       do not build command line programs
108 109 110 111
  --disable-ffmpeg         disable ffmpeg build
  --disable-ffplay         disable ffplay build
  --disable-ffprobe        disable ffprobe build
  --disable-ffserver       disable ffserver build
112

113
Documentation options:
114
  --disable-doc            do not build documentation
115 116 117 118 119 120
  --disable-htmlpages      do not build HTML documentation pages
  --disable-manpages       do not build man documentation pages
  --disable-podpages       do not build POD documentation pages
  --disable-txtpages       do not build text documentation pages

Component options:
121 122 123
  --disable-avdevice       disable libavdevice build
  --disable-avcodec        disable libavcodec build
  --disable-avformat       disable libavformat build
124
  --disable-avutil         disable libavutil build
Michael Niedermayer's avatar
Michael Niedermayer committed
125
  --disable-swresample     disable libswresample build
126
  --disable-swscale        disable libswscale build
127
  --disable-postproc       disable libpostproc build
128
  --disable-avfilter       disable libavfilter build
129
  --enable-avresample      enable libavresample build [no]
130
  --disable-pthreads       disable pthreads [auto]
131
  --disable-w32threads     disable Win32 threads [auto]
132
  --disable-os2threads     disable OS/2 threads [auto]
133 134
  --enable-x11grab         enable X11 grabbing [no]
  --disable-network        disable network support [no]
135
  --disable-dct            disable DCT code
136 137
  --disable-dwt            disable DWT code
  --disable-lsp            disable LSP code
138
  --disable-lzo            disable LZO decoder code
139 140
  --disable-mdct           disable MDCT code
  --disable-rdft           disable RDFT code
141 142
  --disable-fft            disable FFT code
  --enable-dxva2           enable DXVA2 code
143
  --enable-vaapi           enable VAAPI code [autodetect]
144
  --enable-vda             enable VDA code   [autodetect]
145
  --enable-vdpau           enable VDPAU code [autodetect]
146 147

Individual component options:
148
  --disable-everything     disable all components listed below
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  --disable-encoder=NAME   disable encoder NAME
  --enable-encoder=NAME    enable encoder NAME
  --disable-encoders       disable all encoders
  --disable-decoder=NAME   disable decoder NAME
  --enable-decoder=NAME    enable decoder NAME
  --disable-decoders       disable all decoders
  --disable-hwaccel=NAME   disable hwaccel NAME
  --enable-hwaccel=NAME    enable hwaccel NAME
  --disable-hwaccels       disable all hwaccels
  --disable-muxer=NAME     disable muxer NAME
  --enable-muxer=NAME      enable muxer NAME
  --disable-muxers         disable all muxers
  --disable-demuxer=NAME   disable demuxer NAME
  --enable-demuxer=NAME    enable demuxer NAME
  --disable-demuxers       disable all demuxers
  --enable-parser=NAME     enable parser NAME
  --disable-parser=NAME    disable parser NAME
  --disable-parsers        disable all parsers
  --enable-bsf=NAME        enable bitstream filter NAME
  --disable-bsf=NAME       disable bitstream filter NAME
  --disable-bsfs           disable all bitstream filters
  --enable-protocol=NAME   enable protocol NAME
  --disable-protocol=NAME  disable protocol NAME
  --disable-protocols      disable all protocols
173
  --enable-indev=NAME      enable input device NAME
174 175
  --disable-indev=NAME     disable input device NAME
  --disable-indevs         disable input devices
176 177
  --enable-outdev=NAME     enable output device NAME
  --disable-outdev=NAME    disable output device NAME
178 179 180 181 182 183 184 185 186
  --disable-outdevs        disable output devices
  --disable-devices        disable all devices
  --enable-filter=NAME     enable filter NAME
  --disable-filter=NAME    disable filter NAME
  --disable-filters        disable all filters

External library support:
  --enable-avisynth        enable reading of AVISynth script files [no]
  --enable-bzlib           enable bzlib [autodetect]
187
  --enable-fontconfig      enable fontconfig
Stefano Sabatini's avatar
Stefano Sabatini committed
188
  --enable-frei0r          enable frei0r video filtering
189
  --enable-gnutls          enable gnutls [no]
190
  --enable-libaacplus      enable AAC+ encoding via libaacplus [no]
191
  --enable-libass          enable libass subtitles rendering [no]
Petri Hintukainen's avatar
Petri Hintukainen committed
192
  --enable-libbluray       enable BluRay reading using libbluray [no]
Paul B Mahol's avatar
Paul B Mahol committed
193
  --enable-libcaca         enable textual display using libcaca
194
  --enable-libcelt         enable CELT decoding via libcelt [no]
195
  --enable-libcdio         enable audio CD grabbing with libcdio
196 197
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                           and libraw1394 [no]
198 199
  --enable-libfaac         enable AAC encoding via libfaac [no]
  --enable-libfdk-aac      enable AAC encoding via libfdk-aac [no]
200
  --enable-libflite        enable flite (voice synthesis) support via libflite [no]
201
  --enable-libfreetype     enable libfreetype [no]
202
  --enable-libgsm          enable GSM de/encoding via libgsm [no]
203
  --enable-libiec61883     enable iec61883 via libiec61883 [no]
204
  --enable-libilbc         enable iLBC de/encoding via libilbc [no]
205
  --enable-libmodplug      enable ModPlug via libmodplug [no]
206 207 208
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
  --enable-libnut          enable NUT (de)muxing via libnut,
                           native (de)muxer exists [no]
209 210 211
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
  --enable-libopencv       enable video filtering via libopencv [no]
212
  --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
213
  --enable-libopus         enable Opus decoding via libopus [no]
214
  --enable-libpulse        enable Pulseaudio input via libpulse [no]
215
  --enable-librtmp         enable RTMP[E] support via librtmp [no]
216
  --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
217
  --enable-libsoxr         enable Include libsoxr resampling [no]
218
  --enable-libspeex        enable Speex de/encoding via libspeex [no]
Mohamed Naufal's avatar
Mohamed Naufal committed
219
  --enable-libstagefright-h264  enable H.264 decoding via libstagefright [no]
220
  --enable-libtheora       enable Theora encoding via libtheora [no]
221
  --enable-libtwolame      enable MP2 encoding via libtwolame [no]
222
  --enable-libutvideo      enable Ut Video encoding and decoding via libutvideo [no]
223
  --enable-libv4l2         enable libv4l2/v4l-utils [no]
224
  --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
225
  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
226
  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,
227
                           native implementation exists [no]
228
  --enable-libvpx          enable VP8 de/encoding via libvpx [no]
229
  --enable-libx264         enable H.264 encoding via x264 [no]
230
  --enable-libxavs         enable AVS encoding via xavs [no]
231 232
  --enable-libxvid         enable Xvid encoding via xvidcore,
                           native MPEG-4/Xvid encoder exists [no]
233
  --enable-openal          enable OpenAL 1.1 capture support [no]
234
  --enable-openssl         enable openssl [no]
235 236 237 238 239 240 241 242 243 244
  --enable-zlib            enable zlib [autodetect]

Advanced options (experts only):
  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
  --enable-cross-compile   assume a cross-compiler is used
  --sysroot=PATH           root of cross-build tree
  --sysinclude=PATH        location of cross-build system headers
  --target-os=OS           compiler targets OS [$target_os]
  --target-exec=CMD        command to run executables on target
  --target-path=DIR        path to view of build directory on target
245
  --toolchain=NAME         set tool defaults according to NAME
246
  --nm=NM                  use nm tool NM [$nm_default]
247
  --ar=AR                  use archive tool AR [$ar_default]
248
  --as=AS                  use assembler AS [$as_default]
249
  --yasmexe=EXE            use yasm-compatible assembler EXE [$yasmexe_default]
250
  --cc=CC                  use C compiler CC [$cc_default]
Mohamed Naufal's avatar
Mohamed Naufal committed
251
  --cxx=CXX                use C compiler CXX [$cxx_default]
252
  --dep-cc=DEPCC           use dependency generator DEPCC [$cc_default]
253
  --ld=LD                  use linker LD [$ld_default]
254 255
  --host-cc=HOSTCC         use host C compiler HOSTCC
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
256
  --host-ld=HOSTLD         use host linker HOSTLD
257 258
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
  --host-libs=HLIBS        use libs HLIBS when linking for host
259
  --host-os=OS             compiler host OS [$target_os]
260
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
Mohamed Naufal's avatar
Mohamed Naufal committed
261
  --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS]
262 263 264
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
  --extra-libs=ELIBS       add ELIBS [$ELIBS]
  --extra-version=STRING   version string suffix []
265
  --optflags=OPTFLAGS      override optimization-related compiler flags
266
  --build-suffix=SUFFIX    library name suffix []
267
  --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
268
  --progs-suffix=SUFFIX    program name suffix []
269 270 271
  --arch=ARCH              select architecture [$arch]
  --cpu=CPU                select the minimum required CPU (affects
                           instruction selection, may crash on older CPUs)
272 273
  --enable-pic             build position-independent code
  --enable-sram            allow use of on-chip SRAM
274
  --enable-thumb           compile for Thumb instruction set
275 276 277 278 279 280
  --disable-symver         disable symbol versioning
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
  --disable-safe-bitstream-reader
                           disable buffer boundary checking in bitreaders
                           (faster, but may crash)
  --enable-memalign-hack   emulate memalign, interferes with memory debuggers
281
  --enable-lto             use link-time optimization
282 283

Optimization options (experts only):
284
  --disable-asm            disable all assembler optimizations
285 286 287 288
  --disable-altivec        disable AltiVec optimizations
  --disable-amd3dnow       disable 3DNow! optimizations
  --disable-amd3dnowext    disable 3DNow! extended optimizations
  --disable-mmx            disable MMX optimizations
289
  --disable-mmxext         disable MMXEXT optimizations
290
  --disable-sse            disable SSE optimizations
291 292
  --disable-sse2           disable SSE2 optimizations
  --disable-sse3           disable SSE3 optimizations
293
  --disable-ssse3          disable SSSE3 optimizations
294 295
  --disable-sse4           disable SSE4 optimizations
  --disable-sse42          disable SSE4.2 optimizations
296
  --disable-avx            disable AVX optimizations
297
  --disable-fma4           disable FMA4 optimizations
298 299 300
  --disable-armv5te        disable armv5te optimizations
  --disable-armv6          disable armv6 optimizations
  --disable-armv6t2        disable armv6t2 optimizations
301
  --disable-vfp            disable VFP optimizations
302
  --disable-neon           disable NEON optimizations
303
  --disable-vis            disable VIS optimizations
304
  --disable-inline-asm     disable use of inline assembler
305
  --disable-yasm           disable use of yasm assembler
306 307 308 309
  --disable-mips32r2       disable MIPS32R2 optimizations
  --disable-mipsdspr1      disable MIPS DSP ASE R1 optimizations
  --disable-mipsdspr2      disable MIPS DSP ASE R2 optimizations
  --disable-mipsfpu        disable floating point MIPS optimizations
310
  --disable-fast-unaligned consider unaligned accesses slow
311

312
Developer options (useful when working on FFmpeg itself):
313
  --enable-coverage        build with test coverage instrumentation
314 315 316 317
  --disable-debug          disable debugging symbols
  --enable-debug=LEVEL     set the debug level [$debuglevel]
  --disable-optimizations  disable compiler optimizations
  --enable-extra-warnings  enable more compiler warnings
318
  --disable-stripping      disable stripping of executables and shared libraries
319
  --assert-level=level     0(default), 1 or 2, amount of assertion testing,
320
                           2 causes a slowdown at runtime.
321
  --enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data
322 323 324
  --valgrind=VALGRIND      run "make fate" tests through valgrind to detect memory
                           leaks and errors, using the specified valgrind binary.
                           Cannot be combined with --target-exec
325
  --enable-ftrapv          Trap arithmetic overflows
326 327
  --samples=PATH           location of test samples for FATE, if not set use
                           \$FATE_SAMPLES at make invocation time.
328 329
  --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
                           should be used only for debugging purposes)
330 331 332 333 334 335 336 337
  --enable-random          randomly enable/disable components
  --disable-random
  --enable-random=LIST     randomly enable/disable specific components or
  --disable-random=LIST    component groups. LIST is a comma-separated list
                           of NAME[:PROB] entries where NAME is a component
                           (group) and PROB the probability associated with
                           NAME (default 0.5).
  --random-seed=VALUE      seed value for --enable/disable-random
338 339 340

NOTE: Object files are built at the place where configure is launched.
EOF
341
  exit 0
342
}
343

344 345
quotes='""'

346
log(){
347
    echo "$@" >> $logfile
348 349
}

350
log_file(){
Måns Rullgård's avatar
Måns Rullgård committed
351
    log BEGIN $1
352
    pr -n -t $1 >> $logfile
Måns Rullgård's avatar
Måns Rullgård committed
353 354 355
    log END $1
}

356
echolog(){
Måns Rullgård's avatar
Måns Rullgård committed
357
    log "$@"
358
    echo "$@"
359 360
}

361 362 363 364 365
warn(){
    log "WARNING: $*"
    WARNINGS="${WARNINGS}WARNING: $*\n"
}

366 367 368
die(){
    echolog "$@"
    cat <<EOF
369

370
If you think configure made a mistake, make sure you are using the latest
371
version from Git.  If the latest version fails, report the problem to the
372
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
373
EOF
374
    if disabled logging; then
375
        cat <<EOF
376 377
Rerun configure with logging enabled (do not use --disable-logging), and
include the log this produces with your report.
378 379
EOF
    else
380
        cat <<EOF
381 382
Include the log file "$logfile" produced by configure as this will help
solving the problem.
383 384
EOF
    fi
385 386 387
    exit 1
}

388
# Avoid locale weirdness, besides we really just want to translate ASCII.
389
toupper(){
390
    echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
391 392
}

393
tolower(){
394
    echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
395 396
}

397 398 399 400
c_escape(){
    echo "$*" | sed 's/["\\]/\\\0/g'
}

401 402
sh_quote(){
    v=$(echo "$1" | sed "s/'/'\\\\''/g")
403
    test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'"
404 405 406
    echo "$v"
}

407 408 409 410
cleanws(){
    echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//'
}

411 412 413 414
filter(){
    pat=$1
    shift
    for v; do
415
        eval "case $v in $pat) echo $v ;; esac"
416 417 418
    done
}

419 420 421 422 423 424 425 426
filter_out(){
    pat=$1
    shift
    for v; do
        eval "case $v in $pat) ;; *) echo $v ;; esac"
    done
}

427 428 429
map(){
    m=$1
    shift
430
    for v; do eval $m; done
431 432
}

433 434 435 436 437 438
add_suffix(){
    suffix=$1
    shift
    for v; do echo ${v}${suffix}; done
}

439 440 441 442 443 444 445 446
set_all(){
    value=$1
    shift
    for var in $*; do
        eval $var=$value
    done
}

447 448 449 450 451 452 453 454
set_weak(){
    value=$1
    shift
    for var; do
        eval : \${$var:=$value}
    done
}

455 456 457 458 459 460 461 462 463 464
set_safe(){
    var=$1
    shift
    eval $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')='$*'
}

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

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
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
}

484 485 486 487 488 489 490 491
enable(){
    set_all yes $*
}

disable(){
    set_all no $*
}

492 493 494 495 496 497 498 499
enable_weak(){
    set_weak yes $*
}

disable_weak(){
    set_weak no $*
}

500
enable_safe(){
501 502 503
    for var; do
        enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
    done
504 505 506
}

disable_safe(){
507 508 509
    for var; do
        disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
    done
510 511
}

512 513 514 515
do_enable_deep(){
    for var; do
        enabled $var && continue
        eval sel="\$${var}_select"
516 517
        eval sgs="\$${var}_suggest"
        pushvar var sgs
518
        enable_deep $sel
519 520
        popvar sgs
        enable_deep_weak $sgs
521 522 523 524 525 526 527 528 529
        popvar var
    done
}

enable_deep(){
    do_enable_deep $*
    enable $*
}

530 531 532 533 534
enable_deep_weak(){
    do_enable_deep $*
    enable_weak $*
}

535
enabled(){
536 537
    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xyes"
538 539
}

540
disabled(){
541 542
    test "${1#!}" = "$1" && op== || op=!=
    eval test "x\$${1#!}" $op "xno"
543 544
}

545 546 547 548 549 550
enabled_all(){
    for opt; do
        enabled $opt || return 1
    done
}

551 552 553 554 555 556
disabled_all(){
    for opt; do
        disabled $opt || return 1
    done
}

557 558 559 560 561 562
enabled_any(){
    for opt; do
        enabled $opt && return 0
    done
}

563 564 565 566
disabled_any(){
    for opt; do
        disabled $opt && return 0
    done
567
    return 1
568 569
}

570 571
set_default(){
    for opt; do
572
        eval : \${$opt:=\$${opt}_default}
573 574 575
    done
}

576 577 578 579 580 581 582 583 584
is_in(){
    value=$1
    shift
    for var in $*; do
        [ $var = $value ] && return 0
    done
    return 1
}

585
do_check_deps(){
586
    for cfg; do
587
        cfg="${cfg#!}"
588 589 590
        enabled ${cfg}_checking && die "Circular dependency for $cfg."
        disabled ${cfg}_checking && continue
        enable ${cfg}_checking
591
        append allopts $cfg
592

593 594
        eval dep_all="\$${cfg}_deps"
        eval dep_any="\$${cfg}_deps_any"
595
        eval dep_sel="\$${cfg}_select"
596
        eval dep_sgs="\$${cfg}_suggest"
597 598
        eval dep_ifa="\$${cfg}_if"
        eval dep_ifn="\$${cfg}_if_any"
599

600
        pushvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
601
        do_check_deps $dep_all $dep_any $dep_sel $dep_sgs $dep_ifa $dep_ifn
602
        popvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
603

604 605
        [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
        [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
Måns Rullgård's avatar
Måns Rullgård committed
606 607
        enabled_all  $dep_all || disable $cfg
        enabled_any  $dep_any || disable $cfg
608
        disabled_any $dep_sel && disable $cfg
609

610
        if enabled $cfg; then
611
            enable_deep $dep_sel
612
            enable_deep_weak $dep_sgs
613 614
        fi

615
        disable ${cfg}_checking
616 617 618
    done
}

619 620 621 622 623 624 625 626 627 628 629 630
check_deps(){
    unset allopts

    do_check_deps "$@"

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

631 632
print_config(){
    pfx=$1
633 634
    files=$2
    shift 2
635 636 637 638 639 640 641 642 643 644 645 646 647 648
    map 'eval echo "$v \${$v:-no}"' "$@" |
    awk "BEGIN { split(\"$files\", files) }
        {
            c = \"$pfx\" toupper(\$1);
            v = \$2;
            sub(/yes/, 1, v);
            sub(/no/,  0, v);
            for (f in files) {
                file = files[f];
                if (file ~ /\\.h\$/) {
                    printf(\"#define %s %d\\n\", c, v) >>file;
                } else if (file ~ /\\.asm\$/) {
                    printf(\"%%define %s %d\\n\", c, v) >>file;
                } else if (file ~ /\\.mak\$/) {
649
                    n = -v ? \"\" : \"!\";
650 651 652 653
                    printf(\"%s%s=yes\\n\", n, c) >>file;
                }
            }
        }"
654 655
}

656 657 658 659
print_enabled(){
    suf=$1
    shift
    for v; do
660
        enabled $v && printf "%s\n" ${v%$suf};
661 662 663
    done
}

664 665 666 667 668 669
append(){
    var=$1
    shift
    eval "$var=\"\$$var $*\""
}

670 671 672 673 674 675
prepend(){
    var=$1
    shift
    eval "$var=\"$* \$$var\""
}

676
add_cppflags(){
677
    append CPPFLAGS "$@"
678 679
}

680
add_cflags(){
681
    append CFLAGS $($cflags_filter "$@")
682 683
}

Mohamed Naufal's avatar
Mohamed Naufal committed
684
add_cxxflags(){
685
    append CXXFLAGS $($cflags_filter "$@")
Mohamed Naufal's avatar
Mohamed Naufal committed
686 687
}

688
add_asflags(){
689
    append ASFLAGS $($asflags_filter "$@")
690 691
}

692
add_ldflags(){
693
    append LDFLAGS $($ldflags_filter "$@")
694 695 696
}

add_extralibs(){
697
    prepend extralibs $($ldflags_filter "$@")
698 699
}

700 701 702 703 704 705
add_host_cflags(){
    append host_cflags $($host_cflags_filter "$@")
}

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

708 709 710 711 712 713
add_compat(){
    append compat_objs $1
    shift
    map 'add_cppflags -D$v' "$@"
}

714
check_cmd(){
715
    log "$@"
716
    "$@" >> $logfile 2>&1
717 718
}

719 720 721 722
cc_o(){
    eval printf '%s\\n' $CC_O
}

723 724 725 726
cc_e(){
    eval printf '%s\\n' $CC_E
}

727
check_cc(){
728
    log check_cc "$@"
729
    cat > $TMPC
730
    log_file $TMPC
731
    check_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC
732 733
}

Mohamed Naufal's avatar
Mohamed Naufal committed
734 735 736 737
check_cxx(){
    log check_cxx "$@"
    cat > $TMPCPP
    log_file $TMPCPP
738
    check_cmd $cxx $CPPFLAGS $CFLAGS $CXXFLAGS "$@" $CXX_C -o $TMPO $TMPCPP
Mohamed Naufal's avatar
Mohamed Naufal committed
739 740
}

741 742
check_cpp(){
    log check_cpp "$@"
743
    cat > $TMPC
744
    log_file $TMPC
745
    check_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC
746 747
}

748 749 750 751
as_o(){
    eval printf '%s\\n' $AS_O
}

752 753
check_as(){
    log check_as "$@"
754 755 756
    cat > $TMPS
    log_file $TMPS
    check_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $(as_o $TMPO) $TMPS
757 758
}

759 760
check_inline_asm(){
    log check_inline_asm "$@"
761
    name="$1"
762
    code="$2"
763
    shift 2
764
    disable $name
765
    check_cc "$@" <<EOF && enable $name
766
void foo(void){ __asm__ volatile($code); }
767 768 769
EOF
}

770 771 772 773 774 775
check_insn(){
    log check_insn "$@"
    check_inline_asm ${1}_inline "\"$2\""
    echo "$2" | check_as && enable ${1}_external || disable ${1}_external
}

Loren Merritt's avatar
Loren Merritt committed
776 777 778 779 780
check_yasm(){
    log check_yasm "$@"
    echo "$1" > $TMPS
    log_file $TMPS
    shift 1
781
    check_cmd $yasmexe $YASMFLAGS -Werror "$@" -o $TMPO $TMPS
Loren Merritt's avatar
Loren Merritt committed
782 783
}

784 785 786 787
ld_o(){
    eval printf '%s\\n' $LD_O
}

788
check_ld(){
789
    log check_ld "$@"
Mohamed Naufal's avatar
Mohamed Naufal committed
790 791
    type=$1
    shift 1
792 793
    flags=$(filter_out '-l*' $@)
    libs=$(filter '-l*' $@)
794
    check_$type $($cflags_filter $flags) || return
795 796
    flags=$($ldflags_filter $flags)
    libs=$($ldflags_filter $libs)
797
    check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
798 799
}

800 801 802 803 804 805 806 807 808 809 810 811 812 813
check_code(){
    log check_code "$@"
    check=$1
    headers=$2
    code=$3
    shift 3
    {
        for hdr in $headers; do
            echo "#include <$hdr>"
        done
        echo "int main(void) { $code; return 0; }"
    } | check_$check "$@"
}

814 815
check_cppflags(){
    log check_cppflags "$@"
816
    check_cc "$@" <<EOF && append CPPFLAGS "$@"
817 818 819 820
int x;
EOF
}

821
check_cflags(){
822
    log check_cflags "$@"
823
    set -- $($cflags_filter "$@")
824
    check_cc "$@" <<EOF && append CFLAGS "$@"
825 826 827 828
int x;
EOF
}

Mohamed Naufal's avatar
Mohamed Naufal committed
829 830
check_cxxflags(){
    log check_cxxflags "$@"
831
    set -- $($cflags_filter "$@")
Mohamed Naufal's avatar
Mohamed Naufal committed
832 833 834 835 836
    check_cxx "$@" <<EOF && append CXXFLAGS "$@"
int x;
EOF
}

837 838
test_ldflags(){
    log test_ldflags "$@"
Mohamed Naufal's avatar
Mohamed Naufal committed
839
    check_ld "cc" "$@" <<EOF
840
int main(void){ return 0; }
841 842 843
EOF
}

844 845 846 847 848
check_ldflags(){
    log check_ldflags "$@"
    test_ldflags "$@" && add_ldflags "$@"
}

849
check_header(){
850
    log check_header "$@"
851 852
    header=$1
    shift
853 854
    disable_safe $header
    check_cpp "$@" <<EOF && enable_safe $header
855 856 857 858 859 860
#include <$header>
int x;
EOF
}

check_func(){
861
    log check_func "$@"
862 863
    func=$1
    shift
Måns Rullgård's avatar
Måns Rullgård committed
864
    disable $func
Mohamed Naufal's avatar
Mohamed Naufal committed
865
    check_ld "cc" "$@" <<EOF && enable $func
866
extern int $func();
867
int main(void){ $func(); }
868 869 870
EOF
}

871
check_mathfunc(){
872
    log check_mathfunc "$@"
873
    func=$1
874 875 876
    narg=$2
    shift 2
    test $narg = 2 && args="f, g" || args="f"
877 878 879
    disable $func
    check_ld "cc" "$@" <<EOF && enable $func
#include <math.h>
880
float foo(float f, float g) { return $func($args); }
881 882 883 884
int main(void){ return (int) foo; }
EOF
}

885 886
check_func_headers(){
    log check_func_headers "$@"
887
    headers=$1
888
    funcs=$2
889
    shift 2
890 891 892 893 894 895 896 897
    {
        for hdr in $headers; do
            echo "#include <$hdr>"
        done
        for func in $funcs; do
            echo "long check_$func(void) { return (long) $func; }"
        done
        echo "int main(void) { return 0; }"
Mohamed Naufal's avatar
Mohamed Naufal committed
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
    } | check_ld "cc" "$@" && enable $funcs && enable_safe $headers
}

check_class_headers_cpp(){
    log check_class_headers_cpp "$@"
    headers=$1
    classes=$2
    shift 2
    {
        for hdr in $headers; do
            echo "#include <$hdr>"
        done
        echo "int main(void) { "
        i=1
        for class in $classes; do
            echo "$class obj$i;"
            i=$(expr $i + 1)
        done
        echo "return 0; }"
    } | check_ld "cxx" "$@" && enable $funcs && enable_safe $headers
918 919
}

920 921 922 923
check_cpp_condition(){
    log check_cpp_condition "$@"
    header=$1
    condition=$2
924
    shift 2
925
    check_cpp "$@" <<EOF
926 927 928 929 930 931 932
#include <$header>
#if !($condition)
#error "unsatisfied condition: $condition"
#endif
EOF
}

933 934 935 936 937
check_lib(){
    log check_lib "$@"
    header="$1"
    func="$2"
    shift 2
938
    check_header $header && check_func $func "$@" && add_extralibs "$@"
939 940
}

941 942 943
check_lib2(){
    log check_lib2 "$@"
    headers="$1"
944
    funcs="$2"
945
    shift 2
946
    check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
947 948
}

Mohamed Naufal's avatar
Mohamed Naufal committed
949 950 951 952 953 954 955 956
check_lib_cpp(){
    log check_lib_cpp "$@"
    headers="$1"
    classes="$2"
    shift 2
    check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@"
}

957 958 959 960 961 962
check_pkg_config(){
    log check_pkg_config "$@"
    pkg="$1"
    headers="$2"
    funcs="$3"
    shift 3
963
    $pkg_config --exists $pkg 2>/dev/null || return
964 965 966 967 968 969 970
    pkg_cflags=$($pkg_config --cflags $pkg)
    pkg_libs=$($pkg_config --libs $pkg)
    check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
        set_safe ${pkg}_cflags $pkg_cflags   &&
        set_safe ${pkg}_libs   $pkg_libs
}

971
check_exec(){
Mohamed Naufal's avatar
Mohamed Naufal committed
972
    check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
973 974
}

975
check_exec_crash(){
976
    code=$(cat)
977 978 979 980 981 982 983

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

984
    (check_exec "$@") >> $logfile 2>&1 <<EOF
985 986 987 988
#include <signal.h>
static void sighandler(int sig){
    raise(SIGTERM);
}
989 990 991
int func(void){
    $code
}
992
int (*func_ptr)(void) = func;
Diego Biurrun's avatar
Diego Biurrun committed
993
int main(void){
994 995 996 997 998 999
    signal(SIGILL, sighandler);
    signal(SIGFPE, sighandler);
    signal(SIGSEGV, sighandler);
#ifdef SIGBUS
    signal(SIGBUS, sighandler);
#endif
1000
    return func_ptr();
1001 1002 1003 1004
}
EOF
}

1005 1006 1007 1008 1009
check_type(){
    log check_type "$@"
    headers=$1
    type=$2
    shift 2
1010
    disable_safe "$type"
1011
    check_code cc "$headers" "$type v" "$@" && enable_safe "$type"
1012 1013
}

1014 1015 1016 1017 1018 1019 1020
check_struct(){
    log check_type "$@"
    headers=$1
    struct=$2
    member=$3
    shift 3
    disable_safe "${struct}_${member}"
1021 1022
    check_code cc "$headers" "const void *p = &(($struct *)0)->$member" "$@" &&
        enable_safe "${struct}_${member}"
1023 1024
}

1025 1026 1027 1028 1029 1030
require(){
    name="$1"
    header="$2"
    func="$3"
    shift 3
    check_lib $header $func "$@" || die "ERROR: $name not found"
1031 1032
}

1033 1034 1035 1036 1037 1038 1039 1040
require2(){
    name="$1"
    headers="$2"
    func="$3"
    shift 3
    check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
}

Mohamed Naufal's avatar
Mohamed Naufal committed
1041 1042 1043 1044 1045 1046 1047 1048
require_cpp(){
    name="$1"
    headers="$2"
    classes="$3"
    shift 3
    check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found"
}

1049 1050 1051 1052 1053 1054 1055
require_pkg_config(){
    pkg="$1"
    check_pkg_config "$@" || die "ERROR: $pkg not found"
    add_cflags    $(get_safe ${pkg}_cflags)
    add_extralibs $(get_safe ${pkg}_libs)
}

1056 1057 1058 1059
hostcc_o(){
    eval printf '%s\\n' $HOSTCC_O
}

1060 1061 1062 1063
check_host_cc(){
    log check_host_cc "$@"
    cat > $TMPC
    log_file $TMPC
1064
    check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC
1065 1066 1067 1068
}

check_host_cflags(){
    log check_host_cflags "$@"
1069
    set -- $($host_cflags_filter "$@")
1070 1071 1072 1073 1074
    check_host_cc "$@" <<EOF && append host_cflags "$@"
int x;
EOF
}

1075 1076 1077 1078 1079 1080
apply(){
    file=$1
    shift
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
}

1081
cp_if_changed(){
1082 1083
    cmp -s "$1" "$2" && echo "$2 is unchanged" && return
    mkdir -p "$(dirname $2)"
Mans Rullgard's avatar
Mans Rullgard committed
1084
    $cp_f "$1" "$2"
1085 1086
}

1087 1088 1089
# CONFIG_LIST contains configurable options, while HAVE_LIST is for
# system-dependent things.

1090 1091 1092 1093 1094
COMPONENT_LIST="
    bsfs
    decoders
    demuxers
    encoders
Vitor Sessak's avatar
Vitor Sessak committed
1095
    filters
1096
    hwaccels
1097
    indevs
1098
    muxers
1099
    outdevs
1100 1101 1102 1103
    parsers
    protocols
"

1104 1105 1106 1107 1108 1109 1110 1111
DOCUMENT_LIST="
    doc
    htmlpages
    manpages
    podpages
    txtpages
"

1112 1113 1114 1115 1116 1117 1118
LIBRARY_LIST="
    avcodec
    avdevice
    avfilter
    avformat
    avresample
    avutil
1119
    postproc
1120
    swresample
1121 1122 1123
    swscale
"

1124
PROGRAM_LIST="
1125 1126 1127
    ffplay
    ffprobe
    ffserver
1128 1129 1130
    ffmpeg
"

1131 1132
CONFIG_LIST="
    $COMPONENT_LIST
1133
    $DOCUMENT_LIST
1134
    $LIBRARY_LIST
1135
    $PROGRAM_LIST
1136
    avisynth
1137
    bzlib
1138
    crystalhd
1139
    dct
1140
    dwt
1141
    dxva2
1142
    fast_unaligned
1143
    fft
1144
    fontconfig
Stefano Sabatini's avatar
Stefano Sabatini committed
1145
    frei0r
1146
    ftrapv
1147
    gnutls
1148
    gpl
1149
    gray
Aurelien Jacobs's avatar
Aurelien Jacobs committed
1150
    hardcoded_tables
1151
    incompatible_fork_abi
tipok's avatar
tipok committed
1152
    libaacplus
1153
    libass
Petri Hintukainen's avatar
Petri Hintukainen committed
1154
    libbluray
Paul B Mahol's avatar
Paul B Mahol committed
1155
    libcaca
1156
    libcdio
1157
    libcelt
Ramiro Polla's avatar
Ramiro Polla committed
1158
    libdc1394
1159
    libfaac
1160
    libfdk_aac
1161
    libflite
1162
    libfreetype
1163
    libgsm
1164
    libiec61883
1165
    libilbc
1166
    libmodplug
1167
    libmp3lame
1168
    libnut
1169 1170
    libopencore_amrnb
    libopencore_amrwb
1171
    libopencv
1172
    libopenjpeg
1173
    libopus
1174
    libpulse
1175
    librtmp
1176
    libschroedinger
1177
    libsoxr
1178
    libspeex
Mohamed Naufal's avatar
Mohamed Naufal committed
1179
    libstagefright_h264
1180
    libtheora
1181
    libtwolame
1182
    libutvideo
1183
    libv4l2
1184
    libvo_aacenc
1185
    libvo_amrwbenc
1186
    libvorbis
James Zern's avatar
James Zern committed
1187
    libvpx
1188
    libx264
1189
    libxavs
1190
    libxvid
1191
    lsp
1192
    lzo
1193
    mdct
1194
    memalign_hack
1195
    memory_poisoning
1196
    network
1197
    nonfree
1198
    openal
1199
    openssl
1200
    pic
1201
    rdft
1202
    runtime_cpudetect
1203
    safe_bitstream_reader
1204
    shared
1205
    small
1206
    sram
1207
    static
1208
    swscale_alpha
1209
    thumb
1210
    vaapi
1211
    vda
1212
    vdpau
1213
    version3
1214
    xmm_clobber_test
1215
    x11grab
1216
    zlib
1217
"
1218

1219 1220 1221
THREADS_LIST='
    pthreads
    w32threads
1222
    os2threads
1223 1224
'

1225
ARCH_LIST='
1226
    aarch64
1227
    alpha
1228
    arm
1229 1230 1231
    avr32
    avr32_ap
    avr32_uc
1232 1233 1234 1235
    bfin
    ia64
    m68k
    mips
1236
    mips64
1237
    parisc
1238
    ppc