Statistics
| Branch: | Revision:

ffmpeg / configure @ ae550ce9

History | View | Annotate | Download (83.1 KB)

1
#!/bin/sh
2
#
3
# FFmpeg configure script
4
#
5
# Copyright (c) 2000-2002 Fabrice Bellard
6
# Copyright (c) 2005-2008 Diego Biurrun
7
# Copyright (c) 2005-2008 Mans Rullgard
8
#
9

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

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

    
17
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
E1="$?"
25

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

    
29
if test "$E1" != 0 || test "$E2" = 0; then
30
    echo "Broken shell detected.  Trying alternatives."
31
    export FF_CONF_EXEC
32
    if test "0$FF_CONF_EXEC" -lt 1; then
33
        FF_CONF_EXEC=1
34
        try_exec bash "$0" "$@"
35
    fi
36
    if test "0$FF_CONF_EXEC" -lt 2; then
37
        FF_CONF_EXEC=2
38
        try_exec ksh "$0" "$@"
39
    fi
40
    if test "0$FF_CONF_EXEC" -lt 3; then
41
        FF_CONF_EXEC=3
42
        try_exec /usr/xpg4/bin/sh "$0" "$@"
43
    fi
44
    echo "No compatible shell script interpreter found."
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
    if test "$BASH_VERSION" = '2.04.0(1)-release'; then
51
        echo "This bash version ($BASH_VERSION) is broken on your platform."
52
        echo "Upgrade to a later version if available."
53
    fi
54
    exit 1
55
fi
56

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

    
62
Standard options:
63
  --help                   print this message
64
  --logfile=FILE           log tests and output to FILE [config.err]
65
  --disable-logging        do not log configure debug information
66
  --prefix=PREFIX          install in PREFIX [$prefix]
67
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
68
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
69
  --libdir=DIR             install libs in DIR [PREFIX/lib]
70
  --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
71
  --incdir=DIR             install includes in DIR [PREFIX/include]
72
  --mandir=DIR             install man page in DIR [PREFIX/share/man]
73

    
74
Configuration options:
75
  --disable-static         do not build static libraries [no]
76
  --enable-shared          build shared libraries [no]
77
  --enable-gpl             allow use of GPL code, the resulting libs
78
                           and binaries will be under GPL [no]
79
  --enable-version3        upgrade (L)GPL to version 3 [no]
80
  --enable-nonfree         allow use of nonfree code, the resulting libs
81
                           and binaries will be unredistributable [no]
82
  --disable-doc            do not build documentation
83
  --disable-ffmpeg         disable ffmpeg build
84
  --disable-ffplay         disable ffplay build
85
  --disable-ffserver       disable ffserver build
86
  --enable-postproc        enable GPLed postprocessing support [no]
87
  --enable-avfilter        video filter support [no]
88
  --enable-avfilter-lavf   video filters dependent on avformat [no]
89
  --enable-beosthreads     use BeOS threads [no]
90
  --enable-os2threads      use OS/2 threads [no]
91
  --enable-pthreads        use pthreads [no]
92
  --enable-w32threads      use Win32 threads [no]
93
  --enable-x11grab         enable X11 grabbing [no]
94
  --disable-network        disable network support [no]
95
  --disable-ipv6           disable IPv6 support [no]
96
  --disable-mpegaudio-hp   faster (but less accurate) MPEG audio decoding [no]
97
  --enable-gray            enable full grayscale support (slower color)
98
  --disable-swscale-alpha  disable alpha channel support in swscale
99
  --disable-fastdiv        disable table-based division
100
  --enable-small           optimize for size instead of speed
101
  --disable-aandct         disable AAN DCT code
102
  --disable-fft            disable FFT code
103
  --disable-golomb         disable Golomb code
104
  --disable-lpc            disable LPC code
105
  --disable-mdct           disable MDCT code
106
  --disable-rdft           disable RDFT code
107
  --disable-vaapi          disable VAAPI code
108
  --disable-vdpau          disable VDPAU code
109
  --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
110
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
111
  --enable-memalign-hack   emulate memalign, interferes with memory debuggers
112
  --enable-beos-netserver  enable BeOS netserver
113
  --disable-encoder=NAME   disable encoder NAME
114
  --enable-encoder=NAME    enable encoder NAME
115
  --disable-encoders       disable all encoders
116
  --disable-decoder=NAME   disable decoder NAME
117
  --enable-decoder=NAME    enable decoder NAME
118
  --disable-decoders       disable all decoders
119
  --disable-hwaccel=NAME   disable hwaccel NAME
120
  --enable-hwaccel=NAME    enable hwaccel NAME
121
  --disable-hwaccels       disable all hwaccels
122
  --disable-muxer=NAME     disable muxer NAME
123
  --enable-muxer=NAME      enable muxer NAME
124
  --disable-muxers         disable all muxers
125
  --disable-demuxer=NAME   disable demuxer NAME
126
  --enable-demuxer=NAME    enable demuxer NAME
127
  --disable-demuxers       disable all demuxers
128
  --enable-parser=NAME     enable parser NAME
129
  --disable-parser=NAME    disable parser NAME
130
  --disable-parsers        disable all parsers
131
  --enable-bsf=NAME        enable bitstream filter NAME
132
  --disable-bsf=NAME       disable bitstream filter NAME
133
  --disable-bsfs           disable all bitstream filters
134
  --enable-protocol=NAME   enable protocol NAME
135
  --disable-protocol=NAME  disable protocol NAME
136
  --disable-protocols      disable all protocols
137
  --disable-indev=NAME     disable input device NAME
138
  --disable-outdev=NAME    disable output device NAME
139
  --disable-indevs         disable input devices
140
  --disable-outdevs        disable output devices
141
  --disable-devices        disable all devices
142
  --enable-filter=NAME     enable filter NAME
143
  --disable-filter=NAME    disable filter NAME
144
  --disable-filters        disable all filters
145
  --list-decoders          show all available decoders
146
  --list-encoders          show all available encoders
147
  --list-hwaccels          show all available hardware accelerators
148
  --list-muxers            show all available muxers
149
  --list-demuxers          show all available demuxers
150
  --list-parsers           show all available parsers
151
  --list-protocols         show all available protocols
152
  --list-bsfs              show all available bitstream filters
153
  --list-indevs            show all available input devices
154
  --list-outdevs           show all available output devices
155
  --list-filters           show all available filters
156

    
157
External library support:
158
  --enable-avisynth        enable reading of AVISynth script files [no]
159
  --enable-bzlib           enable bzlib [autodetect]
160
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
161
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
162
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
163
                           and libraw1394 [no]
164
  --enable-libdirac        enable Dirac support via libdirac [no]
165
  --enable-libfaac         enable FAAC support via libfaac [no]
166
  --enable-libfaad         enable FAAD support via libfaad [no]
167
  --enable-libfaadbin      open libfaad.so.0 at runtime [no]
168
  --enable-libgsm          enable GSM support via libgsm [no]
169
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
170
  --enable-libnut          enable NUT (de)muxing via libnut,
171
                           native (de)muxer exists [no]
172
  --enable-libopenjpeg     enable JPEG 2000 decoding via OpenJPEG [no]
173
  --enable-libschroedinger enable Dirac support via libschroedinger [no]
174
  --enable-libspeex        enable Speex decoding via libspeex [no]
175
  --enable-libtheora       enable Theora encoding via libtheora [no]
176
  --enable-libvorbis       enable Vorbis encoding via libvorbis,
177
                           native implementation exists [no]
178
  --enable-libx264         enable H.264 encoding via x264 [no]
179
  --enable-libxvid         enable Xvid encoding via xvidcore,
180
                           native MPEG-4/Xvid encoder exists [no]
181
  --enable-mlib            enable Sun medialib [no]
182
  --enable-zlib            enable zlib [autodetect]
183

    
184
Advanced options (experts only):
185
  --source-path=PATH       path to source code [$source_path]
186
  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
187
  --enable-cross-compile   assume a cross-compiler is used
188
  --sysroot=PATH           root of cross-build tree
189
  --sysinclude=PATH        location of cross-build system headers
190
  --target-os=OS           compiler targets OS [$target_os]
191
  --target-exec=CMD        command to run executables on target
192
  --target-path=DIR        path to view of build directory on target
193
  --nm=NM                  use nm tool
194
  --as=AS                  use assembler AS [$as_default]
195
  --cc=CC                  use C compiler CC [$cc_default]
196
  --ld=LD                  use linker LD
197
  --host-cc=HOSTCC         use host C compiler HOSTCC
198
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
199
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
200
  --host-libs=HLIBS        use libs HLIBS when linking for host
201
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
202
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
203
  --extra-libs=ELIBS       add ELIBS [$ELIBS]
204
  --extra-version=STRING   version string suffix []
205
  --build-suffix=SUFFIX    library name suffix []
206
  --arch=ARCH              select architecture [$arch]
207
  --cpu=CPU                select the minimum required CPU (affects
208
                           instruction selection, may crash on older CPUs)
209
  --enable-powerpc-perf    enable performance report on PPC
210
                           (requires enabling PMC)
211
  --disable-altivec        disable AltiVec optimizations
212
  --disable-amd3dnow       disable 3DNow! optimizations
213
  --disable-amd3dnowext    disable 3DNow! extended optimizations
214
  --disable-mmx            disable MMX optimizations
215
  --disable-mmx2           disable MMX2 optimizations
216
  --disable-sse            disable SSE optimizations
217
  --disable-ssse3          disable SSSE3 optimizations
218
  --disable-armv5te        disable armv5te optimizations
219
  --disable-armv6          disable armv6 optimizations
220
  --disable-armv6t2        disable armv6t2 optimizations
221
  --disable-armvfp         disable ARM VFP optimizations
222
  --disable-iwmmxt         disable iwmmxt optimizations
223
  --disable-mmi            disable MMI optimizations
224
  --disable-neon           disable neon optimizations
225
  --disable-vis            disable VIS optimizations
226
  --disable-yasm           disable use of yasm assembler
227
  --enable-pic             build position-independent code
228

    
229
Developer options (useful when working on FFmpeg itself):
230
  --disable-debug          disable debugging symbols
231
  --enable-debug=LEVEL     set the debug level [$debuglevel]
232
  --enable-gprof           enable profiling with gprof [$gprof]
233
  --disable-optimizations  disable compiler optimizations
234
  --enable-extra-warnings  enable more compiler warnings
235
  --disable-stripping      disable stripping of executables and shared libraries
236

    
237
NOTE: Object files are built at the place where configure is launched.
238
EOF
239
  exit 0
