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