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