240
}
241

    
242
log(){
243
    echo "$@" >> $logfile
244
}
245

    
246
log_file(){
247
    log BEGIN $1
248
    pr -n -t $1 >> $logfile
249
    log END $1
250
}
251

    
252
echolog(){
253
    log "$@"
254
    echo "$@"
255
}
256

    
257
die(){
258
    echolog "$@"
259
    cat <<EOF
260

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

    
279
# Avoid locale weirdness, besides we really just want to translate ASCII.
280
toupper(){
281
    echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
282
}
283

    
284
tolower(){
285
    echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
286
}
287

    
288
c_escape(){
289
    echo "$*" | sed 's/["\\]/\\\0/g'
290
}
291

    
292
sh_quote(){
293
    v=$(echo "$1" | sed "s/'/'\\\\''/g")
294
    test "$v" = "${v#*[ |&;<>()$\`\\\"\'*?\[\]#~=%]}" || v="'$v'"
295
    echo "$v"
296
}
297

    
298
filter(){
299
    pat=$1
300
    shift
301
    for v; do
302
        eval "case $v in $pat) echo $v ;; esac"
303
    done
304
}
305

    
306
set_all(){
307
    value=$1
308
    shift
309
    for var in $*; do
310
        eval $var=$value
311
    done
312
}
313

    
314
set_weak(){
315
    value=$1
316
    shift
317
    for var; do
318
        eval : \${$var:=$value}
319
    done
320
}
321

    
322
pushvar(){
323
    for var in $*; do
324
        eval level=\${${var}_level:=0}
325
        eval ${var}_${level}="\$$var"
326
        eval ${var}_level=$(($level+1))
327
    done
328
}
329

    
330
popvar(){
331
    for var in $*; do
332
        eval level=\${${var}_level:-0}
333
        test $level = 0 && continue
334
        eval level=$(($level-1))
335
        eval $var="\${${var}_${level}}"
336
        eval ${var}_level=$level
337
        eval unset ${var}_${level}
338
    done
339
}
340

    
341
enable(){
342
    set_all yes $*
343
}
344

    
345
disable(){
346
    set_all no $*
347
}
348

    
349
enable_weak(){
350
    set_weak yes $*
351
}
352

    
353
disable_weak(){
354
    set_weak no $*
355
}
356

    
357
enable_safe(){
358
    for var; do
359
        enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
360
    done
361
}
362

    
363
disable_safe(){
364
    for var; do
365
        disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
366
    done
367
}
368

    
369
do_enable_deep(){
370
    for var; do
371
        enabled $var && continue
372
        eval sel="\$${var}_select"
373
        eval sgs="\$${var}_suggest"
374
        pushvar var sgs
375
        enable_deep $sel
376
        popvar sgs
377
        enable_deep_weak $sgs
378
        popvar var
379
    done
380
}
381

    
382
enable_deep(){
383
    do_enable_deep $*
384
    enable $*
385
}
386

    
387
enable_deep_weak(){
388
    do_enable_deep $*
389
    enable_weak $*
390
}
391

    
392
enabled(){
393
    test "${1#!}" = "$1" && op== || op=!=
394
    eval test "x\$${1#!}" $op "xyes"
395
}
396

    
397
disabled(){
398
    test "${1#!}" = "$1" && op== || op=!=
399
    eval test "x\$${1#!}" $op "xno"
400
}
401

    
402
enabled_all(){
403
    for opt; do
404
        enabled $opt || return 1
405
    done
406
}
407

    
408
disabled_all(){
409
    for opt; do
410
        disabled $opt || return 1
411
    done
412
}
413

    
414
enabled_any(){
415
    for opt; do
416
        enabled $opt && return 0
417
    done
418
}
419

    
420
disabled_any(){
421
    for opt; do
422
        disabled $opt && return 0
423
    done
424
    return 1
425
}
426

    
427
set_default(){
428
    for opt; do
429
        eval : \${$opt:=\$${opt}_default}
430
    done
431
}
432

    
433
is_in(){
434
    value=$1
435
    shift
436
    for var in $*; do
437
        [ $var = $value ] && return 0
438
    done
439
    return 1
440
}
441

    
442
check_deps(){
443
    for cfg; do
444
        cfg="${cfg#!}"
445
        enabled ${cfg}_checking && die "Circular dependency for $cfg."
446
        disabled ${cfg}_checking && continue
447
        enable ${cfg}_checking
448

    
449
        eval dep_all="\$${cfg}_deps"
450
        eval dep_any="\$${cfg}_deps_any"
451
        eval dep_sel="\$${cfg}_select"
452
        eval dep_sgs="\$${cfg}_suggest"
453

    
454
        pushvar cfg dep_all dep_any dep_sel dep_sgs
455
        check_deps $dep_all $dep_any $dep_sel $dep_sgs
456
        popvar cfg dep_all dep_any dep_sel dep_sgs
457

    
458
        enabled_all  $dep_all || disable $cfg
459
        enabled_any  $dep_any || disable $cfg
460
        disabled_any $dep_sel && disable $cfg
461

    
462
        if enabled $cfg; then
463
            eval dep_extralibs="\$${cfg}_extralibs"
464
            test -n "$dep_extralibs" && add_extralibs $dep_extralibs
465
            enable_deep $dep_sel
466
            enable_deep_weak $dep_sgs
467
        fi
468

    
469
        disable ${cfg}_checking
470
    done
471
}
472

    
473
print_config(){
474
    pfx=$1
475
    header=$2
476
    makefile=$3
477
    shift 3
478
    for cfg; do
479
        ucname="$(toupper $cfg)"
480
        if enabled $cfg; then
481
            echo "#define ${pfx}${ucname} 1" >> $header
482
            echo "${pfx}${ucname}=yes" >> $makefile
483
        else
484
            echo "#define ${pfx}${ucname} 0" >> $header
485
        fi
486
    done
487
}
488

    
489
flags_saved(){
490
    (: ${SAVE_CFLAGS?}) 2> /dev/null
491
}
492

    
493
save_flags(){
494
    flags_saved && return
495
    SAVE_CFLAGS="$CFLAGS"
496
    SAVE_LDFLAGS="$LDFLAGS"
497
    SAVE_extralibs="$extralibs"
498
}
499

    
500
restore_flags(){
501
    flags_saved || return
502
    CFLAGS="$SAVE_CFLAGS"
503
    LDFLAGS="$SAVE_LDFLAGS"
504
    extralibs="$SAVE_extralibs"
505
    unset SAVE_CFLAGS
506
    unset SAVE_LDFLAGS
507
    unset SAVE_extralibs
508
}
509

    
510
temp_cflags(){
511
    save_flags
512
    CFLAGS="$CFLAGS $*"
513
}
514

    
515
temp_ldflags(){
516
    save_flags
517
    LDFLAGS="$LDFLAGS $*"
518
}
519

    
520
temp_extralibs(){
521
    save_flags
522
    extralibs="$extralibs $*"
523
}
524

    
525
append(){
526
    var=$1
527
    shift
528
    flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
529
    eval "$var=\"\$$var $*\""
530
}
531

    
532
add_cppflags(){
533
    append CPPFLAGS $($filter_cppflags "$@")
534
}
535

    
536
add_cflags(){
537
    append CFLAGS $($filter_cflags "$@")
538
}
539

    
540
add_asflags(){
541
    append ASFLAGS $($filter_asflags "$@")
542
}
543

    
544
add_ldflags(){
545
    append LDFLAGS "$@"
546
}
547

    
548
add_extralibs(){
549
    append extralibs "$@"
550
}
551

    
552
check_cmd(){
553
    log "$@"
554
    "$@" >> $logfile 2>&1
555
}
556

    
557
check_cc(){
558
    log check_cc "$@"
559
    cat > $TMPC
560
    log_file $TMPC
561
    check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC
562
}
563

    
564
check_cpp(){
565
    log check_cpp "$@"
566
    cat > $TMPC
567
    log_file $TMPC
568
    check_cmd $cc $CPPFLAGS $CFLAGS "$@" -E -o $TMPO $TMPC
569
}
570

    
571
check_as(){
572
    log check_as "$@"
573
    cat > $TMPC
574
    log_file $TMPC
575
    check_cmd $as $CPPFLAGS $ASFLAGS "$@" -c -o $TMPO $TMPC
576
}
577

    
578
check_asm(){
579
    log check_asm "$@"
580
    name="$1"
581
    asm="$2"
582
    shift 2
583
    disable $name
584
    check_as "$@" <<EOF && enable $name
585
void foo(void){ __asm__ volatile($asm); }
586
EOF
587
}
588

    
589
check_yasm(){
590
    log check_yasm "$@"
591
    echo "$1" > $TMPS
592
    log_file $TMPS
593
    shift 1
594
    check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
595
}
596

    
597
check_ld(){
598
    log check_ld "$@"
599
    check_cc || return
600
    flags=''
601
    libs=''
602
    for f; do
603
        test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
604
    done
605
    check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs
606
}
607

    
608
check_cppflags(){
609
    log check_cppflags "$@"
610
    set -- $($filter_cppflags "$@")
611
    check_cc "$@" <<EOF && append CPPFLAGS "$@"
612
int x;
613
EOF
614
}
615

    
616
check_cflags(){
617
    log check_cflags "$@"
618
    set -- $($filter_cflags "$@")
619
    check_cc "$@" <<EOF && append CFLAGS "$@"
620
int x;
621
EOF
622
}
623

    
624
check_ldflags(){
625
    log check_ldflags "$@"
626
    check_ld "$@" <<EOF && add_ldflags "$@"
627
int main(void){ return 0; }
628
EOF
629
}
630

    
631
check_header(){
632
    log check_header "$@"
633
    header=$1
634
    shift
635
    disable_safe $header
636
    check_cpp "$@" <<EOF && enable_safe $header
637
#include <$header>
638
int x;
639
EOF
640
}
641

    
642
check_func(){
643
    log check_func "$@"
644
    func=$1
645
    shift
646
    disable $func
647
    check_ld "$@" <<EOF && enable $func
648
extern int $func();
649
int main(void){ $func(); }
650
EOF
651
}
652

    
653
check_func_headers(){
654
    log check_func_headers "$@"
655
    headers=$1
656
    func=$2
657
    shift 2
658
    disable $func
659
    incs=""
660
    for hdr in $headers; do
661
        incs="$incs
662
#include <$hdr>"
663
    done
664
    check_ld "$@" <<EOF && enable $func && enable_safe $headers
665
$incs
666
int main(int argc, char **argv){
667
    return (long) $func;
668
}
669
EOF
670
}
671

    
672
check_cpp_condition(){
673
    log check_cpp_condition "$@"
674
    header=$1
675
    condition=$2
676
    check_cpp <<EOF
677
#include <$header>
678
#if !($condition)
679
#error "unsatisfied condition: $condition"
680
#endif
681
EOF
682
}
683

    
684
check_lib(){
685
    log check_lib "$@"
686
    header="$1"
687
    func="$2"
688
    shift 2
689
    temp_extralibs "$@"
690
    check_header $header && check_func $func && add_extralibs "$@"
691
    err=$?
692
    restore_flags
693
    return $err
694
}
695

    
696
check_lib2(){
697
    log check_lib2 "$@"
698
    headers="$1"
699
    func="$2"
700
    shift 2
701
    temp_extralibs "$@"
702
    check_func_headers "$headers" $func && add_extralibs "$@"
703
    err=$?
704
    restore_flags
705
    return $err
706
}
707

    
708
check_exec(){
709
    check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
710
}
711

    
712
check_exec_crash(){
713
    code=$(cat)
714

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

    
721
    (check_exec "$@") >> $logfile 2>&1 <<EOF
722
#include <signal.h>
723
static void sighandler(int sig){
724
    raise(SIGTERM);
725
}
726
int main(void){
727
    signal(SIGILL, sighandler);
728
    signal(SIGFPE, sighandler);
729
    signal(SIGSEGV, sighandler);
730
#ifdef SIGBUS
731
    signal(SIGBUS, sighandler);
732
#endif
733
    { $code }
734
}
735
EOF
736
}
737

    
738
check_type(){
739
    log check_type "$@"
740
    headers=$1
741
    type=$2
742
    shift 2
743
    disable_safe "$type"
744
    incs=""
745
    for hdr in $headers; do
746
        incs="$incs
747
#include <$hdr>"
748
    done
749
    check_cc "$@" <<EOF && enable_safe "$type"
750
$incs
751
$type v;
752
EOF
753
}
754

    
755
require(){
756
    name="$1"
757
    header="$2"
758
    func="$3"
759
    shift 3
760
    check_lib $header $func "$@" || die "ERROR: $name not found"
761
}
762

    
763
require2(){
764
    name="$1"
765
    headers="$2"
766
    func="$3"
767
    shift 3
768
    check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
769
}
770

    
771
check_foo_config(){
772
    cfg=$1
773
    pkg=$2
774
    header=$3
775
    func=$4
776
    shift 4
777
    disable $cfg
778
    check_cmd ${pkg}-config --version
779
    err=$?
780
    if test "$err" = 0; then
781
        temp_cflags $(${pkg}-config --cflags)
782
        temp_extralibs $(${pkg}-config --libs)
783
        check_lib "$@" $header $func && enable $cfg
784
    fi
785
    return $err
786
}
787

    
788
check_host_cc(){
789
    log check_host_cc "$@"
790
    cat > $TMPC
791
    log_file $TMPC
792
    check_cmd $host_cc $host_cflags "$@" -c -o $TMPO $TMPC
793
}
794

    
795
check_host_cflags(){
796
    log check_host_cflags "$@"
797
    check_host_cc "$@" <<EOF && append host_cflags "$@"
798
int x;
799
EOF
800
}
801

    
802
apply(){
803
    file=$1
804
    shift
805
    "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
806
}
807

    
808
# CONFIG_LIST contains configurable options, while HAVE_LIST is for
809
# system-dependent things.
810

    
811
COMPONENT_LIST="
812
    bsfs
813
    decoders
814
    demuxers
815
    encoders
816
    filters
817
    hwaccels
818
    indevs
819
    muxers
820
    outdevs
821
    parsers
822
    protocols
823
"
824

    
825
CONFIG_LIST="
826
    $COMPONENT_LIST
827
    aandct
828
    avfilter
829
    avfilter_lavf
830
    avisynth
831
    beos_netserver
832
    bzlib
833
    doc
834
    fastdiv
835
    ffmpeg
836
    ffplay
837
    ffserver
838
    fft
839
    golomb
840
    gpl
841
    gprof
842
    gray
843
    hardcoded_tables
844
    ipv6
845
    libdc1394
846
    libdirac
847
    libfaac
848
    libfaad
849
    libfaadbin
850
    libgsm
851
    libmp3lame
852
    libnut
853
    libopencore_amrnb
854
    libopencore_amrwb
855
    libopenjpeg
856
    libschroedinger
857
    libspeex
858
    libtheora
859
    libvorbis
860
    libx264
861
    libxvid
862
    lpc
863
    mdct
864
    memalign_hack
865
    mlib
866
    mpegaudio_hp
867
    network
868
    nonfree
869
    pic
870
    postproc
871
    powerpc_perf
872
    rdft
873
    runtime_cpudetect
874
    shared
875
    small
876
    static
877
    swscale_alpha
878
    vaapi
879
    vdpau
880
    version3
881
    x11grab
882
    zlib
883
"
884

    
885
THREADS_LIST='
886
    beosthreads
887
    os2threads
888
    pthreads
889
    w32threads
890
'
891

    
892
ARCH_LIST='
893
    alpha
894
    arm
895
    avr32
896
    avr32_ap
897
    avr32_uc
898
    bfin
899
    ia64
900
    m68k
901
    mips
902
    mips64
903
    parisc
904
    ppc
905
    ppc64
906
    s390
907
    sh4
908
    sparc
909
    sparc64
910
    x86
911
    x86_32
912
    x86_64
913
'
914

    
915
ARCH_EXT_LIST='
916
    altivec
917
    amd3dnow
918
    amd3dnowext
919
    armv5te
920
    armv6
921
    armv6t2
922
    armvfp
923
    iwmmxt
924
    mmi
925
    mmx
926
    mmx2
927
    neon
928
    ppc4xx
929
    sse
930
    ssse3
931
    vis
932
'
933

    
934
HAVE_LIST="
935
    $ARCH_EXT_LIST
936
    $THREADS_LIST
937
    alsa_asoundlib_h
938
    altivec_h
939
    arpa_inet_h
940
    attribute_packed
941
    bigendian
942
    bswap
943
    closesocket
944
    cmov
945
    conio_h
946
    dcbzl
947
    dev_bktr_ioctl_bt848_h
948
    dev_bktr_ioctl_meteor_h
949
    dev_ic_bt8xx_h
950
    dev_video_meteor_ioctl_meteor_h
951
    dev_video_bktr_ioctl_bt848_h
952
    dlfcn_h
953
    dlopen
954
    dos_paths
955
    ebp_available
956
    ebx_available
957
    fast_64bit
958
    fast_cmov
959
    fast_unaligned
960
    fork
961
    gethrtime
962
    GetProcessTimes
963
    getrusage
964
    inet_aton
965
    inline_asm
966
    isatty
967
    ldbrx
968
    libdc1394_1
969
    libdc1394_2
970
    llrint
971
    log2
972
    loongson
973
    lrint
974
    lrintf
975
    lzo1x_999_compress
976
    machine_ioctl_bt848_h
977
    machine_ioctl_meteor_h
978
    malloc_h
979
    memalign
980
    mkstemp
981
    pld
982
    posix_memalign
983
    round
984
    roundf
985
    sdl
986
    sdl_video_size
987
    setmode
988
    socklen_t
989
    soundcard_h
990
    poll_h
991
    sys_mman_h
992
    sys_resource_h
993
    sys_select_h
994
    sys_soundcard_h
995
    sys_videoio_h
996
    ten_operands
997
    termios_h
998
    threads
999
    truncf
1000
    vfp_args
1001
    VirtualAlloc
1002
    winsock2_h
1003
    xform_asm
1004
    yasm
1005
"
1006

    
1007
# options emitted with CONFIG_ prefix but not available on command line
1008
CONFIG_EXTRA="
1009
    gplv3
1010
    lgplv3
1011
"
1012

    
1013
CMDLINE_SELECT="
1014
    $ARCH_EXT_LIST
1015
    $CONFIG_LIST
1016
    $THREADS_LIST
1017
    cross_compile
1018
    debug
1019
    extra_warnings
1020
    logging
1021
    optimizations
1022
    stripping
1023
    yasm
1024
"
1025

    
1026
PATHS_LIST='
1027
    bindir
1028
    datadir
1029
    incdir
1030
    libdir
1031
    mandir
1032
    prefix
1033
    shlibdir
1034
'
1035

    
1036
CMDLINE_SET="
1037
    $PATHS_LIST
1038
    arch
1039
    as
1040
    build_suffix
1041
    cc
1042
    cpu
1043
    cross_prefix
1044
    dep_cc
1045
    extra_version
1046
    host_cc
1047
    host_cflags
1048
    host_ldflags
1049
    host_libs
1050
    host_os
1051
    ld
1052
    logfile
1053
    nm
1054
    source_path
1055
    sysinclude
1056
    sysroot
1057
    target_exec
1058
    target_os
1059
    target_path
1060
"
1061

    
1062
CMDLINE_APPEND="
1063
    extra_cflags
1064
"
1065

    
1066
# code dependency declarations
1067

    
1068
# architecture extensions
1069
altivec_deps="ppc"
1070
amd3dnow_deps="mmx"
1071
amd3dnowext_deps="amd3dnow"
1072
armv5te_deps="arm"
1073
armv6_deps="arm"
1074
armv6t2_deps="arm"
1075
armvfp_deps="arm"
1076
iwmmxt_deps="arm"
1077
mmi_deps="mips"
1078
mmx_deps="x86"
1079
mmx2_deps="mmx"
1080
neon_deps="arm"
1081
ppc4xx_deps="ppc"
1082
sse_deps="mmx"
1083
ssse3_deps="sse"
1084
vis_deps="sparc"
1085

    
1086
need_memalign="altivec neon sse"
1087
inline_asm_deps="!tms470"
1088

    
1089
# decoders / encoders / hardware accelerators
1090
aac_decoder_select="fft mdct aac_parser"
1091
aac_encoder_select="fft mdct"
1092
ac3_decoder_select="fft mdct ac3_parser"
1093
alac_encoder_select="lpc"
1094
atrac3_decoder_select="fft mdct"
1095
cavs_decoder_select="golomb"
1096
cook_decoder_select="fft mdct"
1097
cscd_decoder_suggest="zlib"
1098
dca_decoder_select="fft mdct"
1099
dnxhd_encoder_select="aandct"
1100
dxa_decoder_select="zlib"
1101
eac3_decoder_select="ac3_decoder"
1102
eamad_decoder_select="aandct"
1103
eatgq_decoder_select="aandct"
1104
eatqi_decoder_select="aandct"
1105
ffv1_decoder_select="golomb"
1106
flac_decoder_select="golomb"
1107
flac_encoder_select="golomb lpc"
1108
flashsv_decoder_select="zlib"
1109
flashsv_encoder_select="zlib"
1110
flv_decoder_select="h263_decoder"
1111
flv_encoder_select="h263_encoder"
1112
h261_encoder_select="aandct"
1113
h263_decoder_select="h263_parser"
1114
h263_encoder_select="aandct"
1115
h263_vaapi_hwaccel_deps="va_va_h"
1116
h263_vaapi_hwaccel_select="vaapi h263_decoder"
1117
h263i_decoder_select="h263_decoder"
1118
h263p_encoder_select="h263_encoder"
1119
h264_decoder_select="golomb"
1120
h264_vaapi_hwaccel_deps="va_va_h"
1121
h264_vaapi_hwaccel_select="vaapi"
1122
h264_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1123
h264_vdpau_decoder_select="vdpau h264_decoder"
1124
imc_decoder_select="fft mdct"
1125
jpegls_decoder_select="golomb"
1126
jpegls_encoder_select="golomb"
1127
ljpeg_encoder_select="aandct"
1128
loco_decoder_select="golomb"
1129
mjpeg_encoder_select="aandct"
1130
mlp_decoder_select="mlp_parser"
1131
mpeg1video_encoder_select="aandct"
1132
mpeg2video_encoder_select="aandct"
1133
mpeg4_decoder_select="h263_decoder mpeg4video_parser"
1134
mpeg4_encoder_select="h263_encoder"
1135
mpeg_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1136
mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
1137
mpeg1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1138
mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
1139
mpeg2_vaapi_hwaccel_deps="va_va_h"
1140
mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
1141
mpeg4_vaapi_hwaccel_deps="va_va_h"
1142
mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
1143
mpeg4_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1144
mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
1145
mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
1146
mpeg_xvmc_decoder_select="mpegvideo_decoder"
1147
msmpeg4v1_decoder_select="h263_decoder"
1148
msmpeg4v1_encoder_select="h263_encoder"
1149
msmpeg4v2_decoder_select="h263_decoder"
1150
msmpeg4v2_encoder_select="h263_encoder"
1151
msmpeg4v3_decoder_select="h263_decoder"
1152
msmpeg4v3_encoder_select="h263_encoder"
1153
nellymoser_decoder_select="fft mdct"
1154
nellymoser_encoder_select="fft mdct"
1155
png_decoder_select="zlib"
1156
png_encoder_select="zlib"
1157
qdm2_decoder_select="fft mdct rdft"
1158
rv10_decoder_select="h263_decoder"
1159
rv10_encoder_select="h263_encoder"
1160
rv20_decoder_select="h263_decoder"
1161
rv20_encoder_select="h263_encoder"
1162
rv30_decoder_select="golomb"
1163
rv40_decoder_select="golomb"
1164
shorten_decoder_select="golomb"
1165
sonic_decoder_select="golomb"
1166
sonic_encoder_select="golomb"
1167
sonic_ls_encoder_select="golomb"
1168
svq3_decoder_select="golomb"
1169
svq3_decoder_suggest="zlib"
1170
theora_decoder_select="vp3_decoder"
1171
tiff_decoder_suggest="zlib"
1172
tiff_encoder_suggest="zlib"
1173
truehd_decoder_select="mlp_decoder"
1174
tscc_decoder_select="zlib"
1175
vc1_decoder_select="h263_decoder"
1176
vc1_vaapi_hwaccel_deps="va_va_h"
1177
vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
1178
vc1_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1179
vc1_vdpau_decoder_select="vdpau vc1_decoder"
1180
vorbis_decoder_select="fft mdct"
1181
vorbis_encoder_select="fft mdct"
1182
vp6a_decoder_select="vp6_decoder"
1183
vp6f_decoder_select="vp6_decoder"
1184
wmav1_decoder_select="fft mdct"
1185
wmav1_encoder_select="fft mdct"
1186
wmav2_decoder_select="fft mdct"
1187
wmav2_encoder_select="fft mdct"
1188
wmv1_decoder_select="h263_decoder"
1189
wmv1_encoder_select="h263_encoder"
1190
wmv2_decoder_select="h263_decoder"
1191
wmv2_encoder_select="h263_encoder"
1192
wmv3_decoder_select="vc1_decoder"
1193
wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
1194
wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
1195
zlib_decoder_select="zlib"
1196
zlib_encoder_select="zlib"
1197
zmbv_decoder_select="zlib"
1198
zmbv_encoder_select="zlib"
1199

    
1200
# parsers
1201
h264_parser_select="golomb"
1202

    
1203
# bitstream_filters
1204
aac_adtstoasc_bsf_select="aac_parser"
1205

    
1206
# external libraries
1207
libdirac_decoder_deps="libdirac !libschroedinger"
1208
libdirac_encoder_deps="libdirac"
1209
libfaac_encoder_deps="libfaac"
1210
libfaad_decoder_deps="libfaad"
1211
libfaadbin_decoder_extralibs='$ldl'
1212
libgsm_decoder_deps="libgsm"
1213
libgsm_encoder_deps="libgsm"
1214
libgsm_ms_decoder_deps="libgsm"
1215
libgsm_ms_encoder_deps="libgsm"
1216
libmp3lame_encoder_deps="libmp3lame"
1217
libopencore_amrnb_decoder_deps="libopencore_amrnb"
1218
libopencore_amrnb_encoder_deps="libopencore_amrnb"
1219
libopencore_amrwb_decoder_deps="libopencore_amrwb"
1220
libopenjpeg_decoder_deps="libopenjpeg"
1221
libschroedinger_decoder_deps="libschroedinger"
1222
libschroedinger_encoder_deps="libschroedinger"
1223
libspeex_decoder_deps="libspeex"
1224
libtheora_encoder_deps="libtheora"
1225
libvorbis_encoder_deps="libvorbis"
1226
libx264_encoder_deps="libx264"
1227
libxvid_encoder_deps="libxvid"
1228

    
1229
# demuxers / muxers
1230
ac3_demuxer_deps="ac3_parser"
1231
asf_stream_muxer_select="asf_muxer"
1232
avisynth_demuxer_deps="avisynth"
1233
dirac_demuxer_deps="dirac_parser"
1234
eac3_demuxer_select="ac3_parser"
1235
ipod_muxer_select="mov_muxer"
1236
libnut_demuxer_deps="libnut"
1237
libnut_muxer_deps="libnut"
1238
matroska_audio_muxer_select="matroska_muxer"
1239
matroska_demuxer_suggest="zlib bzlib"
1240
mov_demuxer_suggest="zlib"
1241
mp3_demuxer_deps="mpegaudio_parser"
1242
mp4_muxer_select="mov_muxer"
1243
mpegtsraw_demuxer_select="mpegts_demuxer"
1244
mxf_d10_muxer_select="mxf_muxer"
1245
ogg_demuxer_select="golomb"
1246
psp_muxer_select="mov_muxer"
1247
rtp_muxer_deps="network rtp_protocol"
1248
rtsp_demuxer_deps="sdp_demuxer"
1249
sdp_demuxer_deps="rtp_protocol mpegts_demuxer"
1250
spdif_muxer_select="aac_parser"
1251
tg2_muxer_select="mov_muxer"
1252
tgp_muxer_select="mov_muxer"
1253
w64_demuxer_deps="wav_demuxer"
1254

    
1255
# indevs / outdevs
1256
alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
1257
alsa_indev_extralibs="-lasound"
1258
alsa_outdev_deps="alsa_asoundlib_h"
1259
alsa_outdev_extralibs="-lasound"
1260
audio_beos_indev_deps="audio_beos"
1261
audio_beos_indev_extralibs="-lmedia -lbe"
1262
audio_beos_outdev_deps="audio_beos"
1263
audio_beos_outdev_extralibs="-lmedia -lbe"
1264
bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
1265
dv1394_indev_deps="dv1394 dv_demuxer"
1266
jack_indev_deps="jack_jack_h"
1267
jack_indev_extralibs="-ljack"
1268
libdc1394_indev_deps="libdc1394"
1269
oss_indev_deps_any="soundcard_h sys_soundcard_h"
1270
oss_outdev_deps_any="soundcard_h sys_soundcard_h"
1271
v4l_indev_deps="linux_videodev_h"
1272
v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
1273
vfwcap_indev_deps="capCreateCaptureWindow"
1274
vfwcap_indev_extralibs="-lvfw32"
1275
x11_grab_device_indev_deps="x11grab XShmCreateImage"
1276
x11_grab_device_indev_extralibs="-lX11 -lXext -lXfixes"
1277

    
1278
# protocols
1279
gopher_protocol_deps="network"
1280
http_protocol_deps="network"
1281
rtmp_protocol_deps="tcp_protocol"
1282
rtp_protocol_deps="udp_protocol"
1283
tcp_protocol_deps="network"
1284
udp_protocol_deps="network"
1285

    
1286
# filters
1287
movie_filter_deps="avfilter_lavf"
1288

    
1289
# programs
1290
ffplay_deps="sdl"
1291
ffserver_deps="ffm_muxer rtp_protocol rtsp_demuxer"
1292
ffserver_extralibs='$ldl'
1293

    
1294
doc_deps="texi2html"
1295

    
1296
# default parameters
1297

    
1298
logfile="config.err"
1299

    
1300
# installation paths
1301
prefix_default="/usr/local"
1302
bindir_default='${prefix}/bin'
1303
datadir_default='${prefix}/share/ffmpeg'
1304
incdir_default='${prefix}/include'
1305
libdir_default='${prefix}/lib'
1306
mandir_default='${prefix}/share/man'
1307
shlibdir_default="$libdir_default"
1308

    
1309
# toolchain
1310
ar="ar"
1311
cc_default="gcc"
1312
cc_version=\"unknown\"
1313
host_cc_default="gcc"
1314
ln_s="ln -sf"
1315
nm_default="nm"
1316
objformat="elf"
1317
ranlib="ranlib"
1318
strip="strip"
1319
yasmexe="yasm"
1320

    
1321
# machine
1322
arch=$(uname -m)
1323
cpu="generic"
1324

    
1325
# OS
1326
target_os=$(tolower $(uname -s))
1327
host_os=$target_os
1328

    
1329
# configurable options
1330
enable debug
1331
enable doc
1332
enable fastdiv
1333
enable ffmpeg
1334
enable ffplay
1335
enable ffserver
1336
enable ipv6
1337
enable mpegaudio_hp
1338
enable network
1339
enable optimizations
1340
enable protocols
1341
enable static
1342
enable stripping
1343
enable swscale_alpha
1344

    
1345
# build settings
1346
SHFLAGS='-shared -Wl,-soname,$$(@F)'
1347
FFSERVERLDFLAGS=-Wl,-E
1348
LIBPREF="lib"
1349
LIBSUF=".a"
1350
FULLNAME='$(NAME)$(BUILDSUF)'
1351
LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)'
1352
SLIBPREF="lib"
1353
SLIBSUF=".so"
1354
SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
1355
SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
1356
SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
1357
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
1358

    
1359
CC_O='-o $@'
1360

    
1361
host_cflags='-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -O3 -g -Wall'
1362
host_libs='-lm'
1363

    
1364
target_path='.'
1365

    
1366
# gcc stupidly only outputs the basename of targets with -MM, but we need the
1367
# full relative path for objects in subdirectories for non-recursive Make.
1368
DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
1369
DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -MM'
1370

    
1371
# find source path
1372
source_path="$(dirname "$0")"
1373
enable source_path_used
1374
if test -f configure; then
1375
    source_path="$(pwd)"
