Autodetect PowerPC vs. PowerPC64.
[ffmpeg.git] / configure
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.log]
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-avconv         disable avconv build
85   --disable-ffplay         disable ffplay build
86   --disable-ffprobe        disable ffprobe build
87   --disable-ffserver       disable ffserver build
88   --disable-avdevice       disable libavdevice build
89   --disable-avcodec        disable libavcodec build
90   --disable-avformat       disable libavformat build
91   --disable-swscale        disable libswscale build
92   --disable-postproc       disable libpostproc build
93   --disable-avfilter       disable video filter support [no]
94   --disable-pthreads       disable pthreads [auto]
95   --enable-w32threads      use Win32 threads [no]
96   --enable-x11grab         enable X11 grabbing [no]
97   --disable-network        disable network support [no]
98   --enable-gray            enable full grayscale support (slower color)
99   --disable-swscale-alpha  disable alpha channel support in swscale
100   --disable-fastdiv        disable table-based division
101   --enable-small           optimize for size instead of speed
102   --disable-aandct         disable AAN DCT code
103   --disable-dct            disable DCT code
104   --disable-fft            disable FFT code
105   --disable-golomb         disable Golomb code
106   --disable-huffman        disable Huffman code
107   --disable-lpc            disable LPC code
108   --disable-mdct           disable MDCT code
109   --disable-rdft           disable RDFT code
110   --enable-vaapi           enable VAAPI code [autodetect]
111   --enable-vdpau           enable VDPAU code [autodetect]
112   --disable-dxva2          disable DXVA2 code
113   --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
114   --enable-hardcoded-tables use hardcoded tables instead of runtime generation
115   --enable-memalign-hack   emulate memalign, interferes with memory debuggers
116   --disable-everything     disable all components listed below
117   --disable-encoder=NAME   disable encoder NAME
118   --enable-encoder=NAME    enable encoder NAME
119   --disable-encoders       disable all encoders
120   --disable-decoder=NAME   disable decoder NAME
121   --enable-decoder=NAME    enable decoder NAME
122   --disable-decoders       disable all decoders
123   --disable-hwaccel=NAME   disable hwaccel NAME
124   --enable-hwaccel=NAME    enable hwaccel NAME
125   --disable-hwaccels       disable all hwaccels
126   --disable-muxer=NAME     disable muxer NAME
127   --enable-muxer=NAME      enable muxer NAME
128   --disable-muxers         disable all muxers
129   --disable-demuxer=NAME   disable demuxer NAME
130   --enable-demuxer=NAME    enable demuxer NAME
131   --disable-demuxers       disable all demuxers
132   --enable-parser=NAME     enable parser NAME
133   --disable-parser=NAME    disable parser NAME
134   --disable-parsers        disable all parsers
135   --enable-bsf=NAME        enable bitstream filter NAME
136   --disable-bsf=NAME       disable bitstream filter NAME
137   --disable-bsfs           disable all bitstream filters
138   --enable-protocol=NAME   enable protocol NAME
139   --disable-protocol=NAME  disable protocol NAME
140   --disable-protocols      disable all protocols
141   --disable-indev=NAME     disable input device NAME
142   --disable-outdev=NAME    disable output device NAME
143   --disable-indevs         disable input devices
144   --disable-outdevs        disable output devices
145   --disable-devices        disable all devices
146   --enable-filter=NAME     enable filter NAME
147   --disable-filter=NAME    disable filter NAME
148   --disable-filters        disable all filters
149   --list-decoders          show all available decoders
150   --list-encoders          show all available encoders
151   --list-hwaccels          show all available hardware accelerators
152   --list-muxers            show all available muxers
153   --list-demuxers          show all available demuxers
154   --list-parsers           show all available parsers
155   --list-protocols         show all available protocols
156   --list-bsfs              show all available bitstream filters
157   --list-indevs            show all available input devices
158   --list-outdevs           show all available output devices
159   --list-filters           show all available filters
160
161 External library support:
162   --enable-avisynth        enable reading of AVISynth script files [no]
163   --enable-bzlib           enable bzlib [autodetect]
164   --enable-libcelt         enable CELT/Opus decoding via libcelt [no]
165   --enable-frei0r          enable frei0r video filtering
166   --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
167   --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
168   --enable-libopencv       enable video filtering via libopencv [no]
169   --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
170                            and libraw1394 [no]
171   --enable-libdirac        enable Dirac support via libdirac [no]
172   --enable-libfaac         enable FAAC support via libfaac [no]
173   --enable-libfreetype     enable libfreetype [no]
174   --enable-libgsm          enable GSM support via libgsm [no]
175   --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
176   --enable-libnut          enable NUT (de)muxing via libnut,
177                            native (de)muxer exists [no]
178   --enable-libopenjpeg     enable JPEG 2000 decoding via OpenJPEG [no]
179   --enable-librtmp         enable RTMP[E] support via librtmp [no]
180   --enable-libschroedinger enable Dirac support via libschroedinger [no]
181   --enable-libspeex        enable Speex decoding via libspeex [no]
182   --enable-libtheora       enable Theora encoding via libtheora [no]
183   --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
184   --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
185   --enable-libvorbis       enable Vorbis encoding via libvorbis,
186                            native implementation exists [no]
187   --enable-libvpx          enable VP8 support via libvpx [no]
188   --enable-libx264         enable H.264 encoding via x264 [no]
189   --enable-libxavs         enable AVS encoding via xavs [no]
190   --enable-libxvid         enable Xvid encoding via xvidcore,
191                            native MPEG-4/Xvid encoder exists [no]
192   --enable-openal          enable OpenAL 1.1 capture support [no]
193   --enable-mlib            enable Sun medialib [no]
194   --enable-zlib            enable zlib [autodetect]
195
196 Advanced options (experts only):
197   --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
198   --enable-cross-compile   assume a cross-compiler is used
199   --sysroot=PATH           root of cross-build tree
200   --sysinclude=PATH        location of cross-build system headers
201   --target-os=OS           compiler targets OS [$target_os]
202   --target-exec=CMD        command to run executables on target
203   --target-path=DIR        path to view of build directory on target
204   --nm=NM                  use nm tool
205   --ar=AR                  use archive tool AR [$ar_default]
206   --as=AS                  use assembler AS [$as_default]
207   --cc=CC                  use C compiler CC [$cc_default]
208   --ld=LD                  use linker LD
209   --host-cc=HOSTCC         use host C compiler HOSTCC
210   --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
211   --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
212   --host-libs=HLIBS        use libs HLIBS when linking for host
213   --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
214   --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
215   --extra-libs=ELIBS       add ELIBS [$ELIBS]
216   --extra-version=STRING   version string suffix []
217   --build-suffix=SUFFIX    library name suffix []
218   --progs-suffix=SUFFIX    program name suffix []
219   --arch=ARCH              select architecture [$arch]
220   --cpu=CPU                select the minimum required CPU (affects
221                            instruction selection, may crash on older CPUs)
222   --disable-asm            disable all assembler optimizations
223   --disable-altivec        disable AltiVec optimizations
224   --disable-amd3dnow       disable 3DNow! optimizations
225   --disable-amd3dnowext    disable 3DNow! extended optimizations
226   --disable-mmx            disable MMX optimizations
227   --disable-mmx2           disable MMX2 optimizations
228   --disable-sse            disable SSE optimizations
229   --disable-ssse3          disable SSSE3 optimizations
230   --disable-avx            disable AVX optimizations
231   --disable-armv5te        disable armv5te optimizations
232   --disable-armv6          disable armv6 optimizations
233   --disable-armv6t2        disable armv6t2 optimizations
234   --disable-armvfp         disable ARM VFP optimizations
235   --disable-iwmmxt         disable iwmmxt optimizations
236   --disable-mmi            disable MMI optimizations
237   --disable-neon           disable neon optimizations
238   --disable-vis            disable VIS optimizations
239   --disable-yasm           disable use of yasm assembler
240   --enable-pic             build position-independent code
241   --malloc-prefix=PFX      prefix malloc and related names with PFX
242   --enable-sram            allow use of on-chip SRAM
243   --disable-symver         disable symbol versioning
244   --optflags               override optimization-related compiler flags
245
246 Developer options (useful when working on FFmpeg itself):
247   --disable-debug          disable debugging symbols
248   --enable-debug=LEVEL     set the debug level [$debuglevel]
249   --disable-optimizations  disable compiler optimizations
250   --enable-extra-warnings  enable more compiler warnings
251   --disable-stripping      disable stripping of executables and shared libraries
252   --samples=PATH           location of test samples for FATE, if not set use
253                            \$FATE_SAMPLES at make invocation time.
254
255 NOTE: Object files are built at the place where configure is launched.
256 EOF
257   exit 0
258 }
259
260 quotes='""'
261
262 log(){
263     echo "$@" >> $logfile
264 }
265
266 log_file(){
267     log BEGIN $1
268     pr -n -t $1 >> $logfile
269     log END $1
270 }
271
272 echolog(){
273     log "$@"
274     echo "$@"
275 }
276
277 warn(){
278     log "WARNING: $*"
279     WARNINGS="${WARNINGS}WARNING: $*\n"
280 }
281
282 die(){
283     echolog "$@"
284     cat <<EOF
285
286 If you think configure made a mistake, make sure you are using the latest
287 version from Git.  If the latest version fails, report the problem to the
288 ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
289 EOF
290     if disabled logging; then
291         cat <<EOF
292 Rerun configure with logging enabled (do not use --disable-logging), and
293 include the log this produces with your report.
294 EOF
295     else
296 cat <<EOF
297 Include the log file "$logfile" produced by configure as this will help
298 solving the problem.
299 EOF
300     fi
301     exit 1
302 }
303
304 # Avoid locale weirdness, besides we really just want to translate ASCII.
305 toupper(){
306     echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
307 }
308
309 tolower(){
310     echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
311 }
312
313 c_escape(){
314     echo "$*" | sed 's/["\\]/\\\0/g'
315 }
316
317 sh_quote(){
318     v=$(echo "$1" | sed "s/'/'\\\\''/g")
319     test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'"
320     echo "$v"
321 }
322
323 cleanws(){
324     echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//'
325 }
326
327 filter(){
328     pat=$1
329     shift
330     for v; do
331         eval "case $v in $pat) echo $v ;; esac"
332     done
333 }
334
335 filter_out(){
336     pat=$1
337     shift
338     for v; do
339         eval "case $v in $pat) ;; *) echo $v ;; esac"
340     done
341 }
342
343 map(){
344     m=$1
345     shift
346     for v; do eval $m; done
347 }
348
349 set_all(){
350     value=$1
351     shift
352     for var in $*; do
353         eval $var=$value
354     done
355 }
356
357 set_weak(){
358     value=$1
359     shift
360     for var; do
361         eval : \${$var:=$value}
362     done
363 }
364
365 set_safe(){
366     var=$1
367     shift
368     eval $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')='$*'
369 }
370
371 get_safe(){
372     eval echo \$$(echo "$1" | sed 's/[^A-Za-z0-9_]/_/g')
373 }
374
375 pushvar(){
376     for var in $*; do
377         eval level=\${${var}_level:=0}
378         eval ${var}_${level}="\$$var"
379         eval ${var}_level=$(($level+1))
380     done
381 }
382
383 popvar(){
384     for var in $*; do
385         eval level=\${${var}_level:-0}
386         test $level = 0 && continue
387         eval level=$(($level-1))
388         eval $var="\${${var}_${level}}"
389         eval ${var}_level=$level
390         eval unset ${var}_${level}
391     done
392 }
393
394 enable(){
395     set_all yes $*
396 }
397
398 disable(){
399     set_all no $*
400 }
401
402 enable_weak(){
403     set_weak yes $*
404 }
405
406 disable_weak(){
407     set_weak no $*
408 }
409
410 enable_safe(){
411     for var; do
412         enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
413     done
414 }
415
416 disable_safe(){
417     for var; do
418         disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
419     done
420 }
421
422 do_enable_deep(){
423     for var; do
424         enabled $var && continue
425         eval sel="\$${var}_select"
426         eval sgs="\$${var}_suggest"
427         pushvar var sgs
428         enable_deep $sel
429         popvar sgs
430         enable_deep_weak $sgs
431         popvar var
432     done
433 }
434
435 enable_deep(){
436     do_enable_deep $*
437     enable $*
438 }
439
440 enable_deep_weak(){
441     do_enable_deep $*
442     enable_weak $*
443 }
444
445 enabled(){
446     test "${1#!}" = "$1" && op== || op=!=
447     eval test "x\$${1#!}" $op "xyes"
448 }
449
450 disabled(){
451     test "${1#!}" = "$1" && op== || op=!=
452     eval test "x\$${1#!}" $op "xno"
453 }
454
455 enabled_all(){
456     for opt; do
457         enabled $opt || return 1
458     done
459 }
460
461 disabled_all(){
462     for opt; do
463         disabled $opt || return 1
464     done
465 }
466
467 enabled_any(){
468     for opt; do
469         enabled $opt && return 0
470     done
471 }
472
473 disabled_any(){
474     for opt; do
475         disabled $opt && return 0
476     done
477     return 1
478 }
479
480 set_default(){
481     for opt; do
482         eval : \${$opt:=\$${opt}_default}
483     done
484 }
485
486 is_in(){
487     value=$1
488     shift
489     for var in $*; do
490         [ $var = $value ] && return 0
491     done
492     return 1
493 }
494
495 check_deps(){
496     for cfg; do
497         cfg="${cfg#!}"
498         enabled ${cfg}_checking && die "Circular dependency for $cfg."
499         disabled ${cfg}_checking && continue
500         enable ${cfg}_checking
501
502         eval dep_all="\$${cfg}_deps"
503         eval dep_any="\$${cfg}_deps_any"
504         eval dep_sel="\$${cfg}_select"
505         eval dep_sgs="\$${cfg}_suggest"
506         eval dep_ifa="\$${cfg}_if"
507         eval dep_ifn="\$${cfg}_if_any"
508
509         pushvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
510         check_deps $dep_all $dep_any $dep_sel $dep_sgs $dep_ifa $dep_ifn
511         popvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
512
513         [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
514         [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
515         enabled_all  $dep_all || disable $cfg
516         enabled_any  $dep_any || disable $cfg
517         disabled_any $dep_sel && disable $cfg
518
519         if enabled $cfg; then
520             eval dep_extralibs="\$${cfg}_extralibs"
521             test -n "$dep_extralibs" && add_extralibs $dep_extralibs
522             enable_deep $dep_sel
523             enable_deep_weak $dep_sgs
524         fi
525
526         disable ${cfg}_checking
527     done
528 }
529
530 print_config_h(){
531     enabled $1 && v=1 || v=0
532     echo "#define $2 $v"
533 }
534
535 print_config_mak(){
536     enabled $1 && v= || v=!
537     echo "$v$2=yes"
538 }
539
540 print_config_asm(){
541     enabled $1 && echo "%define $2"
542 }
543
544 print_config(){
545     pfx=$1
546     files=$2
547     shift 2
548     for cfg; do
549         ucname="$(toupper $cfg)"
550         for f in $files; do
551             "print_config_${f##*.}" $cfg ${pfx}${ucname} >>$f
552         done
553     done
554 }
555
556 print_enabled(){
557     test "$1" = -n && end=" " && shift || end="\n"
558     suf=$1
559     shift
560     for v; do
561         enabled $v && printf "%s$end" ${v%$suf};
562     done
563 }
564
565 append(){
566     var=$1
567     shift
568     eval "$var=\"\$$var $*\""
569 }
570
571 prepend(){
572     var=$1
573     shift
574     eval "$var=\"$* \$$var\""
575 }
576
577 add_cppflags(){
578     append CPPFLAGS $($filter_cppflags "$@")
579 }
580
581 add_cflags(){
582     append CFLAGS $($filter_cflags "$@")
583 }
584
585 add_asflags(){
586     append ASFLAGS $($filter_asflags "$@")
587 }
588
589 add_ldflags(){
590     append LDFLAGS "$@"
591 }
592
593 add_extralibs(){
594     prepend extralibs "$@"
595 }
596
597 check_cmd(){
598     log "$@"
599     "$@" >> $logfile 2>&1
600 }
601
602 check_cc(){
603     log check_cc "$@"
604     cat > $TMPC
605     log_file $TMPC
606     check_cmd $cc $CPPFLAGS $CFLAGS "$@" -c -o $TMPO $TMPC
607 }
608
609 check_cpp(){
610     log check_cpp "$@"
611     cat > $TMPC
612     log_file $TMPC
613     check_cmd $cc $CPPFLAGS $CFLAGS "$@" -E -o $TMPO $TMPC
614 }
615
616 check_as(){
617     log check_as "$@"
618     cat > $TMPC
619     log_file $TMPC
620     check_cmd $as $CPPFLAGS $ASFLAGS "$@" -c -o $TMPO $TMPC
621 }
622
623 check_asm(){
624     log check_asm "$@"
625     name="$1"
626     code="$2"
627     shift 2
628     disable $name
629     check_as "$@" <<EOF && enable $name
630 void foo(void){ __asm__ volatile($code); }
631 EOF
632 }
633
634 check_yasm(){
635     log check_yasm "$@"
636     echo "$1" > $TMPS
637     log_file $TMPS
638     shift 1
639     check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
640 }
641
642 check_ld(){
643     log check_ld "$@"
644     flags=''
645     libs=''
646     for f; do
647         test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f"
648     done
649     check_cc $($filter_cflags $flags) || return
650     check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $libs $extralibs
651 }
652
653 check_cppflags(){
654     log check_cppflags "$@"
655     set -- $($filter_cppflags "$@")
656     check_cc "$@" <<EOF && append CPPFLAGS "$@"
657 int x;
658 EOF
659 }
660
661 check_cflags(){
662     log check_cflags "$@"
663     set -- $($filter_cflags "$@")
664     check_cc "$@" <<EOF && append CFLAGS "$@"
665 int x;
666 EOF
667 }
668
669 test_ldflags(){
670     log test_ldflags "$@"
671     check_ld "$@" <<EOF
672 int main(void){ return 0; }
673 EOF
674 }
675
676 check_ldflags(){
677     log check_ldflags "$@"
678     test_ldflags "$@" && add_ldflags "$@"
679 }
680
681 check_header(){
682     log check_header "$@"
683     header=$1
684     shift
685     disable_safe $header
686     check_cpp "$@" <<EOF && enable_safe $header
687 #include <$header>
688 int x;
689 EOF
690 }
691
692 check_func(){
693     log check_func "$@"
694     func=$1
695     shift
696     disable $func
697     check_ld "$@" <<EOF && enable $func
698 extern int $func();
699 int main(void){ $func(); }
700 EOF
701 }
702
703 check_mathfunc(){
704     log check_mathfunc "$@"
705     func=$1
706     shift
707     disable $func
708     check_ld "$@" <<EOF && enable $func
709 #include <math.h>
710 float foo(float f) { return $func(f); }
711 int main(void){ return 0; }
712 EOF
713 }
714
715 check_func_headers(){
716     log check_func_headers "$@"
717     headers=$1
718     funcs=$2
719     shift 2
720     {
721         for hdr in $headers; do
722             echo "#include <$hdr>"
723         done
724         for func in $funcs; do
725             echo "long check_$func(void) { return (long) $func; }"
726         done
727         echo "int main(void) { return 0; }"
728     } | check_ld "$@" && enable $funcs && enable_safe $headers
729 }
730
731 check_cpp_condition(){
732     log check_cpp_condition "$@"
733     header=$1
734     condition=$2
735     shift 2
736     check_cpp $($filter_cppflags "$@") <<EOF
737 #include <$header>
738 #if !($condition)
739 #error "unsatisfied condition: $condition"
740 #endif
741 EOF
742 }
743
744 check_lib(){
745     log check_lib "$@"
746     header="$1"
747     func="$2"
748     shift 2
749     check_header $header && check_func $func "$@" && add_extralibs "$@"
750 }
751
752 check_lib2(){
753     log check_lib2 "$@"
754     headers="$1"
755     funcs="$2"
756     shift 2
757     check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
758 }
759
760 check_pkg_config(){
761     log check_pkg_config "$@"
762     pkg="$1"
763     headers="$2"
764     funcs="$3"
765     shift 3
766     $pkg_config --exists $pkg 2>/dev/null || return
767     pkg_cflags=$($pkg_config --cflags $pkg)
768     pkg_libs=$($pkg_config --libs $pkg)
769     check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
770         set_safe ${pkg}_cflags $pkg_cflags   &&
771         set_safe ${pkg}_libs   $pkg_libs
772 }
773
774 check_exec(){
775     check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
776 }
777
778 check_exec_crash(){
779     code=$(cat)
780
781     # exit() is not async signal safe.  _Exit (C99) and _exit (POSIX)
782     # are safe but may not be available everywhere.  Thus we use
783     # raise(SIGTERM) instead.  The check is run in a subshell so we
784     # can redirect the "Terminated" message from the shell.  SIGBUS
785     # is not defined by standard C so it is used conditionally.
786
787     (check_exec "$@") >> $logfile 2>&1 <<EOF
788 #include <signal.h>
789 static void sighandler(int sig){
790     raise(SIGTERM);
791 }
792 int main(void){
793     signal(SIGILL, sighandler);
794     signal(SIGFPE, sighandler);
795     signal(SIGSEGV, sighandler);
796 #ifdef SIGBUS
797     signal(SIGBUS, sighandler);
798 #endif
799     { $code }
800 }
801 EOF
802 }
803
804 check_type(){
805     log check_type "$@"
806     headers=$1
807     type=$2
808     shift 2
809     disable_safe "$type"
810     incs=""
811     for hdr in $headers; do
812         incs="$incs
813 #include <$hdr>"
814     done
815     check_cc "$@" <<EOF && enable_safe "$type"
816 $incs
817 $type v;
818 EOF
819 }
820
821 check_struct(){
822     log check_type "$@"
823     headers=$1
824     struct=$2
825     member=$3
826     shift 3
827     disable_safe "${struct}_${member}"
828     incs=""
829     for hdr in $headers; do
830         incs="$incs
831 #include <$hdr>"
832     done
833     check_cc "$@" <<EOF && enable_safe "${struct}_${member}"
834 $incs
835 const void *p = &(($struct *)0)->$member;
836 EOF
837 }
838
839 require(){
840     name="$1"
841     header="$2"
842     func="$3"
843     shift 3
844     check_lib $header $func "$@" || die "ERROR: $name not found"
845 }
846
847 require2(){
848     name="$1"
849     headers="$2"
850     func="$3"
851     shift 3
852     check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
853 }
854
855 require_pkg_config(){
856     pkg="$1"
857     check_pkg_config "$@" || die "ERROR: $pkg not found"
858     add_cflags    $(get_safe ${pkg}_cflags)
859     add_extralibs $(get_safe ${pkg}_libs)
860 }
861
862 check_host_cc(){
863     log check_host_cc "$@"
864     cat > $TMPC
865     log_file $TMPC
866     check_cmd $host_cc $host_cflags "$@" -c -o $TMPO $TMPC
867 }
868
869 check_host_cflags(){
870     log check_host_cflags "$@"
871     check_host_cc "$@" <<EOF && append host_cflags "$@"
872 int x;
873 EOF
874 }
875
876 apply(){
877     file=$1
878     shift
879     "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
880 }
881
882 cp_if_changed(){
883     cmp -s "$1" "$2" && echo "$2 is unchanged" && return
884     mkdir -p "$(dirname $2)"
885     cp -f "$1" "$2"
886 }
887
888 # CONFIG_LIST contains configurable options, while HAVE_LIST is for
889 # system-dependent things.
890
891 COMPONENT_LIST="
892     bsfs
893     decoders
894     demuxers
895     encoders
896     filters
897     hwaccels
898     indevs
899     muxers
900     outdevs
901     parsers
902     protocols
903 "
904
905 CONFIG_LIST="
906     $COMPONENT_LIST
907     aandct
908     ac3dsp
909     avcodec
910     avdevice
911     avfilter
912     avformat
913     avisynth
914     bzlib
915     crystalhd
916     dct
917     doc
918     dwt
919     dxva2
920     fastdiv
921     ffmpeg
922     avconv
923     ffplay
924     ffprobe
925     ffserver
926     fft
927     frei0r
928     golomb
929     gpl
930     gray
931     h264dsp
932     h264pred
933     hardcoded_tables
934     huffman
935     libcelt
936     libdc1394
937     libdirac
938     libfaac
939     libfreetype
940     libgsm
941     libmp3lame
942     libnut
943     libopencore_amrnb
944     libopencore_amrwb
945     libopencv
946     libopenjpeg
947     librtmp
948     libschroedinger
949     libspeex
950     libtheora
951     libvo_aacenc
952     libvo_amrwbenc
953     libvorbis
954     libvpx
955     libx264
956     libxavs
957     libxvid
958     lpc
959     lsp
960     mdct
961     memalign_hack
962     mlib
963     mpegaudiodsp
964     network
965     nonfree
966     openal
967     pic
968     postproc
969     rdft
970     rtpdec
971     runtime_cpudetect
972     shared
973     sinewin
974     small
975     sram
976     static
977     swscale
978     swscale_alpha
979     thumb
980     vaapi
981     vdpau
982     version3
983     x11grab
984     zlib
985 "
986
987 THREADS_LIST='
988     pthreads
989     w32threads
990 '
991
992 ARCH_LIST='
993     alpha
994     arm
995     avr32
996     avr32_ap
997     avr32_uc
998     bfin
999     ia64
1000     m68k
1001     mips
1002     mips64
1003     parisc
1004     ppc
1005     ppc64
1006     s390
1007     sh4
1008     sparc
1009     sparc64
1010     tomi
1011     x86
1012     x86_32
1013     x86_64
1014 '
1015
1016 ARCH_EXT_LIST='
1017     altivec
1018     amd3dnow
1019     amd3dnowext
1020     armv5te
1021     armv6
1022     armv6t2
1023     armvfp
1024     avx
1025     iwmmxt
1026     mmi
1027     mmx
1028     mmx2
1029     neon
1030     ppc4xx
1031     sse
1032     ssse3
1033     vfpv3
1034     vis
1035 '
1036
1037 HAVE_LIST_PUB='
1038     bigendian
1039     fast_unaligned
1040 '
1041
1042 HAVE_LIST="
1043     $ARCH_EXT_LIST
1044     $HAVE_LIST_PUB
1045     $THREADS_LIST
1046     aligned_stack
1047     alsa_asoundlib_h
1048     altivec_h
1049     arpa_inet_h
1050     attribute_may_alias
1051     attribute_packed
1052     bswap
1053     closesocket
1054     cmov
1055     dcbzl
1056     dev_bktr_ioctl_bt848_h
1057     dev_bktr_ioctl_meteor_h
1058     dev_ic_bt8xx_h
1059     dev_video_meteor_ioctl_meteor_h
1060     dev_video_bktr_ioctl_bt848_h
1061     dlfcn_h
1062     dlopen
1063     dos_paths
1064     ebp_available
1065     ebx_available
1066     exp2
1067     exp2f
1068     fast_64bit
1069     fast_clz
1070     fast_cmov
1071     fcntl
1072     fork
1073     getaddrinfo
1074     gethrtime
1075     GetProcessMemoryInfo
1076     GetProcessTimes
1077     getrusage
1078     gnu_as
1079     struct_rusage_ru_maxrss
1080     ibm_asm
1081     inet_aton
1082     inline_asm
1083     isatty
1084     kbhit
1085     ldbrx
1086     llrint
1087     llrintf
1088     local_aligned_16
1089     local_aligned_8
1090     localtime_r
1091     log2
1092     log2f
1093     loongson
1094     lrint
1095     lrintf
1096     lzo1x_999_compress
1097     machine_ioctl_bt848_h
1098     machine_ioctl_meteor_h
1099     malloc_h
1100     MapViewOfFile
1101     memalign
1102     mkstemp
1103     mmap
1104     posix_memalign
1105     round
1106     roundf
1107     sdl
1108     sdl_video_size
1109     setmode
1110     sndio_h
1111     socklen_t
1112     soundcard_h
1113     poll_h
1114     setrlimit
1115     strerror_r
1116     strptime
1117     strtok_r
1118     struct_addrinfo
1119     struct_ipv6_mreq
1120     struct_sockaddr_in6
1121     struct_sockaddr_sa_len
1122     struct_sockaddr_storage
1123     symver
1124     symver_gnu_asm
1125     symver_asm_label
1126     sys_mman_h
1127     sys_resource_h
1128     sys_select_h
1129     sys_soundcard_h
1130     sys_videoio_h
1131     termios_h
1132     threads
1133     trunc
1134     truncf
1135     vfp_args
1136     VirtualAlloc
1137     winsock2_h
1138     xform_asm
1139     xmm_clobbers
1140     yasm
1141 "
1142
1143 # options emitted with CONFIG_ prefix but not available on command line
1144 CONFIG_EXTRA="
1145     avutil
1146     gplv3
1147     lgplv3
1148 "
1149
1150 CMDLINE_SELECT="
1151     $ARCH_EXT_LIST
1152     $CONFIG_LIST
1153     $THREADS_LIST
1154     asm
1155     cross_compile
1156     debug
1157     extra_warnings
1158     logging
1159     optimizations
1160     stripping
1161     symver
1162     yasm
1163 "
1164
1165 PATHS_LIST='
1166     bindir
1167     datadir
1168     incdir
1169     libdir
1170     mandir
1171     prefix
1172     shlibdir
1173 '
1174
1175 CMDLINE_SET="
1176     $PATHS_LIST
1177     ar
1178     arch
1179     as
1180     build_suffix
1181     progs_suffix
1182     cc
1183     cpu
1184     cross_prefix
1185     dep_cc
1186     extra_version
1187     host_cc
1188     host_cflags
1189     host_ldflags
1190     host_libs
1191     host_os
1192     install
1193     ld
1194     logfile
1195     malloc_prefix
1196     nm
1197     optflags
1198     pkg_config
1199     samples
1200     strip
1201     sysinclude
1202     sysroot
1203     target_exec
1204     target_os
1205     target_path
1206 "
1207
1208 CMDLINE_APPEND="
1209     extra_cflags
1210 "
1211
1212 # code dependency declarations
1213
1214 # architecture extensions
1215
1216 armv5te_deps="arm"
1217 armv6_deps="arm"
1218 armv6t2_deps="arm"
1219 armvfp_deps="arm"
1220 iwmmxt_deps="arm"
1221 neon_deps="arm"
1222 vfpv3_deps="armvfp"
1223
1224 mmi_deps="mips"
1225
1226 altivec_deps="ppc"
1227 ppc4xx_deps="ppc"
1228
1229 vis_deps="sparc"
1230
1231 x86_64_suggest="cmov fast_cmov"
1232 amd3dnow_deps="mmx"
1233 amd3dnowext_deps="amd3dnow"
1234 mmx_deps="x86"
1235 mmx2_deps="mmx"
1236 sse_deps="mmx"
1237 ssse3_deps="sse"
1238 avx_deps="ssse3"
1239
1240 aligned_stack_if_any="ppc x86"
1241 fast_64bit_if_any="alpha ia64 mips64 parisc64 ppc64 sparc64 x86_64"
1242 fast_clz_if_any="alpha armv5te avr32 mips ppc x86"
1243 fast_unaligned_if_any="armv6 ppc x86"
1244
1245 need_memalign="altivec neon sse"
1246 inline_asm_deps="!tms470"
1247
1248 symver_if_any="symver_asm_label symver_gnu_asm"
1249
1250 # subsystems
1251 dct_select="rdft"
1252 mdct_select="fft"
1253 rdft_select="fft"
1254 mpegaudiodsp_select="dct"
1255
1256 # decoders / encoders / hardware accelerators
1257 aac_decoder_select="mdct sinewin"
1258 aac_encoder_select="mdct sinewin"
1259 aac_latm_decoder_select="aac_decoder aac_latm_parser"
1260 ac3_decoder_select="mdct ac3dsp ac3_parser"
1261 ac3_encoder_select="mdct ac3dsp"
1262 ac3_fixed_encoder_select="mdct ac3dsp"
1263 alac_encoder_select="lpc"
1264 amrnb_decoder_select="lsp"
1265 amrwb_decoder_select="lsp"
1266 atrac1_decoder_select="mdct sinewin"
1267 atrac3_decoder_select="mdct"
1268 binkaudio_dct_decoder_select="mdct rdft dct sinewin"
1269 binkaudio_rdft_decoder_select="mdct rdft sinewin"
1270 cavs_decoder_select="golomb"
1271 cook_decoder_select="mdct sinewin"
1272 cscd_decoder_suggest="zlib"
1273 dca_decoder_select="mdct"
1274 dnxhd_encoder_select="aandct"
1275 dxa_decoder_select="zlib"
1276 eac3_decoder_select="ac3_decoder"
1277 eac3_encoder_select="mdct ac3dsp"
1278 eamad_decoder_select="aandct"
1279 eatgq_decoder_select="aandct"
1280 eatqi_decoder_select="aandct"
1281 ffv1_decoder_select="golomb"
1282 flac_decoder_select="golomb"
1283 flac_encoder_select="golomb lpc"
1284 flashsv_decoder_select="zlib"
1285 flashsv_encoder_select="zlib"
1286 flashsv2_encoder_select="zlib"
1287 flashsv2_decoder_select="zlib"
1288 flv_decoder_select="h263_decoder"
1289 flv_encoder_select="h263_encoder"
1290 fraps_decoder_select="huffman"
1291 h261_encoder_select="aandct"
1292 h263_decoder_select="h263_parser"
1293 h263_encoder_select="aandct"
1294 h263_vaapi_hwaccel_select="vaapi h263_decoder"
1295 h263i_decoder_select="h263_decoder"
1296 h263p_encoder_select="h263_encoder"
1297 h264_decoder_select="golomb h264dsp h264pred"
1298 h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
1299 h264_dxva2_hwaccel_deps="dxva2api_h"
1300 h264_dxva2_hwaccel_select="dxva2 h264_decoder"
1301 h264_vaapi_hwaccel_select="vaapi"
1302 h264_vdpau_decoder_select="vdpau h264_decoder"
1303 imc_decoder_select="fft mdct sinewin"
1304 jpegls_decoder_select="golomb"
1305 jpegls_encoder_select="golomb"
1306 ljpeg_encoder_select="aandct"
1307 loco_decoder_select="golomb"
1308 mjpeg_encoder_select="aandct"
1309 mlp_decoder_select="mlp_parser"
1310 mp1_decoder_select="mpegaudiodsp"
1311 mp2_decoder_select="mpegaudiodsp"
1312 mp3adu_decoder_select="mpegaudiodsp"
1313 mp3_decoder_select="mpegaudiodsp"
1314 mp3on4_decoder_select="mpegaudiodsp"
1315 mp1float_decoder_select="mpegaudiodsp"
1316 mp2float_decoder_select="mpegaudiodsp"
1317 mp3adufloat_decoder_select="mpegaudiodsp"
1318 mp3float_decoder_select="mpegaudiodsp"
1319 mp3on4float_decoder_select="mpegaudiodsp"
1320 mpeg1video_encoder_select="aandct"
1321 mpeg2video_encoder_select="aandct"
1322 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
1323 mpeg4_encoder_select="h263_encoder"
1324 mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder"
1325 mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder"
1326 mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder"
1327 mpeg2_crystalhd_decoder_select="crystalhd"
1328 mpeg2_dxva2_hwaccel_deps="dxva2api_h"
1329 mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder"
1330 mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder"
1331 mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder"
1332 mpeg4_crystalhd_decoder_select="crystalhd"
1333 mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder"
1334 mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder"
1335 mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
1336 mpeg_xvmc_decoder_select="mpegvideo_decoder"
1337 msmpeg4_crystalhd_decoder_select="crystalhd"
1338 msmpeg4v1_decoder_select="h263_decoder"
1339 msmpeg4v1_encoder_select="h263_encoder"
1340 msmpeg4v2_decoder_select="h263_decoder"
1341 msmpeg4v2_encoder_select="h263_encoder"
1342 msmpeg4v3_decoder_select="h263_decoder"
1343 msmpeg4v3_encoder_select="h263_encoder"
1344 nellymoser_decoder_select="mdct sinewin"
1345 nellymoser_encoder_select="mdct sinewin"
1346 png_decoder_select="zlib"
1347 png_encoder_select="zlib"
1348 qcelp_decoder_select="lsp"
1349 qdm2_decoder_select="mdct rdft mpegaudiodsp"
1350 ra_144_encoder_select="lpc"
1351 rv10_decoder_select="h263_decoder"
1352 rv10_encoder_select="h263_encoder"
1353 rv20_decoder_select="h263_decoder"
1354 rv20_encoder_select="h263_encoder"
1355 rv30_decoder_select="golomb h264pred"
1356 rv40_decoder_select="golomb h264pred"
1357 shorten_decoder_select="golomb"
1358 sipr_decoder_select="lsp"
1359 snow_decoder_select="dwt"
1360 snow_encoder_select="aandct dwt"
1361 sonic_decoder_select="golomb"
1362 sonic_encoder_select="golomb"
1363 sonic_ls_encoder_select="golomb"
1364 svq1_encoder_select="aandct"
1365 svq3_decoder_select="golomb h264dsp h264pred"
1366 svq3_decoder_suggest="zlib"
1367 theora_decoder_select="vp3_decoder"
1368 tiff_decoder_suggest="zlib"
1369 tiff_encoder_suggest="zlib"
1370 truehd_decoder_select="mlp_decoder"
1371 tscc_decoder_select="zlib"
1372 twinvq_decoder_select="mdct lsp sinewin"
1373 vc1_decoder_select="h263_decoder"
1374 vc1_crystalhd_decoder_select="crystalhd"
1375 vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex"
1376 vc1_dxva2_hwaccel_select="dxva2 vc1_decoder"
1377 vc1_vaapi_hwaccel_select="vaapi vc1_decoder"
1378 vc1_vdpau_decoder_select="vdpau vc1_decoder"
1379 vc1image_decoder_select="vc1_decoder"
1380 vorbis_decoder_select="mdct"
1381 vorbis_encoder_select="mdct"
1382 vp6_decoder_select="huffman"
1383 vp6a_decoder_select="vp6_decoder"
1384 vp6f_decoder_select="vp6_decoder"
1385 vp8_decoder_select="h264pred"
1386 wmapro_decoder_select="mdct sinewin"
1387 wmav1_decoder_select="mdct sinewin"
1388 wmav1_encoder_select="mdct sinewin"
1389 wmav2_decoder_select="mdct sinewin"
1390 wmav2_encoder_select="mdct sinewin"
1391 wmavoice_decoder_select="lsp rdft dct mdct sinewin"
1392 wmv1_decoder_select="h263_decoder"
1393 wmv1_encoder_select="h263_encoder"
1394 wmv2_decoder_select="h263_decoder"
1395 wmv2_encoder_select="h263_encoder"
1396 wmv3_decoder_select="vc1_decoder"
1397 wmv3_crystalhd_decoder_select="crystalhd"
1398 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
1399 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
1400 wmv3_vdpau_decoder_select="vc1_vdpau_decoder"
1401 wmv3image_decoder_select="wmv3_decoder"
1402 zlib_decoder_select="zlib"
1403 zlib_encoder_select="zlib"
1404 zmbv_decoder_select="zlib"
1405 zmbv_encoder_select="zlib"
1406
1407 crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
1408 vaapi_deps="va_va_h"
1409 vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1410
1411 # parsers
1412 h264_parser_select="golomb h264dsp h264pred"
1413
1414 # external libraries
1415 libcelt_decoder_deps="libcelt"
1416 libdirac_decoder_deps="libdirac !libschroedinger"
1417 libdirac_encoder_deps="libdirac"
1418 libfaac_encoder_deps="libfaac"
1419 libgsm_decoder_deps="libgsm"
1420 libgsm_encoder_deps="libgsm"
1421 libgsm_ms_decoder_deps="libgsm"
1422 libgsm_ms_encoder_deps="libgsm"
1423 libmp3lame_encoder_deps="libmp3lame"
1424 libopencore_amrnb_decoder_deps="libopencore_amrnb"
1425 libopencore_amrnb_encoder_deps="libopencore_amrnb"
1426 libopencore_amrwb_decoder_deps="libopencore_amrwb"
1427 libopenjpeg_decoder_deps="libopenjpeg"
1428 libschroedinger_decoder_deps="libschroedinger"
1429 libschroedinger_encoder_deps="libschroedinger"
1430 libspeex_decoder_deps="libspeex"
1431 libtheora_encoder_deps="libtheora"
1432 libvo_aacenc_encoder_deps="libvo_aacenc"
1433 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
1434 libvorbis_encoder_deps="libvorbis"
1435 libvpx_decoder_deps="libvpx"
1436 libvpx_encoder_deps="libvpx"
1437 libx264_encoder_deps="libx264"
1438 libxavs_encoder_deps="libxavs"
1439 libxvid_encoder_deps="libxvid"
1440
1441 # demuxers / muxers
1442 ac3_demuxer_select="ac3_parser"
1443 asf_stream_muxer_select="asf_muxer"
1444 avisynth_demuxer_deps="avisynth"
1445 dirac_demuxer_select="dirac_parser"
1446 eac3_demuxer_select="ac3_parser"
1447 flac_demuxer_select="flac_parser"
1448 ipod_muxer_select="mov_muxer"
1449 libnut_demuxer_deps="libnut"
1450 libnut_muxer_deps="libnut"
1451 matroska_audio_muxer_select="matroska_muxer"
1452 matroska_demuxer_suggest="zlib bzlib"
1453 mov_demuxer_suggest="zlib"
1454 mp3_demuxer_select="mpegaudio_parser"
1455 mp4_muxer_select="mov_muxer"
1456 mpegtsraw_demuxer_select="mpegts_demuxer"
1457 mxf_d10_muxer_select="mxf_muxer"
1458 ogg_demuxer_select="golomb"
1459 psp_muxer_select="mov_muxer"
1460 rtp_demuxer_select="sdp_demuxer"
1461 rtpdec_select="asf_demuxer rm_demuxer rtp_protocol mpegts_demuxer mov_demuxer"
1462 rtsp_demuxer_select="http_protocol rtpdec"
1463 rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol"
1464 sap_demuxer_select="sdp_demuxer"
1465 sap_muxer_select="rtp_muxer rtp_protocol"
1466 sdp_demuxer_select="rtpdec"
1467 spdif_muxer_select="aac_parser"
1468 tg2_muxer_select="mov_muxer"
1469 tgp_muxer_select="mov_muxer"
1470 w64_demuxer_deps="wav_demuxer"
1471
1472 # indevs / outdevs
1473 alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
1474 alsa_outdev_deps="alsa_asoundlib_h"
1475 bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
1476 dshow_indev_deps="IBaseFilter"
1477 dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid"
1478 dv1394_indev_deps="dv1394 dv_demuxer"
1479 fbdev_indev_deps="linux_fb_h"
1480 jack_indev_deps="jack_jack_h sem_timedwait"
1481 lavfi_indev_deps="avfilter"
1482 libdc1394_indev_deps="libdc1394"
1483 openal_indev_deps="openal"
1484 oss_indev_deps_any="soundcard_h sys_soundcard_h"
1485 oss_outdev_deps_any="soundcard_h sys_soundcard_h"
1486 sdl_outdev_deps="sdl"
1487 sndio_indev_deps="sndio_h"
1488 sndio_outdev_deps="sndio_h"
1489 v4l_indev_deps="linux_videodev_h"
1490 v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
1491 vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
1492 vfwcap_indev_extralibs="-lavicap32"
1493 x11_grab_device_indev_deps="x11grab XShmCreateImage"
1494 x11_grab_device_indev_extralibs="-lX11 -lXext -lXfixes"
1495
1496 # protocols
1497 gopher_protocol_deps="network"
1498 http_protocol_deps="network"
1499 http_protocol_select="tcp_protocol"
1500 mmsh_protocol_select="http_protocol"
1501 mmst_protocol_deps="network"
1502 rtmp_protocol_select="tcp_protocol"
1503 rtp_protocol_select="udp_protocol"
1504 tcp_protocol_deps="network"
1505 udp_protocol_deps="network"
1506
1507 # filters
1508 abuffer_filter_deps="strtok_r"
1509 aformat_filter_deps="strtok_r"
1510 amovie_filter_deps="avcodec avformat"
1511 blackframe_filter_deps="gpl"
1512 boxblur_filter_deps="gpl"
1513 cropdetect_filter_deps="gpl"
1514 delogo_filter_deps="gpl"
1515 drawtext_filter_deps="libfreetype"
1516 frei0r_filter_deps="frei0r dlopen strtok_r"
1517 frei0r_src_filter_deps="frei0r dlopen strtok_r"
1518 hqdn3d_filter_deps="gpl"
1519 movie_filter_deps="avcodec avformat"
1520 mp_filter_deps="gpl avcodec"
1521 mptestsrc_filter_deps="gpl"
1522 negate_filter_deps="lut_filter"
1523 ocv_filter_deps="libopencv"
1524 scale_filter_deps="swscale"
1525 yadif_filter_deps="gpl"
1526
1527 # libraries
1528 avdevice_deps="avcodec avformat"
1529 avformat_deps="avcodec"
1530 postproc_deps="gpl"
1531
1532 # programs
1533 ffmpeg_deps="avcodec avformat swscale"
1534 ffmpeg_select="buffer_filter buffersink_filter"
1535 avconv_deps="avcodec avformat swscale"
1536 avconv_select="buffer_filter"
1537 ffplay_deps="avcodec avformat swscale sdl"
1538 ffplay_select="buffersink_filter rdft"
1539 ffprobe_deps="avcodec avformat"
1540 ffserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer"
1541 ffserver_extralibs='$ldl'
1542
1543 doc_deps="texi2html"
1544
1545 # tests
1546
1547 test_deps(){
1548     suf1=$1
1549     suf2=$2
1550     shift 2
1551     for v; do
1552         dep=${v%=*}
1553         tests=${v#*=}
1554         for name in ${tests}; do
1555             eval ${name}_test_deps="'${dep}$suf1 ${dep}$suf2'"
1556         done
1557     done
1558 }
1559
1560 test_deps _encoder _decoder                                             \
1561     adpcm_g726=g726                                                     \
1562     adpcm_ima_qt                                                        \
1563     adpcm_ima_wav                                                       \
1564     adpcm_ms                                                            \
1565     adpcm_swf                                                           \
1566     adpcm_yamaha=adpcm_yam                                              \
1567     alac                                                                \
1568     asv1                                                                \
1569     asv2                                                                \
1570     bmp                                                                 \
1571     dnxhd="dnxhd_1080i dnxhd_720p dnxhd_720p_rd"                        \
1572     dvvideo="dv dv50"                                                   \
1573     ffv1                                                                \
1574     flac                                                                \
1575     flashsv                                                             \
1576     flv                                                                 \
1577     gif                                                                 \
1578     h261                                                                \
1579     h263="h263 h263p"                                                   \
1580     huffyuv                                                             \
1581     jpegls                                                              \
1582     mjpeg="jpg mjpeg ljpeg"                                             \
1583     mp2                                                                 \
1584     mpeg1video="mpeg mpeg1b"                                            \
1585     mpeg2video="mpeg2 mpeg2thread"                                      \
1586     mpeg4="mpeg4 mpeg4adv mpeg4nr mpeg4thread error rc"                 \
1587     msmpeg4v3=msmpeg4                                                   \
1588     msmpeg4v2                                                           \
1589     pbm=pbmpipe                                                         \
1590     pcx                                                                 \
1591     pgm="pgm pgmpipe"                                                   \
1592     png                                                                 \
1593     ppm="ppm ppmpipe"                                                   \
1594     rawvideo="rgb yuv"                                                  \
1595     roq                                                                 \
1596     rv10                                                                \
1597     rv20                                                                \
1598     sgi                                                                 \
1599     snow="snow snowll"                                                  \
1600     svq1                                                                \
1601     targa=tga                                                           \
1602     tiff                                                                \
1603     wmav1                                                               \
1604     wmav2                                                               \
1605     wmv1                                                                \
1606     wmv2                                                                \
1607
1608 test_deps _muxer _demuxer                                               \
1609     aiff                                                                \
1610     pcm_alaw=alaw                                                       \
1611     asf                                                                 \
1612     au                                                                  \
1613     avi                                                                 \
1614     dv=dv_fmt                                                           \
1615     ffm                                                                 \
1616     flv=flv_fmt                                                         \
1617     gxf                                                                 \
1618     matroska=mkv                                                        \
1619     mmf                                                                 \
1620     mov                                                                 \
1621     pcm_mulaw=mulaw                                                     \
1622     mxf="mxf mxf_d10"                                                   \
1623     nut                                                                 \
1624     ogg                                                                 \
1625     rawvideo=pixfmt                                                     \
1626     rm                                                                  \
1627     swf                                                                 \
1628     mpegts=ts                                                           \
1629     voc                                                                 \
1630     wav                                                                 \
1631     yuv4mpegpipe=yuv4mpeg                                               \
1632
1633 ac3_fixed_test_deps="ac3_fixed_encoder ac3_decoder rm_muxer rm_demuxer"
1634 mpg_test_deps="mpeg1system_muxer mpegps_demuxer"
1635
1636 # default parameters
1637
1638 logfile="config.log"
1639
1640 # installation paths
1641 prefix_default="/usr/local"
1642 bindir_default='${prefix}/bin'
1643 datadir_default='${prefix}/share/ffmpeg'
1644 incdir_default='${prefix}/include'
1645 libdir_default='${prefix}/lib'
1646 mandir_default='${prefix}/share/man'
1647 shlibdir_default="$libdir_default"
1648
1649 # toolchain
1650 ar_default="ar"
1651 cc_default="gcc"
1652 cc_version=\"unknown\"
1653 host_cc_default="gcc"
1654 install="install"
1655 ln_s="ln -sf"
1656 nm_default="nm"
1657 objformat="elf"
1658 pkg_config_default=pkg-config
1659 ranlib="ranlib"
1660 strip_default="strip"
1661 yasmexe="yasm"
1662 nogas=":"
1663
1664 nm_opts='-g'
1665
1666 # machine
1667 arch_default=$(uname -m)
1668 cpu="generic"
1669
1670 # OS
1671 target_os_default=$(tolower $(uname -s))
1672 host_os=$target_os_default
1673
1674 # configurable options
1675 enable avcodec
1676 enable avdevice
1677 enable avfilter
1678 enable avformat
1679 enable avutil
1680 enable asm
1681 enable debug
1682 enable doc
1683 enable fastdiv
1684 enable ffmpeg
1685 enable avconv
1686 enable ffplay
1687 enable ffprobe
1688 enable ffserver
1689 enable network
1690 enable optimizations
1691 enable postproc
1692 enable protocols
1693 enable static
1694 enable stripping
1695 enable swscale
1696 enable swscale_alpha
1697
1698 # build settings
1699 SHFLAGS='-shared -Wl,-soname,$$(@F)'
1700 FFSERVERLDFLAGS=-Wl,-E
1701 LIBPREF="lib"
1702 LIBSUF=".a"
1703 FULLNAME='$(NAME)$(BUILDSUF)'
1704 LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)'
1705 SLIBPREF="lib"
1706 SLIBSUF=".so"
1707 SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
1708 SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
1709 SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
1710 LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
1711 SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
1712 SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
1713
1714 AS_O='-o $@'
1715 CC_O='-o $@'
1716
1717 host_cflags='-D_ISOC99_SOURCE -O3 -g'
1718 host_libs='-lm'
1719
1720 target_path='$(CURDIR)'
1721
1722 # since the object filename is not given with the -MM flag, the compiler
1723 # is only able to print the basename, and we must add the path ourselves
1724 DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
1725 DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -MM'
1726
1727 # find source path
1728 if test -f configure; then
1729     source_path=.
1730 else
1731     source_path=$(cd $(dirname "$0"); pwd)
1732     echo "$source_path" | grep -q '[[:blank:]]' &&
1733         die "Out of tree builds are impossible with whitespace in source path."
1734     test -e "$source_path/config.h" &&
1735         die "Out of tree builds are impossible with config.h in source dir."
1736 fi
1737
1738 for v in "$@"; do
1739     r=${v#*=}
1740     l=${v%"$r"}
1741     r=$(sh_quote "$r")
1742     FFMPEG_CONFIGURATION="${FFMPEG_CONFIGURATION# } ${l}${r}"
1743 done
1744
1745 find_things(){
1746     thing=$1
1747     pattern=$2
1748     file=$source_path/$3
1749     sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file"
1750 }
1751
1752 ENCODER_LIST=$(find_things  encoder  ENC      libavcodec/allcodecs.c)
1753 DECODER_LIST=$(find_things  decoder  DEC      libavcodec/allcodecs.c)
1754 HWACCEL_LIST=$(find_things  hwaccel  HWACCEL  libavcodec/allcodecs.c)
1755 PARSER_LIST=$(find_things   parser   PARSER   libavcodec/allcodecs.c)
1756 BSF_LIST=$(find_things      bsf      BSF      libavcodec/allcodecs.c)
1757 MUXER_LIST=$(find_things    muxer    _MUX     libavformat/allformats.c)
1758 DEMUXER_LIST=$(find_things  demuxer  DEMUX    libavformat/allformats.c)
1759 OUTDEV_LIST=$(find_things   outdev   OUTDEV   libavdevice/alldevices.c)
1760 INDEV_LIST=$(find_things    indev    _IN      libavdevice/alldevices.c)
1761 PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c)
1762 FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
1763
1764 find_tests(){
1765     map "echo ${2}\${v}_test" $(ls "$source_path"/tests/ref/$1 | grep -v '[^-a-z0-9_]')
1766 }
1767
1768 ACODEC_TESTS=$(find_tests acodec)
1769 VCODEC_TESTS=$(find_tests vsynth1)
1770 LAVF_TESTS=$(find_tests lavf)
1771 LAVFI_TESTS=$(find_tests lavfi)
1772 SEEK_TESTS=$(find_tests seek seek_)
1773
1774 pcm_test_deps=$(map 'echo ${v%_*}_decoder $v' $(filter pcm_* $ENCODER_LIST))
1775
1776 for n in $COMPONENT_LIST; do
1777     v=$(toupper ${n%s})_LIST
1778     eval enable \$$v
1779     eval ${n}_if_any="\$$v"
1780 done
1781
1782 enable $ARCH_EXT_LIST $ACODEC_TESTS $VCODEC_TESTS $LAVF_TESTS $LAVFI_TESTS $SEEK_TESTS
1783
1784 die_unknown(){
1785     echo "Unknown option \"$1\"."
1786     echo "See $0 --help for available options."
1787     exit 1
1788 }
1789
1790 show_list() {
1791     suffix=_$1
1792     shift
1793     echo $* | sed s/$suffix//g | tr ' ' '\n' | sort | pr -3 -t
1794     exit 0
1795 }
1796
1797 for opt do
1798     optval="${opt#*=}"
1799     case "$opt" in
1800     --extra-ldflags=*) add_ldflags $optval
1801     ;;
1802     --extra-libs=*) add_extralibs $optval
1803     ;;
1804     --disable-devices) disable $INDEV_LIST $OUTDEV_LIST
1805     ;;
1806     --enable-debug=*) debuglevel="$optval"
1807     ;;
1808     --disable-everything)
1809     map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST
1810     ;;
1811     --enable-*=*|--disable-*=*)
1812     eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/')
1813     is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
1814     eval list=\$$(toupper $thing)_LIST
1815     name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
1816     $action $(filter "$name" $list)
1817     ;;
1818     --enable-?*|--disable-?*)
1819     eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
1820     if is_in $option $COMPONENT_LIST; then
1821         test $action = disable && action=unset
1822         eval $action \$$(toupper ${option%s})_LIST
1823     elif is_in $option $CMDLINE_SELECT; then
1824         $action $option
1825     else
1826         die_unknown $opt
1827     fi
1828     ;;
1829     --list-*)
1830         NAME="${opt#--list-}"
1831         is_in $NAME $COMPONENT_LIST || die_unknown $opt
1832         NAME=${NAME%s}
1833         eval show_list $NAME \$$(toupper $NAME)_LIST
1834     ;;
1835     --help|-h) show_help
1836     ;;
1837     *)
1838     optname="${opt%%=*}"
1839     optname="${optname#--}"
1840     optname=$(echo "$optname" | sed 's/-/_/g')
1841     if is_in $optname $CMDLINE_SET; then
1842         eval $optname='$optval'
1843     elif is_in $optname $CMDLINE_APPEND; then
1844         append $optname "$optval"
1845     else
1846          die_unknown $opt
1847     fi
1848     ;;
1849     esac
1850 done
1851
1852 disabled logging && logfile=/dev/null
1853
1854 echo "# $0 $FFMPEG_CONFIGURATION" > $logfile
1855 set >> $logfile
1856
1857 test -n "$cross_prefix" && enable cross_compile
1858
1859 if enabled cross_compile; then
1860     test -n "$arch" && test -n "$target_os" ||
1861         die "Must specify target arch and OS when cross-compiling"
1862 fi
1863
1864 set_default arch target_os
1865
1866 ar_default="${cross_prefix}${ar_default}"
1867 cc_default="${cross_prefix}${cc_default}"
1868 nm_default="${cross_prefix}${nm_default}"
1869 pkg_config_default="${cross_prefix}${pkg_config_default}"
1870 ranlib="${cross_prefix}${ranlib}"
1871 strip_default="${cross_prefix}${strip_default}"
1872
1873 sysinclude_default="${sysroot}/usr/include"
1874
1875 set_default cc nm pkg_config strip sysinclude
1876 enabled cross_compile || host_cc_default=$cc
1877 set_default host_cc
1878
1879 if ! $pkg_config --version >/dev/null 2>&1; then
1880     warn "$pkg_config not found, library detection may fail."
1881     pkg_config=false
1882 fi
1883
1884 exesuf() {
1885     case $1 in
1886         mingw32*|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;;
1887     esac
1888 }
1889
1890 EXESUF=$(exesuf $target_os)
1891 HOSTEXESUF=$(exesuf $host_os)
1892
1893 # set temporary file name
1894 : ${TMPDIR:=$TEMPDIR}
1895 : ${TMPDIR:=$TMP}
1896 : ${TMPDIR:=/tmp}
1897
1898 if ! check_cmd mktemp -u XXXXXX; then
1899     # simple replacement for missing mktemp
1900     # NOT SAFE FOR GENERAL USE
1901     mktemp(){
1902         echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$"
1903     }
1904 fi
1905
1906 tmpfile(){
1907     tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 &&
1908         (set -C; exec > $tmp) 2>/dev/null ||
1909         die "Unable to create temporary file in $TMPDIR."
1910     append TMPFILES $tmp
1911     eval $1=$tmp
1912 }
1913
1914 trap 'rm -f -- $TMPFILES' EXIT
1915
1916 tmpfile TMPC  .c
1917 tmpfile TMPE  $EXESUF
1918 tmpfile TMPH  .h
1919 tmpfile TMPO  .o
1920 tmpfile TMPS  .S
1921 tmpfile TMPV  .ver
1922 tmpfile TMPSH .sh
1923 tmpfile TMPASM .asm
1924
1925 unset -f mktemp
1926
1927 chmod +x $TMPE
1928
1929 # make sure we can execute files in $TMPDIR
1930 cat > $TMPSH 2>> $logfile <<EOF
1931 #! /bin/sh
1932 EOF
1933 chmod +x $TMPSH >> $logfile 2>&1
1934 if ! $TMPSH >> $logfile 2>&1; then
1935     cat <<EOF
1936 Unable to create and execute files in $TMPDIR.  Set the TMPDIR environment
1937 variable to another directory and make sure that it is not mounted noexec.
1938 EOF
1939     die "Sanity test failed."
1940 fi
1941
1942 filter_cflags=echo
1943 filter_cppflags=echo
1944 filter_asflags=echo
1945
1946 if   $cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
1947     cc_type=llvm_gcc
1948     cc_version=__VERSION__
1949     gcc_extra_ver=$(expr "$($cc --version | head -n1)" : '.*\((.*)\)')
1950     cc_ident="llvm-gcc $($cc -dumpversion) $gcc_extra_ver"
1951     CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1952     AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1953     speed_cflags='-O3'
1954     size_cflags='-Os'
1955 elif $cc -v 2>&1 | grep -qi ^gcc; then
1956     cc_type=gcc
1957     cc_version=__VERSION__
1958     gcc_version=$($cc --version | head -n1)
1959     gcc_basever=$($cc -dumpversion)
1960     gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)')
1961     gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)")
1962     cc_ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver")
1963     if ! $cc -dumpversion | grep -q '^2\.'; then
1964         CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1965         AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
1966     fi
1967     speed_cflags='-O3'
1968     size_cflags='-Os'
1969 elif $cc --version 2>/dev/null | grep -q Intel; then
1970     cc_type=icc
1971     cc_version="AV_STRINGIFY(__INTEL_COMPILER)"
1972     cc_ident=$($cc --version | head -n1)
1973     icc_version=$($cc -dumpversion)
1974     CC_DEPFLAGS='-MMD'
1975     AS_DEPFLAGS='-MMD'
1976     speed_cflags='-O3'
1977     size_cflags='-Os'
1978     noopt_cflags='-O1'
1979 elif $cc -v 2>&1 | grep -q xlc; then
1980     cc_type=xlc
1981     cc_version="AV_STRINGIFY(__IBMC__)"
1982     cc_ident=$($cc -qversion 2>/dev/null | head -n1)
1983     speed_cflags='-O5'
1984     size_cflags='-O5 -qcompact'
1985 elif $cc -V 2>/dev/null | grep -q Compaq; then
1986     cc_type=ccc
1987     cc_version="AV_STRINGIFY(__DECC_VER)"
1988     cc_ident=$($cc -V | head -n1 | cut -d' ' -f1-3)
1989     DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -M'
1990     debuglevel=3
1991     add_ldflags -Wl,-z,now # calls to libots crash without this
1992     speed_cflags='-fast'
1993     size_cflags='-O1'
1994 elif $cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then
1995     test -d "$sysroot" || die "No valid sysroot specified."
1996     cc_type=armcc
1997     cc_version="AV_STRINGIFY(__ARMCC_VERSION)"
1998     cc_ident=$($cc --vsn | head -n1)
1999     armcc_conf="$PWD/armcc.conf"
2000     $cc --arm_linux_configure                 \
2001         --arm_linux_config_file="$armcc_conf" \
2002         --configure_sysroot="$sysroot"        \
2003         --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
2004         die "Error creating armcc configuration file."
2005     $cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc
2006     cc="$cc --arm_linux_config_file=$armcc_conf --translate_gcc"
2007     as_default="${cross_prefix}gcc"
2008     CC_DEPFLAGS='-MMD'
2009     AS_DEPFLAGS='-MMD'
2010     speed_cflags='-O3'
2011     size_cflags='-Os'
2012     filter_asflags="filter_out -W${armcc_opt}*"
2013 elif $cc -version 2>/dev/null | grep -q TMS470; then
2014     cc_type=tms470
2015     cc_version="AV_STRINGIFY(__TI_COMPILER_VERSION__)"
2016     cc_ident=$($cc -version | head -n1 | tr -s ' ')
2017     cc="$cc --gcc --abi=eabi -eo=.o -mc -me"
2018     CC_O='-fr=$(@D)'
2019     as_default="${cross_prefix}gcc"
2020     ld_default="${cross_prefix}gcc"
2021     TMPO=$(basename $TMPC .c).o
2022     append TMPFILES $TMPO
2023     add_cflags -D__gnuc_va_list=va_list -D__USER_LABEL_PREFIX__=
2024     CC_DEPFLAGS='-ppa -ppd=$(@:.o=.d)'
2025     AS_DEPFLAGS='-MMD'
2026     speed_cflags='-O3 -mf=5'
2027     size_cflags='-O3 -mf=2'
2028     filter_cflags=tms470_flags
2029     tms470_flags(){
2030         for flag; do
2031             case $flag in
2032                 -march=*|-mcpu=*)
2033                     case "${flag#*=}" in
2034                         armv7-a|cortex-a*)      echo -mv=7a8 ;;
2035                         armv7-r|cortex-r*)      echo -mv=7r4 ;;
2036                         armv7-m|cortex-m*)      echo -mv=7m3 ;;
2037                         armv6*|arm11*)          echo -mv=6   ;;
2038                         armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
2039                                                 echo -mv=5e  ;;
2040                         armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
2041                     esac
2042                     ;;
2043                 -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
2044                 -mfpu=vfp)      echo --float_support=vfpv2        ;;
2045                 -mfpu=vfpv3)    echo --float_support=vfpv3        ;;
2046                 -msoft-float)   echo --float_support=vfplib       ;;
2047                 -O[0-3]|-mf=*)  echo $flag                        ;;
2048                 -g)             echo -g -mn                       ;;
2049                 -pds=*)         echo $flag                        ;;
2050             esac
2051         done
2052     }
2053 elif $cc -v 2>&1 | grep -q clang; then
2054     cc_type=clang
2055     $cc -dM -E $TMPC | grep -q __clang_version__ &&
2056         cc_version=__clang_version__ || cc_version=__VERSION__
2057     cc_ident=$($cc --version | head -n1)
2058     CC_DEPFLAGS='-MMD'
2059     AS_DEPFLAGS='-MMD'
2060     speed_cflags='-O3'
2061     size_cflags='-Os'
2062 elif $cc -V 2>&1 | grep -q Sun; then
2063     cc_type=suncc
2064     cc_version="AV_STRINGIFY(__SUNPRO_C)"
2065     cc_ident=$($cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
2066     DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
2067     DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -xM1'
2068     add_ldflags -xc99
2069     speed_cflags='-O5'
2070     size_cflags='-O5 -xspace'
2071     filter_cflags=suncc_flags
2072     suncc_flags(){
2073         for flag; do
2074             case $flag in
2075                 -march=*|-mcpu=*)
2076                     case "${flag#*=}" in
2077                         native)                   echo -xtarget=native       ;;
2078                         v9|niagara)               echo -xarch=sparc          ;;
2079                         ultrasparc)               echo -xarch=sparcvis       ;;
2080                         ultrasparc3|niagara2)     echo -xarch=sparcvis2      ;;
2081                         i586|pentium)             echo -xchip=pentium        ;;
2082                         i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
2083                         pentium3*|c3-2)           echo -xtarget=pentium3     ;;
2084                         pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
2085                         pentium4*)          echo -xtarget=pentium4           ;;
2086                         prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
2087                         *-sse3)             echo -xarch=sse3                 ;;
2088                         core2)              echo -xarch=ssse3 -xchip=core2   ;;
2089                         amdfam10|barcelona)       echo -xarch=sse4_1         ;;
2090                         athlon-4|athlon-[mx]p)    echo -xarch=ssea           ;;
2091                         k8|opteron|athlon64|athlon-fx)
2092                                                   echo -xarch=sse2a          ;;
2093                         athlon*)                  echo -xarch=pentium_proa   ;;
2094                     esac
2095                     ;;
2096                 -std=c99)             echo -xc99              ;;
2097                 -fomit-frame-pointer) echo -xregs=frameptr    ;;
2098                 -fPIC)                echo -KPIC -xcode=pic32 ;;
2099                 -W*,*)                echo $flag              ;;
2100                 -f*-*|-W*)                                    ;;
2101                 *)                    echo $flag              ;;
2102             esac
2103         done
2104     }
2105 elif $cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
2106     cc_type=pathscale
2107     cc_version=__PATHSCALE__
2108     cc_ident=$($cc -v 2>&1 | head -n1 | tr -d :)
2109     CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
2110     AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
2111     speed_cflags='-O2'
2112     size_cflags='-Os'
2113     filter_cflags='filter_out -Wdisabled-optimization'
2114 elif $cc -v 2>&1 | grep -q Open64; then
2115     cc_type=open64
2116     cc_version=__OPEN64__
2117     cc_ident=$($cc -v 2>&1 | head -n1 | tr -d :)
2118     CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
2119     AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@'
2120     speed_cflags='-O2'
2121     size_cflags='-Os'
2122     filter_cflags='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
2123 fi
2124
2125 test -n "$cc_type" && enable $cc_type ||
2126     warn "Unknown C compiler $cc, unable to select optimal CFLAGS"
2127
2128 : ${as_default:=$cc}
2129 : ${dep_cc_default:=$cc}
2130 : ${ld_default:=$cc}
2131 set_default ar as dep_cc ld
2132
2133 test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD
2134 test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD
2135
2136 add_cflags $extra_cflags
2137 add_asflags $extra_cflags
2138
2139 if test -n "$sysroot"; then
2140     case "$cc_type" in
2141         gcc|llvm_gcc|clang)
2142             add_cppflags --sysroot="$sysroot"
2143             add_ldflags --sysroot="$sysroot"
2144         ;;
2145         tms470)
2146             add_cppflags -I"$sysinclude"
2147             add_ldflags  --sysroot="$sysroot"
2148         ;;
2149     esac
2150 fi
2151
2152 if test "$cpu" = host; then
2153     enabled cross_compile && die "--cpu=host makes no sense when cross-compiling."
2154
2155     case "$cc_type" in
2156         gcc|llvm_gcc)
2157             check_native(){
2158                 $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
2159                 sed -n "/cc1.*$1=/{
2160                             s/.*$1=\\([^ ]*\\).*/\\1/
2161                             p
2162                             q
2163                         }" $TMPE
2164             }
2165             cpu=$(check_native -march || check_native -mcpu)
2166         ;;
2167     esac
2168
2169     test "${cpu:-host}" = host && die "--cpu=host not supported with compiler $cc"
2170 fi
2171
2172 # Deal with common $arch aliases
2173 case "$arch" in
2174     arm*)
2175         arch="arm"
2176     ;;
2177     mips|mipsel|IP*)
2178         arch="mips"
2179     ;;
2180     mips64*)
2181         arch="mips"
2182         subarch="mips64"
2183     ;;
2184     parisc|hppa)
2185         arch="parisc"
2186     ;;
2187     parisc64|hppa64)
2188         arch="parisc"
2189         subarch="parisc64"
2190     ;;
2191     "Power Macintosh"|ppc|powerpc|ppc64|powerpc64)
2192         arch="ppc"
2193     ;;
2194     s390|s390x)
2195         arch="s390"
2196     ;;
2197     sh4|sh)
2198         arch="sh4"
2199     ;;
2200     sun4u|sparc64)
2201         arch="sparc"
2202         subarch="sparc64"
2203     ;;
2204     i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64)
2205         arch="x86"
2206     ;;
2207 esac
2208
2209 is_in $arch $ARCH_LIST || warn "unknown architecture $arch"
2210 enable $arch
2211
2212 # Add processor-specific flags
2213 if test "$cpu" = generic; then
2214     : do nothing
2215 elif enabled ppc; then
2216
2217     case $(tolower $cpu) in
2218         601|ppc601|powerpc601)
2219             cpuflags="-mcpu=601"
2220             disable altivec
2221         ;;
2222         603*|ppc603*|powerpc603*)
2223             cpuflags="-mcpu=603"
2224             disable altivec
2225         ;;
2226         604*|ppc604*|powerpc604*)
2227             cpuflags="-mcpu=604"
2228             disable altivec
2229         ;;
2230         g3|75*|ppc75*|powerpc75*)
2231             cpuflags="-mcpu=750 -mpowerpc-gfxopt"
2232             disable altivec
2233         ;;
2234         g4|745*|ppc745*|powerpc745*)
2235             cpuflags="-mcpu=7450 -mpowerpc-gfxopt"
2236         ;;
2237         74*|ppc74*|powerpc74*)
2238             cpuflags="-mcpu=7400 -mpowerpc-gfxopt"
2239         ;;
2240         g5|970|ppc970|powerpc970|power4*)
2241             cpuflags="-mcpu=970 -mpowerpc-gfxopt -mpowerpc64"
2242         ;;
2243         cell)
2244             cpuflags="-mcpu=cell"
2245             enable ldbrx
2246         ;;
2247         e500v2)
2248             cpuflags="-mcpu=8548 -mhard-float -mfloat-gprs=double"
2249             disable altivec
2250         ;;
2251         e500)
2252             cpuflags="-mcpu=8540 -mhard-float"
2253             disable altivec
2254         ;;
2255     esac
2256
2257 elif enabled x86; then
2258
2259     case $cpu in
2260         i[345]86|pentium)
2261             cpuflags="-march=$cpu"
2262             disable mmx
2263         ;;
2264         # targets that do NOT support conditional mov (cmov)
2265         pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
2266             cpuflags="-march=$cpu"
2267             disable cmov
2268         ;;
2269         # targets that do support conditional mov (cmov)
2270         i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64*|k8*|opteron*|athlon-fx|core2|amdfam10|barcelona|atom)
2271             cpuflags="-march=$cpu"
2272             enable cmov
2273             enable fast_cmov
2274         ;;
2275         # targets that do support conditional mov but on which it's slow
2276         pentium4|pentium4m|prescott|nocona)
2277             cpuflags="-march=$cpu"
2278             enable cmov
2279             disable fast_cmov
2280         ;;
2281     esac
2282
2283 elif enabled sparc; then
2284
2285     case $cpu in
2286         niagara)
2287             cpuflags="-mcpu=$cpu"
2288             disable vis
2289         ;;
2290         sparc64)
2291             cpuflags="-mcpu=v9"
2292         ;;
2293     esac
2294
2295 elif enabled arm; then
2296
2297     case $cpu in
2298         armv*)
2299             cpuflags="-march=$cpu"
2300             subarch=$(echo $cpu | sed 's/[^a-z0-9]//g')
2301         ;;
2302         *)
2303             cpuflags="-mcpu=$cpu"
2304             case $cpu in
2305                 cortex-a*)                               subarch=armv7a  ;;
2306                 cortex-r*)                               subarch=armv7r  ;;
2307                 cortex-m*)                 enable thumb; subarch=armv7m  ;;
2308                 arm11*)                                  subarch=armv6   ;;
2309                 arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) subarch=armv5te ;;
2310                 armv4*|arm7*|arm9[24]*)                  subarch=armv4   ;;
2311             esac
2312         ;;
2313     esac
2314
2315 elif enabled alpha; then
2316
2317     enabled ccc && cpuflags="-arch $cpu" || cpuflags="-mcpu=$cpu"
2318
2319 elif enabled bfin; then
2320
2321     cpuflags="-mcpu=$cpu"
2322
2323 elif enabled mips; then
2324
2325     cpuflags="-march=$cpu"
2326
2327 elif enabled avr32; then
2328
2329     case $cpu in
2330         ap7[02]0[0-2])
2331             subarch="avr32_ap"
2332             cpuflags="-mpart=$cpu"
2333         ;;
2334         ap)
2335             subarch="avr32_ap"
2336             cpuflags="-march=$cpu"
2337         ;;
2338         uc3[ab]*)
2339             subarch="avr32_uc"
2340             cpuflags="-mcpu=$cpu"
2341         ;;
2342         uc)
2343             subarch="avr32_uc"
2344             cpuflags="-march=$cpu"
2345         ;;
2346     esac
2347
2348 fi
2349
2350 add_cflags $cpuflags
2351 add_asflags $cpuflags
2352
2353 # compiler sanity check
2354 check_exec <<EOF
2355 int main(void){ return 0; }
2356 EOF
2357 if test "$?" != 0; then
2358     echo "$cc is unable to create an executable file."
2359     if test -z "$cross_prefix" && ! enabled cross_compile ; then
2360         echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
2361         echo "Only do this if you know what cross compiling means."
2362     fi
2363     die "C compiler test failed."
2364 fi
2365
2366 add_cppflags -D_ISOC99_SOURCE
2367 check_cflags -std=c99
2368 check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
2369 #include <stdlib.h>
2370 EOF
2371 check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE
2372 #include <stdlib.h>
2373 EOF
2374
2375 check_host_cflags -std=c99
2376 check_host_cflags -Wall
2377
2378 case "$arch" in
2379     alpha|ia64|mips|parisc|sparc)
2380         spic=$shared
2381     ;;
2382     x86)
2383         subarch="x86_32"
2384         check_cc <<EOF && subarch="x86_64"
2385         int test[(int)sizeof(char*) - 7];
2386 EOF
2387         if test "$subarch" = "x86_64"; then
2388             spic=$shared
2389         fi
2390     ;;
2391     ppc)
2392         check_cc <<EOF && subarch="ppc64"
2393         int test[(int)sizeof(char*) - 7];
2394 EOF
2395     ;;
2396 esac
2397
2398 enable $subarch
2399 enabled spic && enable pic
2400
2401 # OS specific
2402 case $target_os in
2403     haiku)
2404         prefix_default="/boot/common"
2405         network_extralibs="-lnetwork"
2406         host_libs=
2407         ;;
2408     sunos)
2409         FFSERVERLDFLAGS=""
2410         SHFLAGS='-shared -Wl,-h,$$(@F)'
2411         enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
2412         network_extralibs="-lsocket -lnsl"
2413         add_cppflags -D__EXTENSIONS__
2414         nm_opts='-P -g'
2415         ;;
2416     netbsd)
2417         disable symver
2418         oss_indev_extralibs="-lossaudio"
2419         oss_outdev_extralibs="-lossaudio"
2420         ;;
2421     openbsd)
2422         enable malloc_aligned
2423         # On OpenBSD 4.5. the compiler does not use PIC unless
2424         # explicitly using -fPIC. FFmpeg builds fine without PIC,
2425         # however the generated executable will not do anything
2426         # (simply quits with exit-code 1, no crash, no output).
2427         # Thus explicitly enable PIC here.
2428         enable pic
2429         disable symver
2430         SHFLAGS='-shared'
2431         oss_indev_extralibs="-lossaudio"
2432         oss_outdev_extralibs="-lossaudio"
2433         ;;
2434     dragonfly)
2435         enable malloc_aligned
2436         disable symver
2437         ;;
2438     freebsd)
2439         enable malloc_aligned
2440         ;;
2441     bsd/os)
2442         add_extralibs -lpoll -lgnugetopt
2443         strip="strip -d"
2444         ;;
2445     darwin)
2446         enable malloc_aligned
2447         gas="gas-preprocessor.pl $cc"
2448         enabled ppc && add_asflags -force_cpusubtype_ALL
2449         SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
2450         enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
2451         strip="${strip} -x"
2452         add_ldflags -Wl,-dynamic,-search_paths_first
2453         SLIBSUF=".dylib"
2454         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
2455         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
2456         FFSERVERLDFLAGS=-Wl,-bind_at_load
2457         objformat="macho"
2458         enabled x86_64 && objformat="macho64"
2459         enabled_any pic shared ||
2460             { check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
2461         ;;
2462     mingw32*)
2463         if test $target_os = "mingw32ce"; then
2464             disable network
2465         else
2466             target_os=mingw32
2467         fi
2468         LIBTARGET=i386
2469         if enabled x86_64; then
2470             enable malloc_aligned
2471             LIBTARGET=x64
2472         elif enabled arm; then
2473             LIBTARGET=arm-wince
2474         fi
2475         shlibdir_default="$bindir_default"
2476         SLIBPREF=""
2477         SLIBSUF=".dll"
2478         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
2479         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
2480         SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
2481         SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
2482         SLIB_INSTALL_LINKS=
2483         SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
2484         SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
2485         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'
2486         objformat="win32"
2487         enable dos_paths
2488         check_cflags -fno-common
2489         check_cpp_condition _mingw.h "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) \
2490                                       || (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
2491                 die "ERROR: MinGW runtime version must be >= 3.15."
2492         add_cppflags -U__STRICT_ANSI__
2493         ;;
2494     cygwin*)
2495         target_os=cygwin
2496         shlibdir_default="$bindir_default"
2497         SLIBPREF="cyg"
2498         SLIBSUF=".dll"
2499         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
2500         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
2501         SHFLAGS='-shared -Wl,--enable-auto-image-base'
2502         objformat="win32"
2503         enable dos_paths
2504         check_cflags -fno-common
2505         add_cppflags -U__STRICT_ANSI__
2506         ;;
2507     *-dos|freedos|opendos)
2508         network_extralibs="-lsocket"
2509         objformat="coff"
2510         enable dos_paths
2511         add_cppflags -U__STRICT_ANSI__
2512         ;;
2513     linux)
2514         add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
2515         enable dv1394
2516         ;;
2517     irix*)
2518         target_os=irix
2519         ranlib="echo ignoring ranlib"
2520         ;;
2521     os/2*)
2522         strip="lxlite -CS"
2523         ln_s="cp -f"
2524         objformat="aout"
2525         add_cppflags -D_GNU_SOURCE
2526         add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
2527         SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
2528         FFSERVERLDFLAGS=""
2529         LIBSUF="_s.a"
2530         SLIBPREF=""
2531         SLIBSUF=".dll"
2532         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
2533         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)'
2534         SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(NAME).def; \
2535           echo PROTMODE >> $(SUBDIR)$(NAME).def; \
2536           echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(NAME).def; \
2537           echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(NAME).def; \
2538           echo EXPORTS >> $(SUBDIR)$(NAME).def; \
2539           emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def'
2540         SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \
2541           emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
2542         SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib'
2543         enable dos_paths
2544         ;;
2545     gnu/kfreebsd)
2546         add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
2547         ;;
2548     gnu)
2549         add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
2550         ;;
2551     qnx)
2552         add_cppflags -D_QNX_SOURCE
2553         network_extralibs="-lsocket"
2554         ;;
2555     symbian)
2556         SLIBSUF=".dll"
2557         enable dos_paths
2558         add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default
2559         add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS
2560         add_ldflags -Wl,--target1-abs,--no-undefined \
2561                     -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \
2562                     -Wl,--entry=_E32Startup -Wl,-u,_E32Startup
2563         add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \
2564                       -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \
2565                       -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib
2566         ;;
2567     none)
2568         ;;
2569     *)
2570         die "Unknown OS '$target_os'."
2571         ;;
2572 esac
2573
2574 echo "config:$arch:$subarch:$cpu:$target_os:$cc_ident:$FFMPEG_CONFIGURATION" >config.fate
2575
2576 check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable pic
2577
2578 set_default $PATHS_LIST
2579
2580 # we need to build at least one lib type
2581 if ! enabled_any static shared; then
2582     cat <<EOF
2583 At least one library type must be built.
2584 Specify --enable-static to build the static libraries or --enable-shared to
2585 build the shared libraries as well. To only build the shared libraries specify
2586 --disable-static in addition to --enable-shared.
2587 EOF
2588     exit 1;
2589 fi
2590
2591 die_license_disabled() {
2592     enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
2593 }
2594
2595 die_license_disabled gpl libx264
2596 die_license_disabled gpl libxavs
2597 die_license_disabled gpl libxvid
2598 die_license_disabled gpl x11grab
2599
2600 die_license_disabled nonfree libfaac
2601
2602 die_license_disabled version3 libopencore_amrnb
2603 die_license_disabled version3 libopencore_amrwb
2604 die_license_disabled version3 libvo_aacenc
2605 die_license_disabled version3 libvo_amrwbenc
2606
2607 enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
2608
2609 disabled optimizations || check_cflags -fomit-frame-pointer
2610
2611 enable_pic() {
2612     enable pic
2613     add_cppflags -DPIC
2614     add_cflags   -fPIC
2615     add_asflags  -fPIC
2616 }
2617
2618 enabled pic && enable_pic
2619
2620 check_cc <<EOF || die "Symbol mangling check failed."
2621 int ff_extern;
2622 EOF
2623 sym=$($nm $nm_opts $TMPO | awk '/ff_extern/{ print substr($0, match($0, /[^ \t]*ff_extern/)) }')
2624 extern_prefix=${sym%%ff_extern*}
2625
2626 check_cc <<EOF && enable inline_asm
2627 void foo(void) { __asm__ volatile ("" ::); }
2628 EOF
2629
2630 _restrict=
2631 for restrict_keyword in restrict __restrict__ __restrict; do
2632     check_cc <<EOF && _restrict=$restrict_keyword && break
2633 void foo(char * $restrict_keyword p);
2634 EOF
2635 done
2636
2637 check_cc <<EOF && enable attribute_packed
2638 struct { int x; } __attribute__((packed)) x;
2639 EOF
2640
2641 check_cc <<EOF && enable attribute_may_alias
2642 union { int x; } __attribute__((may_alias)) x;
2643 EOF
2644
2645 check_cc <<EOF || die "endian test failed"
2646 unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
2647 EOF
2648 od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
2649
2650 if enabled alpha; then
2651
2652     check_cflags -mieee
2653
2654 elif enabled arm; then
2655
2656     enabled thumb && check_cflags -mthumb || check_cflags -marm
2657     nogas=die
2658
2659     if     check_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then
2660         enable vfp_args
2661     elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then
2662         case "${cross_prefix:-$cc}" in
2663             *hardfloat*)         enable vfp_args;   fpabi=vfp ;;
2664             *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
2665 __asm__ (".eabi_attribute 28, 1");
2666 int main(void) { return 0; }
2667 EOF
2668         esac
2669         warn "Compiler does not indicate floating-point ABI, guessing $fpabi."
2670     fi
2671
2672     enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"'
2673     enabled armv6   && check_asm armv6   '"sadd16 r0, r0, r0"'
2674     enabled armv6t2 && check_asm armv6t2 '"movt r0, #0"'
2675     enabled armvfp  && check_asm armvfp  '"fadds s0, s0, s0"'
2676     enabled iwmmxt  && check_asm iwmmxt  '"wunpckelub wr6, wr4"'
2677     enabled neon    && check_asm neon    '"vadd.i16 q0, q0, q0"'
2678     enabled vfpv3   && check_asm vfpv3   '"vmov.f32 s0, #1.0"'
2679
2680     enabled_all armv6t2 shared !pic && enable_pic
2681
2682 elif enabled mips; then
2683
2684     check_asm loongson '"dmult.g $1, $2, $3"'
2685     enabled mmi     && check_asm mmi     '"lq $2, 0($2)"'
2686
2687 elif enabled ppc; then
2688
2689     enable local_aligned_8 local_aligned_16
2690
2691     check_asm dcbzl     '"dcbzl 0, %0" :: "r"(0)'
2692     check_asm ibm_asm   '"add 0, 0, 0"'
2693     check_asm ppc4xx    '"maclhw r10, r11, r12"'
2694     check_asm xform_asm '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)'
2695
2696     # AltiVec flags: The FSF version of GCC differs from the Apple version
2697     if enabled altivec; then
2698         nogas=warn
2699         check_cflags -maltivec -mabi=altivec &&
2700         { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
2701         check_cflags -faltivec
2702
2703         # check if our compiler supports Motorola AltiVec C API
2704         check_cc <<EOF || disable altivec
2705 $inc_altivec_h
2706 int main(void) {
2707     vector signed int v1, v2, v3;
2708     v1 = vec_add(v2,v3);
2709     return 0;
2710 }
2711 EOF
2712
2713         # check if our compiler supports braces for vector declarations
2714         check_cc <<EOF || die "You need a compiler that supports {} in AltiVec vector declarations."
2715 $inc_altivec_h
2716 int main (void) { (vector int) {1}; return 0; }
2717 EOF
2718     fi
2719
2720 elif enabled sparc; then
2721
2722     enabled vis && check_asm vis '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc &&
2723         add_cflags -mcpu=ultrasparc -mtune=ultrasparc
2724
2725 elif enabled x86; then
2726
2727     enable local_aligned_8 local_aligned_16
2728
2729     # check whether EBP is available on x86
2730     # As 'i' is stored on the stack, this program will crash
2731     # if the base pointer is used to access it because the
2732     # base pointer is cleared in the inline assembly code.
2733     check_exec_crash <<EOF && enable ebp_available
2734     volatile int i=0;
2735     __asm__ volatile (
2736         "xorl %%ebp, %%ebp"
2737     ::: "%ebp");
2738     return i;
2739 EOF
2740
2741     # check whether EBX is available on x86
2742     check_asm ebx_available '""::"b"(0)' &&
2743         check_asm ebx_available '"":::"%ebx"'
2744
2745     # check whether xmm clobbers are supported
2746     check_asm xmm_clobbers '"":::"%xmm0"'
2747
2748     # check whether binutils is new enough to compile SSSE3/MMX2
2749     enabled ssse3 && check_asm ssse3 '"pabsw %xmm0, %xmm0"'
2750     enabled mmx2  && check_asm mmx2  '"pmaxub %mm0, %mm1"'
2751
2752     check_asm bswap '"bswap %%eax" ::: "%eax"'
2753
2754     if ! disabled_any asm mmx yasm; then
2755         if check_cmd $yasmexe --version; then
2756             enabled x86_64 && yasm_extra="-m amd64"
2757             yasm_debug="-g dwarf2"
2758         elif check_cmd nasm -v; then
2759             yasmexe=nasm
2760             yasm_debug="-g -F dwarf"
2761             enabled x86_64 && test "$objformat" = elf && objformat=elf64
2762         fi
2763
2764         YASMFLAGS="-f $objformat $yasm_extra"
2765         enabled pic               && append YASMFLAGS "-DPIC"
2766         test -n "$extern_prefix"  && append YASMFLAGS "-DPREFIX"
2767         case "$objformat" in
2768             elf*) enabled debug && append YASMFLAGS $yasm_debug ;;
2769         esac
2770
2771         check_yasm "pextrd [eax], xmm0, 1" && enable yasm ||
2772             die "yasm not found, use --disable-yasm for a crippled build"
2773         check_yasm "vextractf128 xmm0, ymm0, 0" || disable avx
2774     fi
2775
2776     case "$cpu" in
2777         athlon*|opteron*|k8*|pentium|pentium-mmx|prescott|nocona|atom|geode)
2778             disable fast_clz
2779         ;;
2780     esac
2781
2782 fi
2783
2784 if enabled asm; then
2785     as=${gas:=$as}
2786     check_asm gnu_as '".macro m n\n\\n:.int 0\n.endm\nm x"' ||
2787         $nogas "GNU assembler not found, install gas-preprocessor"
2788 fi
2789
2790 check_ldflags -Wl,--as-needed
2791
2792 if check_func dlopen; then
2793     ldl=
2794 elif check_func dlopen -ldl; then
2795     ldl=-ldl
2796 fi
2797
2798 if enabled network; then
2799     check_type "sys/types.h sys/socket.h" socklen_t
2800     check_type netdb.h "struct addrinfo"
2801     check_type netinet/in.h "struct ipv6_mreq" -D_DARWIN_C_SOURCE
2802     check_type netinet/in.h "struct sockaddr_in6"
2803     check_type "sys/types.h sys/socket.h" "struct sockaddr_storage"
2804     check_struct "sys/types.h sys/socket.h" "struct sockaddr" sa_len
2805     # Prefer arpa/inet.h over winsock2
2806     if check_header arpa/inet.h ; then
2807         check_func closesocket
2808     elif check_header winsock2.h ; then
2809         check_func_headers winsock2.h closesocket -lws2 && \
2810             network_extralibs="-lws2" || \
2811         { check_func_headers winsock2.h closesocket -lws2_32 && \
2812             network_extralibs="-lws2_32"; }
2813         check_type ws2tcpip.h socklen_t
2814         check_type ws2tcpip.h "struct addrinfo"
2815         check_type ws2tcpip.h "struct ipv6_mreq"
2816         check_type ws2tcpip.h "struct sockaddr_in6"
2817         check_type ws2tcpip.h "struct sockaddr_storage"
2818         check_struct winsock2.h "struct sockaddr" sa_len
2819     else
2820         disable network
2821     fi
2822 fi
2823
2824 # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
2825 check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; }
2826
2827 check_func  fcntl
2828 check_func  fork
2829 check_func  getaddrinfo $network_extralibs
2830 check_func  gethrtime
2831 check_func  getrusage
2832 check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
2833 check_func  inet_aton $network_extralibs
2834 check_func  isatty
2835 check_func  localtime_r
2836 check_func  ${malloc_prefix}memalign            && enable memalign
2837 check_func  mkstemp
2838 check_func  mmap
2839 check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
2840 check_func  setrlimit
2841 check_func  strerror_r
2842 check_func  strptime
2843 check_func  strtok_r
2844 check_func_headers conio.h kbhit
2845 check_func_headers io.h setmode
2846 check_func_headers lzo/lzo1x.h lzo1x_999_compress
2847 check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
2848 check_func_headers windows.h GetProcessTimes
2849 check_func_headers windows.h MapViewOfFile
2850 check_func_headers windows.h VirtualAlloc
2851
2852 check_header dlfcn.h
2853 check_header dxva2api.h
2854 check_header libcrystalhd/libcrystalhd_if.h
2855 check_header malloc.h
2856 check_header poll.h
2857 check_header sys/mman.h
2858 check_header sys/resource.h
2859 check_header sys/select.h
2860 check_header termios.h
2861 check_header vdpau/vdpau.h
2862 check_header vdpau/vdpau_x11.h
2863 check_header X11/extensions/XvMClib.h
2864
2865 check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex
2866
2867 disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable  zlib
2868 disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
2869
2870 # check for some common methods of building with pthread support
2871 # do this before the optional library checks as some of them require pthreads
2872 if ! disabled pthreads && ! enabled w32threads; then
2873     enable pthreads
2874     if check_func pthread_create; then
2875         :
2876     elif check_func pthread_create -pthread; then
2877         add_cflags -pthread
2878         add_extralibs -pthread
2879     elif check_func pthread_create -pthreads; then
2880         add_cflags -pthreads
2881         add_extralibs -pthreads
2882     elif check_func pthread_create -lpthreadGC2; then
2883         add_extralibs -lpthreadGC2
2884     elif ! check_lib pthread.h pthread_create -lpthread; then
2885         disable pthreads
2886     fi
2887 fi
2888
2889 for thread in $THREADS_LIST; do
2890     if enabled $thread; then
2891         test -n "$thread_type" &&
2892             die "ERROR: Only one thread type must be selected." ||
2893             thread_type="$thread"
2894     fi
2895 done
2896
2897 check_lib math.h sin -lm && LIBM="-lm"
2898 disabled crystalhd || check_lib libcrystalhd/libcrystalhd_if.h DtsCrystalHDVersion -lcrystalhd || disable crystalhd
2899 enabled vaapi && require vaapi va/va.h vaInitialize -lva
2900
2901 check_mathfunc exp2
2902 check_mathfunc exp2f
2903 check_mathfunc llrint
2904 check_mathfunc llrintf
2905 check_mathfunc log2
2906 check_mathfunc log2f
2907 check_mathfunc lrint
2908 check_mathfunc lrintf
2909 check_mathfunc round
2910 check_mathfunc roundf
2911 check_mathfunc trunc
2912 check_mathfunc truncf
2913
2914 # these are off by default, so fail if requested and not available
2915 enabled avisynth   && require2 vfw32 "windows.h vfw.h" AVIFileInit -lavifil32
2916 enabled libcelt    && require libcelt celt/celt.h celt_decode -lcelt0
2917 enabled frei0r     && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
2918 enabled libdc1394  && require_pkg_config libdc1394-2 dc1394/dc1394.h dc1394_new
2919 enabled libdirac   && require_pkg_config dirac                          \
2920     "libdirac_decoder/dirac_parser.h libdirac_encoder/dirac_encoder.h"  \
2921     "dirac_decoder_init dirac_encoder_init"
2922 enabled libfaac    && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
2923 enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType
2924 enabled libgsm     && require  libgsm gsm/gsm.h gsm_create -lgsm
2925 enabled libmp3lame && require  "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
2926 enabled libnut     && require  libnut libnut.h nut_demuxer_init -lnut
2927 enabled libopencore_amrnb  && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
2928 enabled libopencore_amrwb  && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
2929 enabled libopencv  && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
2930 enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg
2931 enabled librtmp    && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
2932 enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
2933 enabled libspeex   && require  libspeex speex/speex.h speex_decoder_init -lspeex
2934 enabled libtheora  && require  libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
2935 enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
2936 enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
2937 enabled libvorbis  && require  libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
2938 enabled libvpx     && {
2939     enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
2940                                 die "ERROR: libvpx decoder version must be >=0.9.1"; }
2941     enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
2942                                 die "ERROR: libvpx encoder version must be >=0.9.6"; } }
2943 enabled libx264    && require  libx264 x264.h x264_encoder_encode -lx264 &&
2944                       { check_cpp_condition x264.h "X264_BUILD >= 115" ||
2945                         die "ERROR: libx264 version must be >= 0.115."; }
2946 enabled libxavs    && require  libxavs xavs.h xavs_encoder_encode -lxavs
2947 enabled libxvid    && require  libxvid xvid.h xvid_global -lxvidcore
2948 enabled openal     && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
2949                         check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } ||
2950                         die "ERROR: openal not found"; } &&
2951                       { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
2952                         die "ERROR: openal version must be 1.1 or compatible"; }
2953 enabled mlib       && require  mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
2954
2955 SDL_CONFIG="${cross_prefix}sdl-config"
2956 if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then
2957     check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
2958     enable sdl &&
2959     check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size
2960 else
2961   if "${SDL_CONFIG}" --version > /dev/null 2>&1; then
2962     sdl_cflags=$("${SDL_CONFIG}" --cflags)
2963     sdl_libs=$("${SDL_CONFIG}" --libs)
2964     check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs &&
2965     check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
2966     enable sdl &&
2967     check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size
2968   fi
2969 fi
2970 enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs
2971
2972 texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
2973
2974 check_header linux/fb.h
2975 check_header linux/videodev.h
2976 check_header linux/videodev2.h
2977 check_header sys/videoio.h
2978
2979 check_func_headers "windows.h vfw.h" capCreateCaptureWindow "$vfwcap_indev_extralibs"
2980 # check that WM_CAP_DRIVER_CONNECT is defined to the proper value
2981 # w32api 3.12 had it defined wrong
2982 check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
2983
2984 check_type "dshow.h" IBaseFilter
2985
2986 # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
2987 { check_header dev/bktr/ioctl_meteor.h &&
2988   check_header dev/bktr/ioctl_bt848.h; } ||
2989 { check_header machine/ioctl_meteor.h &&
2990   check_header machine/ioctl_bt848.h; } ||
2991 { check_header dev/video/meteor/ioctl_meteor.h &&
2992   check_header dev/video/bktr/ioctl_bt848.h; } ||
2993 check_header dev/ic/bt8xx.h
2994
2995 check_header sndio.h
2996 if check_struct sys/soundcard.h audio_buf_info bytes; then
2997     enable_safe sys/soundcard.h
2998 else
2999     check_cc -D__BSD_VISIBLE -D__XSI_VISIBLE <<EOF && add_cppflags -D__BSD_VISIBLE -D__XSI_VISIBLE && enable_safe sys/soundcard.h
3000     #include <sys/soundcard.h>
3001     audio_buf_info abc;
3002 EOF
3003 fi
3004 check_header soundcard.h
3005
3006 enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
3007
3008 enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait
3009
3010 enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
3011
3012 enabled x11grab                         &&
3013 check_header X11/Xlib.h                 &&
3014 check_header X11/extensions/XShm.h      &&
3015 check_header X11/extensions/Xfixes.h    &&
3016 check_func XOpenDisplay -lX11           &&
3017 check_func XShmCreateImage -lX11 -lXext &&
3018 check_func XFixesGetCursorImage -lX11 -lXext -lXfixes
3019
3020 if ! disabled vaapi; then
3021     check_lib va/va.h vaInitialize -lva && {
3022         check_cpp_condition va/va_version.h "VA_CHECK_VERSION(0,32,0)" ||
3023         warn "Please upgrade to VA-API >= 0.32 if you would like full VA-API support.";
3024     } || disable vaapi
3025 fi
3026
3027 if ! disabled vdpau && enabled vdpau_vdpau_h; then
3028 check_cpp_condition \
3029     vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
3030     { echolog "Please upgrade to libvdpau >= 0.2 if you would like vdpau support." &&
3031       disable vdpau; }
3032 fi
3033
3034 enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
3035
3036 # add some useful compiler flags if supported
3037 check_cflags -Wdeclaration-after-statement
3038 check_cflags -Wall
3039 check_cflags -Wno-parentheses
3040 check_cflags -Wno-switch
3041 check_cflags -Wno-format-zero-length
3042 check_cflags -Wdisabled-optimization
3043 check_cflags -Wpointer-arith
3044 check_cflags -Wredundant-decls
3045 check_cflags -Wno-pointer-sign
3046 check_cflags -Wcast-qual
3047 check_cflags -Wwrite-strings
3048 check_cflags -Wtype-limits
3049 check_cflags -Wundef
3050 check_cflags -Wmissing-prototypes
3051 check_cflags -Wno-pointer-to-int-cast
3052 enabled extra_warnings && check_cflags -Winline
3053
3054 # add some linker flags
3055 check_ldflags -Wl,--warn-common
3056 check_ldflags -Wl,-rpath-link=libpostproc:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil
3057 test_ldflags -Wl,-Bsymbolic && append SHFLAGS -Wl,-Bsymbolic
3058
3059 echo "X{};" > $TMPV
3060 if test_ldflags -Wl,--version-script,$TMPV; then
3061     append SHFLAGS '-Wl,--version-script,\$(SUBDIR)lib\$(NAME).ver'
3062     check_cc <<EOF && enable symver_asm_label
3063 void ff_foo(void) __asm__ ("av_foo@VERSION");
3064 void ff_foo(void) { ${inline_asm+__asm__($quotes);} }
3065 EOF
3066     check_cc <<EOF && enable symver_gnu_asm
3067 __asm__(".symver ff_foo,av_foo@VERSION");
3068 void ff_foo(void) {}
3069 EOF
3070 fi
3071
3072 if [ -n "$optflags" ]; then
3073     add_cflags $optflags
3074 elif enabled small; then
3075     add_cflags $size_cflags
3076 elif enabled optimizations; then
3077     add_cflags $speed_cflags
3078 else
3079     add_cflags $noopt_cflags
3080 fi
3081 check_cflags -fno-math-errno
3082 check_cflags -fno-signed-zeros
3083
3084 if enabled icc; then
3085     # Just warnings, no remarks
3086     check_cflags -w1
3087     # -wd: Disable following warnings
3088     # 144, 167, 556: -Wno-pointer-sign
3089     # 1292: attribute "foo" ignored
3090     # 10006: ignoring unknown option -fno-signed-zeros
3091     # 10148: ignoring unknown option -Wno-parentheses
3092     # 10156: ignoring option '-W'; no argument required
3093     check_cflags -wd144,167,556,1292,10006,10148,10156
3094     # 11030: Warning unknown option --as-needed
3095     # 10156: ignoring option '-export'; no argument required
3096     check_ldflags -wd10156,11030
3097     # Allow to compile with optimizations
3098     check_ldflags -march=$cpu
3099     # icc 11.0 and 11.1 work with ebp_available, but don't pass the test
3100     enable ebp_available
3101     if enabled x86_32; then
3102         test ${icc_version%%.*} -ge 11 && \
3103             check_cflags -falign-stack=maintain-16-byte || \
3104             disable aligned_stack
3105     fi
3106 elif enabled ccc; then
3107     # disable some annoying warnings
3108     add_cflags -msg_disable cvtu32to64
3109     add_cflags -msg_disable embedcomment
3110     add_cflags -msg_disable needconstext
3111     add_cflags -msg_disable nomainieee
3112     add_cflags -msg_disable ptrmismatch1
3113     add_cflags -msg_disable unreachcode
3114 elif enabled gcc; then
3115     check_cflags -fno-tree-vectorize
3116     check_cflags -Werror=implicit-function-declaration
3117     check_cflags -Werror=missing-prototypes
3118 elif enabled llvm_gcc; then
3119     check_cflags -mllvm -stack-alignment=16
3120 elif enabled clang; then
3121     check_cflags -mllvm -stack-alignment=16
3122     check_cflags -Qunused-arguments
3123 elif enabled armcc; then
3124     # 2523: use of inline assembler is deprecated
3125     add_cflags -W${armcc_opt},--diag_suppress=2523
3126     add_cflags -W${armcc_opt},--diag_suppress=1207
3127     add_cflags -W${armcc_opt},--diag_suppress=1293 # assignment in condition
3128     add_cflags -W${armcc_opt},--diag_suppress=3343 # hardfp compat
3129     add_cflags -W${armcc_opt},--diag_suppress=167  # pointer sign
3130     add_cflags -W${armcc_opt},--diag_suppress=513  # pointer sign
3131 elif enabled tms470; then
3132     add_cflags -pds=824 -pds=837
3133 elif enabled pathscale; then
3134     add_cflags -fstrict-overflow -OPT:wrap_around_unsafe_opt=OFF
3135 fi
3136
3137 enabled_any $THREADS_LIST      && enable threads
3138
3139 check_deps $CONFIG_LIST       \
3140            $CONFIG_EXTRA      \
3141            $HAVE_LIST         \
3142            $DECODER_LIST      \
3143            $ENCODER_LIST      \
3144            $HWACCEL_LIST      \
3145            $PARSER_LIST       \
3146            $BSF_LIST          \
3147            $DEMUXER_LIST      \
3148            $MUXER_LIST        \
3149            $FILTER_LIST       \
3150            $INDEV_LIST        \
3151            $OUTDEV_LIST       \
3152            $PROTOCOL_LIST     \
3153            $ACODEC_TESTS      \
3154            $VCODEC_TESTS      \
3155            $LAVF_TESTS        \
3156            $LAVFI_TESTS       \
3157            $SEEK_TESTS        \
3158
3159 enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
3160
3161 if test $target_os == "haiku"; then
3162     disable memalign
3163     disable posix_memalign
3164 fi
3165
3166 ! enabled_any memalign posix_memalign malloc_aligned &&
3167     enabled_any $need_memalign && enable memalign_hack
3168
3169 echo "install prefix            $prefix"
3170 echo "source path               $source_path"
3171 echo "C compiler                $cc"
3172 echo "ARCH                      $arch ($cpu)"
3173 if test "$build_suffix" != ""; then
3174     echo "build suffix              $build_suffix"
3175 fi
3176 if test "$progs_suffix" != ""; then
3177     echo "progs suffix              $progs_suffix"
3178 fi
3179 if test "$extra_version" != ""; then
3180     echo "version string suffix     $extra_version"
3181 fi
3182 echo "big-endian                ${bigendian-no}"
3183 echo "runtime cpu detection     ${runtime_cpudetect-no}"
3184 if enabled x86; then
3185     echo "${yasmexe}                      ${yasm-no}"
3186     echo "MMX enabled               ${mmx-no}"
3187     echo "MMX2 enabled              ${mmx2-no}"
3188     echo "3DNow! enabled            ${amd3dnow-no}"
3189     echo "3DNow! extended enabled   ${amd3dnowext-no}"
3190     echo "SSE enabled               ${sse-no}"
3191     echo "SSSE3 enabled             ${ssse3-no}"
3192     echo "AVX enabled               ${avx-no}"
3193     echo "CMOV enabled              ${cmov-no}"
3194     echo "CMOV is fast              ${fast_cmov-no}"
3195     echo "EBX available             ${ebx_available-no}"
3196     echo "EBP available             ${ebp_available-no}"
3197 fi
3198 if enabled arm; then
3199     echo "ARMv5TE enabled           ${armv5te-no}"
3200     echo "ARMv6 enabled             ${armv6-no}"
3201     echo "ARMv6T2 enabled           ${armv6t2-no}"
3202     echo "ARM VFP enabled           ${armvfp-no}"
3203     echo "IWMMXT enabled            ${iwmmxt-no}"
3204     echo "NEON enabled              ${neon-no}"
3205 fi
3206 if enabled mips; then
3207     echo "MMI enabled               ${mmi-no}"
3208 fi
3209 if enabled ppc; then
3210     echo "AltiVec enabled           ${altivec-no}"
3211     echo "PPC 4xx optimizations     ${ppc4xx-no}"
3212     echo "dcbzl available           ${dcbzl-no}"
3213 fi
3214 if enabled sparc; then
3215     echo "VIS enabled               ${vis-no}"
3216 fi
3217 echo "debug symbols             ${debug-no}"
3218 echo "strip symbols             ${stripping-no}"
3219 echo "optimize for size         ${small-no}"
3220 echo "optimizations             ${optimizations-no}"
3221 echo "static                    ${static-no}"
3222 echo "shared                    ${shared-no}"
3223 echo "postprocessing support    ${postproc-no}"
3224 echo "new filter support        ${avfilter-no}"
3225 echo "network support           ${network-no}"
3226 echo "threading support         ${thread_type-no}"
3227 echo "SDL support               ${sdl-no}"
3228 echo "Sun medialib support      ${mlib-no}"
3229 echo "libdxva2 enabled          ${dxva2-no}"
3230 echo "libva enabled             ${vaapi-no}"
3231 echo "libvdpau enabled          ${vdpau-no}"
3232 echo "AVISynth enabled          ${avisynth-no}"
3233 echo "libcelt enabled           ${libcelt-no}"
3234 echo "frei0r enabled            ${frei0r-no}"
3235 echo "libdc1394 support         ${libdc1394-no}"
3236 echo "libdirac enabled          ${libdirac-no}"
3237 echo "libfaac enabled           ${libfaac-no}"
3238 echo "libgsm enabled            ${libgsm-no}"
3239 echo "libmp3lame enabled        ${libmp3lame-no}"
3240 echo "libnut enabled            ${libnut-no}"
3241 echo "libopencore-amrnb support ${libopencore_amrnb-no}"
3242 echo "libopencore-amrwb support ${libopencore_amrwb-no}"
3243 echo "libopencv support         ${libopencv-no}"
3244 echo "libopenjpeg enabled       ${libopenjpeg-no}"
3245 echo "librtmp enabled           ${librtmp-no}"
3246 echo "libschroedinger enabled   ${libschroedinger-no}"
3247 echo "libspeex enabled          ${libspeex-no}"
3248 echo "libtheora enabled         ${libtheora-no}"
3249 echo "libvo-aacenc support      ${libvo_aacenc-no}"
3250 echo "libvo-amrwbenc support    ${libvo_amrwbenc-no}"
3251 echo "libvorbis enabled         ${libvorbis-no}"
3252 echo "libvpx enabled            ${libvpx-no}"
3253 echo "libx264 enabled           ${libx264-no}"
3254 echo "libxavs enabled           ${libxavs-no}"
3255 echo "libxvid enabled           ${libxvid-no}"
3256 echo "openal enabled            ${openal-no}"
3257 echo "zlib enabled              ${zlib-no}"
3258 echo "bzlib enabled             ${bzlib-no}"
3259 echo
3260
3261 for type in decoder encoder hwaccel parser demuxer muxer protocol filter bsf indev outdev; do
3262     echo "Enabled ${type}s:"
3263     eval list=\$$(toupper $type)_LIST
3264     print_enabled '_*' $list | sort | pr -r -3 -t
3265     echo
3266 done
3267
3268 license="LGPL version 2.1 or later"
3269 if enabled nonfree; then
3270     license="nonfree and unredistributable"
3271 elif enabled gplv3; then
3272     license="GPL version 3 or later"
3273 elif enabled lgplv3; then
3274     license="LGPL version 3 or later"
3275 elif enabled gpl; then
3276     license="GPL version 2 or later"
3277 fi
3278
3279 echo "License: $license"
3280
3281 echo "Creating config.mak and config.h..."
3282
3283 test -e Makefile || $ln_s "$source_path/Makefile" .
3284
3285 enabled stripping || strip="echo skipping strip"
3286
3287 config_files="$TMPH config.mak"
3288
3289 cat > config.mak <<EOF
3290 # Automatically generated by configure - do not modify!
3291 ifndef FFMPEG_CONFIG_MAK
3292 FFMPEG_CONFIG_MAK=1
3293 FFMPEG_CONFIGURATION=$FFMPEG_CONFIGURATION
3294 prefix=$prefix
3295 LIBDIR=\$(DESTDIR)$libdir
3296 SHLIBDIR=\$(DESTDIR)$shlibdir
3297 INCDIR=\$(DESTDIR)$incdir
3298 BINDIR=\$(DESTDIR)$bindir
3299 DATADIR=\$(DESTDIR)$datadir
3300 MANDIR=\$(DESTDIR)$mandir
3301 SRC_PATH=$source_path
3302 ifndef MAIN_MAKEFILE
3303 SRC_PATH:=\$(SRC_PATH:.%=..%)
3304 endif
3305 CC_IDENT=$cc_ident
3306 ARCH=$arch
3307 CC=$cc
3308 AS=$as
3309 LD=$ld
3310 DEPCC=$dep_cc
3311 YASM=$yasmexe
3312 YASMDEP=$yasmexe
3313 AR=$ar
3314 RANLIB=$ranlib
3315 CP=cp -p
3316 LN_S=$ln_s
3317 STRIP=$strip
3318 CPPFLAGS=$CPPFLAGS
3319 CFLAGS=$CFLAGS
3320 ASFLAGS=$ASFLAGS
3321 AS_O=$CC_O
3322 CC_O=$CC_O
3323 LDFLAGS=$LDFLAGS
3324 FFSERVERLDFLAGS=$FFSERVERLDFLAGS
3325 SHFLAGS=$SHFLAGS
3326 YASMFLAGS=$YASMFLAGS
3327 BUILDSUF=$build_suffix
3328 PROGSSUF=$progs_suffix
3329 FULLNAME=$FULLNAME
3330 LIBPREF=$LIBPREF
3331 LIBSUF=$LIBSUF
3332 LIBNAME=$LIBNAME
3333 SLIBPREF=$SLIBPREF
3334 SLIBSUF=$SLIBSUF
3335 EXESUF=$EXESUF
3336 EXTRA_VERSION=$extra_version
3337 DEPFLAGS=$DEPFLAGS
3338 CCDEP=$CCDEP
3339 ASDEP=$ASDEP
3340 CC_DEPFLAGS=$CC_DEPFLAGS
3341 AS_DEPFLAGS=$AS_DEPFLAGS
3342 HOSTCC=$host_cc
3343 HOSTCFLAGS=$host_cflags
3344 HOSTEXESUF=$HOSTEXESUF
3345 HOSTLDFLAGS=$host_ldflags
3346 HOSTLIBS=$host_libs
3347 TARGET_EXEC=$target_exec
3348 TARGET_PATH=$target_path
3349 SDL_LIBS=$sdl_libs
3350 SDL_CFLAGS=$sdl_cflags
3351 LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
3352 EXTRALIBS=$extralibs
3353 INSTALL=$install
3354 LIBTARGET=${LIBTARGET}
3355 SLIBNAME=${SLIBNAME}
3356 SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}
3357 SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}
3358 SLIB_CREATE_DEF_CMD=${SLIB_CREATE_DEF_CMD}
3359 SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}
3360 SLIB_INSTALL_NAME=${SLIB_INSTALL_NAME}
3361 SLIB_INSTALL_LINKS=${SLIB_INSTALL_LINKS}
3362 SLIB_INSTALL_EXTRA_LIB=${SLIB_INSTALL_EXTRA_LIB}
3363 SLIB_INSTALL_EXTRA_SHLIB=${SLIB_INSTALL_EXTRA_SHLIB}
3364 SAMPLES:=${samples:-\$(FATE_SAMPLES)}
3365 EOF
3366
3367 get_version(){
3368     name=$1
3369     file=$source_path/$2
3370     eval $(grep "#define ${name}_VERSION_M" "$file" | awk '{ print $2"="$3 }')
3371     eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO
3372     lcname=$(tolower $name)
3373     eval echo "${lcname}_VERSION=\$${name}_VERSION" >> config.mak
3374     eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> config.mak
3375 }
3376
3377 get_version LIBSWSCALE  libswscale/swscale.h
3378 get_version LIBPOSTPROC libpostproc/postprocess.h
3379 get_version LIBAVCODEC  libavcodec/version.h
3380 get_version LIBAVDEVICE libavdevice/avdevice.h
3381 get_version LIBAVFORMAT libavformat/version.h
3382 get_version LIBAVUTIL   libavutil/avutil.h
3383 get_version LIBAVFILTER libavfilter/avfilter.h
3384
3385 cat > $TMPH <<EOF
3386 /* Automatically generated by configure - do not modify! */
3387 #ifndef FFMPEG_CONFIG_H
3388 #define FFMPEG_CONFIG_H
3389 #define FFMPEG_CONFIGURATION "$(c_escape $FFMPEG_CONFIGURATION)"
3390 #define FFMPEG_LICENSE "$(c_escape $license)"
3391 #define FFMPEG_DATADIR "$(eval c_escape $datadir)"
3392 #define AVCONV_DATADIR "$(eval c_escape $datadir)"
3393 #define CC_TYPE "$cc_type"
3394 #define CC_VERSION $cc_version
3395 #define restrict $_restrict
3396 #define EXTERN_PREFIX "${extern_prefix}"
3397 #define EXTERN_ASM ${extern_prefix}
3398 #define SLIBSUF "$SLIBSUF"
3399 EOF
3400
3401 test -n "$malloc_prefix" &&
3402     echo "#define MALLOC_PREFIX $malloc_prefix" >>$TMPH
3403
3404 if enabled small || disabled optimizations; then
3405     echo "#undef  av_always_inline"  >> $TMPH
3406     if enabled small; then
3407         echo "#define av_always_inline inline"  >> $TMPH
3408     else
3409         echo "#define av_always_inline av_unused"  >> $TMPH
3410     fi
3411 fi
3412
3413 if enabled yasm; then
3414     append config_files $TMPASM
3415     printf '' >$TMPASM
3416 fi
3417
3418 print_config ARCH_   "$config_files" $ARCH_LIST
3419 print_config HAVE_   "$config_files" $HAVE_LIST
3420 print_config CONFIG_ "$config_files" $CONFIG_LIST       \
3421                                      $CONFIG_EXTRA      \
3422                                      $DECODER_LIST      \
3423                                      $ENCODER_LIST      \
3424                                      $HWACCEL_LIST      \
3425                                      $PARSER_LIST       \
3426                                      $BSF_LIST          \
3427                                      $DEMUXER_LIST      \
3428                                      $MUXER_LIST        \
3429                                      $FILTER_LIST       \
3430                                      $PROTOCOL_LIST     \
3431                                      $INDEV_LIST        \
3432                                      $OUTDEV_LIST       \
3433
3434 cat >>config.mak <<EOF
3435 ACODEC_TESTS=$(print_enabled -n _test $ACODEC_TESTS)
3436 VCODEC_TESTS=$(print_enabled -n _test $VCODEC_TESTS)
3437 LAVF_TESTS=$(print_enabled   -n _test $LAVF_TESTS)
3438 LAVFI_TESTS=$(print_enabled  -n _test $LAVFI_TESTS)
3439 SEEK_TESTS=$(print_enabled   -n _test $SEEK_TESTS)
3440 EOF
3441
3442 echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH
3443 echo "endif # FFMPEG_CONFIG_MAK" >> config.mak
3444
3445 # Do not overwrite an unchanged config.h to avoid superfluous rebuilds.
3446 cp_if_changed $TMPH config.h
3447 touch .config
3448
3449 enabled yasm && cp_if_changed $TMPASM config.asm
3450
3451 cat > $TMPH <<EOF
3452 /* Generated by ffconf */
3453 #ifndef AVUTIL_AVCONFIG_H
3454 #define AVUTIL_AVCONFIG_H
3455 EOF
3456
3457 print_config AV_HAVE_ $TMPH $HAVE_LIST_PUB
3458
3459 echo "#endif /* AVUTIL_AVCONFIG_H */" >> $TMPH
3460
3461 cp_if_changed $TMPH libavutil/avconfig.h
3462
3463 test -n "$WARNINGS" && printf "\n$WARNINGS"
3464
3465 # build pkg-config files
3466
3467 pkgconfig_generate(){
3468 name=$1
3469 shortname=${name#lib}${build_suffix}
3470 comment=$2
3471 version=$3
3472 libs=$4
3473 requires=$5
3474 enabled ${name#lib} || return 0
3475 mkdir -p $name
3476 cat <<EOF > $name/$name.pc
3477 prefix=$prefix
3478 exec_prefix=\${prefix}
3479 libdir=$libdir
3480 includedir=$incdir
3481
3482 Name: $name
3483 Description: $comment
3484 Version: $version
3485 Requires: $(enabled shared || echo $requires)
3486 Requires.private: $(enabled shared && echo $requires)
3487 Conflicts:
3488 Libs: -L\${libdir} -l${shortname} $(enabled shared || echo $libs)
3489 Libs.private: $(enabled shared && echo $libs)
3490 Cflags: -I\${includedir}
3491 EOF
3492 cat <<EOF > $name/$name-uninstalled.pc
3493 prefix=
3494 exec_prefix=
3495 libdir=\${pcfiledir}
3496 includedir=${source_path}
3497
3498 Name: $name
3499 Description: $comment
3500 Version: $version
3501 Requires: $requires
3502 Conflicts:
3503 Libs: \${libdir}/${LIBPREF}${shortname}${LIBSUF} $libs
3504 Cflags: -I\${includedir}
3505 EOF
3506 }
3507
3508 pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" "$LIBM"
3509 pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION"
3510 pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION"
3511 pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION"
3512 pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs"
3513 pkgconfig_generate libpostproc "FFmpeg postprocessing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION"
3514 pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION"