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