1376
    disable source_path_used
1377
else
1378
    source_path="$(cd "$source_path"; pwd)"
1379
    echo "$source_path" | grep -q '[[:blank:]]' &&
1380
        die "Out of tree builds are impossible with whitespace in source path."
1381
    test -e "$source_path/config.h" &&
1382
        die "Out of tree builds are impossible with config.h in source dir."
1383
fi
1384

    
1385
for v in "$@"; do
1386
    r=${v#*=}
1387
    l=${v%"$r"}
1388
    r=$(sh_quote "$r")
1389
    FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
1390
done
1391

    
1392
find_things(){
1393
    thing=$1
1394
    pattern=$2
1395
    file=$source_path/$3
1396
    sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file"
1397
}
1398

    
1399
ENCODER_LIST=$(find_things  encoder  ENC      libavcodec/allcodecs.c)
1400
DECODER_LIST=$(find_things  decoder  DEC      libavcodec/allcodecs.c)
1401
HWACCEL_LIST=$(find_things  hwaccel  HWACCEL  libavcodec/allcodecs.c)
1402
PARSER_LIST=$(find_things   parser   PARSER   libavcodec/allcodecs.c)
1403
BSF_LIST=$(find_things      bsf      BSF      libavcodec/allcodecs.c)
1404
MUXER_LIST=$(find_things    muxer    _MUX     libavformat/allformats.c)
1405
DEMUXER_LIST=$(find_things  demuxer  DEMUX    libavformat/allformats.c)
1406
OUTDEV_LIST=$(find_things   outdev   OUTDEV   libavdevice/alldevices.c)
1407
INDEV_LIST=$(find_things    indev    _IN      libavdevice/alldevices.c)
1408
PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c)
1409
FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
1410

    
1411
enable $ARCH_EXT_LIST \
1412
       $DECODER_LIST \
