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