1413
       $ENCODER_LIST \
1414
       $HWACCEL_LIST \
1415
       $PARSER_LIST \
1416
       $BSF_LIST \
1417
       $DEMUXER_LIST \
1418
       $MUXER_LIST \
1419
       $FILTER_LIST \
1420
       $PROTOCOL_LIST \
1421
       $INDEV_LIST \
1422
       $OUTDEV_LIST \
1423

    
1424
die_unknown(){
1425
    echo "Unknown option \"$1\"."
1426
    echo "See $0 --help for available options."
1427
    exit 1
1428
}
1429

    
1430
show_list() {
1431
    suffix=_$1
1432
    shift
1433
    echo $* | sed s/$suffix//g | tr ' ' '\n' | sort
1434
    exit 0
1435
}
1436

    
1437
for opt do
1438
    optval="${opt#*=}"
1439
    case "$opt" in
1440
    --extra-ldflags=*) add_ldflags $optval
1441
    ;;
1442
    --extra-libs=*) add_extralibs $optval
1443
    ;;
1444
    --disable-devices) disable $INDEV_LIST $OUTDEV_LIST
1445
    ;;
1446
    --enable-debug=*) debuglevel="$optval"
1447
    ;;
1448
    --enable-*=*|--disable-*=*)
1449
    eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/')
1450
    is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
1451
    eval list=\$$(toupper $thing)_LIST
1452
    name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
1453
    $action $(filter "$name" $list)
1454
    ;;
1455
    --enable-?*|--disable-?*)
1456
    eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
1457
    if is_in $option $COMPONENT_LIST; then
1458
        test $action = disable && action=unset
1459
        eval $action \$$(toupper ${option%s})_LIST
1460
    elif is_in $option $CMDLINE_SELECT; then
1461
        $action $option
1462
    else
1463
        die_unknown $opt
1464
    fi
1465
    ;;
1466
    --list-*)
1467
        NAME="${opt#--list-}"
1468
        is_in $NAME $COMPONENT_LIST || die_unknown $opt
1469
        NAME=${NAME%s}
1470
        eval show_list $NAME \$$(toupper $NAME)_LIST
1471
    ;;
1472
    --help|-h) show_help
1473
    ;;
1474
    *)
1475
    optname="${opt%%=*}"
1476
    optname="${optname#--}"
1477
    optname=$(echo "$optname" | sed 's/-/_/g')
1478
    if is_in $optname $CMDLINE_SET; then
1479
        eval $optname='$optval'
1480
    elif is_in $optname $CMDLINE_APPEND; then
1481
        append $optname "$optval"
1482
    else
1483
         die_unknown $opt
1484
    fi
1485
    ;;
1486
    esac
1487
done
1488

    
1489
disabled logging && logfile=/dev/null
1490

    
1491
echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
1492
set >> $logfile
1493

    
1494
test -n "$cross_prefix" && enable cross_compile
1495

    
1496
ar="${cross_prefix}${ar}"
1497
cc_default="${cross_prefix}${cc_default}"
1498
nm_default="${cross_prefix}${nm_default}"
1499
ranlib="${cross_prefix}${ranlib}"
1500
strip="${cross_prefix}${strip}"
1501

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

    
1504
set_default cc nm sysinclude
1505
enabled cross_compile || host_cc_default=$cc
1506
set_default host_cc
1507

    
1508
exesuf() {
1509
    case $1 in
1510
        mingw32*|cygwin*|*-dos|freedos|opendos|os/2*) echo .exe ;;
1511
    esac
1512
}
1513

    
1514
EXESUF=$(exesuf $target_os)
1515
HOSTEXESUF=$(exesuf $host_os)
1516

    
1517
# set temporary file name
1518
: ${TMPDIR:=$TEMPDIR}
1519
: ${TMPDIR:=$TMP}
1520
: ${TMPDIR:=/tmp}
1521

    
1522
if ! check_cmd type mktemp; then
1523
    # simple replacement for missing mktemp
1524
    # NOT SAFE FOR GENERAL USE
1525
    mktemp(){
1526
        echo "${2%XXX*}.${HOSTNAME}.${UID}.$$"
1527
    }
1528
fi
1529

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

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

    
1541
tmpfile TMPC  .c
1542
tmpfile TMPE  $EXESUF
1543
tmpfile TMPH  .h
1544
tmpfile TMPO  .o
1545
tmpfile TMPS  .S
1546
tmpfile TMPSH .sh
1547

    
1548
unset -f mktemp
1549

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

    
1563
filter_cflags=echo
1564
filter_cppflags=echo
1565
filter_asflags=echo
1566

    
1567
if   $cc -v 2>&1 | grep -qi ^gcc; then
1568
    cc_type=gcc
1569
    cc_version=__VERSION__
1570
    if ! $cc -dumpversion | grep -q '^2\.'; then
1571
        CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1572
        AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1573
    fi
1574
elif $cc --version 2>/dev/null | grep -q Intel; then
1575
    cc_type=icc
1576
    cc_version="AV_STRINGIFY(__INTEL_COMPILER)"
1577
    CC_DEPFLAGS='-MMD'
1578
    AS_DEPFLAGS='-MMD'
1579
elif $cc -v 2>&1 | grep -q xlc; then
1580
    cc_type=xlc
1581
    cc_version="AV_STRINGIFY(__IBMC__)"
1582
elif $cc -V 2>/dev/null | grep -q Compaq; then
1583
    cc_type=ccc
1584
    cc_version="AV_STRINGIFY(__DECC_VER)"
1585
    DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -M'
1586
    debuglevel=3
1587
    add_ldflags -Wl,-z,now # calls to libots crash without this
1588
elif $cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then
1589
    test -d "$sysroot" || die "No valid sysroot specified."
1590
    cc_type=armcc
1591
    cc_version="AV_STRINGIFY(__ARMCC_VERSION)"
1592
    armcc_conf="$PWD/armcc.conf"
1593
    $cc --arm_linux_configure                 \
1594
        --arm_linux_config_file="$armcc_conf" \
1595
        --configure_sysroot="$sysroot"        \
1596
        --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
1597
        die "Error creating armcc configuration file."
1598
    cc="$cc --arm_linux_config_file=$armcc_conf --translate_gcc"
1599
    as_default="${cross_prefix}gcc"
1600
    CC_DEPFLAGS='-MMD'
1601
    AS_DEPFLAGS='-MMD'
1602
elif $cc -version 2>/dev/null | grep -q TMS470; then
1603
    cc_type=tms470
1604
    cc_version="AV_STRINGIFY(__TI_COMPILER_VERSION__)"
1605
    cc="$cc --gcc --abi=eabi -eo=.o -mc -me"
1606
    CC_O='-fr=$(@D)'
1607
    as_default="${cross_prefix}gcc"
1608
    ld_default="${cross_prefix}gcc"
1609
    TMPO=$(basename $TMPC .c).o
1610
    append TMPFILES $TMPO
1611
    add_cflags -D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__=
1612
    CC_DEPFLAGS='-ppa -ppd=$(@:.o=.d)'
1613
    AS_DEPFLAGS='-MMD'
1614
    filter_cflags=tms470_flags
1615
    tms470_flags(){
1616
        for flag; do
1617
            case $flag in
1618
                -march=*|-mcpu=*)
1619
                    case "${flag#*=}" in
1620
                        armv7-a|cortex-a*)      echo -mv=7a8 ;;
1621
                        armv7-r|cortex-r*)      echo -mv=7r4 ;;
1622
                        armv7-m|cortex-m*)      echo -mv=7m3 ;;
1623
                        armv6*|arm11*)          echo -mv=6   ;;
1624
                        armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
1625
                                                echo -mv=5e  ;;
1626
                        armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
1627
                    esac
1628
                    ;;
1629
                -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
1630
                -mfpu=vfp)      echo --float_support=vfpv2        ;;
1631
                -msoft-float)   echo --float_support=vfplib       ;;
1632
                -Os)            echo -O3 -mf=2                    ;;
1633
                -O[0-3])        echo $flag -mf=5                  ;;
1634
                -g)             echo -g -mn                       ;;
1635
            esac
1636
        done
1637
    }
1638
elif $cc -v 2>&1 | grep -q clang; then
1639
    cc_type=clang
1640
    cc_version=__VERSION__
1641
    CC_DEPFLAGS='-MMD'
1642
    AS_DEPFLAGS='-MMD'
1643
elif $cc -V 2>&1 | grep -q Sun; then
1644
    cc_type=suncc
1645
    cc_version="AV_STRINGIFY(__SUNPRO_C)"
1646
    DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
1647
    DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -xM1'
1648
    filter_cflags=suncc_flags
1649
    suncc_flags(){
1650
        for flag; do
1651
            case $flag in
1652
                -march=*|-mcpu=*)
1653
                    case "${flag#*=}" in
1654
                        native)                   echo -xtarget=native       ;;
1655
                        v9)                       echo -xarch=sparc          ;;
1656
                        ultrasparc)               echo -xarch=sparcvis       ;;
1657
                        ultrasparc3|niagara*)     echo -xarch=sparcvis2      ;;
1658
                        i586|pentium)             echo -xchip=pentium        ;;
1659
                        i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
1660
                        pentium3*|c3-2)           echo -xtarget=pentium3     ;;
1661
                        pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
1662
                        pentium4*)          echo -xtarget=pentium4           ;;
1663
                        prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
1664
                        *-sse3)             echo -xarch=sse3                 ;;
1665
                        core2)              echo -xarch=ssse3 -xchip=core2   ;;
1666
                        amdfam10|barcelona)       echo -xarch=sse4_1         ;;
1667
                        athlon-4|athlon-[mx]p)    echo -xarch=ssea           ;;
1668
                        k8|opteron|athlon64|athlon-fx)
1669
                                                  echo -xarch=sse2a          ;;
1670
                        athlon*)                  echo -xarch=pentium_proa   ;;
1671
                    esac
1672
                    ;;
1673
                -std=c99)             echo -xc99              ;;
1674
                -fomit-frame-pointer) echo -xregs=frameptr    ;;
1675
                -fPIC)                echo -KPIC -xcode=pic32 ;;
1676
                -Os)                  echo -O5 -xspace        ;;
1677
                -W*,*)                echo $flag              ;;
1678
                -f*-*|-W*)                                    ;;
1679
                *)                    echo $flag              ;;
1680
            esac
1681
        done
1682
    }
1683
fi
1684

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

    
1687
: ${as_default:=$cc}
1688
: ${dep_cc_default:=$cc}
1689
: ${ld_default:=$cc}
1690
set_default as dep_cc ld
1691

    
1692
test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD
1693
test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD
1694

    
1695
add_cflags $extra_cflags
1696
add_asflags $extra_cflags
1697

    
1698
if test -n "$sysroot"; then
1699
    case "$cc_type" in
1700
        gcc)
1701
            add_cppflags --sysroot="$sysroot"
1702
            add_ldflags --sysroot="$sysroot"
1703
        ;;
1704
        tms470)
1705
            add_cppflags -I"$sysinclude"
1706
            add_ldflags  --sysroot="$sysroot"
1707
        ;;
1708
        clang)
1709
            add_cppflags -isysroot="$sysroot"
1710
            add_ldflags -isysroot="$sysroot"
1711
        ;;
1712
    esac
1713
fi
1714

    
1715
if test "$cpu" = host; then
1716
    enabled cross_compile && die "--cpu=host makes no sense when cross-compiling."
1717

    
1718
    case "$cc_type" in
1719
        gcc)
1720
            check_native(){
1721
                $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
1722
                awk "/$1=/{ match(\$0, /$1=(\\w+)/, a);print a[1];exit }" $TMPE
1723
            }
1724
            cpu=$(check_native -march || check_native -mcpu)
1725
        ;;
1726
    esac
1727

    
1728
    test "${cpu:-host}" = host && die "--cpu=host not supported with compiler $cc"
1729
fi
1730

    
1731
# Add processor-specific flags
1732
case $cpu in
1733
    601|ppc601|PowerPC601)
1734
        cpuflags="-mcpu=601"
1735
    ;;
1736
    603*|ppc603*|PowerPC603*)
1737
        cpuflags="-mcpu=603"
1738
    ;;
1739
    604*|ppc604*|PowerPC604*)
1740
        cpuflags="-mcpu=604"
1741
    ;;
1742
    G3|g3|75*|ppc75*|PowerPC75*)
1743
        cpuflags="-mcpu=750 -mpowerpc-gfxopt"
1744
    ;;
1745
    G4|g4|745*|ppc745*|PowerPC745*)
1746
        cpuflags="-mcpu=7450 -mpowerpc-gfxopt"
1747
    ;;
1748
    74*|ppc74*|PowerPC74*)
1749
        cpuflags="-mcpu=7400 -mpowerpc-gfxopt"
1750
    ;;
1751
    G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
1752
        cpuflags="-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
1753
    ;;
1754
    Cell|CELL|cell)
1755
        cpuflags="-mcpu=cell"
1756
        enable ldbrx
1757
    ;;
1758
    # targets that do NOT support conditional mov (cmov)
1759
    i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
1760
        cpuflags="-march=$cpu"
1761
        disable cmov
1762
    ;;
1763
    # targets that do support conditional mov (cmov)
1764
    i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2|amdfam10)
1765
        cpuflags="-march=$cpu"
1766
        enable cmov
1767
        enable fast_cmov
1768
    ;;
1769
    # targets that do support conditional mov but on which it's slow
1770
    pentium4|pentium4m|prescott|nocona)
1771
        cpuflags="-march=$cpu"
1772
        enable cmov
1773
        disable fast_cmov
1774
    ;;
1775
    sparc64)
1776
        cpuflags="-mcpu=v9"
1777
    ;;
1778
    arm11*|cortex*)
1779
        cpuflags="-mcpu=$cpu"
1780
        enable fast_unaligned
1781
    ;;
1782
    armv[67]*)
1783
        cpuflags="-march=$cpu"
1784
        enable fast_unaligned
1785
    ;;
1786
    armv*)
1787
        cpuflags="-march=$cpu"
1788
    ;;
1789
    arm*)
1790
        cpuflags="-mcpu=$cpu"
1791
    ;;
1792
    ev4|ev45|ev5|ev56|pca56|ev6|ev67)
1793
        enabled ccc && cpuflags="-arch $cpu" || cpuflags="-mcpu=$cpu"
1794
    ;;
1795
    bf*)
1796
        cpuflags="-mcpu=$cpu"
1797
    ;;
1798
    mips*|[45]k*|[237]4k*|m4k|r*000|loongson2[ef])
1799
        cpuflags="-march=$cpu"
1800
    ;;
1801
    ap7[02]0[0-2])
1802
        subarch="avr32_ap"
1803
        cpuflags="-mpart=$cpu"
1804
    ;;
1805
    ap)
1806
        subarch="avr32_ap"
1807
        cpuflags="-march=$cpu"
1808
    ;;
1809
    uc3[ab]*)
1810
        subarch="avr32_uc"
1811
        cpuflags="-mcpu=$cpu"
1812
    ;;
1813
    uc)
1814
        subarch="avr32_uc"
1815
        cpuflags="-march=$cpu"
1816
    ;;
1817
    generic)
1818
    ;;
1819
    *)
1820
        echo "WARNING: Unknown CPU \"$cpu\", ignored."
1821
    ;;
1822
esac
1823

    
1824
add_cflags $cpuflags
1825
add_asflags $cpuflags
1826

    
1827
# compiler sanity check
1828
check_exec <<EOF
1829
int main(void){ return 0; }
1830
EOF
1831
if test "$?" != 0; then
1832
    echo "$cc is unable to create an executable file."
1833
    if test -z "$cross_prefix" && ! enabled cross_compile ; then
1834
        echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
1835
        echo "Only do this if you know what cross compiling means."
1836
    fi
1837
    die "C compiler test failed."
1838
fi
1839

    
1840
add_cppflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112
1841
check_cflags -std=c99
1842
check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
1843
#include <stdlib.h>
1844
EOF
1845
check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE
1846
#include <stdlib.h>
1847
EOF
1848

    
1849
check_host_cflags -std=c99
1850

    
1851
case "$arch" in
1852
    alpha)
1853
        arch="alpha"
1854
        enable fast_64bit
1855
        check_cflags -mieee
1856
        spic=$shared
1857
    ;;
1858
    arm|armv[4567]*l)
1859
        arch="arm"
1860
    ;;
1861
    avr32)
1862
    ;;
1863
    bfin)
1864
        arch="bfin"
1865
    ;;
1866
    ia64)
1867
        arch="ia64"
1868
        enable fast_64bit
1869
        spic=$shared
1870
        # HACK: currently fails to build if .bss is > 4MB and shared libs are built
1871
        enabled shared && enable_weak hardcoded_tables
1872
    ;;
1873
    m68k)
1874
        arch="m68k"
1875
    ;;
1876
    mips|mipsel|IP*)
1877
        arch="mips"
1878
        spic=$shared
1879
    ;;
1880
    mips64)
1881
        arch="mips"
1882
        subarch="mips64"
1883
        enable fast_64bit
1884
        spic=$shared
1885
    ;;
1886
    parisc|hppa)
1887
        arch="parisc"
1888
        spic=$shared
1889
    ;;
1890
    parisc64|hppa64)
1891
        arch="parisc"
1892
        enable fast_64bit
1893
        spic=$shared
1894
    ;;
1895
    "Power Macintosh"|ppc|powerpc)
1896
        arch="ppc"
1897
        enable fast_unaligned
1898
    ;;
1899
    ppc64)
1900
        arch="ppc"
1901
        subarch="ppc64"
1902
        enable fast_64bit
1903
        enable fast_unaligned
1904
    ;;
1905
    s390|s390x)
1906
        arch="s390"
1907
    ;;
1908
    sh4|sh)
1909
        arch="sh4"
1910
    ;;
1911
    sparc)
1912
        arch="sparc"
1913
        spic=$shared
1914
    ;;
1915
    sun4u|sparc64)
1916
        arch="sparc"
1917
        subarch="sparc64"
1918
        enable fast_64bit
1919
        spic=$shared
1920
    ;;
1921
    i386|i486|i586|i686|i86pc|BePC|x86_64|amd64)
1922
        arch="x86"
1923
        subarch="x86_32"
1924
        enable fast_unaligned
1925
        check_cc <<EOF && enable fast_64bit && subarch="x86_64" && spic=$shared
1926
        int test[(int)sizeof(char*) - 7];
1927
EOF
1928
        if test "$subarch" = "x86_64"; then
1929
            enable cmov
1930
            enable fast_cmov
1931
        fi
1932
    ;;
1933
    *)
1934
        arch="unknown"
1935
    ;;
1936
esac
1937

    
1938
enable $arch $subarch
1939
enabled spic && enable pic
1940
check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
1941

    
1942
# OS specific
1943
case $target_os in
1944
    beos|haiku|zeta)
1945
        prefix_default="$HOME/config"
1946
        # 3 gcc releases known for BeOS, each with ugly bugs
1947
        gcc_version="$($cc -v 2>&1 | grep version | cut -d ' ' -f3-)"
1948
        case "$gcc_version" in
1949
          2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
1950
            disable mmx
1951
            ;;
1952
          *20010315*) echo "BeBits gcc"
1953
            add_cflags -fno-expensive-optimizations
1954
            ;;
1955
        esac
1956
        SHFLAGS=-nostart
1957
        # enable BeOS things
1958
        enable audio_beos
1959
        # no need for libm, but the inet stuff
1960
        # Check for BONE
1961
        # XXX: actually should check for NOT net_server
1962
        if echo $BEINCLUDES | grep -q 'headers/be/bone'; then
1963
            network_extralibs="-lbind -lsocket"
1964
        else
1965
            enable beos_netserver
1966
            network_extralibs="-lnet"
1967
        fi ;;
1968
    sunos)
1969
        FFSERVERLDFLAGS=""
1970
        SHFLAGS='-shared -Wl,-h,$$(@F)'
1971
        enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
1972
        network_extralibs="-lsocket -lnsl"
1973
        add_cppflags -D__EXTENSIONS__
1974
        ;;
1975
    netbsd)
1976
        oss_indev_extralibs="-lossaudio"
1977
        oss_outdev_extralibs="-lossaudio"
1978
        ;;
1979
    openbsd)
1980
        enable malloc_aligned
1981
        # On OpenBSD 4.5. the compiler does not use PIC unless
1982
        # explicitly using -fPIC. FFmpeg builds fine without PIC,
1983
        # however the generated executable will not do anything
1984
        # (simply quits with exit-code 1, no crash, no output).
1985
        # Thus explicitly enable PIC here.
1986
        enable pic
1987
        SHFLAGS='-shared'
1988
        oss_indev_extralibs="-lossaudio"
1989
        oss_outdev_extralibs="-lossaudio"
1990
        ;;
1991
    freebsd|dragonfly)
1992
        enable malloc_aligned
1993
        ;;
1994
    bsd/os)
1995
        osextralibs="-lpoll -lgnugetopt"
1996
        strip="strip -d"
1997
        ;;
1998
    darwin)
1999
        enable malloc_aligned
2000
        SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR) -Wl,-read_only_relocs,suppress'
2001
        strip="strip -x"
2002
        FFLDFLAGS="-Wl,-dynamic,-search_paths_first"
2003
        SLIBSUF=".dylib"
2004
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
2005
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
2006
        FFSERVERLDFLAGS=-Wl,-bind_at_load
2007
        objformat="macho"
2008
        enabled x86_64 && objformat="macho64"
2009
        enabled_any pic shared ||
2010
            { check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
2011
        ;;
2012
    mingw32*)
2013
        if test $target_os = "mingw32ce"; then
2014
            disable network
2015
        else
2016
            target_os=mingw32
2017
        fi
2018
        LIBTARGET=i386
2019
        if enabled x86_64; then
2020
            enable malloc_aligned
2021
            LIBTARGET=x64
2022
        elif enabled arm; then
2023
            LIBTARGET=arm
2024
        fi
2025
        shlibdir_default="$bindir_default"
2026
        disable ffserver
2027
        SLIBPREF=""
2028
        SLIBSUF=".dll"
2029
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
2030
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
2031
        SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)'
2032
        SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \
2033
            install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"; \
2034
            install -d "$(LIBDIR)"; \
2035
            install -m 644 $(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) "$(LIBDIR)/lib$(SLIBNAME:$(SLIBSUF)=.dll.a)"'
2036
        SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"'
2037
        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'
2038
        objformat="win32"
2039
        enable dos_paths
2040
        check_cflags -fno-common
2041
        if ! enabled x86_64; then
2042
            check_cpp_condition _mingw.h "(__MINGW32_MAJOR_VERSION > 3) || (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
2043
                die "ERROR: MinGW runtime version must be >= 3.15."
2044
            enabled_any avisynth vfwcap_indev &&
2045
                { check_cpp_condition w32api.h "(__W32API_MAJOR_VERSION > 3) || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION >= 13)" ||
2046
                  die "ERROR: avisynth and vfwcap_indev require w32api version 3.13 or later."; }
2047
            fi
2048
        ;;
2049
    cygwin*)
2050
        target_os=cygwin
2051
        shlibdir_default="$bindir_default"
2052
        SLIBPREF="cyg"
2053
        SLIBSUF=".dll"
2054
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
2055
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
2056
        SHFLAGS='-shared -Wl,--enable-auto-image-base'
2057
        objformat="win32"
2058
        enable dos_paths
2059
        check_cflags -fno-common
2060
        ;;
2061
    *-dos|freedos|opendos)
2062
        disable ffplay ffserver
2063
        disable $INDEV_LIST $OUTDEV_LIST
2064
        network_extralibs="-lsocket"
2065
        objformat="coff"
2066
        enable dos_paths
2067
        ;;
2068
    linux)
2069
        enable dv1394
2070
        ;;
2071
    irix*)
2072
        target_os=irix
2073
        ranlib="echo ignoring ranlib"
2074
        ;;
2075
    os/2*)
2076
        strip="lxlite"
2077
        ln_s="cp -f"
2078
        FFLDFLAGS="-Zomf -Zbin-files -Zargs-wild -Zmap"
2079
        SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
2080
        FFSERVERLDFLAGS=""
2081
        LIBSUF="_s.a"
2082
        SLIBPREF=""
2083
        SLIBSUF=".dll"
2084
        SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
2085
        SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)'
2086
        SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(NAME).def; \
2087
          echo PROTMODE >> $(SUBDIR)$(NAME).def; \
2088
          echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(NAME).def; \
2089
          echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(NAME).def; \
2090
          echo EXPORTS >> $(SUBDIR)$(NAME).def; \
2091
          emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def'
2092
        SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \
2093
          emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
2094
        SLIB_INSTALL_EXTRA_CMD='install -m 644 $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"'
2095
        SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib'
2096
        enable dos_paths
2097
        ;;
2098
    gnu/kfreebsd)
2099
        ;;
2100
    gnu)
2101
        ;;
2102

    
2103
    *)
2104
        die "Unknown OS '$target_os'."
2105
        ;;
2106
esac
2107

    
2108
set_default $PATHS_LIST
2109

    
2110
add_extralibs $osextralibs
2111

    
2112
# Combine FFLDFLAGS and the LDFLAGS environment variable.
2113
LDFLAGS="$FFLDFLAGS $LDFLAGS"
2114

    
2115
# we need to build at least one lib type
2116
if ! enabled_any static shared; then
2117
    cat <<EOF
2118
At least one library type must be built.
2119
Specify --enable-static to build the static libraries or --enable-shared to
2120
build the shared libraries as well. To only build the shared libraries specify
2121
--disable-static in addition to --enable-shared.
2122
EOF
2123
    exit 1;
2124
fi
2125

    
2126
disabled static && LIBNAME=""
2127

    
2128
if enabled_any libfaad libfaadbin ; then
2129
    if check_header faad.h; then
2130
        check_cc <<EOF
2131
#include <faad.h>
2132
#ifndef FAAD2_VERSION
2133
ok faad1
2134
#endif
2135
int main(void) { return 0; }
2136
EOF
2137
        test $? = 0 && enable libfaad2
2138
    else
2139
        die "FAAD test failed."
2140
    fi
2141
fi
2142

    
2143

    
2144
die_license_disabled() {
2145
    enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
2146
}
2147

    
2148
die_license_disabled gpl libfaad2
2149
die_license_disabled gpl libx264
2150
die_license_disabled gpl libxvid
2151
die_license_disabled gpl postproc
2152
die_license_disabled gpl x11grab
2153

    
2154
die_license_disabled nonfree libfaac
2155

    
2156
die_license_disabled version3 libopencore_amrnb
2157
die_license_disabled version3 libopencore_amrwb
2158

    
2159
enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
2160

    
2161
check_deps $ARCH_EXT_LIST
2162

    
2163
disabled optimizations || check_cflags -fomit-frame-pointer
2164

    
2165
enable_pic() {
2166
    enable pic
2167
    add_cppflags -DPIC
2168
    add_cflags   -fPIC
2169
    add_asflags  -fPIC
2170
}
2171

    
2172
enabled pic && enable_pic
2173

    
2174
check_cc <<EOF || die "Symbol mangling check failed."
2175
int ff_extern;
2176
EOF
2177
sym=$($nm -P -g $TMPO | grep ff_extern)
2178
extern_prefix=${sym%%ff_extern*}
2179

    
2180
check_cc <<EOF && enable inline_asm
2181
void foo(void) { __asm__ volatile ("" ::); }
2182
EOF
2183

    
2184
_restrict=
2185
for restrict_keyword in restrict __restrict__ __restrict; do
2186
    check_cc <<EOF && _restrict=$restrict_keyword && break
2187
void foo(char * $restrict_keyword p);
2188
EOF
2189
done
2190

    
2191
check_cc <<EOF && enable attribute_packed
2192
struct { int x; } __attribute__((packed)) x;
2193
EOF
2194

    
2195
check_cc <<EOF || die "endian test failed"
2196
unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
2197
EOF
2198
od -A n -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
2199

    
2200
if enabled arm; then
2201

    
2202
    check_cflags -marm
2203

    
2204
    check_ld <<EOF && enable vfp_args
2205
__asm__ (".eabi_attribute 28, 1");
2206
int main(void) { return 0; }
2207
EOF
2208

    
2209
    # We have to check if pld is a nop and disable it.
2210
    check_asm pld '"pld [r0]"'
2211

    
2212
    enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"'
2213
    enabled armv6   && check_asm armv6   '"sadd16 r0, r0, r0"'
2214
    enabled armv6t2 && check_asm armv6t2 '"movt r0, #0"'
2215
    enabled armvfp  && check_asm armvfp  '"fadds s0, s0, s0"'
2216
    enabled iwmmxt  && check_asm iwmmxt  '"wunpckelub wr6, wr4"'
2217
    enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
2218

    
2219
    enabled_all armv6t2 shared !pic && enable_pic
2220

    
2221
elif enabled mips; then
2222

    
2223
    check_asm loongson '"dmult.g $1, $2, $3"'
2224
    enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
2225

    
2226
elif enabled ppc; then
2227

    
2228
    check_asm dcbzl     '"dcbzl 0, 1"'
2229
    check_asm ppc4xx    '"maclhw r10, r11, r12"'
2230
    check_asm xform_asm '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)'
2231

    
2232
    # AltiVec flags: The FSF version of GCC differs from the Apple version
2233
    if enabled altivec; then
2234
        check_cflags -maltivec -mabi=altivec &&
2235
        { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
2236
        check_cflags -faltivec
2237

    
2238
        # check if our compiler supports Motorola AltiVec C API
2239
        check_cc <<EOF || disable altivec
2240
$inc_altivec_h
2241
int main(void) {
2242
    vector signed int v1, v2, v3;
2243
    v1 = vec_add(v2,v3);
2244
    return 0;
2245
}
2246
EOF
2247

    
2248
        # check if our compiler supports braces for vector declarations
2249
        check_cc <<EOF || die "You need a compiler that supports {} in AltiVec vector declarations."
2250
$inc_altivec_h
2251
int main (void) { (vector int) {1}; return 0; }
2252
EOF
2253
    fi
2254

    
2255
elif enabled sparc; then
2256

    
2257
    enabled vis && check_asm vis '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc &&
2258
        add_cflags -mcpu=ultrasparc -mtune=ultrasparc
2259

    
2260
elif enabled x86; then
2261

    
2262
    # check whether EBP is available on x86
2263
    # As 'i' is stored on the stack, this program will crash
2264
    # if the base pointer is used to access it because the
2265
    # base pointer is cleared in the inline assembly code.
2266
    check_exec_crash <<EOF && enable ebp_available
2267
    volatile int i=0;
2268
    __asm__ volatile (
2269
        "xorl %%ebp, %%ebp"
2270
    ::: "%ebp");
2271
    return i;
2272
EOF
2273

    
2274
    # check whether EBX is available on x86
2275
    check_asm ebx_available '""::"b"(0)' &&
2276
        check_asm ebx_available '"":::"%ebx"'
2277

    
2278
    # check whether more than 10 operands are supported
2279
    check_cc <<EOF && enable ten_operands
2280
int main(void) {
2281
    int x=0;
2282
    __asm__ volatile(
2283
        ""
2284
        :"+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x), "+&rm"(x)
2285
    );
2286
    return 0;
2287
}
2288
EOF
2289

    
2290
    # check whether binutils is new enough to compile SSSE3/MMX2
2291
    enabled ssse3 && check_asm ssse3 '"pabsw %xmm0, %xmm0"'
2292
    enabled mmx2  && check_asm mmx2  '"pmaxub %mm0, %mm1"'
2293

    
2294
    check_asm bswap '"bswap %%eax" ::: "%eax"'
2295

    
2296
    YASMFLAGS="-f $objformat -DARCH_$(toupper $subarch)"
2297
    enabled     x86_64        && append YASMFLAGS "-m amd64"
2298
    enabled     pic           && append YASMFLAGS "-DPIC"
2299
    test -n "$extern_prefix"  && append YASMFLAGS "-DPREFIX"
2300
    case "$objformat" in
2301
        elf) enabled debug && append YASMFLAGS "-g dwarf2" ;;
2302
    esac
2303
    disabled yasm || { check_yasm "pabsw xmm0, xmm0" && enable yasm; }
2304

    
2305
fi
2306

    
2307
if check_func dlopen; then
2308
    ldl=
2309
elif check_func dlopen -ldl; then
2310
    ldl=-ldl
2311
fi
2312

    
2313
# Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
2314
check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; }
2315

    
2316
check_func  fork
2317
check_func  gethrtime
2318
check_func  getrusage
2319
check_func  inet_aton $network_extralibs
2320
check_func  isatty
2321
check_func  memalign
2322
check_func  mkstemp
2323
check_func  posix_memalign
2324
check_func_headers io.h setmode
2325
check_func_headers lzo/lzo1x.h lzo1x_999_compress
2326
check_func_headers windows.h GetProcessTimes
2327
check_func_headers windows.h VirtualAlloc
2328

    
2329
check_header conio.h
2330
check_header dlfcn.h
2331
check_header malloc.h
2332
check_header poll.h
2333
check_header sys/mman.h
2334
check_header sys/resource.h
2335
check_header sys/select.h
2336
check_header termios.h
2337
check_header vdpau/vdpau.h
2338
check_header vdpau/vdpau_x11.h
2339
check_header X11/extensions/XvMClib.h
2340

    
2341
if ! enabled_any memalign memalign_hack posix_memalign malloc_aligned &&
2342
     enabled_any $need_memalign ; then
2343
    die "Error, no aligned memory allocator but SSE enabled, disable it or use --enable-memalign-hack."
2344
fi
2345

    
2346
disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable  zlib
2347
disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
2348

    
2349
# check for some common methods of building with pthread support
2350
# do this before the optional library checks as some of them require pthreads
2351
if enabled pthreads; then
2352
    if check_func pthread_create; then
2353
        :
2354
    elif check_func pthread_create -pthread; then
2355
        add_cflags -pthread
2356
        add_extralibs -pthread
2357
    elif check_func pthread_create -pthreads; then
2358
        add_cflags -pthreads
2359
        add_extralibs -pthreads
2360
    elif check_func pthread_create -lpthreadGC2; then
2361
        add_extralibs -lpthreadGC2
2362
    elif ! check_lib pthread.h pthread_create -lpthread; then
2363
        die "ERROR: can't find pthreads library"
2364
    fi
2365
fi
2366

    
2367
for thread in $THREADS_LIST; do
2368
    if enabled $thread; then
2369
        test -n "$thread_type" &&
2370
            die "ERROR: Only one thread type must be selected." ||
2371
            thread_type="$thread"
2372
    fi
2373
done
2374

    
2375
check_lib math.h sin -lm
2376
check_lib va/va.h vaInitialize -lva
2377

    
2378
check_func llrint
2379
check_func log2
2380
check_func lrint
2381
check_func lrintf
2382
check_func round
2383
check_func roundf
2384
check_func truncf
2385

    
2386
# these are off by default, so fail if requested and not available
2387
enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32
2388
enabled libdirac   && add_cflags $(pkg-config --cflags dirac) &&
2389
                      require  libdirac libdirac_decoder/dirac_parser.h dirac_decoder_init $(pkg-config --libs dirac) &&
2390
                      require  libdirac libdirac_encoder/dirac_encoder.h dirac_encoder_init $(pkg-config --libs dirac)
2391
enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
2392
enabled libfaad    && require2 libfaad faad.h faacDecOpen -lfaad
2393
enabled libgsm     && require  libgsm gsm.h gsm_create -lgsm
2394
enabled libmp3lame && require  libmp3lame lame/lame.h lame_init -lmp3lame -lm
2395
enabled libnut     && require  libnut libnut.h nut_demuxer_init -lnut
2396
enabled libopencore_amrnb  && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb -lm
2397
enabled libopencore_amrwb  && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb -lm
2398
enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg
2399
enabled libschroedinger && add_cflags $(pkg-config --cflags schroedinger-1.0) &&
2400
                           require libschroedinger schroedinger/schro.h schro_init $(pkg-config --libs schroedinger-1.0)
2401
enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
2402
enabled libtheora  && require  libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
2403
enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
2404
enabled libx264    && require  libx264 x264.h x264_encoder_encode -lx264 -lm &&
2405
                      { check_cpp_condition x264.h "X264_BUILD >= 79" ||
2406
                        die "ERROR: libx264 version must be >= 0.79."; }
2407
enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore
2408
enabled mlib       && require  mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
2409

    
2410
# libdc1394 check
2411
if enabled libdc1394; then
2412
    { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 &&
2413
        enable libdc1394_2; } ||
2414
    { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 &&
2415
        enable libdc1394_1; } ||
2416
    die "ERROR: No version of libdc1394 found "
2417
fi
2418

    
2419
disable sdl_too_old
2420
disable sdl
2421
SDL_CONFIG="${cross_prefix}sdl-config"
2422
if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
2423
    sdl_cflags=$("${SDL_CONFIG}" --cflags)
2424
    sdl_libs=$("${SDL_CONFIG}" --libs)
2425
    temp_cflags $sdl_cflags
2426
    temp_extralibs $sdl_libs
2427
    if check_lib2 SDL.h SDL_Init; then
2428
        _sdlversion=$("${SDL_CONFIG}" --version | sed 's/[^0-9]//g')
2429
        if test "$_sdlversion" -lt 121 ; then
2430
            enable sdl_too_old
2431
        else
2432
            enable sdl
2433
            check_cc $sdl_cflags <<EOF && enable sdl_video_size
2434
#include <SDL.h>
2435
int main(int argc, char **argv){
2436
    const SDL_VideoInfo *vi = SDL_GetVideoInfo();
2437
    int w = vi->current_w;
2438
    return 0;
2439
}
2440
EOF
2441
        fi
2442
    fi
2443
    restore_flags
2444
fi
2445

    
2446
texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
2447

    
2448
if enabled network; then
2449
    check_type "sys/types.h sys/socket.h" socklen_t
2450
    # Prefer arpa/inet.h over winsock2
2451
    if check_header arpa/inet.h ; then
2452
        check_func closesocket
2453
    elif check_header winsock2.h ; then
2454
        check_func_headers winsock2.h closesocket -lws2 && \
2455
            network_extralibs="-lws2" || \
2456
        { check_func_headers winsock2.h closesocket -lws2_32 && \
2457
            network_extralibs="-lws2_32"; }
2458
        check_type ws2tcpip.h socklen_t
2459
    else
2460
        disable network
2461
    fi
2462
fi
2463

    
2464
enabled_all network ipv6 && check_ld <<EOF || disable ipv6
2465
#include <sys/types.h>
2466
#include <sys/socket.h>
2467
#include <netinet/in.h>
2468
#include <netdb.h>
2469
int main(void) {
2470
    struct sockaddr_storage saddr;
2471
    struct ipv6_mreq mreq6;
2472
    getaddrinfo(0,0,0,0);
2473
    getnameinfo(0,0,0,0,0,0,0);
2474
    IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0);
2475
}
2476
EOF
2477

    
2478
check_header linux/videodev.h
2479
check_header linux/videodev2.h
2480
check_header sys/videoio.h
2481

    
2482
check_func_headers "windows.h vfw.h" capCreateCaptureWindow -lvfw32
2483

    
2484
# check for ioctl_meteor.h, ioctl_bt848.h and alternatives
2485
{ check_header dev/bktr/ioctl_meteor.h &&
2486
  check_header dev/bktr/ioctl_bt848.h; } ||
2487
{ check_header machine/ioctl_meteor.h &&
2488
  check_header machine/ioctl_bt848.h; } ||
2489
{ check_header dev/video/meteor/ioctl_meteor.h &&
2490
  check_header dev/video/bktr/ioctl_bt848.h; } ||
2491
check_header dev/ic/bt8xx.h
2492

    
2493
check_header sys/soundcard.h
2494
check_header soundcard.h
2495

    
2496
enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
2497

    
2498
enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack
2499

    
2500
enabled x11grab                         &&
2501
check_header X11/Xlib.h                 &&
2502
check_header X11/extensions/XShm.h      &&
2503
check_header X11/extensions/Xfixes.h    &&
2504
check_func XOpenDisplay -lX11           &&
2505
check_func XShmCreateImage -lX11 -lXext &&
2506
check_func XFixesGetCursorImage -lX11 -lXext -lXfixes
2507

    
2508
if enabled vdpau_vdpau_h; then
2509
check_cpp_condition \
2510
    vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
2511
    { echolog "Please upgrade to libvdpau >= 0.2 if you would like vdpau support." &&
2512
      disable vdpau; }
2513
fi
2514

    
2515
enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
2516

    
2517
# add some useful compiler flags if supported
2518
check_cflags -Wdeclaration-after-statement
2519
check_cflags -Wall
2520
check_cflags -Wno-switch
2521
check_cflags -Wdisabled-optimization
2522
check_cflags -Wpointer-arith
2523
check_cflags -Wredundant-decls
2524
check_cflags -Wno-pointer-sign
2525
check_cflags -Wcast-qual
2526
check_cflags -Wwrite-strings
2527
check_cflags -Wtype-limits
2528
check_cflags -Wundef
2529
enabled extra_warnings && check_cflags -Winline
2530

    
2531
# add some linker flags
2532
check_ldflags -Wl,--warn-common
2533
check_ldflags -Wl,--as-needed
2534
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'
2535
check_ldflags -Wl,-Bsymbolic
2536

    
2537
if enabled small; then
2538
    check_cflags -Os            # not all compilers support -Os
2539
    optimizations="small"
2540
elif enabled optimizations; then
2541
    if enabled xlc; then
2542
        add_cflags  -O5
2543
        add_ldflags -O5
2544
    elif enabled suncc; then
2545
        add_cflags -O5
2546
    elif enabled ccc; then
2547
        add_cflags -fast
2548
    else
2549
        add_cflags -O3
2550
    fi
2551
fi
2552
check_cflags -fno-math-errno
2553
check_cflags -fno-signed-zeros
2554

    
2555
if enabled icc; then
2556
    # Just warnings, no remarks
2557
    check_cflags -w1
2558
    # -wd: Disable following warnings
2559
    # 144, 167, 556: -Wno-pointer-sign
2560
    # 10006: ignoring unknown option -fno-signed-zeros
2561
    # 10156: ignoring option '-W'; no argument required
2562
    check_cflags -wd144,167,556,10006,10156
2563
    # 11030: Warning unknown option --as-needed
2564
    # 10156: ignoring option '-export'; no argument required
2565
    check_ldflags -wd10156,11030
2566
    # Allow to compile with optimizations
2567
    check_ldflags -march=$cpu
2568
    # icc 11.0 and 11.1 work with ebp_available, but don't pass the test
2569
    enable ebp_available
2570
elif enabled ccc; then
2571
    # disable some annoying warnings
2572
    add_cflags -msg_disable cvtu32to64
2573
    add_cflags -msg_disable embedcomment
2574
    add_cflags -msg_disable needconstext
2575
    add_cflags -msg_disable nomainieee
2576
    add_cflags -msg_disable ptrmismatch1
2577
    add_cflags -msg_disable unreachcode
2578
elif enabled gcc; then
2579
    check_cflags -fno-tree-vectorize
2580
elif enabled clang; then
2581
    check_cflags -Qunused-arguments
2582
fi
2583

    
2584
if enabled gprof; then
2585
    add_cflags  -p
2586
    add_ldflags -p
2587
fi
2588

    
2589
# Find out if the .align argument is a power of two or not.
2590
check_asm asmalign_pot '".align 3"'
2591

    
2592
enabled_any $DECODER_LIST      && enable decoders
2593
enabled_any $ENCODER_LIST      && enable encoders
2594
enabled_any $HWACCEL_LIST      && enable hwaccels
2595
enabled_any $BSF_LIST          && enable bsfs
2596
enabled_any $DEMUXER_LIST      && enable demuxers
2597
enabled_any $MUXER_LIST        && enable muxers
2598
enabled_any $FILTER_LIST       && enable filters
2599
enabled_any $INDEV_LIST        && enable indevs
2600
enabled_any $OUTDEV_LIST       && enable outdevs
2601
enabled_any $PROTOCOL_LIST     && enable protocols
2602

    
2603
enabled_any $THREADS_LIST      && enable threads
2604

    
2605
check_deps $CONFIG_LIST       \
2606
           $CONFIG_EXTRA      \
2607
           $HAVE_LIST         \
2608
           $DECODER_LIST      \
2609
           $ENCODER_LIST      \
2610
           $HWACCEL_LIST      \
2611
           $PARSER_LIST       \
2612
           $BSF_LIST          \
2613
           $DEMUXER_LIST      \
2614
           $MUXER_LIST        \
2615
           $FILTER_LIST       \
2616
           $INDEV_LIST        \
2617
           $OUTDEV_LIST       \
2618
           $PROTOCOL_LIST     \
2619

    
2620
echo "install prefix            $prefix"
2621
echo "source path               $source_path"
2622
echo "C compiler                $cc"
2623
echo ".align is power-of-two    $asmalign_pot"
2624
echo "ARCH                      $arch ($cpu)"
2625
if test "$build_suffix" != ""; then
2626
    echo "build suffix              $build_suffix"
2627
fi
2628
if test "$extra_version" != ""; then
2629
    echo "version string suffix     $extra_version"
2630
fi
2631
echo "big-endian                ${bigendian-no}"
2632
echo "runtime cpu detection     ${runtime_cpudetect-no}"
2633
if enabled x86; then
2634
    echo "yasm                      ${yasm-no}"
2635
    echo "MMX enabled               ${mmx-no}"
2636
    echo "MMX2 enabled              ${mmx2-no}"
2637
    echo "3DNow! enabled            ${amd3dnow-no}"
2638
    echo "3DNow! extended enabled   ${amd3dnowext-no}"
2639
    echo "SSE enabled               ${sse-no}"
2640
    echo "SSSE3 enabled             ${ssse3-no}"
2641
    echo "CMOV enabled              ${cmov-no}"
2642
    echo "CMOV is fast              ${fast_cmov-no}"
2643
    echo "EBX available             ${ebx_available-no}"
2644
    echo "EBP available             ${ebp_available-no}"
2645
    echo "10 operands supported     ${ten_operands-no}"
2646
fi
2647
if enabled arm; then
2648
    echo "ARMv5TE enabled           ${armv5te-no}"
2649
    echo "ARMv6 enabled             ${armv6-no}"
2650
    echo "ARMv6T2 enabled           ${armv6t2-no}"
2651
    echo "ARM VFP enabled           ${armvfp-no}"
2652
    echo "IWMMXT enabled            ${iwmmxt-no}"
2653
    echo "NEON enabled              ${neon-no}"
2654
fi
2655
if enabled mips; then
2656
    echo "MMI enabled               ${mmi-no}"
2657
fi
2658
if enabled ppc; then
2659
    echo "AltiVec enabled           ${altivec-no}"
2660
    echo "PPC 4xx optimizations     ${ppc4xx-no}"
2661
    echo "dcbzl available           ${dcbzl-no}"
2662
    echo "performance report        ${powerpc_perf-no}"
2663
fi
2664
if enabled sparc; then
2665
    echo "VIS enabled               ${vis-no}"
2666
fi
2667
echo "gprof enabled             ${gprof-no}"
2668
echo "debug symbols             ${debug-no}"
2669
echo "strip symbols             ${stripping-no}"
2670
echo "optimizations             ${optimizations-no}"
2671
echo "static                    ${static-no}"
2672
echo "shared                    ${shared-no}"
2673
echo "postprocessing support    ${postproc-no}"
2674
echo "new filter support        ${avfilter-no}"
2675
echo "filters using lavformat   ${avfilter_lavf-no}"
2676
echo "network support           ${network-no}"
2677
if enabled network; then
2678
    echo "IPv6 support              ${ipv6-no}"
2679
fi
2680
echo "threading support         ${thread_type-no}"
2681
echo "SDL support               ${sdl-no}"
2682
if enabled sdl_too_old; then
2683
    echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support."
2684
fi
2685
echo "Sun medialib support      ${mlib-no}"
2686
echo "AVISynth enabled          ${avisynth-no}"
2687
echo "libdc1394 support         ${libdc1394-no}"
2688
echo "libdirac enabled          ${libdirac-no}"
2689
echo "libfaac enabled           ${libfaac-no}"
2690
echo "libfaad enabled           ${libfaad-no}"
2691
echo "libfaad dlopened          ${libfaadbin-no}"
2692
echo "libgsm enabled            ${libgsm-no}"
2693
echo "libmp3lame enabled        ${libmp3lame-no}"
2694
echo "libnut enabled            ${libnut-no}"
2695
echo "libopencore-amrnb support ${libopencore_amrnb-no}"
2696
echo "libopencore-amrwb support ${libopencore_amrwb-no}"
2697
echo "libopenjpeg enabled       ${libopenjpeg-no}"
2698
echo "libschroedinger enabled   ${libschroedinger-no}"
2699
echo "libspeex enabled          ${libspeex-no}"
2700
echo "libtheora enabled         ${libtheora-no}"
2701
echo "libvorbis enabled         ${libvorbis-no}"
2702
echo "libx264 enabled           ${libx264-no}"
2703
echo "libxvid enabled           ${libxvid-no}"
2704
echo "zlib enabled              ${zlib-no}"
2705
echo "bzlib enabled             ${bzlib-no}"
2706
echo
2707

    
2708
for type in decoder encoder hwaccel parser demuxer muxer protocol filter bsf indev outdev; do
2709
    echo "Enabled ${type}s:"
2710
    eval list=\$$(toupper $type)_LIST
2711
    for part in $list; do
2712
        enabled $part && echo ${part%_*}
2713
    done | sort | pr -3 -t
2714
    echo
2715
done
2716

    
2717
license="LGPL version 2.1 or later"
2718
if enabled nonfree; then
2719
    license="nonfree and unredistributable"
2720
elif enabled gplv3; then
2721
    license="GPL version 3 or later"
2722
elif enabled lgplv3; then
2723
    license="LGPL version 3 or later"
2724
elif enabled gpl; then
2725
    license="GPL version 2 or later"
2726
fi
2727

    
2728
echo "License: $license"
2729

    
2730
echo "Creating config.mak and config.h..."
2731

    
2732
enabled stripping || strip="echo skipping strip"
2733

    
2734
cat > config.mak <<EOF
2735
# Automatically generated by configure - do not modify!
2736
ifndef FFMPEG_CONFIG_MAK
2737
FFMPEG_CONFIG_MAK=1
2738
FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION
2739
prefix=$prefix
2740
LIBDIR=\$(DESTDIR)$libdir
2741
SHLIBDIR=\$(DESTDIR)$shlibdir
2742
INCDIR=\$(DESTDIR)$incdir
2743
BINDIR=\$(DESTDIR)$bindir
2744
DATADIR=\$(DESTDIR)$datadir
2745
MANDIR=\$(DESTDIR)$mandir
2746
SRC_PATH="$source_path"
2747
SRC_PATH_BARE=$source_path
2748
BUILD_ROOT="$PWD"
2749
ARCH=$arch
2750
CC=$cc
2751
AS=$as
2752
LD=$ld
2753
DEPCC=$dep_cc
2754
YASM=$yasmexe
2755
AR=$ar
2756
RANLIB=$ranlib
2757
LN_S=$ln_s
2758
STRIP=$strip
2759
CPPFLAGS=$CPPFLAGS
2760
CFLAGS=$CFLAGS
2761
ASFLAGS=$ASFLAGS
2762
CC_O=$CC_O
2763
LDFLAGS=$LDFLAGS
2764
FFSERVERLDFLAGS=$FFSERVERLDFLAGS
2765
SHFLAGS=$SHFLAGS
2766
YASMFLAGS=$YASMFLAGS
2767
BUILDSUF=$build_suffix
2768
FULLNAME=$FULLNAME
2769
LIBPREF=$LIBPREF
2770
LIBSUF=$LIBSUF
2771
LIBNAME=$LIBNAME
2772
SLIBPREF=$SLIBPREF
2773
SLIBSUF=$SLIBSUF
2774
EXESUF=$EXESUF
2775
EXTRA_VERSION=$extra_version
2776
DEPFLAGS=$DEPFLAGS
2777
CCDEP=$CCDEP
2778
ASDEP=$ASDEP
2779
CC_DEPFLAGS=$CC_DEPFLAGS
2780
AS_DEPFLAGS=$AS_DEPFLAGS
2781
HOSTCC=$host_cc
2782
HOSTCFLAGS=$host_cflags
2783
HOSTEXESUF=$HOSTEXESUF
2784
HOSTLDFLAGS=$host_ldflags
2785
HOSTLIBS=$host_libs
2786
TARGET_EXEC=$target_exec
2787
TARGET_PATH=$target_path
2788
SDL_LIBS=$sdl_libs
2789
SDL_CFLAGS=$sdl_cflags
2790
LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
2791
EXTRALIBS=$extralibs
2792
EOF
2793

    
2794
get_version(){
2795
    name=$1
2796
    file=$source_path/$2
2797
    eval $(grep "#define ${name}_VERSION_M" "$file" | awk '{ print $2"="$3 }')
2798
    eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO
2799
    lcname=$(tolower $name)
2800
    eval echo "${lcname}_VERSION=\$${name}_VERSION" >> config.mak
2801
    eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> config.mak
2802
}
2803

    
2804
get_version LIBSWSCALE  libswscale/swscale.h
2805
get_version LIBPOSTPROC libpostproc/postprocess.h
2806
get_version LIBAVCODEC  libavcodec/avcodec.h
2807
get_version LIBAVDEVICE libavdevice/avdevice.h
2808
get_version LIBAVFORMAT libavformat/avformat.h
2809
get_version LIBAVUTIL   libavutil/avutil.h
2810
get_version LIBAVFILTER libavfilter/avfilter.h
2811

    
2812
enabled shared && cat >> config.mak <<EOF
2813
LIBTARGET=${LIBTARGET}
2814
SLIBNAME=${SLIBNAME}
2815
SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}
2816
SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}
2817
SLIB_CREATE_DEF_CMD=${SLIB_CREATE_DEF_CMD}
2818
SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}
2819
SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}
2820
SLIB_UNINSTALL_EXTRA_CMD=${SLIB_UNINSTALL_EXTRA_CMD}
2821
EOF
2822

    
2823
enabled asmalign_pot || align_shift="1 <<"
2824

    
2825
cat > $TMPH <<EOF
2826
/* Automatically generated by configure - do not modify! */
2827
#ifndef FFMPEG_CONFIG_H
2828
#define FFMPEG_CONFIG_H
2829
#define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
2830
#define FFMPEG_LICENSE "$(c_escape $license)"
2831
#define FFMPEG_DATADIR "$(eval c_escape $datadir)"
2832
#define CC_TYPE "$cc_type"
2833
#define CC_VERSION $cc_version
2834
#define restrict $_restrict
2835
#define ASMALIGN(ZEROBITS) ".align $align_shift " #ZEROBITS "\\n\\t"
2836
#define EXTERN_PREFIX "${extern_prefix}"
2837
#define EXTERN_ASM ${extern_prefix}
2838
EOF
2839

    
2840
if enabled small || disabled optimizations; then
2841
    echo "#define av_always_inline"  >> $TMPH
2842
fi
2843

    
2844
print_config ARCH_   $TMPH config.mak $ARCH_LIST
2845
print_config HAVE_   $TMPH config.mak $HAVE_LIST
2846
print_config CONFIG_ $TMPH config.mak $CONFIG_LIST       \
2847
                                      $CONFIG_EXTRA      \
2848
                                      $DECODER_LIST      \
2849
                                      $ENCODER_LIST      \
2850
                                      $HWACCEL_LIST      \
2851
                                      $PARSER_LIST       \
2852
                                      $BSF_LIST          \
2853
                                      $DEMUXER_LIST      \
2854
                                      $MUXER_LIST        \
2855
                                      $FILTER_LIST       \
2856
                                      $PROTOCOL_LIST     \
2857
                                      $INDEV_LIST        \
2858
                                      $OUTDEV_LIST       \
2859

    
2860
echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
2861
echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
2862

    
2863
# Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
2864
cmp -s $TMPH config.h &&
2865
    echo "config.h is unchanged" ||
2866
    mv -f $TMPH config.h
2867

    
2868
# build tree in object directory if source path is different from current one
2869
if enabled source_path_used; then
2870
    DIRS="
2871
        doc
2872
        libavcodec
2873
        libavcodec/$arch
2874
        libavdevice
2875
        libavfilter
2876
        libavformat
2877
        libavutil
2878
        libavutil/$arch
2879
        libpostproc
2880
        libswscale
2881
        libswscale/$arch
2882
        tests
2883
        tools
2884
    "
2885
    FILES="
2886
        Makefile
2887
        common.mak
2888
        subdir.mak
2889
        doc/texi2pod.pl
2890
        libavcodec/Makefile
2891
        libavdevice/Makefile
2892
        libavfilter/Makefile
2893
        libavformat/Makefile
2894
        libavutil/Makefile
2895
        libpostproc/Makefile
2896
        libswscale/Makefile
2897
    "
2898
    for dir in $DIRS ; do
2899
        mkdir -p $dir
2900
    done
2901
    for f in $FILES ; do
2902
        $ln_s "$source_path/$f" $f
2903
    done
2904
fi
2905

    
2906

    
2907
# build pkg-config files
2908

    
2909
pkgconfig_generate(){
2910
name=$1
2911
shortname=${name#lib}${build_suffix}
2912
comment=$2
2913
version=$3
2914
libs=$4
2915
requires=$5
2916
cat <<EOF > $name/$name.pc
2917
prefix=$prefix
2918
exec_prefix=\${prefix}
2919
libdir=$libdir
2920
includedir=$incdir
2921

    
2922
Name: $name
2923
Description: $comment
2924
Version: $version
2925
Requires: $(enabled shared || echo $requires)
2926
Requires.private: $(enabled shared && echo $requires)
2927
Conflicts:
2928
Libs: -L\${libdir} -l${shortname} $(enabled shared || echo $libs)
2929
Libs.private: $(enabled shared && echo $libs)
2930
Cflags: -I\${includedir}
2931
EOF
2932
cat <<EOF > $name/$name-uninstalled.pc
2933
prefix=
2934
exec_prefix=
2935
libdir=\${pcfiledir}
2936
includedir=${source_path}
2937

    
2938
Name: $name
2939
Description: $comment
2940
Version: $version
2941
Requires: $requires
2942
Conflicts:
2943
Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
2944
Cflags: -I\${includedir}
2945
EOF
2946
}
2947

    
2948
pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION"
2949
pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
2950
pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
2951
pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
2952
enabled avfilter &&
2953
    pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
2954
enabled postproc &&
2955
    pkgconfig_generate libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION"
2956
pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"