Add a libwebp encoder
[ffmpeg.git] / configure
1 #!/bin/sh
2 #
3 # Libav configure script
4 #
5 # Copyright (c) 2000-2002 Fabrice Bellard
6 # Copyright (c) 2005-2008 Diego Biurrun
7 # Copyright (c) 2005-2008 Mans Rullgard
8 #
9
10 # Prevent locale nonsense from breaking basic text processing.
11 LC_ALL=C
12 export LC_ALL
13
14 # make sure we are running under a compatible shell
15 # try to make this part work with most shells
16
17 try_exec(){
18     echo "Trying shell $1"
19     type "$1" > /dev/null 2>&1 && exec "$@"
20 }
21
22 unset foo
23 (: ${foo%%bar}) 2> /dev/null
24 E1="$?"
25
26 (: ${foo?}) 2> /dev/null
27 E2="$?"
28
29 if test "$E1" != 0 || test "$E2" = 0; then
30     echo "Broken shell detected.  Trying alternatives."
31     export FF_CONF_EXEC
32     if test "0$FF_CONF_EXEC" -lt 1; then
33         FF_CONF_EXEC=1
34         try_exec bash "$0" "$@"
35     fi
36     if test "0$FF_CONF_EXEC" -lt 2; then
37         FF_CONF_EXEC=2
38         try_exec ksh "$0" "$@"
39     fi
40     if test "0$FF_CONF_EXEC" -lt 3; then
41         FF_CONF_EXEC=3
42         try_exec /usr/xpg4/bin/sh "$0" "$@"
43     fi
44     echo "No compatible shell script interpreter found."
45     echo "This configure script requires a POSIX-compatible shell"
46     echo "such as bash or ksh."
47     echo "THIS IS NOT A BUG IN LIBAV, DO NOT REPORT IT AS SUCH."
48     echo "Instead, install a working POSIX-compatible shell."
49     echo "Disabling this configure test will create a broken Libav."
50     if test "$BASH_VERSION" = '2.04.0(1)-release'; then
51         echo "This bash version ($BASH_VERSION) is broken on your platform."
52         echo "Upgrade to a later version if available."
53     fi
54     exit 1
55 fi
56
57 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 Help options:
65   --help                   print this message
66   --list-decoders          show all available decoders
67   --list-encoders          show all available encoders
68   --list-hwaccels          show all available hardware accelerators
69   --list-demuxers          show all available demuxers
70   --list-muxers            show all available muxers
71   --list-parsers           show all available parsers
72   --list-protocols         show all available protocols
73   --list-bsfs              show all available bitstream filters
74   --list-indevs            show all available input devices
75   --list-outdevs           show all available output devices
76   --list-filters           show all available filters
77
78 Standard options:
79   --logfile=FILE           log tests and output to FILE [config.log]
80   --disable-logging        do not log configure debug information
81   --prefix=PREFIX          install in PREFIX [$prefix]
82   --bindir=DIR             install binaries in DIR [PREFIX/bin]
83   --datadir=DIR            install data files in DIR [PREFIX/share/avconv]
84   --docdir=DIR             install documentation in DIR [PREFIX/share/doc/libav]
85   --libdir=DIR             install libs in DIR [PREFIX/lib]
86   --shlibdir=DIR           install shared libs in DIR [PREFIX/lib]
87   --incdir=DIR             install includes in DIR [PREFIX/include]
88   --mandir=DIR             install man page in DIR [PREFIX/share/man]
89
90 Licensing options:
91   --enable-gpl             allow use of GPL code, the resulting libs
92                            and binaries will be under GPL [no]
93   --enable-version3        upgrade (L)GPL to version 3 [no]
94   --enable-nonfree         allow use of nonfree code, the resulting libs
95                            and binaries will be unredistributable [no]
96
97 Configuration options:
98   --disable-static         do not build static libraries [no]
99   --enable-shared          build shared libraries [no]
100   --enable-small           optimize for size instead of speed
101   --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary)
102   --enable-gray            enable full grayscale support (slower color)
103   --disable-swscale-alpha  disable alpha channel support in swscale
104   --disable-all            disable building components, libraries and programs
105
106 Program options:
107   --disable-programs       do not build command line programs
108   --disable-avconv         disable avconv build
109   --disable-avplay         disable avplay build
110   --disable-avprobe        disable avprobe build
111   --disable-avserver       disable avserver build
112
113 Component options:
114   --disable-doc            do not build documentation
115   --disable-avdevice       disable libavdevice build
116   --disable-avcodec        disable libavcodec build
117   --disable-avformat       disable libavformat build
118   --disable-avutil         disable libavutil build
119   --disable-swscale        disable libswscale build
120   --disable-avfilter       disable video filter support [no]
121   --disable-avresample     disable libavresample build [no]
122   --disable-pthreads       disable pthreads [auto]
123   --disable-w32threads     disable Win32 threads [auto]
124   --disable-network        disable network support [no]
125   --disable-dct            disable DCT code
126   --disable-error-resilience disable error resilience code
127   --disable-lsp            disable LSP code
128   --disable-lzo            disable LZO decoder code
129   --disable-mdct           disable MDCT code
130   --disable-rdft           disable RDFT code
131   --disable-fft            disable FFT code
132
133 Hardware accelerators:
134   --enable-dxva2           enable DXVA2 code
135   --enable-vaapi           enable VAAPI code
136   --enable-vda             enable VDA code
137   --enable-vdpau           enable VDPAU code
138
139 Individual component options:
140   --disable-everything     disable all components listed below
141   --disable-encoder=NAME   disable encoder NAME
142   --enable-encoder=NAME    enable encoder NAME
143   --disable-encoders       disable all encoders
144   --disable-decoder=NAME   disable decoder NAME
145   --enable-decoder=NAME    enable decoder NAME
146   --disable-decoders       disable all decoders
147   --disable-hwaccel=NAME   disable hwaccel NAME
148   --enable-hwaccel=NAME    enable hwaccel NAME
149   --disable-hwaccels       disable all hwaccels
150   --disable-muxer=NAME     disable muxer NAME
151   --enable-muxer=NAME      enable muxer NAME
152   --disable-muxers         disable all muxers
153   --disable-demuxer=NAME   disable demuxer NAME
154   --enable-demuxer=NAME    enable demuxer NAME
155   --disable-demuxers       disable all demuxers
156   --enable-parser=NAME     enable parser NAME
157   --disable-parser=NAME    disable parser NAME
158   --disable-parsers        disable all parsers
159   --enable-bsf=NAME        enable bitstream filter NAME
160   --disable-bsf=NAME       disable bitstream filter NAME
161   --disable-bsfs           disable all bitstream filters
162   --enable-protocol=NAME   enable protocol NAME
163   --disable-protocol=NAME  disable protocol NAME
164   --disable-protocols      disable all protocols
165   --enable-indev=NAME      enable input device NAME
166   --disable-indev=NAME     disable input device NAME
167   --disable-indevs         disable input devices
168   --enable-outdev=NAME     enable output device NAME
169   --disable-outdev=NAME    disable output device NAME
170   --disable-outdevs        disable output devices
171   --disable-devices        disable all devices
172   --enable-filter=NAME     enable filter NAME
173   --disable-filter=NAME    disable filter NAME
174   --disable-filters        disable all filters
175
176 External library support:
177   --enable-avisynth        enable reading of AviSynth script files [no]
178   --enable-bzlib           enable bzlib [autodetect]
179   --enable-frei0r          enable frei0r video filtering
180   --enable-gnutls          enable gnutls [no]
181   --enable-libcdio         enable audio CD grabbing with libcdio
182   --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
183                            and libraw1394 [no]
184   --enable-libfaac         enable AAC encoding via libfaac [no]
185   --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
186   --enable-libfreetype     enable libfreetype [no]
187   --enable-libgsm          enable GSM de/encoding via libgsm [no]
188   --enable-libilbc         enable iLBC de/encoding via libilbc [no]
189   --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
190   --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
191   --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
192   --enable-libopencv       enable video filtering via libopencv [no]
193   --enable-libopenjpeg     enable JPEG 2000 de/encoding via OpenJPEG [no]
194   --enable-libopus         enable Opus decoding via libopus [no]
195   --enable-libpulse        enable Pulseaudio input via libpulse [no]
196   --enable-librtmp         enable RTMP[E] support via librtmp [no]
197   --enable-libschroedinger enable Dirac de/encoding via libschroedinger [no]
198   --enable-libspeex        enable Speex de/encoding via libspeex [no]
199   --enable-libtheora       enable Theora encoding via libtheora [no]
200   --enable-libvo-aacenc    enable AAC encoding via libvo-aacenc [no]
201   --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
202   --enable-libvorbis       enable Vorbis encoding via libvorbis [no]
203   --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
204   --enable-libwavpack      enable wavpack encoding via libwavpack [no]
205   --enable-libwebp         enable WebP encoding via libwebp [no]
206   --enable-libx264         enable H.264 encoding via x264 [no]
207   --enable-libxavs         enable AVS encoding via xavs [no]
208   --enable-libxvid         enable Xvid encoding via xvidcore,
209                            native MPEG-4/Xvid encoder exists [no]
210   --enable-openssl         enable openssl [no]
211   --enable-x11grab         enable X11 grabbing [no]
212   --enable-zlib            enable zlib [autodetect]
213
214 Advanced options (experts only):
215   --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]
216   --enable-cross-compile   assume a cross-compiler is used
217   --sysroot=PATH           root of cross-build tree
218   --sysinclude=PATH        location of cross-build system headers
219   --target-os=OS           compiler targets OS [$target_os]
220   --target-exec=CMD        command to run executables on target
221   --target-path=DIR        path to view of build directory on target
222   --target-samples=DIR     path to samples directory on target
223   --toolchain=NAME         set tool defaults according to NAME
224   --nm=NM                  use nm tool
225   --ar=AR                  use archive tool AR [$ar_default]
226   --as=AS                  use assembler AS [$as_default]
227   --cc=CC                  use C compiler CC [$cc_default]
228   --dep-cc=DEPCC           use dependency generator DEPCC [$cc_default]
229   --ld=LD                  use linker LD
230   --host-cc=HOSTCC         use host C compiler HOSTCC
231   --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
232   --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host
233   --host-ld=HOSTLD         use host linker HOSTLD
234   --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
235   --host-libs=HLIBS        use libs HLIBS when linking for host
236   --host-os=OS             compiler host OS [$target_os]
237   --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]
238   --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]
239   --extra-libs=ELIBS       add ELIBS [$ELIBS]
240   --extra-version=STRING   version string suffix []
241   --optflags=OPTFLAGS      override optimization-related compiler flags
242   --build-suffix=SUFFIX    library name suffix []
243   --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
244   --arch=ARCH              select architecture [$arch]
245   --cpu=CPU                select the minimum required CPU (affects
246                            instruction selection, may crash on older CPUs)
247   --enable-pic             build position-independent code
248   --enable-sram            allow use of on-chip SRAM
249   --enable-thumb           compile for Thumb instruction set
250   --disable-symver         disable symbol versioning
251   --enable-hardcoded-tables use hardcoded tables instead of runtime generation
252   --disable-safe-bitstream-reader
253                            disable buffer boundary checking in bitreaders
254                            (faster, but may crash)
255   --enable-memalign-hack   emulate memalign, interferes with memory debuggers
256   --enable-lto             use link-time optimization
257
258 Optimization options (experts only):
259   --disable-asm            disable all assembler optimizations
260   --disable-altivec        disable AltiVec optimizations
261   --disable-amd3dnow       disable 3DNow! optimizations
262   --disable-amd3dnowext    disable 3DNow! extended optimizations
263   --disable-mmx            disable MMX optimizations
264   --disable-mmxext         disable MMXEXT optimizations
265   --disable-sse            disable SSE optimizations
266   --disable-sse2           disable SSE2 optimizations
267   --disable-sse3           disable SSE3 optimizations
268   --disable-ssse3          disable SSSE3 optimizations
269   --disable-sse4           disable SSE4 optimizations
270   --disable-sse42          disable SSE4.2 optimizations
271   --disable-avx            disable AVX optimizations
272   --disable-fma4           disable FMA4 optimizations
273   --disable-avx2           disable AVX2 optimizations
274   --disable-armv5te        disable armv5te optimizations
275   --disable-armv6          disable armv6 optimizations
276   --disable-armv6t2        disable armv6t2 optimizations
277   --disable-vfp            disable VFP optimizations
278   --disable-neon           disable NEON optimizations
279   --disable-vis            disable VIS optimizations
280   --disable-inline-asm     disable use of inline assembler
281   --disable-yasm           disable use of yasm assembler
282
283 Developer options (useful when working on Libav itself):
284   --disable-debug          disable debugging symbols
285   --enable-debug=LEVEL     set the debug level [$debuglevel]
286   --disable-optimizations  disable compiler optimizations
287   --enable-extra-warnings  enable more compiler warnings
288   --samples=PATH           location of test samples for FATE, if not set use
289                            \$LIBAV_SAMPLES at make invocation time.
290   --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
291                            should be used only for debugging purposes)
292   --enable-random          randomly enable/disable components
293   --disable-random
294   --enable-random=LIST     randomly enable/disable specific components or
295   --disable-random=LIST    component groups. LIST is a comma-separated list
296                            of NAME[:PROB] entries where NAME is a component
297                            (group) and PROB the probability associated with
298                            NAME (default 0.5).
299   --random-seed=VALUE      seed value for --enable/disable-random
300
301 NOTE: Object files are built at the place where configure is launched.
302 EOF
303   exit 0
304 }
305
306 quotes='""'
307
308 log(){
309     echo "$@" >> $logfile
310 }
311
312 log_file(){
313     log BEGIN $1
314     pr -n -t $1 >> $logfile
315     log END $1
316 }
317
318 echolog(){
319     log "$@"
320     echo "$@"
321 }
322
323 warn(){
324     log "WARNING: $*"
325     WARNINGS="${WARNINGS}WARNING: $*\n"
326 }
327
328 die(){
329     echolog "$@"
330     cat <<EOF
331
332 If you think configure made a mistake, make sure you are using the latest
333 version from Git.  If the latest version fails, report the problem to the
334 libav-tools@libav.org mailing list or IRC #libav on irc.freenode.net.
335 EOF
336     if disabled logging; then
337         cat <<EOF
338 Rerun configure with logging enabled (do not use --disable-logging), and
339 include the log this produces with your report.
340 EOF
341     else
342         cat <<EOF
343 Include the log file "$logfile" produced by configure as this will help
344 solving the problem.
345 EOF
346     fi
347     exit 1
348 }
349
350 # Avoid locale weirdness, besides we really just want to translate ASCII.
351 toupper(){
352     echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
353 }
354
355 tolower(){
356     echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz
357 }
358
359 c_escape(){
360     echo "$*" | sed 's/["\\]/\\\0/g'
361 }
362
363 sh_quote(){
364     v=$(echo "$1" | sed "s/'/'\\\\''/g")
365     test "x$v" = "x${v#*[!A-Za-z0-9_/.+-]}" || v="'$v'"
366     echo "$v"
367 }
368
369 cleanws(){
370     echo "$@" | sed 's/^ *//;s/  */ /g;s/ *$//'
371 }
372
373 filter(){
374     pat=$1
375     shift
376     for v; do
377         eval "case $v in $pat) echo $v ;; esac"
378     done
379 }
380
381 filter_out(){
382     pat=$1
383     shift
384     for v; do
385         eval "case $v in $pat) ;; *) echo $v ;; esac"
386     done
387 }
388
389 map(){
390     m=$1
391     shift
392     for v; do eval $m; done
393 }
394
395 add_suffix(){
396     suffix=$1
397     shift
398     for v; do echo ${v}${suffix}; done
399 }
400
401 set_all(){
402     value=$1
403     shift
404     for var in $*; do
405         eval $var=$value
406     done
407 }
408
409 set_weak(){
410     value=$1
411     shift
412     for var; do
413         eval : \${$var:=$value}
414     done
415 }
416
417 sanitize_var_name(){
418     echo $@ | sed 's/[^A-Za-z0-9_]/_/g'
419 }
420
421 set_safe(){
422     var=$1
423     shift
424     eval $(sanitize_var_name "$var")='$*'
425 }
426
427 get_safe(){
428     eval echo \$$(sanitize_var_name "$1")
429 }
430
431 pushvar(){
432     for pvar in $*; do
433         eval level=\${${pvar}_level:=0}
434         eval ${pvar}_${level}="\$$pvar"
435         eval ${pvar}_level=$(($level+1))
436     done
437 }
438
439 popvar(){
440     for pvar in $*; do
441         eval level=\${${pvar}_level:-0}
442         test $level = 0 && continue
443         eval level=$(($level-1))
444         eval $pvar="\${${pvar}_${level}}"
445         eval ${pvar}_level=$level
446         eval unset ${pvar}_${level}
447     done
448 }
449
450 enable(){
451     set_all yes $*
452 }
453
454 disable(){
455     set_all no $*
456 }
457
458 enable_weak(){
459     set_weak yes $*
460 }
461
462 disable_weak(){
463     set_weak no $*
464 }
465
466 enable_safe(){
467     for var; do
468         enable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
469     done
470 }
471
472 disable_safe(){
473     for var; do
474         disable $(echo "$var" | sed 's/[^A-Za-z0-9_]/_/g')
475     done
476 }
477
478 do_enable_deep(){
479     for var; do
480         enabled $var && continue
481         eval sel="\$${var}_select"
482         eval sgs="\$${var}_suggest"
483         pushvar var sgs
484         enable_deep $sel
485         popvar sgs
486         enable_deep_weak $sgs
487         popvar var
488     done
489 }
490
491 enable_deep(){
492     do_enable_deep $*
493     enable $*
494 }
495
496 enable_deep_weak(){
497     for var; do
498         disabled $var && continue
499         pushvar var
500         do_enable_deep $var
501         popvar var
502         enable_weak $var
503     done
504 }
505
506 enabled(){
507     test "${1#!}" = "$1" && op== || op=!=
508     eval test "x\$${1#!}" $op "xyes"
509 }
510
511 disabled(){
512     test "${1#!}" = "$1" && op== || op=!=
513     eval test "x\$${1#!}" $op "xno"
514 }
515
516 enabled_all(){
517     for opt; do
518         enabled $opt || return 1
519     done
520 }
521
522 disabled_all(){
523     for opt; do
524         disabled $opt || return 1
525     done
526 }
527
528 enabled_any(){
529     for opt; do
530         enabled $opt && return 0
531     done
532 }
533
534 disabled_any(){
535     for opt; do
536         disabled $opt && return 0
537     done
538     return 1
539 }
540
541 set_default(){
542     for opt; do
543         eval : \${$opt:=\$${opt}_default}
544     done
545 }
546
547 is_in(){
548     value=$1
549     shift
550     for var in $*; do
551         [ $var = $value ] && return 0
552     done
553     return 1
554 }
555
556 do_check_deps(){
557     for cfg; do
558         cfg="${cfg#!}"
559         enabled ${cfg}_checking && die "Circular dependency for $cfg."
560         disabled ${cfg}_checking && continue
561         enable ${cfg}_checking
562         append allopts $cfg
563
564         eval dep_all="\$${cfg}_deps"
565         eval dep_any="\$${cfg}_deps_any"
566         eval dep_sel="\$${cfg}_select"
567         eval dep_sgs="\$${cfg}_suggest"
568         eval dep_ifa="\$${cfg}_if"
569         eval dep_ifn="\$${cfg}_if_any"
570
571         pushvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
572         do_check_deps $dep_all $dep_any $dep_sel $dep_sgs $dep_ifa $dep_ifn
573         popvar cfg dep_all dep_any dep_sel dep_sgs dep_ifa dep_ifn
574
575         [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
576         [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
577         enabled_all  $dep_all || disable $cfg
578         enabled_any  $dep_any || disable $cfg
579         disabled_any $dep_sel && disable $cfg
580
581         if enabled $cfg; then
582             enable_deep $dep_sel
583             enable_deep_weak $dep_sgs
584         fi
585
586         disable ${cfg}_checking
587     done
588 }
589
590 check_deps(){
591     unset allopts
592
593     do_check_deps "$@"
594
595     for cfg in $allopts; do
596         enabled $cfg || continue
597         eval dep_extralibs="\$${cfg}_extralibs"
598         test -n "$dep_extralibs" && add_extralibs $dep_extralibs
599     done
600 }
601
602 print_config(){
603     pfx=$1
604     files=$2
605     shift 2
606     map 'eval echo "$v \${$v:-no}"' "$@" |
607     awk "BEGIN { split(\"$files\", files) }
608         {
609             c = \"$pfx\" toupper(\$1);
610             v = \$2;
611             sub(/yes/, 1, v);
612             sub(/no/,  0, v);
613             for (f in files) {
614                 file = files[f];
615                 if (file ~ /\\.h\$/) {
616                     printf(\"#define %s %d\\n\", c, v) >>file;
617                 } else if (file ~ /\\.asm\$/) {
618                     printf(\"%%define %s %d\\n\", c, v) >>file;
619                 } else if (file ~ /\\.mak\$/) {
620                     n = -v ? \"\" : \"!\";
621                     printf(\"%s%s=yes\\n\", n, c) >>file;
622                 }
623             }
624         }"
625 }
626
627 print_enabled(){
628     suf=$1
629     shift
630     for v; do
631         enabled $v && printf "%s\n" ${v%$suf};
632     done
633 }
634
635 append(){
636     var=$1
637     shift
638     eval "$var=\"\$$var $*\""
639 }
640
641 prepend(){
642     var=$1
643     shift
644     eval "$var=\"$* \$$var\""
645 }
646
647 add_cppflags(){
648     append CPPFLAGS "$@"
649 }
650
651 add_cflags(){
652     append CFLAGS $($cflags_filter "$@")
653 }
654
655 add_asflags(){
656     append ASFLAGS $($asflags_filter "$@")
657 }
658
659 add_ldflags(){
660     append LDFLAGS $($ldflags_filter "$@")
661 }
662
663 add_stripflags(){
664     append STRIPFLAGS "$@"
665 }
666
667 add_extralibs(){
668     prepend extralibs $($ldflags_filter "$@")
669 }
670
671 add_host_cppflags(){
672     append host_cppflags "$@"
673 }
674
675 add_host_cflags(){
676     append host_cflags $($host_cflags_filter "$@")
677 }
678
679 add_host_ldflags(){
680     append host_ldflags $($host_ldflags_filter "$@")
681 }
682
683 add_compat(){
684     append compat_objs $1
685     shift
686     map 'add_cppflags -D$v' "$@"
687 }
688
689 check_cmd(){
690     log "$@"
691     "$@" >> $logfile 2>&1
692 }
693
694 cc_o(){
695     eval printf '%s\\n' $CC_O
696 }
697
698 cc_e(){
699     eval printf '%s\\n' $CC_E
700 }
701
702 check_cc(){
703     log check_cc "$@"
704     cat > $TMPC
705     log_file $TMPC
706     check_cmd $cc $CPPFLAGS $CFLAGS "$@" $CC_C $(cc_o $TMPO) $TMPC
707 }
708
709 check_cpp(){
710     log check_cpp "$@"
711     cat > $TMPC
712     log_file $TMPC
713     check_cmd $cc $CPPFLAGS $CFLAGS "$@" $(cc_e $TMPO) $TMPC
714 }
715
716 as_o(){
717     eval printf '%s\\n' $AS_O
718 }
719
720 check_as(){
721     log check_as "$@"
722     cat > $TMPS
723     log_file $TMPS
724     check_cmd $as $CPPFLAGS $ASFLAGS "$@" $AS_C $(as_o $TMPO) $TMPS
725 }
726
727 check_inline_asm(){
728     log check_inline_asm "$@"
729     name="$1"
730     code="$2"
731     shift 2
732     disable $name
733     check_cc "$@" <<EOF && enable $name
734 void foo(void){ __asm__ volatile($code); }
735 EOF
736 }
737
738 check_insn(){
739     log check_insn "$@"
740     check_inline_asm ${1}_inline "\"$2\""
741     echo "$2" | check_as && enable ${1}_external || disable ${1}_external
742 }
743
744 check_yasm(){
745     log check_yasm "$@"
746     echo "$1" > $TMPS
747     log_file $TMPS
748     shift 1
749     check_cmd $yasmexe $YASMFLAGS "$@" -o $TMPO $TMPS
750 }
751
752 ld_o(){
753     eval printf '%s\\n' $LD_O
754 }
755
756 check_ld(){
757     log check_ld "$@"
758     flags=$(filter_out '-l*' "$@")
759     libs=$(filter '-l*' "$@")
760     check_cc $($cflags_filter $flags) || return
761     flags=$($ldflags_filter $flags)
762     libs=$($ldflags_filter $libs)
763     check_cmd $ld $LDFLAGS $flags $(ld_o $TMPE) $TMPO $libs $extralibs
764 }
765
766 check_code(){
767     log check_code "$@"
768     check=$1
769     headers=$2
770     code=$3
771     shift 3
772     {
773         for hdr in $headers; do
774             echo "#include <$hdr>"
775         done
776         echo "int main(void) { $code; return 0; }"
777     } | check_$check "$@"
778 }
779
780 check_cppflags(){
781     log check_cppflags "$@"
782     check_cc "$@" <<EOF && append CPPFLAGS "$@"
783 int x;
784 EOF
785 }
786
787 test_cflags(){
788     log test_cflags "$@"
789     set -- $($cflags_filter "$@")
790     check_cc "$@" <<EOF
791 int x;
792 EOF
793 }
794
795 check_cflags(){
796     log check_cflags "$@"
797     test_cflags "$@" && add_cflags "$@"
798 }
799
800 test_ldflags(){
801     log test_ldflags "$@"
802     check_ld "$@" <<EOF
803 int main(void){ return 0; }
804 EOF
805 }
806
807 check_ldflags(){
808     log check_ldflags "$@"
809     test_ldflags "$@" && add_ldflags "$@"
810 }
811
812 test_stripflags(){
813     log test_stripflags "$@"
814     # call check_cc to get a fresh TMPO
815     check_cc <<EOF
816 int main(void) { return 0; }
817 EOF
818     check_cmd $strip $STRIPFLAGS "$@" $TMPO
819 }
820
821 check_stripflags(){
822     log check_stripflags "$@"
823     test_stripflags "$@" && add_stripflags "$@"
824 }
825
826 check_header(){
827     log check_header "$@"
828     header=$1
829     shift
830     disable_safe $header
831     check_cpp "$@" <<EOF && enable_safe $header
832 #include <$header>
833 int x;
834 EOF
835 }
836
837 check_func(){
838     log check_func "$@"
839     func=$1
840     shift
841     disable $func
842     check_ld "$@" <<EOF && enable $func
843 extern int $func();
844 int main(void){ $func(); }
845 EOF
846 }
847
848 check_mathfunc(){
849     log check_mathfunc "$@"
850     func=$1
851     narg=$2
852     shift 2
853     test $narg = 2 && args="f, g" || args="f"
854     disable $func
855     check_ld "$@" <<EOF && enable $func
856 #include <math.h>
857 float foo(float f, float g) { return $func($args); }
858 int main(void){ return 0; }
859 EOF
860 }
861
862 check_func_headers(){
863     log check_func_headers "$@"
864     headers=$1
865     funcs=$2
866     shift 2
867     {
868         for hdr in $headers; do
869             echo "#include <$hdr>"
870         done
871         for func in $funcs; do
872             echo "long check_$func(void) { return (long) $func; }"
873         done
874         echo "int main(void) { return 0; }"
875     } | check_ld "$@" && enable $funcs && enable_safe $headers
876 }
877
878 check_cpp_condition(){
879     log check_cpp_condition "$@"
880     header=$1
881     condition=$2
882     shift 2
883     check_cpp "$@" <<EOF
884 #include <$header>
885 #if !($condition)
886 #error "unsatisfied condition: $condition"
887 #endif
888 EOF
889 }
890
891 check_lib(){
892     log check_lib "$@"
893     header="$1"
894     func="$2"
895     shift 2
896     check_header $header && check_func $func "$@" && add_extralibs "$@"
897 }
898
899 check_lib2(){
900     log check_lib2 "$@"
901     headers="$1"
902     funcs="$2"
903     shift 2
904     check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@"
905 }
906
907 check_pkg_config(){
908     log check_pkg_config "$@"
909     pkg="$1"
910     headers="$2"
911     funcs="$3"
912     shift 3
913     check_cmd $pkg_config --exists --print-errors $pkg || return
914     pkg_cflags=$($pkg_config --cflags $pkg)
915     pkg_libs=$($pkg_config --libs $pkg)
916     check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
917         set_safe ${pkg}_cflags $pkg_cflags   &&
918         set_safe ${pkg}_libs   $pkg_libs
919 }
920
921 check_exec(){
922     check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; }
923 }
924
925 check_exec_crash(){
926     code=$(cat)
927
928     # exit() is not async signal safe.  _Exit (C99) and _exit (POSIX)
929     # are safe but may not be available everywhere.  Thus we use
930     # raise(SIGTERM) instead.  The check is run in a subshell so we
931     # can redirect the "Terminated" message from the shell.  SIGBUS
932     # is not defined by standard C so it is used conditionally.
933
934     (check_exec "$@") >> $logfile 2>&1 <<EOF
935 #include <signal.h>
936 static void sighandler(int sig){
937     raise(SIGTERM);
938 }
939 int foo(void){
940     $code
941 }
942 int (*func_ptr)(void) = foo;
943 int main(void){
944     signal(SIGILL, sighandler);
945     signal(SIGFPE, sighandler);
946     signal(SIGSEGV, sighandler);
947 #ifdef SIGBUS
948     signal(SIGBUS, sighandler);
949 #endif
950     return func_ptr();
951 }
952 EOF
953 }
954
955 check_type(){
956     log check_type "$@"
957     headers=$1
958     type=$2
959     shift 2
960     disable_safe "$type"
961     check_code cc "$headers" "$type v" "$@" && enable_safe "$type"
962 }
963
964 check_struct(){
965     log check_struct "$@"
966     headers=$1
967     struct=$2
968     member=$3
969     shift 3
970     disable_safe "${struct}_${member}"
971     check_code cc "$headers" "const void *p = &(($struct *)0)->$member" "$@" &&
972         enable_safe "${struct}_${member}"
973 }
974
975 check_builtin(){
976     log check_builtin "$@"
977     name=$1
978     headers=$2
979     builtin=$3
980     shift 3
981     disable "$name"
982     check_code ld "$headers" "$builtin" "$@" && enable "$name"
983 }
984
985 require(){
986     name="$1"
987     header="$2"
988     func="$3"
989     shift 3
990     check_lib $header $func "$@" || die "ERROR: $name not found"
991 }
992
993 require2(){
994     name="$1"
995     headers="$2"
996     func="$3"
997     shift 3
998     check_lib2 "$headers" $func "$@" || die "ERROR: $name not found"
999 }
1000
1001 require_pkg_config(){
1002     pkg="$1"
1003     check_pkg_config "$@" || die "ERROR: $pkg not found"
1004     add_cflags    $(get_safe ${pkg}_cflags)
1005     add_extralibs $(get_safe ${pkg}_libs)
1006 }
1007
1008 hostcc_e(){
1009     eval printf '%s\\n' $HOSTCC_E
1010 }
1011
1012 hostcc_o(){
1013     eval printf '%s\\n' $HOSTCC_O
1014 }
1015
1016 check_host_cc(){
1017     log check_host_cc "$@"
1018     cat > $TMPC
1019     log_file $TMPC
1020     check_cmd $host_cc $host_cflags "$@" $HOSTCC_C $(hostcc_o $TMPO) $TMPC
1021 }
1022
1023 check_host_cpp(){
1024     log check_host_cpp "$@"
1025     cat > $TMPC
1026     log_file $TMPC
1027     check_cmd $host_cc $HOSTCPPFLAGS $HOSTCFLAGS "$@" $(hostcc_e $TMPO) $TMPC
1028 }
1029
1030 check_host_cppflags(){
1031     log check_host_cppflags "$@"
1032     check_host_cc "$@" <<EOF && append host_cppflags "$@"
1033 int x;
1034 EOF
1035 }
1036
1037 check_host_cflags(){
1038     log check_host_cflags "$@"
1039     set -- $($host_cflags_filter "$@")
1040     check_host_cc "$@" <<EOF && append host_cflags "$@"
1041 int x;
1042 EOF
1043 }
1044
1045 check_host_cpp_condition(){
1046     log check_host_cpp_condition "$@"
1047     header=$1
1048     condition=$2
1049     shift 2
1050     check_host_cpp "$@" <<EOF
1051 #include <$header>
1052 #if !($condition)
1053 #error "unsatisfied condition: $condition"
1054 #endif
1055 EOF
1056 }
1057
1058 apply(){
1059     file=$1
1060     shift
1061     "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp"
1062 }
1063
1064 cp_if_changed(){
1065     cmp -s "$1" "$2" && echo "$2 is unchanged" && return
1066     mkdir -p "$(dirname $2)"
1067     $cp_f "$1" "$2"
1068 }
1069
1070 # CONFIG_LIST contains configurable options, while HAVE_LIST is for
1071 # system-dependent things.
1072
1073 COMPONENT_LIST="
1074     bsfs
1075     decoders
1076     demuxers
1077     encoders
1078     filters
1079     hwaccels
1080     indevs
1081     muxers
1082     outdevs
1083     parsers
1084     protocols
1085 "
1086
1087 EXAMPLE_LIST="
1088     output_example
1089     transcode_aac_example
1090 "
1091
1092 EXTERNAL_LIBRARY_LIST="
1093     avisynth
1094     bzlib
1095     frei0r
1096     gnutls
1097     libcdio
1098     libdc1394
1099     libfaac
1100     libfdk_aac
1101     libfreetype
1102     libgsm
1103     libilbc
1104     libmp3lame
1105     libopencore_amrnb
1106     libopencore_amrwb
1107     libopencv
1108     libopenjpeg
1109     libopus
1110     libpulse
1111     librtmp
1112     libschroedinger
1113     libspeex
1114     libtheora
1115     libvo_aacenc
1116     libvo_amrwbenc
1117     libvorbis
1118     libvpx
1119     libwavpack
1120     libwebp
1121     libx264
1122     libxavs
1123     libxvid
1124     openssl
1125     x11grab
1126     zlib
1127 "
1128
1129 HWACCEL_LIST="
1130     dxva2
1131     vaapi
1132     vda
1133     vdpau
1134 "
1135 LIBRARY_LIST="
1136     avcodec
1137     avdevice
1138     avfilter
1139     avformat
1140     avresample
1141     avutil
1142     swscale
1143 "
1144
1145 PROGRAM_LIST="
1146     avconv
1147     avplay
1148     avprobe
1149     avserver
1150 "
1151
1152 CONFIG_LIST="
1153     $COMPONENT_LIST
1154     $EXAMPLE_LIST
1155     $EXTERNAL_LIBRARY_LIST
1156     $HWACCEL_LIST
1157     $LIBRARY_LIST
1158     $PROGRAM_LIST
1159     dct
1160     doc
1161     error_resilience
1162     fft
1163     gpl
1164     gray
1165     hardcoded_tables
1166     lsp
1167     lzo
1168     mdct
1169     memalign_hack
1170     network
1171     nonfree
1172     pod2man
1173     pic
1174     rdft
1175     runtime_cpudetect
1176     safe_bitstream_reader
1177     shared
1178     small
1179     sram
1180     static
1181     swscale_alpha
1182     texi2html
1183     thumb
1184     version3
1185     xmm_clobber_test
1186 "
1187
1188 THREADS_LIST='
1189     pthreads
1190     w32threads
1191 '
1192
1193 ATOMICS_LIST='
1194     atomics_gcc
1195     atomics_suncc
1196     atomics_win32
1197 '
1198
1199 ARCH_LIST='
1200     aarch64
1201     alpha
1202     arm
1203     avr32
1204     avr32_ap
1205     avr32_uc
1206     bfin
1207     ia64
1208     m68k
1209     mips
1210     mips64
1211     parisc
1212     ppc
1213     ppc64
1214     s390
1215     sh4
1216     sparc
1217     sparc64
1218     tilegx
1219     tilepro
1220     tomi
1221     x86
1222     x86_32
1223     x86_64
1224 '
1225
1226 ARCH_EXT_LIST_ARM='
1227     armv5te
1228     armv6
1229     armv6t2
1230     neon
1231     vfp
1232     vfpv3
1233 '
1234
1235 ARCH_EXT_LIST_X86='
1236     amd3dnow
1237     amd3dnowext
1238     avx
1239     avx2
1240     fma4
1241     i686
1242     mmx
1243     mmxext
1244     sse
1245     sse2
1246     sse3
1247     sse4
1248     sse42
1249     ssse3
1250 '
1251
1252 ARCH_EXT_LIST="
1253     $ARCH_EXT_LIST_ARM
1254     $ARCH_EXT_LIST_X86
1255     altivec
1256     ppc4xx
1257     vis
1258 "
1259
1260 HAVE_LIST_CMDLINE='
1261     inline_asm
1262     symver
1263     yasm
1264 '
1265
1266 HAVE_LIST_PUB='
1267     bigendian
1268     fast_unaligned
1269 '
1270
1271 MATH_FUNCS="
1272     atanf
1273     atan2f
1274     cbrtf
1275     cosf
1276     exp2
1277     exp2f
1278     expf
1279     isinf
1280     isnan
1281     ldexpf
1282     llrint
1283     llrintf
1284     log2
1285     log2f
1286     log10f
1287     lrint
1288     lrintf
1289     powf
1290     rint
1291     round
1292     roundf
1293     sinf
1294     trunc
1295     truncf
1296 "
1297
1298 HAVE_LIST="
1299     $ARCH_EXT_LIST
1300     $(add_suffix _external $ARCH_EXT_LIST)
1301     $(add_suffix _inline   $ARCH_EXT_LIST)
1302     $HAVE_LIST_CMDLINE
1303     $HAVE_LIST_PUB
1304     $THREADS_LIST
1305     $ATOMICS_LIST
1306     $MATH_FUNCS
1307     aligned_malloc
1308     aligned_stack
1309     alsa_asoundlib_h
1310     altivec_h
1311     arpa_inet_h
1312     asm_mod_q
1313     asm_mod_y
1314     atomic_cas_ptr
1315     atomics_native
1316     attribute_may_alias
1317     attribute_packed
1318     cdio_paranoia_h
1319     cdio_paranoia_paranoia_h
1320     closesocket
1321     CommandLineToArgvW
1322     cpunop
1323     CryptGenRandom
1324     dcbzl
1325     dev_bktr_ioctl_bt848_h
1326     dev_bktr_ioctl_meteor_h
1327     dev_ic_bt8xx_h
1328     dev_video_bktr_ioctl_bt848_h
1329     dev_video_meteor_ioctl_meteor_h
1330     direct_h
1331     dlfcn_h
1332     dlopen
1333     dos_paths
1334     dxva_h
1335     ebp_available
1336     ebx_available
1337     fast_64bit
1338     fast_clz
1339     fast_cmov
1340     fcntl
1341     fork
1342     getaddrinfo
1343     gethrtime
1344     getopt
1345     GetProcessAffinityMask
1346     GetProcessMemoryInfo
1347     GetProcessTimes
1348     GetSystemTimeAsFileTime
1349     getrusage
1350     getservbyport
1351     gettimeofday
1352     gnu_as
1353     gsm_h
1354     ibm_asm
1355     inet_aton
1356     io_h
1357     inline_asm_labels
1358     isatty
1359     jack_port_get_latency_range
1360     ldbrx
1361     libc_msvcrt
1362     libdc1394_1
1363     libdc1394_2
1364     local_aligned_16
1365     local_aligned_8
1366     localtime_r
1367     loongson
1368     machine_ioctl_bt848_h
1369     machine_ioctl_meteor_h
1370     machine_rw_barrier
1371     malloc_h
1372     MapViewOfFile
1373     memalign
1374     MemoryBarrier
1375     mkstemp
1376     mm_empty
1377     mmap
1378     mprotect
1379     nanosleep
1380     poll_h
1381     posix_memalign
1382     pragma_deprecated
1383     rdtsc
1384     sched_getaffinity
1385     sdl
1386     SetConsoleTextAttribute
1387     setmode
1388     setrlimit
1389     Sleep
1390     sndio_h
1391     socklen_t
1392     soundcard_h
1393     strerror_r
1394     strptime
1395     strtok_r
1396     struct_addrinfo
1397     struct_group_source_req
1398     struct_ip_mreq_source
1399     struct_ipv6_mreq
1400     struct_pollfd
1401     struct_rusage_ru_maxrss
1402     struct_sockaddr_in6
1403     struct_sockaddr_sa_len
1404     struct_sockaddr_storage
1405     struct_v4l2_frmivalenum_discrete
1406     symver_asm_label
1407     symver_gnu_asm
1408     sync_val_compare_and_swap
1409     sysconf
1410     sysctl
1411     sys_mman_h
1412     sys_param_h
1413     sys_resource_h
1414     sys_select_h
1415     sys_soundcard_h
1416     sys_time_h
1417     sys_un_h
1418     sys_videoio_h
1419     threads
1420     unistd_h
1421     usleep
1422     vdpau_x11
1423     vfp_args
1424     VirtualAlloc
1425     windows_h
1426     winsock2_h
1427     xform_asm
1428     xlib
1429     xmm_clobbers
1430 "
1431
1432 # options emitted with CONFIG_ prefix but not available on the command line
1433 CONFIG_EXTRA="
1434     aandcttables
1435     ac3dsp
1436     audio_frame_queue
1437     dsputil
1438     gcrypt
1439     golomb
1440     gplv3
1441     h263dsp
1442     h264chroma
1443     h264dsp
1444     h264pred
1445     h264qpel
1446     hpeldsp
1447     huffman
1448     lgplv3
1449     lpc
1450     mpegaudio
1451     mpegaudiodsp
1452     mpegvideo
1453     mpegvideoenc
1454     nettle
1455     rangecoder
1456     riffdec
1457     riffenc
1458     rtpdec
1459     rtpenc_chain
1460     sinewin
1461     videodsp
1462     vp3dsp
1463 "
1464
1465 CMDLINE_SELECT="
1466     $ARCH_EXT_LIST
1467     $CONFIG_LIST
1468     $HAVE_LIST_CMDLINE
1469     $THREADS_LIST
1470     asm
1471     cross_compile
1472     debug
1473     extra_warnings
1474     logging
1475     lto
1476     optimizations
1477 "
1478
1479 PATHS_LIST='
1480     bindir
1481     datadir
1482     docdir
1483     incdir
1484     libdir
1485     mandir
1486     prefix
1487     shlibdir
1488 '
1489
1490 CMDLINE_SET="
1491     $PATHS_LIST
1492     ar
1493     arch
1494     as
1495     build_suffix
1496     cc
1497     cpu
1498     cross_prefix
1499     dep_cc
1500     extra_version
1501     host_cc
1502     host_cflags
1503     host_ld
1504     host_ldflags
1505     host_libs
1506     host_os
1507     ld
1508     logfile
1509     malloc_prefix
1510     nm
1511     optflags
1512     pkg_config
1513     random_seed
1514     samples
1515     sysinclude
1516     sysroot
1517     target_exec
1518     target_os
1519     target_path
1520     target_samples
1521     toolchain
1522 "
1523
1524 CMDLINE_APPEND="
1525     extra_cflags
1526     host_cppflags
1527 "
1528
1529 # code dependency declarations
1530
1531 # architecture extensions
1532
1533 armv5te_deps="arm"
1534 armv6_deps="arm"
1535 armv6t2_deps="arm"
1536 neon_deps="arm"
1537 vfp_deps="arm"
1538 vfpv3_deps="vfp"
1539
1540 map 'eval ${v}_inline_deps=inline_asm' $ARCH_EXT_LIST_ARM
1541
1542 altivec_deps="ppc"
1543 ppc4xx_deps="ppc"
1544
1545 vis_deps="sparc"
1546
1547 cpunop_deps="i686"
1548 x86_64_select="i686"
1549 x86_64_suggest="fast_cmov"
1550
1551 amd3dnow_deps="mmx"
1552 amd3dnowext_deps="amd3dnow"
1553 mmx_deps="x86"
1554 mmxext_deps="mmx"
1555 sse_deps="mmxext"
1556 sse2_deps="sse"
1557 sse3_deps="sse2"
1558 ssse3_deps="sse3"
1559 sse4_deps="ssse3"
1560 sse42_deps="sse4"
1561 avx_deps="sse42"
1562 fma4_deps="avx"
1563 avx2_deps="avx"
1564
1565 mmx_external_deps="yasm"
1566 mmx_inline_deps="inline_asm"
1567 mmx_suggest="mmx_external mmx_inline"
1568
1569 for ext in $(filter_out mmx $ARCH_EXT_LIST_X86); do
1570     eval dep=\$${ext}_deps
1571     eval ${ext}_external_deps='"${dep}_external"'
1572     eval ${ext}_inline_deps='"${dep}_inline"'
1573     eval ${ext}_suggest='"${ext}_external ${ext}_inline"'
1574 done
1575
1576 aligned_stack_if_any="ppc x86"
1577 fast_64bit_if_any="alpha ia64 mips64 parisc64 ppc64 sparc64 x86_64"
1578 fast_clz_if_any="alpha avr32 mips ppc x86"
1579 fast_unaligned_if_any="ppc x86"
1580
1581 need_memalign="altivec neon sse"
1582
1583 # system capabilities
1584 log2_deps="!libc_msvcrt"
1585
1586 symver_if_any="symver_asm_label symver_gnu_asm"
1587
1588 # threading support
1589 atomics_gcc_if="sync_val_compare_and_swap"
1590 atomics_suncc_if="atomic_cas_ptr machine_rw_barrier"
1591 atomics_win32_if="MemoryBarrier"
1592 atomics_native_if_any="$ATOMICS_LIST"
1593 threads_if_any="$THREADS_LIST"
1594
1595 # subsystems
1596 dct_select="rdft"
1597 error_resilience_select="dsputil"
1598 lpc_select="dsputil"
1599 mdct_select="fft"
1600 rdft_select="fft"
1601 mpegaudio_select="mpegaudiodsp"
1602 mpegaudiodsp_select="dct"
1603 mpegvideo_select="dsputil hpeldsp videodsp"
1604 mpegvideoenc_select="mpegvideo"
1605
1606 # decoders / encoders
1607 aac_decoder_select="mdct sinewin"
1608 aac_encoder_select="audio_frame_queue mdct sinewin"
1609 aac_latm_decoder_select="aac_decoder aac_latm_parser"
1610 ac3_decoder_select="mdct ac3dsp ac3_parser dsputil"
1611 ac3_encoder_select="mdct ac3dsp dsputil"
1612 ac3_fixed_encoder_select="mdct ac3dsp dsputil"
1613 aic_decoder_select="dsputil golomb"
1614 alac_encoder_select="lpc"
1615 als_decoder_select="dsputil"
1616 amrnb_decoder_select="lsp"
1617 amrwb_decoder_select="lsp"
1618 amv_decoder_select="dsputil hpeldsp"
1619 ape_decoder_select="dsputil"
1620 asv1_decoder_select="dsputil"
1621 asv1_encoder_select="dsputil"
1622 asv2_decoder_select="dsputil"
1623 asv2_encoder_select="dsputil"
1624 atrac1_decoder_select="mdct sinewin"
1625 atrac3_decoder_select="mdct"
1626 bink_decoder_select="dsputil hpeldsp"
1627 binkaudio_dct_decoder_select="mdct rdft dct sinewin"
1628 binkaudio_rdft_decoder_select="mdct rdft sinewin"
1629 cavs_decoder_select="dsputil golomb h264chroma videodsp"
1630 cllc_decoder_select="dsputil"
1631 comfortnoise_encoder_select="lpc"
1632 cook_decoder_select="dsputil mdct sinewin"
1633 cscd_decoder_select="lzo"
1634 cscd_decoder_suggest="zlib"
1635 dca_decoder_select="mdct"
1636 dnxhd_decoder_select="dsputil"
1637 dnxhd_encoder_select="aandcttables dsputil mpegvideoenc"
1638 dvvideo_decoder_select="dsputil"
1639 dvvideo_encoder_select="dsputil"
1640 dxa_decoder_deps="zlib"
1641 eac3_decoder_select="ac3_decoder"
1642 eac3_encoder_select="ac3_encoder"
1643 eamad_decoder_select="aandcttables dsputil mpegvideo"
1644 eatgq_decoder_select="aandcttables dsputil"
1645 eatqi_decoder_select="aandcttables error_resilience mpegvideo"
1646 ffv1_decoder_select="dsputil golomb rangecoder"
1647 ffv1_encoder_select="dsputil rangecoder"
1648 ffvhuff_decoder_select="dsputil"
1649 ffvhuff_encoder_select="dsputil huffman"
1650 flac_decoder_select="golomb"
1651 flac_encoder_select="dsputil golomb lpc"
1652 flashsv_decoder_deps="zlib"
1653 flashsv_encoder_deps="zlib"
1654 flashsv2_decoder_deps="zlib"
1655 flv_decoder_select="h263_decoder"
1656 flv_encoder_select="h263_encoder"
1657 fourxm_decoder_select="dsputil"
1658 fraps_decoder_select="dsputil huffman"
1659 g2m_decoder_deps="zlib"
1660 g2m_decoder_select="dsputil"
1661 h261_decoder_select="error_resilience mpegvideo"
1662 h261_encoder_select="aandcttables mpegvideoenc"
1663 h263_decoder_select="error_resilience h263_parser h263dsp mpegvideo"
1664 h263_encoder_select="aandcttables h263dsp mpegvideoenc"
1665 h263i_decoder_select="h263_decoder"
1666 h263p_encoder_select="h263_encoder"
1667 h264_decoder_select="golomb h264chroma h264dsp h264pred h264qpel videodsp"
1668 h264_decoder_suggest="error_resilience"
1669 hevc_decoder_select="dsputil golomb videodsp"
1670 huffyuv_decoder_select="dsputil"
1671 huffyuv_encoder_select="dsputil huffman"
1672 iac_decoder_select="dsputil fft mdct sinewin"
1673 imc_decoder_select="dsputil fft mdct sinewin"
1674 indeo3_decoder_select="hpeldsp"
1675 interplay_video_decoder_select="hpeldsp"
1676 jpegls_decoder_select="dsputil golomb hpeldsp"
1677 jpegls_encoder_select="golomb"
1678 jv_decoder_select="dsputil"
1679 lagarith_decoder_select="dsputil"
1680 ljpeg_encoder_select="aandcttables mpegvideoenc"
1681 loco_decoder_select="golomb"
1682 mdec_decoder_select="dsputil error_resilience mpegvideo"
1683 metasound_decoder_select="lsp mdct sinewin"
1684 mimic_decoder_select="dsputil hpeldsp"
1685 mjpeg_decoder_select="dsputil hpeldsp"
1686 mjpegb_decoder_select="dsputil hpeldsp"
1687 mjpeg_encoder_select="aandcttables dsputil mpegvideoenc"
1688 mlp_decoder_select="dsputil mlp_parser"
1689 motionpixels_decoder_select="dsputil"
1690 mp1_decoder_select="mpegaudio"
1691 mp1float_decoder_select="mpegaudio"
1692 mp2_decoder_select="mpegaudio"
1693 mp2float_decoder_select="mpegaudio"
1694 mp3_decoder_select="mpegaudio"
1695 mp3adu_decoder_select="mpegaudio"
1696 mp3adufloat_decoder_select="mpegaudio"
1697 mp3float_decoder_select="mpegaudio"
1698 mp3on4_decoder_select="mpegaudio"
1699 mp3on4float_decoder_select="mpegaudio"
1700 mpc7_decoder_select="dsputil mpegaudiodsp"
1701 mpc8_decoder_select="dsputil mpegaudiodsp"
1702 mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h"
1703 mpeg_xvmc_decoder_select="mpeg2video_decoder"
1704 mpeg1video_decoder_select="error_resilience mpegvideo"
1705 mpeg1video_encoder_select="aandcttables mpegvideoenc"
1706 mpeg2video_decoder_select="error_resilience mpegvideo"
1707 mpeg2video_encoder_select="aandcttables mpegvideoenc"
1708 mpeg4_decoder_select="h263_decoder mpeg4video_parser"
1709 mpeg4_encoder_select="h263_encoder"
1710 msmpeg4v1_decoder_select="h263_decoder"
1711 msmpeg4v2_decoder_select="h263_decoder"
1712 msmpeg4v2_encoder_select="h263_encoder"
1713 msmpeg4v3_decoder_select="h263_decoder"
1714 msmpeg4v3_encoder_select="h263_encoder"
1715 mss2_decoder_select="error_resilience vc1_decoder"
1716 mxpeg_decoder_select="dsputil hpeldsp"
1717 nellymoser_decoder_select="mdct sinewin"
1718 nellymoser_encoder_select="audio_frame_queue mdct sinewin"
1719 nuv_decoder_select="dsputil lzo"
1720 png_decoder_deps="zlib"
1721 png_decoder_select="dsputil"
1722 png_encoder_deps="zlib"
1723 png_encoder_select="dsputil"
1724 prores_decoder_select="dsputil"
1725 prores_encoder_select="dsputil"
1726 qcelp_decoder_select="lsp"
1727 qdm2_decoder_select="mdct rdft mpegaudiodsp"
1728 ra_144_encoder_select="audio_frame_queue lpc"
1729 ralf_decoder_select="golomb"
1730 rv10_decoder_select="error_resilience h263_decoder h263dsp"
1731 rv10_encoder_select="h263_encoder"
1732 rv20_decoder_select="error_resilience h263_decoder h263dsp"
1733 rv20_encoder_select="h263_encoder"
1734 rv30_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo videodsp"
1735 rv40_decoder_select="error_resilience golomb h264chroma h264pred h264qpel mpegvideo videodsp"
1736 shorten_decoder_select="golomb"
1737 sipr_decoder_select="lsp"
1738 sp5x_decoder_select="dsputil hpeldsp"
1739 svq1_decoder_select="hpeldsp"
1740 svq1_encoder_select="aandcttables dsputil hpeldsp mpegvideoenc"
1741 svq3_decoder_select="golomb h264chroma h264dsp h264pred h264qpel hpeldsp mpegvideo videodsp"
1742 svq3_decoder_suggest="error_resilience zlib"
1743 tak_decoder_select="dsputil"
1744 theora_decoder_select="vp3_decoder"
1745 tiff_decoder_suggest="zlib"
1746 tiff_encoder_suggest="zlib"
1747 thp_decoder_select="dsputil hpeldsp"
1748 truehd_decoder_select="mlp_decoder"
1749 truemotion2_decoder_select="dsputil"
1750 truespeech_decoder_select="dsputil"
1751 tscc_decoder_deps="zlib"
1752 twinvq_decoder_select="mdct lsp sinewin"
1753 utvideo_decoder_select="dsputil"
1754 utvideo_encoder_select="dsputil huffman"
1755 vble_decoder_select="dsputil"
1756 vc1_decoder_select="error_resilience h263_decoder h264chroma h264qpel"
1757 vc1image_decoder_select="vc1_decoder"
1758 vorbis_decoder_select="mdct"
1759 vorbis_encoder_select="mdct"
1760 vp3_decoder_select="hpeldsp vp3dsp videodsp"
1761 vp5_decoder_select="h264chroma hpeldsp videodsp vp3dsp"
1762 vp6_decoder_select="h264chroma hpeldsp huffman videodsp vp3dsp"
1763 vp6a_decoder_select="vp6_decoder"
1764 vp6f_decoder_select="vp6_decoder"
1765 vp8_decoder_select="h264pred videodsp"
1766 vp9_decoder_select="videodsp"
1767 webp_decoder_select="vp8_decoder"
1768 wmapro_decoder_select="mdct sinewin"
1769 wmav1_decoder_select="mdct sinewin"
1770 wmav1_encoder_select="mdct sinewin"
1771 wmav2_decoder_select="mdct sinewin"
1772 wmav2_encoder_select="mdct sinewin"
1773 wmavoice_decoder_select="lsp rdft dct mdct sinewin"
1774 wmv1_decoder_select="h263_decoder"
1775 wmv1_encoder_select="h263_encoder"
1776 wmv2_decoder_select="h263_decoder videodsp"
1777 wmv2_encoder_select="h263_encoder"
1778 wmv3_decoder_select="vc1_decoder"
1779 wmv3image_decoder_select="wmv3_decoder"
1780 zerocodec_decoder_deps="zlib"
1781 zlib_decoder_deps="zlib"
1782 zlib_encoder_deps="zlib"
1783 zmbv_decoder_deps="zlib"
1784 zmbv_encoder_deps="zlib"
1785
1786 # hardware accelerators
1787 dxva2_deps="dxva2api_h"
1788 vaapi_deps="va_va_h"
1789 vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads"
1790 vda_extralibs="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore"
1791 vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h"
1792
1793 h263_vaapi_hwaccel_deps="vaapi"
1794 h263_vaapi_hwaccel_select="h263_decoder"
1795 h263_vdpau_hwaccel_deps="vdpau"
1796 h263_vdpau_hwaccel_select="h263_decoder"
1797 h264_dxva2_hwaccel_deps="dxva2"
1798 h264_dxva2_hwaccel_select="h264_decoder"
1799 h264_vaapi_hwaccel_deps="vaapi"
1800 h264_vaapi_hwaccel_select="h264_decoder"
1801 h264_vda_hwaccel_deps="vda"
1802 h264_vda_hwaccel_select="h264_decoder"
1803 h264_vdpau_hwaccel_deps="vdpau"
1804 h264_vdpau_hwaccel_select="h264_decoder"
1805 mpeg1_vdpau_hwaccel_deps="vdpau"
1806 mpeg1_vdpau_hwaccel_select="mpeg1video_decoder"
1807 mpeg2_dxva2_hwaccel_deps="dxva2"
1808 mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
1809 mpeg2_vaapi_hwaccel_deps="vaapi"
1810 mpeg2_vaapi_hwaccel_select="mpeg2video_decoder"
1811 mpeg2_vdpau_hwaccel_deps="vdpau"
1812 mpeg2_vdpau_hwaccel_select="mpeg2video_decoder"
1813 mpeg4_vaapi_hwaccel_deps="vaapi"
1814 mpeg4_vaapi_hwaccel_select="mpeg4_decoder"
1815 mpeg4_vdpau_hwaccel_deps="vdpau"
1816 mpeg4_vdpau_hwaccel_select="mpeg4_decoder"
1817 vc1_dxva2_hwaccel_deps="dxva2"
1818 vc1_dxva2_hwaccel_select="vc1_decoder"
1819 vc1_vaapi_hwaccel_deps="vaapi"
1820 vc1_vaapi_hwaccel_select="vc1_decoder"
1821 vc1_vdpau_hwaccel_deps="vdpau"
1822 vc1_vdpau_hwaccel_select="vc1_decoder"
1823 wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel"
1824 wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel"
1825 wmv3_vdpau_hwaccel_select="vc1_vdpau_hwaccel"
1826
1827 # parsers
1828 h264_parser_select="golomb h264chroma h264dsp h264pred h264qpel videodsp"
1829 mpeg4video_parser_select="error_resilience mpegvideo"
1830 mpegvideo_parser_select="error_resilience mpegvideo"
1831 vc1_parser_select="mpegvideo"
1832
1833 # external libraries
1834 libfaac_encoder_deps="libfaac"
1835 libfaac_encoder_select="audio_frame_queue"
1836 libfdk_aac_decoder_deps="libfdk_aac"
1837 libfdk_aac_encoder_deps="libfdk_aac"
1838 libfdk_aac_encoder_select="audio_frame_queue"
1839 libgsm_decoder_deps="libgsm"
1840 libgsm_encoder_deps="libgsm"
1841 libgsm_ms_decoder_deps="libgsm"
1842 libgsm_ms_encoder_deps="libgsm"
1843 libilbc_decoder_deps="libilbc"
1844 libilbc_encoder_deps="libilbc"
1845 libmp3lame_encoder_deps="libmp3lame"
1846 libmp3lame_encoder_select="audio_frame_queue"
1847 libopencore_amrnb_decoder_deps="libopencore_amrnb"
1848 libopencore_amrnb_encoder_deps="libopencore_amrnb"
1849 libopencore_amrnb_encoder_select="audio_frame_queue"
1850 libopencore_amrwb_decoder_deps="libopencore_amrwb"
1851 libopenjpeg_decoder_deps="libopenjpeg"
1852 libopenjpeg_encoder_deps="libopenjpeg"
1853 libopus_decoder_deps="libopus"
1854 libopus_encoder_deps="libopus"
1855 libopus_encoder_select="audio_frame_queue"
1856 libschroedinger_decoder_deps="libschroedinger"
1857 libschroedinger_encoder_deps="libschroedinger"
1858 libspeex_decoder_deps="libspeex"
1859 libspeex_encoder_deps="libspeex"
1860 libspeex_encoder_select="audio_frame_queue"
1861 libtheora_encoder_deps="libtheora"
1862 libvo_aacenc_encoder_deps="libvo_aacenc"
1863 libvo_aacenc_encoder_select="audio_frame_queue"
1864 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
1865 libvorbis_encoder_deps="libvorbis"
1866 libvorbis_encoder_select="audio_frame_queue"
1867 libvpx_vp8_decoder_deps="libvpx"
1868 libvpx_vp8_encoder_deps="libvpx"
1869 libvpx_vp9_decoder_deps="libvpx"
1870 libvpx_vp9_encoder_deps="libvpx"
1871 libwavpack_encoder_deps="libwavpack"
1872 libwebp_encoder_deps="libwebp"
1873 libx264_encoder_deps="libx264"
1874 libxavs_encoder_deps="libxavs"
1875 libxvid_encoder_deps="libxvid"
1876
1877 # demuxers / muxers
1878 ac3_demuxer_select="ac3_parser"
1879 asf_demuxer_select="riffdec"
1880 asf_muxer_select="riffenc"
1881 asf_stream_muxer_select="asf_muxer"
1882 avi_demuxer_select="riffdec"
1883 avi_muxer_select="riffenc"
1884 avisynth_demuxer_deps="avisynth"
1885 avisynth_demuxer_select="riffdec"
1886 caf_demuxer_select="riffdec"
1887 dirac_demuxer_select="dirac_parser"
1888 dxa_demuxer_select="riffdec"
1889 eac3_demuxer_select="ac3_parser"
1890 f4v_muxer_select="mov_muxer"
1891 flac_demuxer_select="flac_parser"
1892 hds_muxer_select="flv_muxer"
1893 hls_muxer_select="mpegts_muxer"
1894 ipod_muxer_select="mov_muxer"
1895 ismv_muxer_select="mov_muxer"
1896 matroska_audio_muxer_select="matroska_muxer"
1897 matroska_demuxer_select="riffdec"
1898 matroska_demuxer_suggest="bzlib lzo zlib"
1899 matroska_muxer_select="riffenc"
1900 mmf_muxer_select="riffenc"
1901 mov_demuxer_select="riffdec"
1902 mov_demuxer_suggest="zlib"
1903 mov_muxer_select="riffenc rtpenc_chain"
1904 mp3_demuxer_select="mpegaudio_parser"
1905 mp4_muxer_select="mov_muxer"
1906 mpegts_muxer_select="adts_muxer latm_muxer"
1907 mpegtsraw_demuxer_select="mpegts_demuxer"
1908 mxf_d10_muxer_select="mxf_muxer"
1909 nut_muxer_select="riffenc"
1910 nuv_demuxer_select="riffdec"
1911 ogg_demuxer_select="golomb"
1912 psp_muxer_select="mov_muxer"
1913 rtp_demuxer_select="sdp_demuxer"
1914 rtpdec_select="asf_demuxer rm_demuxer rtp_protocol mpegts_demuxer mov_demuxer"
1915 rtsp_demuxer_select="http_protocol rtpdec"
1916 rtsp_muxer_select="rtp_muxer http_protocol rtp_protocol rtpenc_chain"
1917 sap_demuxer_select="sdp_demuxer"
1918 sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"
1919 sdp_demuxer_select="rtpdec"
1920 smoothstreaming_muxer_select="ismv_muxer"
1921 spdif_muxer_select="aac_parser"
1922 tak_demuxer_select="tak_parser"
1923 tg2_muxer_select="mov_muxer"
1924 tgp_muxer_select="mov_muxer"
1925 w64_demuxer_select="wav_demuxer"
1926 wav_demuxer_select="riffdec"
1927 wav_muxer_select="riffenc"
1928 webm_muxer_select="riffenc"
1929 wtv_demuxer_select="riffdec"
1930 xmv_demuxer_select="riffdec"
1931 xwma_demuxer_select="riffdec"
1932
1933 # indevs / outdevs
1934 alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp"
1935 alsa_outdev_deps="alsa_asoundlib_h"
1936 bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
1937 dv1394_indev_deps="dv1394"
1938 dv1394_indev_select="dv_demuxer"
1939 fbdev_indev_deps="linux_fb_h"
1940 jack_indev_deps="jack_jack_h pthreads"
1941 libcdio_indev_deps="libcdio"
1942 libdc1394_indev_deps="libdc1394"
1943 oss_indev_deps_any="soundcard_h sys_soundcard_h"
1944 oss_outdev_deps_any="soundcard_h sys_soundcard_h"
1945 pulse_indev_deps="libpulse"
1946 sndio_indev_deps="sndio_h"
1947 sndio_outdev_deps="sndio_h"
1948 v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
1949 vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines"
1950 vfwcap_indev_extralibs="-lavicap32"
1951 x11grab_indev_deps="x11grab XShmCreateImage"
1952
1953 # protocols
1954 ffrtmpcrypt_protocol_deps="!librtmp_protocol"
1955 ffrtmpcrypt_protocol_deps_any="gcrypt nettle openssl"
1956 ffrtmpcrypt_protocol_select="tcp_protocol"
1957 ffrtmphttp_protocol_deps="!librtmp_protocol"
1958 ffrtmphttp_protocol_select="http_protocol"
1959 gopher_protocol_select="network"
1960 httpproxy_protocol_select="tcp_protocol"
1961 http_protocol_select="tcp_protocol"
1962 https_protocol_select="tls_protocol"
1963 librtmp_protocol_deps="librtmp"
1964 librtmpe_protocol_deps="librtmp"
1965 librtmps_protocol_deps="librtmp"
1966 librtmpt_protocol_deps="librtmp"
1967 librtmpte_protocol_deps="librtmp"
1968 mmsh_protocol_select="http_protocol"
1969 mmst_protocol_select="network"
1970 rtmp_protocol_deps="!librtmp_protocol"
1971 rtmp_protocol_select="tcp_protocol"
1972 rtmpe_protocol_select="ffrtmpcrypt_protocol"
1973 rtmps_protocol_deps="!librtmp_protocol"
1974 rtmps_protocol_select="tls_protocol"
1975 rtmpt_protocol_select="ffrtmphttp_protocol"
1976 rtmpte_protocol_select="ffrtmpcrypt_protocol ffrtmphttp_protocol"
1977 rtmpts_protocol_select="ffrtmphttp_protocol https_protocol"
1978 rtp_protocol_select="udp_protocol"
1979 sctp_protocol_deps="struct_sctp_event_subscribe"
1980 sctp_protocol_select="network"
1981 srtp_protocol_select="rtp_protocol"
1982 tcp_protocol_select="network"
1983 tls_protocol_deps_any="openssl gnutls"
1984 tls_protocol_select="tcp_protocol"
1985 udp_protocol_select="network"
1986 unix_protocol_deps="sys_un_h"
1987 unix_protocol_select="network"
1988
1989 # filters
1990 blackframe_filter_deps="gpl"
1991 boxblur_filter_deps="gpl"
1992 cropdetect_filter_deps="gpl"
1993 delogo_filter_deps="gpl"
1994 drawtext_filter_deps="libfreetype"
1995 frei0r_filter_deps="frei0r dlopen strtok_r"
1996 frei0r_filter_extralibs='$ldl'
1997 frei0r_src_filter_deps="frei0r dlopen strtok_r"
1998 frei0r_src_filter_extralibs='$ldl'
1999 hqdn3d_filter_deps="gpl"
2000 interlace_filter_deps="gpl"
2001 resample_filter_deps="avresample"
2002 ocv_filter_deps="libopencv"
2003 scale_filter_deps="swscale"
2004 yadif_filter_deps="gpl"
2005
2006 # examples
2007 output_example_deps="avcodec avformat avutil swscale"
2008 transcode_aac_example_deps="avcodec avformat avresample"
2009
2010 # libraries
2011 avcodec_deps="avutil"
2012 avdevice_deps="avutil avcodec avformat"
2013 avfilter_deps="avutil"
2014 avformat_deps="avutil avcodec"
2015 avresample_deps="avutil"
2016 swscale_deps="avutil"
2017
2018 # programs
2019 avconv_deps="avcodec avfilter avformat avresample swscale"
2020 avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_filter
2021                fps_filter null_filter resample_filter scale_filter
2022                setpts_filter trim_filter"
2023 avplay_deps="avcodec avformat avresample swscale sdl"
2024 avplay_select="rdft"
2025 avprobe_deps="avcodec avformat"
2026 avserver_deps="avformat fork !shared"
2027 avserver_select="ffm_muxer rtp_protocol rtsp_demuxer"
2028 avserver_extralibs='$ldl'
2029
2030 # documentation
2031 pod2man_deps="doc"
2032 texi2html_deps="doc"
2033
2034 # default parameters
2035
2036 logfile="config.log"
2037
2038 # installation paths
2039 prefix_default="/usr/local"
2040 bindir_default='${prefix}/bin'
2041 datadir_default='${prefix}/share/avconv'
2042 docdir_default='${prefix}/share/doc/libav'
2043 incdir_default='${prefix}/include'
2044 libdir_default='${prefix}/lib'
2045 mandir_default='${prefix}/share/man'
2046 shlibdir_default="$libdir_default"
2047
2048 # toolchain
2049 ar_default="ar"
2050 cc_default="gcc"
2051 host_cc_default="gcc"
2052 cp_f="cp -f"
2053 ln_s="ln -s -f"
2054 nm_default="nm -g"
2055 objformat="elf"
2056 pkg_config_default=pkg-config
2057 ranlib="ranlib"
2058 strip="strip"
2059 yasmexe="yasm"
2060
2061 nogas=":"
2062
2063 # machine
2064 arch_default=$(uname -m)
2065 cpu="generic"
2066
2067 # OS
2068 target_os_default=$(tolower $(uname -s))
2069 host_os=$target_os_default
2070
2071 # configurable options
2072 enable $EXAMPLE_LIST $LIBRARY_LIST $PROGRAM_LIST
2073
2074 enable asm
2075 enable debug
2076 enable doc
2077 enable optimizations
2078 enable safe_bitstream_reader
2079 enable static
2080 enable swscale_alpha
2081
2082 # By default, enable only those hwaccels that have no external dependencies.
2083 enable dxva2 vdpau
2084
2085 # build settings
2086 SHFLAGS='-shared -Wl,-soname,$$(@F)'
2087 LIBPREF="lib"
2088 LIBSUF=".a"
2089 FULLNAME='$(NAME)$(BUILDSUF)'
2090 LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)'
2091 SLIBPREF="lib"
2092 SLIBSUF=".so"
2093 SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)'
2094 SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)'
2095 SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
2096 LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
2097 SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
2098 SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
2099
2100 asflags_filter=echo
2101 cflags_filter=echo
2102 ldflags_filter=echo
2103
2104 AS_C='-c'
2105 AS_O='-o $@'
2106 CC_C='-c'
2107 CC_E='-E -o $@'
2108 CC_O='-o $@'
2109 LD_O='-o $@'
2110 LD_LIB='-l%'
2111 LD_PATH='-L'
2112 HOSTCC_C='-c'
2113 HOSTCC_E='-E -o $@'
2114 HOSTCC_O='-o $@'
2115 HOSTLD_O='-o $@'
2116
2117 host_cflags='-O3'
2118 host_cppflags='-D_ISOC99_SOURCE'
2119 host_libs='-lm'
2120 host_cflags_filter=echo
2121 host_ldflags_filter=echo
2122
2123 target_path='$(CURDIR)'
2124
2125 # since the object filename is not given with the -MM flag, the compiler
2126 # is only able to print the basename, and we must add the path ourselves
2127 DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "/^\#.*/d" -e "s,^[[:space:]]*$(*F)\\.o,$(@D)/$(*F).o," > $(@:.o=.d)'
2128 DEPFLAGS='-MM'
2129
2130 # find source path
2131 if test -f configure; then
2132     source_path=.
2133 else
2134     source_path=$(cd $(dirname "$0"); pwd)
2135     echo "$source_path" | grep -q '[[:blank:]]' &&
2136         die "Out of tree builds are impossible with whitespace in source path."
2137     test -e "$source_path/config.h" &&
2138         die "Out of tree builds are impossible with config.h in source dir."
2139 fi
2140
2141 for v in "$@"; do
2142     r=${v#*=}
2143     l=${v%"$r"}
2144     r=$(sh_quote "$r")
2145     LIBAV_CONFIGURATION="${LIBAV_CONFIGURATION# } ${l}${r}"
2146 done
2147
2148 find_things(){
2149     thing=$1
2150     pattern=$2
2151     file=$source_path/$3
2152     sed -n "s/^[^#]*$pattern.*([^,]*, *\([^,]*\)\(,.*\)*).*/\1_$thing/p" "$file"
2153 }
2154
2155 ENCODER_LIST=$(find_things  encoder  ENC      libavcodec/allcodecs.c)
2156 DECODER_LIST=$(find_things  decoder  DEC      libavcodec/allcodecs.c)
2157 HWACCEL_LIST=$(find_things  hwaccel  HWACCEL  libavcodec/allcodecs.c)
2158 PARSER_LIST=$(find_things   parser   PARSER   libavcodec/allcodecs.c)
2159 BSF_LIST=$(find_things      bsf      BSF      libavcodec/allcodecs.c)
2160 MUXER_LIST=$(find_things    muxer    _MUX     libavformat/allformats.c)
2161 DEMUXER_LIST=$(find_things  demuxer  DEMUX    libavformat/allformats.c)
2162 OUTDEV_LIST=$(find_things   outdev   OUTDEV   libavdevice/alldevices.c)
2163 INDEV_LIST=$(find_things    indev    _IN      libavdevice/alldevices.c)
2164 PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c)
2165 FILTER_LIST=$(find_things   filter   FILTER   libavfilter/allfilters.c)
2166
2167 ALL_COMPONENTS="
2168     $BSF_LIST
2169     $DECODER_LIST
2170     $DEMUXER_LIST
2171     $ENCODER_LIST
2172     $FILTER_LIST
2173     $HWACCEL_LIST
2174     $INDEV_LIST
2175     $MUXER_LIST
2176     $OUTDEV_LIST
2177     $PARSER_LIST
2178     $PROTOCOL_LIST
2179 "
2180
2181 for n in $COMPONENT_LIST; do
2182     v=$(toupper ${n%s})_LIST
2183     eval enable \$$v
2184     eval ${n}_if_any="\$$v"
2185 done
2186
2187 enable $ARCH_EXT_LIST
2188
2189 die_unknown(){
2190     echo "Unknown option \"$1\"."
2191     echo "See $0 --help for available options."
2192     exit 1
2193 }
2194
2195 print_3_columns() {
2196     cat | tr ' ' '\n' | sort | pr -r -3 -t
2197 }
2198
2199 show_list() {
2200     suffix=_$1
2201     shift
2202     echo $* | sed s/$suffix//g | print_3_columns
2203     exit 0
2204 }
2205
2206 rand_list(){
2207     IFS=', '
2208     set -- $*
2209     unset IFS
2210     for thing; do
2211         comp=${thing%:*}
2212         prob=${thing#$comp}
2213         prob=${prob#:}
2214         is_in ${comp} $COMPONENT_LIST && eval comp=\$$(toupper ${comp%s})_LIST
2215         echo "prob ${prob:-0.5}"
2216         printf '%s\n' $comp
2217     done
2218 }
2219
2220 do_random(){
2221     action=$1
2222     shift
2223     random_seed=$(awk "BEGIN { srand($random_seed); print srand() }")
2224     $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == \"prob\" { prob = \$2; next } rand() < prob { print }")
2225 }
2226
2227 for opt do
2228     optval="${opt#*=}"
2229     case "$opt" in
2230         --extra-ldflags=*)
2231             add_ldflags $optval
2232         ;;
2233         --extra-libs=*)
2234             add_extralibs $optval
2235         ;;
2236         --disable-devices)
2237             disable $INDEV_LIST $OUTDEV_LIST
2238         ;;
2239         --enable-debug=*)
2240             debuglevel="$optval"
2241         ;;
2242         --disable-programs)
2243             disable $PROGRAM_LIST
2244         ;;
2245         --disable-everything)
2246             map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST
2247         ;;
2248         --disable-all)
2249             map 'eval unset \${$(toupper ${v%s})_LIST}' $COMPONENT_LIST
2250             disable $LIBRARY_LIST $PROGRAM_LIST doc
2251         ;;
2252         --enable-random|--disable-random)
2253             action=${opt%%-random}
2254             do_random ${action#--} $COMPONENT_LIST
2255         ;;
2256         --enable-random=*|--disable-random=*)
2257             action=${opt%%-random=*}
2258             do_random ${action#--} $optval
2259         ;;
2260         --enable-*=*|--disable-*=*)
2261             eval $(echo "${opt%%=*}" | sed 's/--/action=/;s/-/ thing=/')
2262             is_in "${thing}s" $COMPONENT_LIST || die_unknown "$opt"
2263             eval list=\$$(toupper $thing)_LIST
2264             name=$(echo "${optval}" | sed "s/,/_${thing}|/g")_${thing}
2265             $action $(filter "$name" $list)
2266         ;;
2267         --enable-?*|--disable-?*)
2268             eval $(echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g')
2269             if is_in $option $COMPONENT_LIST; then
2270                 test $action = disable && action=unset
2271                 eval $action \$$(toupper ${option%s})_LIST
2272             elif is_in $option $CMDLINE_SELECT; then
2273                 $action $option
2274             else
2275                 die_unknown $opt
2276             fi
2277         ;;
2278         --list-*)
2279             NAME="${opt#--list-}"
2280             is_in $NAME $COMPONENT_LIST || die_unknown $opt
2281             NAME=${NAME%s}
2282             eval show_list $NAME \$$(toupper $NAME)_LIST
2283         ;;
2284         --help|-h) show_help
2285         ;;
2286         *)
2287             optname="${opt%%=*}"
2288             optname="${optname#--}"
2289             optname=$(echo "$optname" | sed 's/-/_/g')
2290             if is_in $optname $CMDLINE_SET; then
2291                 eval $optname='$optval'
2292             elif is_in $optname $CMDLINE_APPEND; then
2293                 append $optname "$optval"
2294             else
2295                 die_unknown $opt
2296             fi
2297         ;;
2298     esac
2299 done
2300
2301 disabled logging && logfile=/dev/null
2302
2303 echo "# $0 $LIBAV_CONFIGURATION" > $logfile
2304 set >> $logfile
2305
2306 test -n "$cross_prefix" && enable cross_compile
2307
2308 if enabled cross_compile; then
2309     test -n "$arch" && test -n "$target_os" ||
2310         die "Must specify target arch and OS when cross-compiling"
2311 fi
2312
2313 ar_default="${cross_prefix}${ar_default}"
2314 cc_default="${cross_prefix}${cc_default}"
2315 nm_default="${cross_prefix}${nm_default}"
2316 pkg_config_default="${cross_prefix}${pkg_config_default}"
2317 ranlib="${cross_prefix}${ranlib}"
2318 strip="${cross_prefix}${strip}"
2319
2320 sysinclude_default="${sysroot}/usr/include"
2321
2322 case "$toolchain" in
2323     clang-asan)
2324         cc_default="clang"
2325         add_cflags  -fsanitize=address
2326         add_ldflags -fsanitize=address
2327     ;;
2328     clang-tsan)
2329         cc_default="clang"
2330         add_cflags  -fsanitize=thread -pie
2331         add_ldflags -fsanitize=thread -pie
2332     ;;
2333     gcc-asan)
2334         cc_default="gcc"
2335         add_cflags  -fsanitize=address
2336         add_ldflags -fsanitize=address
2337     ;;
2338     gcc-tsan)
2339         cc_default="gcc"
2340         add_cflags  -fsanitize=thread -pie -fPIC
2341         add_ldflags -fsanitize=thread -pie -fPIC
2342     ;;
2343     valgrind-massif)
2344         target_exec_default="valgrind"
2345         target_exec_args="--alloc-fn=av_malloc --alloc-fn=av_mallocz"
2346     ;;
2347     valgrind-memcheck)
2348         target_exec_default="valgrind"
2349         target_exec_args="--track-origins=yes --leak-check=full"
2350     ;;
2351     msvc)
2352         # Check whether the current MSVC version needs the C99 converter.
2353         # From MSVC 2013 (compiler major version 18) onwards, it does actually
2354         # support enough of C99 to build libav. Default to the new
2355         # behaviour if the regexp was unable to match anything, since this
2356         # successfully parses the version number of existing supported
2357         # versions that require the converter (MSVC 2010 and 2012).
2358         cl_major_ver=$(cl 2>&1 | sed -n 's/.*Version \([[:digit:]]\{1,\}\)\..*/\1/p')
2359         if [ -z "$cl_major_ver" ] || [ $cl_major_ver -ge 18 ]; then
2360             cc_default="cl"
2361         else
2362             cc_default="c99wrap cl"
2363         fi
2364         ld_default="link"
2365         nm_default="dumpbin -symbols"
2366         ar_default="lib"
2367         target_os_default="win32"
2368         # Use a relative path for TMPDIR. This makes sure all the
2369         # ffconf temp files are written with a relative path, avoiding
2370         # issues with msys/win32 path conversion for MSVC parameters
2371         # such as -Fo<file> or -out:<file>.
2372         TMPDIR=.
2373     ;;
2374     icl)
2375         cc_default="icl"
2376         ld_default="xilink"
2377         nm_default="dumpbin -symbols"
2378         ar_default="xilib"
2379         target_os_default="win32"
2380         TMPDIR=.
2381     ;;
2382     gcov)
2383         add_cflags  -fprofile-arcs -ftest-coverage
2384         add_ldflags -fprofile-arcs -ftest-coverage
2385     ;;
2386     hardened)
2387         add_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all
2388         add_ldflags -Wl,-z,relro -Wl,-z,now
2389     ;;
2390     ?*)
2391         die "Unknown toolchain $toolchain"
2392     ;;
2393 esac
2394
2395 set_default arch cc pkg_config sysinclude target_exec target_os
2396 enabled cross_compile || host_cc_default=$cc
2397 set_default host_cc
2398
2399 if ! $pkg_config --version >/dev/null 2>&1; then
2400     warn "$pkg_config not found, library detection may fail."
2401     pkg_config=false
2402 fi
2403
2404 exesuf() {
2405     case $1 in
2406         mingw32*|win32|win64|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;;
2407     esac
2408 }
2409
2410 EXESUF=$(exesuf $target_os)
2411 HOSTEXESUF=$(exesuf $host_os)
2412
2413 # set temporary file name
2414 : ${TMPDIR:=$TEMPDIR}
2415 : ${TMPDIR:=$TMP}
2416 : ${TMPDIR:=/tmp}
2417
2418 if ! check_cmd mktemp -u XXXXXX; then
2419     # simple replacement for missing mktemp
2420     # NOT SAFE FOR GENERAL USE
2421     mktemp(){
2422         echo "${2%%XXX*}.${HOSTNAME}.${UID}.$$"
2423     }
2424 fi
2425
2426 tmpfile(){
2427     tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 &&
2428         (set -C; exec > $tmp) 2>/dev/null ||
2429         die "Unable to create temporary file in $TMPDIR."
2430     append TMPFILES $tmp
2431     eval $1=$tmp
2432 }
2433
2434 trap 'rm -f -- $TMPFILES' EXIT
2435
2436 tmpfile TMPASM .asm
2437 tmpfile TMPC   .c
2438 tmpfile TMPE   $EXESUF
2439 tmpfile TMPH   .h
2440 tmpfile TMPO   .o
2441 tmpfile TMPS   .S
2442 tmpfile TMPSH  .sh
2443 tmpfile TMPV   .ver
2444
2445 unset -f mktemp
2446
2447 chmod +x $TMPE
2448
2449 # make sure we can execute files in $TMPDIR
2450 cat > $TMPSH 2>> $logfile <<EOF
2451 #! /bin/sh
2452 EOF
2453 chmod +x $TMPSH >> $logfile 2>&1
2454 if ! $TMPSH >> $logfile 2>&1; then
2455     cat <<EOF
2456 Unable to create and execute files in $TMPDIR.  Set the TMPDIR environment
2457 variable to another directory and make sure that it is not mounted noexec.
2458 EOF
2459     die "Sanity test failed."
2460 fi
2461
2462 ccc_flags(){
2463     for flag; do
2464         case $flag in
2465             -std=c99)           echo -c99                       ;;
2466             -mcpu=*)            echo -arch ${flag#*=}           ;;
2467             -mieee)             echo -ieee                      ;;
2468             -O*|-fast)          echo $flag                      ;;
2469             -fno-math-errno)    echo -assume nomath_errno       ;;
2470             -g)                 echo -g3                        ;;
2471             -Wall)              echo -msg_enable level2         ;;
2472             -Wno-pointer-sign)  echo -msg_disable ptrmismatch1  ;;
2473             -Wl,*)              echo $flag                      ;;
2474             -f*|-W*)                                            ;;
2475             *)                  echo $flag                      ;;
2476         esac
2477    done
2478 }
2479
2480 cparser_flags(){
2481     for flag; do
2482         case $flag in
2483             -Wno-switch)             echo -Wno-switch-enum ;;
2484             -Wno-format-zero-length) ;;
2485             -Wdisabled-optimization) ;;
2486             -Wno-pointer-sign)       echo -Wno-other ;;
2487             *)                       echo $flag ;;
2488         esac
2489     done
2490 }
2491
2492 msvc_common_flags(){
2493     for flag; do
2494         case $flag in
2495             # In addition to specifying certain flags under the compiler
2496             # specific filters, they must be specified here as well or else the
2497             # generic catch all at the bottom will print the original flag.
2498             -Wall)                ;;
2499             -std=c99)             ;;
2500             # Common flags
2501             -fomit-frame-pointer) ;;
2502             -g)                   echo -Z7 ;;
2503             -fno-math-errno)      ;;
2504             -fno-common)          ;;
2505             -fno-signed-zeros)    ;;
2506             -fPIC)                ;;
2507             -mthumb)              ;;
2508             -march=*)             ;;
2509             -lz)                  echo zlib.lib ;;
2510             -lavifil32)           echo vfw32.lib ;;
2511             -lavicap32)           echo vfw32.lib user32.lib ;;
2512             -l*)                  echo ${flag#-l}.lib ;;
2513             *)                    echo $flag ;;
2514         esac
2515     done
2516 }
2517
2518 msvc_flags(){
2519     msvc_common_flags "$@"
2520     for flag; do
2521         case $flag in
2522             -Wall)                echo -W4 -wd4244 -wd4127 -wd4018 -wd4389     \
2523                                        -wd4146 -wd4057 -wd4204 -wd4706 -wd4305 \
2524                                        -wd4152 -wd4324 -we4013 -wd4100 -wd4214 \
2525                                        -wd4273 ;;
2526         esac
2527     done
2528 }
2529
2530 icl_flags(){
2531     msvc_common_flags "$@"
2532     for flag; do
2533         case $flag in
2534             # Despite what Intel's documentation says -Wall, which is supported
2535             # on Windows, does enable remarks so disable them here.
2536             -Wall)                echo $flag -Qdiag-disable:remark ;;
2537             -std=c99)             echo -Qstd=c99 ;;
2538         esac
2539     done
2540 }
2541
2542 pgi_flags(){
2543     for flag; do
2544         case $flag in
2545             -flto)                echo -Mipa=fast,libopt,libinline,vestigial ;;
2546             -fomit-frame-pointer) echo -Mnoframe ;;
2547             -g)                   echo -gopt ;;
2548             *)                    echo $flag ;;
2549         esac
2550     done
2551 }
2552
2553 suncc_flags(){
2554     for flag; do
2555         case $flag in
2556             -march=*|-mcpu=*)
2557                 case "${flag#*=}" in
2558                     native)                   echo -xtarget=native       ;;
2559                     v9|niagara)               echo -xarch=sparc          ;;
2560                     ultrasparc)               echo -xarch=sparcvis       ;;
2561                     ultrasparc3|niagara2)     echo -xarch=sparcvis2      ;;
2562                     i586|pentium)             echo -xchip=pentium        ;;
2563                     i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
2564                     pentium3*|c3-2)           echo -xtarget=pentium3     ;;
2565                     pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
2566                     pentium4*)          echo -xtarget=pentium4           ;;
2567                     prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
2568                     *-sse3)             echo -xarch=sse3                 ;;
2569                     core2)              echo -xarch=ssse3 -xchip=core2   ;;
2570                     corei7)           echo -xarch=sse4_2 -xchip=nehalem  ;;
2571                     corei7-avx)       echo -xarch=avx -xchip=sandybridge ;;
2572                     amdfam10|barcelona|bdver*) echo -xarch=sse4_1        ;;
2573                     athlon-4|athlon-[mx]p)     echo -xarch=ssea          ;;
2574                     k8|opteron|athlon64|athlon-fx)
2575                                                echo -xarch=sse2a         ;;
2576                     athlon*)                   echo -xarch=pentium_proa  ;;
2577                 esac
2578                 ;;
2579             -std=c99)             echo -xc99              ;;
2580             -fomit-frame-pointer) echo -xregs=frameptr    ;;
2581             -fPIC)                echo -KPIC -xcode=pic32 ;;
2582             -W*,*)                echo $flag              ;;
2583             -f*-*|-W*|-mimpure-text)                      ;;
2584             -shared)              echo -G                 ;;
2585             *)                    echo $flag              ;;
2586         esac
2587     done
2588 }
2589
2590 tms470_flags(){
2591     for flag; do
2592         case $flag in
2593             -march=*|-mcpu=*)
2594                 case "${flag#*=}" in
2595                     armv7-a|cortex-a*)      echo -mv=7a8 ;;
2596                     armv7-r|cortex-r*)      echo -mv=7r4 ;;
2597                     armv7-m|cortex-m*)      echo -mv=7m3 ;;
2598                     armv6*|arm11*)          echo -mv=6   ;;
2599                     armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
2600                                             echo -mv=5e  ;;
2601                     armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
2602                 esac
2603                 ;;
2604             -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
2605             -mfpu=vfp)      echo --float_support=vfpv2        ;;
2606             -mfpu=vfpv3)    echo --float_support=vfpv3        ;;
2607             -mfpu=vfpv3-d16) echo --float_support=vfpv3d16    ;;
2608             -msoft-float)   echo --float_support=vfplib       ;;
2609             -O[0-3]|-mf=*)  echo $flag                        ;;
2610             -g)             echo -g -mn                       ;;
2611             -pds=*)         echo $flag                        ;;
2612             -D*|-I*)        echo $flag                        ;;
2613             --gcc|--abi=*)  echo $flag                        ;;
2614             -me)            echo $flag                        ;;
2615         esac
2616     done
2617 }
2618
2619 probe_cc(){
2620     pfx=$1
2621     _cc=$2
2622
2623     unset _type _ident _cc_c _cc_e _cc_o _flags _cflags
2624     unset _ld_o _ldflags _ld_lib _ld_path
2625     unset _depflags _DEPCMD _DEPFLAGS
2626     _flags_filter=echo
2627
2628     if $_cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
2629         _type=llvm_gcc
2630         gcc_extra_ver=$(expr "$($_cc --version | head -n1)" : '.*\((.*)\)')
2631         _ident="llvm-gcc $($_cc -dumpversion) $gcc_extra_ver"
2632         _depflags='-MMD -MF $(@:.o=.d) -MT $@'
2633         _cflags_speed='-O3'
2634         _cflags_size='-Os'
2635     elif $_cc -v 2>&1 | grep -qi ^gcc; then
2636         _type=gcc
2637         gcc_version=$($_cc --version | head -n1)
2638         gcc_basever=$($_cc -dumpversion)
2639         gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)')
2640         gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)")
2641         _ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver")
2642         if ! $_cc -dumpversion | grep -q '^2\.'; then
2643             _depflags='-MMD -MF $(@:.o=.d) -MT $@'
2644         fi
2645         _cflags_speed='-O3'
2646         _cflags_size='-Os'
2647     elif $_cc --version 2>/dev/null | grep -q ^icc; then
2648         _type=icc
2649         _ident=$($_cc --version | head -n1)
2650         _depflags='-MMD'
2651         _cflags_speed='-O3'
2652         _cflags_size='-Os'
2653         _cflags_noopt='-O1'
2654     elif $_cc -v 2>&1 | grep -q xlc; then
2655         _type=xlc
2656         _ident=$($_cc -qversion 2>/dev/null | head -n1)
2657         _cflags_speed='-O5'
2658         _cflags_size='-O5 -qcompact'
2659     elif $_cc -V 2>/dev/null | grep -q Compaq; then
2660         _type=ccc
2661         _ident=$($_cc -V | head -n1 | cut -d' ' -f1-3)
2662         _DEPFLAGS='-M'
2663         _cflags_speed='-fast'
2664         _cflags_size='-O1'
2665         _flags_filter=ccc_flags
2666     elif $_cc --vsn 2>/dev/null | grep -q "ARM C/C++ Compiler"; then
2667         test -d "$sysroot" || die "No valid sysroot specified."
2668         _type=armcc
2669         _ident=$($_cc --vsn | head -n1)
2670         armcc_conf="$PWD/armcc.conf"
2671         $_cc --arm_linux_configure                 \
2672              --arm_linux_config_file="$armcc_conf" \
2673              --configure_sysroot="$sysroot"        \
2674              --configure_cpp_headers="$sysinclude" >>$logfile 2>&1 ||
2675              die "Error creating armcc configuration file."
2676         $_cc --vsn | grep -q RVCT && armcc_opt=rvct || armcc_opt=armcc
2677         _flags="--arm_linux_config_file=$armcc_conf --translate_gcc"
2678         as_default="${cross_prefix}gcc"
2679         _depflags='-MMD'
2680         _cflags_speed='-O3'
2681         _cflags_size='-Os'
2682     elif $_cc -version 2>/dev/null | grep -Eq 'TMS470|TI ARM'; then
2683         _type=tms470
2684         _ident=$($_cc -version | head -n1 | tr -s ' ')
2685         _flags='--gcc --abi=eabi -me'
2686         _cc_e='-ppl -fe=$@'
2687         _cc_o='-fe=$@'
2688         _depflags='-ppa -ppd=$(@:.o=.d)'
2689         _cflags_speed='-O3 -mf=5'
2690         _cflags_size='-O3 -mf=2'
2691         _flags_filter=tms470_flags
2692     elif $_cc -v 2>&1 | grep -q clang; then
2693         _type=clang
2694         _ident=$($_cc --version | head -n1)
2695         _depflags='-MMD'
2696         _cflags_speed='-O3'
2697         _cflags_size='-Os'
2698     elif $_cc -V 2>&1 | grep -q Sun; then
2699         _type=suncc
2700         _ident=$($_cc -V 2>&1 | head -n1 | cut -d' ' -f 2-)
2701         _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)'
2702         _DEPFLAGS='-xM1 -xc99'
2703         _ldflags='-std=c99'
2704         _cflags_speed='-O5'
2705         _cflags_size='-O5 -xspace'
2706         _flags_filter=suncc_flags
2707     elif $_cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
2708         _type=pathscale
2709         _ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
2710         _depflags='-MMD -MF $(@:.o=.d) -MT $@'
2711         _cflags_speed='-O2'
2712         _cflags_size='-Os'
2713         _flags_filter='filter_out -Wdisabled-optimization'
2714     elif $_cc -v 2>&1 | grep -q Open64; then
2715         _type=open64
2716         _ident=$($_cc -v 2>&1 | head -n1 | tr -d :)
2717         _depflags='-MMD -MF $(@:.o=.d) -MT $@'
2718         _cflags_speed='-O2'
2719         _cflags_size='-Os'
2720         _flags_filter='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros'
2721     elif $_cc -V 2>&1 | grep -q Portland; then
2722         _type=pgi
2723         _ident="PGI $($_cc -V 2>&1 | awk '/^pgcc/ { print $2; exit }')"
2724         opt_common='-alias=ansi -Mdse -Mlre -Mpre'
2725         _cflags_speed="-O3 -Mautoinline -Munroll=c:4 $opt_common"
2726         _cflags_size="-O2 -Munroll=c:1 $opt_common"
2727         _cflags_noopt="-O1"
2728         _flags_filter=pgi_flags
2729     elif $_cc 2>&1 | grep -q Microsoft; then
2730         _type=msvc
2731         _ident=$($cc 2>&1 | head -n1)
2732         _DEPCMD='$(DEP$(1)) $(DEP$(1)FLAGS) $($(1)DEP_FLAGS) $< 2>&1 | awk '\''/including/ { sub(/^.*file: */, ""); gsub(/\\/, "/"); if (!match($$0, / /)) print "$@:", $$0 }'\'' > $(@:.o=.d)'
2733         _DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -showIncludes -Zs'
2734         _cflags_speed="-O2"
2735         _cflags_size="-O1"
2736         if $_cc 2>&1 | grep -q Linker; then
2737             _ld_o='-out:$@'
2738         else
2739             _ld_o='-Fe$@'
2740         fi
2741         _cc_o='-Fo$@'
2742         _cc_e='-P -Fi$@'
2743         _flags_filter=msvc_flags
2744         _ld_lib='lib%.a'
2745         _ld_path='-libpath:'
2746         _flags='-nologo'
2747         _cflags='-D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -Dinline=__inline -FIstdlib.h -Dstrtoll=_strtoi64'
2748         if [ $pfx = hostcc ]; then
2749             append _cflags -Dsnprintf=_snprintf
2750         fi
2751     elif $_cc 2>&1 | grep -q Intel; then
2752         _type=icl
2753         _ident=$($cc 2>&1 | head -n1)
2754         _depflags='-QMMD -QMF$(@:.o=.d) -QMT$@'
2755         # Not only is O3 broken on 13.x+ but it is slower on all previous
2756         # versions (tested) as well.
2757         _cflags_speed="-O2"
2758         _cflags_size="-O1 -Oi" # -O1 without -Oi miscompiles stuff
2759         if $_cc 2>&1 | grep -q Linker; then
2760             _ld_o='-out:$@'
2761         else
2762             _ld_o='-Fe$@'
2763         fi
2764         _cc_o='-Fo$@'
2765         _cc_e='-P'
2766         _flags_filter=icl_flags
2767         _ld_lib='lib%.a'
2768         _ld_path='-libpath:'
2769         # -Qdiag-error to make icl error when seeing certain unknown arguments
2770         _flags='-nologo -Qdiag-error:4044,10157'
2771         # -Qvec- -Qsimd- to prevent miscompilation, -GS for consistency
2772         # with MSVC which enables it by default.
2773         _cflags='-D_USE_MATH_DEFINES -FIstdlib.h -Dstrtoll=_strtoi64 -Qms0 -Qvec- -Qsimd- -GS'
2774         if [ $pfx = hostcc ]; then
2775             append _cflags -Dsnprintf=_snprintf
2776         fi
2777     elif $_cc --version 2>/dev/null | grep -q ^cparser; then
2778         _type=cparser
2779         _ident=$($_cc --version | head -n1)
2780         _depflags='-MMD'
2781         _cflags_speed='-O4'
2782         _cflags_size='-O2'
2783         _flags_filter=cparser_flags
2784     fi
2785
2786     eval ${pfx}_type=\$_type
2787     eval ${pfx}_ident=\$_ident
2788 }
2789
2790 set_ccvars(){
2791     eval ${1}_C=\${_cc_c-\${${1}_C}}
2792     eval ${1}_E=\${_cc_e-\${${1}_E}}
2793     eval ${1}_O=\${_cc_o-\${${1}_O}}
2794
2795     if [ -n "$_depflags" ]; then
2796         eval ${1}_DEPFLAGS=\$_depflags
2797     else
2798         eval ${1}DEP=\${_DEPCMD:-\$DEPCMD}
2799         eval ${1}DEP_FLAGS=\${_DEPFLAGS:-\$DEPFLAGS}
2800         eval DEP${1}FLAGS=\$_flags
2801     fi
2802 }
2803
2804 probe_cc cc "$cc"
2805 cflags_filter=$_flags_filter
2806 cflags_speed=$_cflags_speed
2807 cflags_size=$_cflags_size
2808 cflags_noopt=$_cflags_noopt
2809 add_cflags $_flags $_cflags
2810 cc_ldflags=$_ldflags
2811 set_ccvars CC
2812
2813 probe_cc hostcc "$host_cc"
2814 host_cflags_filter=$_flags_filter
2815 add_host_cflags  $_flags $_cflags
2816 set_ccvars HOSTCC
2817
2818 test -n "$cc_type" && enable $cc_type ||
2819     warn "Unknown C compiler $cc, unable to select optimal CFLAGS"
2820
2821 : ${as_default:=$cc}
2822 : ${dep_cc_default:=$cc}
2823 : ${ld_default:=$cc}
2824 : ${host_ld_default:=$host_cc}
2825 set_default ar as dep_cc ld host_ld
2826
2827 probe_cc as "$as"
2828 asflags_filter=$_flags_filter
2829 add_asflags $_flags $_cflags
2830 set_ccvars AS
2831
2832 probe_cc ld "$ld"
2833 ldflags_filter=$_flags_filter
2834 add_ldflags $_flags $_ldflags
2835 test "$cc_type" != "$ld_type" && add_ldflags $cc_ldflags
2836 LD_O=${_ld_o-$LD_O}
2837 LD_LIB=${_ld_lib-$LD_LIB}
2838 LD_PATH=${_ld_path-$LD_PATH}
2839
2840 probe_cc hostld "$host_ld"
2841 host_ldflags_filter=$_flags_filter
2842 add_host_ldflags $_flags $_ldflags
2843 HOSTLD_O=${_ld_o-$HOSTLD_O}
2844
2845 if [ -z "$CC_DEPFLAGS" ] && [ "$dep_cc" != "$cc" ]; then
2846     probe_cc depcc "$dep_cc"
2847     CCDEP=${_DEPCMD:-$DEPCMD}
2848     CCDEP_FLAGS=${_DEPFLAGS:=$DEPFLAGS}
2849     DEPCCFLAGS=$_flags
2850 fi
2851
2852 if $ar 2>&1 | grep -q Microsoft; then
2853     arflags="-nologo"
2854     ar_o='-out:$@'
2855 elif $ar 2>&1 | grep -q 'Texas Instruments'; then
2856     arflags="rq"
2857     ar_o='$@'
2858 elif $ar 2>&1 | grep -q 'Usage: ar.*-X.*any'; then
2859     arflags='-Xany -r -c'
2860     ar_o='$@'
2861 else
2862     arflags="rc"
2863     ar_o='$@'
2864 fi
2865
2866 add_cflags $extra_cflags
2867 add_asflags $extra_cflags
2868
2869 if test -n "$sysroot"; then
2870     case "$cc_type" in
2871         gcc|llvm_gcc|clang)
2872             add_cppflags --sysroot="$sysroot"
2873             add_ldflags --sysroot="$sysroot"
2874         ;;
2875         tms470)
2876             add_cppflags -I"$sysinclude"
2877             add_ldflags  --sysroot="$sysroot"
2878         ;;
2879     esac
2880 fi
2881
2882 if test "$cpu" = host; then
2883     enabled cross_compile &&
2884         die "--cpu=host makes no sense when cross-compiling."
2885
2886     case "$cc_type" in
2887         gcc|llvm_gcc)
2888             check_native(){
2889                 $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return
2890                 sed -n "/cc1.*$1=/{
2891                             s/.*$1=\\([^ ]*\\).*/\\1/
2892                             p
2893                             q
2894                         }" $TMPE
2895             }
2896             cpu=$(check_native -march || check_native -mcpu)
2897         ;;
2898     esac
2899
2900     test "${cpu:-host}" = host &&
2901         die "--cpu=host not supported with compiler $cc"
2902 fi
2903
2904 # Deal with common $arch aliases
2905 case "$arch" in
2906     aarch64|arm64)
2907         arch="aarch64"
2908     ;;
2909     arm*)
2910         arch="arm"
2911     ;;
2912     mips*|IP*)
2913         arch="mips"
2914     ;;
2915     parisc*|hppa*)
2916         arch="parisc"
2917     ;;
2918     "Power Macintosh"|ppc*|powerpc*)
2919         arch="ppc"
2920     ;;
2921     s390|s390x)
2922         arch="s390"
2923     ;;
2924     sh4|sh)
2925         arch="sh4"
2926     ;;
2927     sun4u|sparc*)
2928         arch="sparc"
2929     ;;
2930     tilegx|tile-gx)
2931         arch="tilegx"
2932     ;;
2933     i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64)
2934         arch="x86"
2935     ;;
2936 esac
2937
2938 is_in $arch $ARCH_LIST || warn "unknown architecture $arch"
2939 enable $arch
2940
2941 # Add processor-specific flags
2942 if enabled aarch64; then
2943
2944     case $cpu in
2945         armv*)
2946             cpuflags="-march=$cpu"
2947         ;;
2948         *)
2949             cpuflags="-mcpu=$cpu"
2950         ;;
2951     esac
2952
2953 elif enabled alpha; then
2954
2955     cpuflags="-mcpu=$cpu"
2956
2957 elif enabled arm; then
2958
2959     check_arm_arch() {
2960         check_cpp_condition stddef.h \
2961             "defined __ARM_ARCH_${1}__ || defined __TARGET_ARCH_${2:-$1}" \
2962             $cpuflags
2963     }
2964
2965     probe_arm_arch() {
2966         if   check_arm_arch 4;        then echo armv4;
2967         elif check_arm_arch 4T;       then echo armv4t;
2968         elif check_arm_arch 5;        then echo armv5;
2969         elif check_arm_arch 5E;       then echo armv5e;
2970         elif check_arm_arch 5T;       then echo armv5t;
2971         elif check_arm_arch 5TE;      then echo armv5te;
2972         elif check_arm_arch 5TEJ;     then echo armv5te;
2973         elif check_arm_arch 6;        then echo armv6;
2974         elif check_arm_arch 6J;       then echo armv6j;
2975         elif check_arm_arch 6K;       then echo armv6k;
2976         elif check_arm_arch 6Z;       then echo armv6z;
2977         elif check_arm_arch 6ZK;      then echo armv6zk;
2978         elif check_arm_arch 6T2;      then echo armv6t2;
2979         elif check_arm_arch 7;        then echo armv7;
2980         elif check_arm_arch 7A  7_A;  then echo armv7-a;
2981         elif check_arm_arch 7R  7_R;  then echo armv7-r;
2982         elif check_arm_arch 7M  7_M;  then echo armv7-m;
2983         elif check_arm_arch 7EM 7E_M; then echo armv7-m;
2984         elif check_arm_arch 8A  8_A;  then echo armv8-a;
2985         fi
2986     }
2987
2988     [ "$cpu" = generic ] && cpu=$(probe_arm_arch)
2989
2990     case $cpu in
2991         armv*)
2992             cpuflags="-march=$cpu"
2993             subarch=$(echo $cpu | sed 's/[^a-z0-9]//g')
2994         ;;
2995         *)
2996             cpuflags="-mcpu=$cpu"
2997             case $cpu in
2998                 cortex-a*)                               subarch=armv7a  ;;
2999                 cortex-r*)                               subarch=armv7r  ;;
3000                 cortex-m*)                 enable thumb; subarch=armv7m  ;;
3001                 arm11*)                                  subarch=armv6   ;;
3002                 arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) subarch=armv5te ;;
3003                 armv4*|arm7*|arm9[24]*)                  subarch=armv4   ;;
3004                 *)                             subarch=$(probe_arm_arch) ;;
3005             esac
3006         ;;
3007     esac
3008
3009     case "$subarch" in
3010         armv5t*)    enable fast_clz                ;;
3011         armv[6-8]*) enable fast_clz fast_unaligned ;;
3012     esac
3013
3014 elif enabled avr32; then
3015
3016     case $cpu in
3017         ap7[02]0[0-2])
3018             subarch="avr32_ap"
3019             cpuflags="-mpart=$cpu"
3020         ;;
3021         ap)
3022             subarch="avr32_ap"
3023             cpuflags="-march=$cpu"
3024         ;;
3025         uc3[ab]*)
3026             subarch="avr32_uc"
3027             cpuflags="-mcpu=$cpu"
3028         ;;
3029         uc)
3030             subarch="avr32_uc"
3031             cpuflags="-march=$cpu"
3032         ;;
3033     esac
3034
3035 elif enabled bfin; then
3036
3037     cpuflags="-mcpu=$cpu"
3038
3039 elif enabled mips; then
3040
3041     cpuflags="-march=$cpu"
3042
3043 elif enabled ppc; then
3044
3045     case $(tolower $cpu) in
3046         601|ppc601|powerpc601)
3047             cpuflags="-mcpu=601"
3048             disable altivec
3049         ;;
3050         603*|ppc603*|powerpc603*)
3051             cpuflags="-mcpu=603"
3052             disable altivec
3053         ;;
3054         604*|ppc604*|powerpc604*)
3055             cpuflags="-mcpu=604"
3056             disable altivec
3057         ;;
3058         g3|75*|ppc75*|powerpc75*)
3059             cpuflags="-mcpu=750"
3060             disable altivec
3061         ;;
3062         g4|745*|ppc745*|powerpc745*)
3063             cpuflags="-mcpu=7450"
3064         ;;
3065         74*|ppc74*|powerpc74*)
3066             cpuflags="-mcpu=7400"
3067         ;;
3068         g5|970|ppc970|powerpc970)
3069             cpuflags="-mcpu=970"
3070         ;;
3071         power[3-7]*)
3072             cpuflags="-mcpu=$cpu"
3073         ;;
3074         cell)
3075             cpuflags="-mcpu=cell"
3076             enable ldbrx
3077         ;;
3078         e500mc)
3079             cpuflags="-mcpu=e500mc"
3080             disable altivec
3081         ;;
3082         e500v2)
3083             cpuflags="-mcpu=8548 -mhard-float -mfloat-gprs=double"
3084             disable altivec
3085         ;;
3086         e500)
3087             cpuflags="-mcpu=8540 -mhard-float"
3088             disable altivec
3089         ;;
3090     esac
3091
3092 elif enabled sparc; then
3093
3094     case $cpu in
3095         cypress|f93[04]|tsc701|sparcl*|supersparc|hypersparc|niagara|v[789])
3096             cpuflags="-mcpu=$cpu"
3097             disable vis
3098         ;;
3099         ultrasparc*|niagara[234])
3100             cpuflags="-mcpu=$cpu"
3101         ;;
3102     esac
3103
3104 elif enabled x86; then
3105
3106     case $cpu in
3107         i[345]86|pentium)
3108             cpuflags="-march=$cpu"
3109             disable mmx
3110         ;;
3111         # targets that do NOT support nopl and conditional mov (cmov)
3112         pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3)
3113             cpuflags="-march=$cpu"
3114             disable i686
3115         ;;
3116         # targets that do support nopl and conditional mov (cmov)
3117         i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64*|k8*|opteron*|athlon-fx|core2|corei7*|amdfam10|barcelona|atom|bdver*)
3118             cpuflags="-march=$cpu"
3119             enable i686
3120             enable fast_cmov
3121         ;;
3122         # targets that do support conditional mov but on which it's slow
3123         pentium4|pentium4m|prescott|nocona)
3124             cpuflags="-march=$cpu"
3125             enable i686
3126             disable fast_cmov
3127         ;;
3128     esac
3129
3130 fi
3131
3132 if [ "$cpu" != generic ]; then
3133     add_cflags  $cpuflags
3134     add_asflags $cpuflags
3135 fi
3136
3137 # compiler sanity check
3138 check_exec <<EOF
3139 int main(void){ return 0; }
3140 EOF
3141 if test "$?" != 0; then
3142     echo "$cc is unable to create an executable file."
3143     if test -z "$cross_prefix" && ! enabled cross_compile ; then
3144         echo "If $cc is a cross-compiler, use the --enable-cross-compile option."
3145         echo "Only do this if you know what cross compiling means."
3146     fi
3147     die "C compiler test failed."
3148 fi
3149
3150 add_cppflags -D_ISOC99_SOURCE
3151 check_cflags -std=c99
3152 check_cc -D_FILE_OFFSET_BITS=64 <<EOF && add_cppflags -D_FILE_OFFSET_BITS=64
3153 #include <stdlib.h>
3154 EOF
3155 check_cc -D_LARGEFILE_SOURCE <<EOF && add_cppflags -D_LARGEFILE_SOURCE
3156 #include <stdlib.h>
3157 EOF
3158
3159 check_host_cflags -std=c99
3160 check_host_cflags -Wall
3161
3162 check_64bit(){
3163     arch32=$1
3164     arch64=$2
3165     expr=$3
3166     check_code cc "" "int test[2*($expr) - 1]" &&
3167         subarch=$arch64 || subarch=$arch32
3168 }
3169
3170 case "$arch" in
3171     aarch64|alpha|ia64)
3172         spic=$shared
3173     ;;
3174     mips)
3175         check_64bit mips mips64 '_MIPS_SIM > 1'
3176         spic=$shared
3177     ;;
3178     parisc)
3179         check_64bit parisc parisc64 'sizeof(void *) > 4'
3180         spic=$shared
3181     ;;
3182     ppc)
3183         check_64bit ppc ppc64 'sizeof(void *) > 4'
3184         spic=$shared
3185     ;;
3186     sparc)
3187         check_64bit sparc sparc64 'sizeof(void *) > 4'
3188         spic=$shared
3189     ;;
3190     x86)
3191         check_64bit x86_32 x86_64 'sizeof(void *) > 4'
3192         if test "$subarch" = "x86_64"; then
3193             spic=$shared
3194         fi
3195     ;;
3196 esac
3197
3198 enable $subarch
3199 enabled spic && enable_weak pic
3200
3201 # OS specific
3202 case $target_os in
3203     aix)
3204         SHFLAGS=-shared
3205         add_cppflags '-I\$(SRC_PATH)/compat/aix'
3206         enabled shared && add_ldflags -Wl,-brtl
3207         ;;
3208     haiku)
3209         prefix_default="/boot/common"
3210         network_extralibs="-lnetwork"
3211         host_libs=
3212         ;;
3213     sunos)
3214         SHFLAGS='-shared -Wl,-h,$$(@F)'
3215         enabled x86 && SHFLAGS="-mimpure-text $SHFLAGS"
3216         network_extralibs="-lsocket -lnsl"
3217         # When using suncc to build, the Solaris linker will mark
3218         # an executable with each instruction set encountered by
3219         # the Solaris assembler.  As our libraries contain their own
3220         # guards for processor-specific code, instead suppress
3221         # generation of the HWCAPS ELF section on Solaris x86 only.
3222         enabled_all suncc x86 &&
3223             echo "hwcap_1 = OVERRIDE;" > mapfile &&
3224             add_ldflags -Wl,-M,mapfile
3225         nm_default='nm -P -g'
3226         ;;
3227     netbsd)
3228         disable symver
3229         oss_indev_extralibs="-lossaudio"
3230         oss_outdev_extralibs="-lossaudio"
3231         ;;
3232     openbsd|bitrig)
3233         disable symver
3234         SHFLAGS='-shared'
3235         SLIB_INSTALL_NAME='$(SLIBNAME).$(LIBMAJOR).$(LIBMINOR)'
3236         SLIB_INSTALL_LINKS=
3237         oss_indev_extralibs="-lossaudio"
3238         oss_outdev_extralibs="-lossaudio"
3239         ;;
3240     dragonfly)
3241         disable symver
3242         ;;
3243     freebsd)
3244         ;;
3245     bsd/os)
3246         add_extralibs -lpoll -lgnugetopt
3247         ;;
3248     darwin)
3249         gas="gas-preprocessor.pl $cc"
3250         enabled ppc && add_asflags -force_cpusubtype_ALL
3251         SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
3252         enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
3253         add_ldflags -Wl,-dynamic,-search_paths_first
3254         SLIBSUF=".dylib"
3255         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)'
3256         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)'
3257         objformat="macho"
3258         enabled x86_64 && objformat="macho64"
3259         enabled_any pic shared ||
3260             { check_cflags -mdynamic-no-pic && add_asflags -mdynamic-no-pic; }
3261         ;;
3262     mingw32*)
3263         if test $target_os = "mingw32ce"; then
3264             disable network
3265         else
3266             target_os=mingw32
3267         fi
3268         LIBTARGET=i386
3269         if enabled x86_64; then
3270             LIBTARGET="i386:x86-64"
3271         elif enabled arm; then
3272             LIBTARGET=arm-wince
3273         fi
3274         check_ldflags -Wl,--nxcompat
3275         check_ldflags -Wl,--dynamicbase
3276         shlibdir_default="$bindir_default"
3277         SLIBPREF=""
3278         SLIBSUF=".dll"
3279         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
3280         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
3281         SLIB_EXTRA_CMD=-'sed -e "s/ @[^ ]*//" $$(@:$(SLIBSUF)=.orig.def) > $$(@:$(SLIBSUF)=.def); $(DLLTOOL) -m $(LIBTARGET) -d $$(@:$(SLIBSUF)=.def) -l $(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib) -D $(SLIBNAME_WITH_MAJOR)'
3282         SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
3283         SLIB_INSTALL_LINKS=
3284         SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
3285         SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
3286         SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.orig.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base'
3287         objformat="win32"
3288         dlltool="${cross_prefix}dlltool"
3289         ranlib=:
3290         enable dos_paths
3291         ;;
3292     win32|win64)
3293         disable symver
3294         if enabled shared; then
3295             # Link to the import library instead of the normal static library
3296             # for shared libs.
3297             LD_LIB='%.lib'
3298             # Cannot build both shared and static libs with MSVC or icl.
3299             disable static
3300         fi
3301         shlibdir_default="$bindir_default"
3302         SLIBPREF=""
3303         SLIBSUF=".dll"
3304         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
3305         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
3306         SLIB_CREATE_DEF_CMD='$(SRC_PATH)/compat/windows/makedef $(SUBDIR)lib$(NAME).ver $(OBJS) > $$(@:$(SLIBSUF)=.def)'
3307         SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
3308         SLIB_INSTALL_LINKS=
3309         SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)'
3310         SLIB_INSTALL_EXTRA_LIB='$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)'
3311         SHFLAGS='-dll -def:$$(@:$(SLIBSUF)=.def) -implib:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)'
3312         objformat="win32"
3313         ranlib=:
3314         enable dos_paths
3315         ;;
3316     cygwin*)
3317         target_os=cygwin
3318         shlibdir_default="$bindir_default"
3319         SLIBPREF="cyg"
3320         SLIBSUF=".dll"
3321         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)'
3322         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
3323         SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
3324         SLIB_INSTALL_LINKS=
3325         SLIB_INSTALL_EXTRA_LIB='lib$(FULLNAME).dll.a'
3326         SHFLAGS='-shared -Wl,--out-implib,$(SUBDIR)lib$(FULLNAME).dll.a'
3327         objformat="win32"
3328         enable dos_paths
3329         ;;
3330     *-dos|freedos|opendos)
3331         network_extralibs="-lsocket"
3332         objformat="coff"
3333         enable dos_paths
3334         add_cppflags -U__STRICT_ANSI__
3335         ;;
3336     linux)
3337         enable dv1394
3338         ;;
3339     irix*)
3340         target_os=irix
3341         ranlib="echo ignoring ranlib"
3342         ;;
3343     os/2*)
3344         ln_s="cp -f"
3345         objformat="aout"
3346         add_cppflags -D_GNU_SOURCE
3347         add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap
3348         SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf'
3349         LIBSUF="_s.a"
3350         SLIBPREF=""
3351         SLIBSUF=".dll"
3352         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)'
3353         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)'
3354         SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(SUBDIR)$(NAME).def; \
3355             echo PROTMODE >> $(SUBDIR)$(NAME).def; \
3356             echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(SUBDIR)$(NAME).def; \
3357             echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(SUBDIR)$(NAME).def; \
3358             echo EXPORTS >> $(SUBDIR)$(NAME).def; \
3359             emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def'
3360         SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \
3361             emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;'
3362         SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib'
3363         enable dos_paths
3364         ;;
3365     gnu/kfreebsd)
3366         add_cppflags -D_BSD_SOURCE
3367         ;;
3368     gnu)
3369         ;;
3370     qnx)
3371         add_cppflags -D_QNX_SOURCE
3372         network_extralibs="-lsocket"
3373         ;;
3374     symbian)
3375         SLIBSUF=".dll"
3376         enable dos_paths
3377         add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default
3378         add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS
3379         add_ldflags -Wl,--target1-abs,--no-undefined \
3380                     -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \
3381                     -Wl,--entry=_E32Startup -Wl,-u,_E32Startup
3382         add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \
3383                       -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \
3384                       -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib
3385         ;;
3386     osf1)
3387         add_cppflags -D_OSF_SOURCE -D_POSIX_PII -D_REENTRANT
3388         ;;
3389     minix)
3390         ;;
3391     plan9)
3392         add_cppflags -D_C99_SNPRINTF_EXTENSION  \
3393                      -D_REENTRANT_SOURCE        \
3394                      -D_RESEARCH_SOURCE         \
3395                      -DFD_SETSIZE=96            \
3396                      -DHAVE_SOCK_OPTS
3397         add_compat strtod.o strtod=avpriv_strtod
3398         network_extralibs='-lbsd'
3399         exeobjs=compat/plan9/main.o
3400         disable avserver
3401         cp_f='cp'
3402         ;;
3403     none)
3404         ;;
3405     *)
3406         die "Unknown OS '$target_os'."
3407         ;;
3408 esac
3409
3410 # determine libc flavour
3411
3412 probe_libc(){
3413     pfx=$1
3414     pfx_no_=${pfx%_}
3415     # uclibc defines __GLIBC__, so it needs to be checked before glibc.
3416     if check_${pfx}cpp_condition features.h "defined __UCLIBC__"; then
3417         eval ${pfx}libc_type=uclibc
3418         add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
3419     elif check_${pfx}cpp_condition features.h "defined __GLIBC__"; then
3420         eval ${pfx}libc_type=glibc
3421         add_${pfx}cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600
3422     # MinGW headers can be installed on Cygwin, so check for newlib first.
3423     elif check_${pfx}cpp_condition newlib.h "defined _NEWLIB_VERSION"; then
3424         eval ${pfx}libc_type=newlib
3425         add_${pfx}cppflags -U__STRICT_ANSI__
3426     # MinGW64 is backwards compatible with MinGW32, so check for it first.
3427     elif check_${pfx}cpp_condition _mingw.h "defined __MINGW64_VERSION_MAJOR"; then
3428         eval ${pfx}libc_type=mingw64
3429         add_${pfx}cppflags -U__STRICT_ANSI__ -D__USE_MINGW_ANSI_STDIO=1
3430         eval test \$${pfx_no_}cc_type = "gcc" &&
3431             add_${pfx}cppflags -D__printf__=__gnu_printf__
3432     elif check_${pfx}cpp_condition _mingw.h "defined __MINGW_VERSION"  ||
3433          check_${pfx}cpp_condition _mingw.h "defined __MINGW32_VERSION"; then
3434         eval ${pfx}libc_type=mingw32
3435         check_${pfx}cpp_condition _mingw.h "__MINGW32_MAJOR_VERSION > 3 || \
3436             (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" ||
3437             die "ERROR: MinGW32 runtime version must be >= 3.15."
3438         add_${pfx}cppflags -U__STRICT_ANSI__ -D__USE_MINGW_ANSI_STDIO=1
3439         eval test \$${pfx_no_}cc_type = "gcc" &&
3440             add_${pfx}cppflags -D__printf__=__gnu_printf__
3441     elif check_${pfx}cpp_condition crtversion.h "defined _VC_CRT_MAJOR_VERSION"; then
3442         eval ${pfx}libc_type=msvcrt
3443         # The MSVC 2010 headers (Win 7.0 SDK) set _WIN32_WINNT to
3444         # 0x601 by default unless something else is set by the user.
3445         # This can easily lead to us detecting functions only present
3446         # in such new versions and producing binaries requiring windows 7.0.
3447         # Therefore explicitly set the default to XP unless the user has
3448         # set something else on the command line.
3449         check_${pfx}cpp_condition stdlib.h "defined(_WIN32_WINNT)" ||
3450             add_${pfx}cppflags -D_WIN32_WINNT=0x0502
3451     elif check_${pfx}cpp_condition stddef.h "defined __KLIBC__"; then
3452         eval ${pfx}libc_type=klibc
3453     elif check_${pfx}cpp_condition sys/cdefs.h "defined __BIONIC__"; then
3454         eval ${pfx}libc_type=bionic
3455     elif check_${pfx}cpp_condition sys/brand.h "defined LABELED_BRAND_NAME"; then
3456         eval ${pfx}libc_type=solaris
3457         add_${pfx}cppflags -D__EXTENSIONS__ -D_XOPEN_SOURCE=600
3458     fi
3459 }
3460
3461 probe_libc
3462 test -n "$libc_type" && enable libc_$libc_type
3463 probe_libc host_
3464 test -n "$host_libc_type" && enable host_libc_$host_libc_type
3465
3466 case $libc_type in
3467     bionic)
3468         add_compat strtod.o strtod=avpriv_strtod
3469         ;;
3470     msvcrt)
3471         add_compat strtod.o strtod=avpriv_strtod
3472         add_compat msvcrt/snprintf.o snprintf=avpriv_snprintf   \
3473                                      _snprintf=avpriv_snprintf  \
3474                                      vsnprintf=avpriv_vsnprintf
3475         ;;
3476 esac
3477
3478 # hacks for compiler/libc/os combinations
3479
3480 if enabled_all tms470 libc_glibc; then
3481     CPPFLAGS="-I${source_path}/compat/tms470 ${CPPFLAGS}"
3482     add_cppflags -D__USER_LABEL_PREFIX__=
3483     add_cppflags -D__builtin_memset=memset
3484     add_cppflags -D__gnuc_va_list=va_list -D_VA_LIST_DEFINED
3485     add_cflags   -pds=48    # incompatible redefinition of macro
3486 fi
3487
3488 if enabled_all ccc libc_glibc; then
3489     add_ldflags -Wl,-z,now  # calls to libots crash without this
3490 fi
3491
3492 esc(){
3493     echo "$*" | sed 's/%/%25/g;s/:/%3a/g'
3494 }
3495
3496 echo "config:$arch:$subarch:$cpu:$target_os:$(esc $cc_ident):$(esc $LIBAV_CONFIGURATION)" >config.fate
3497
3498 check_cpp_condition stdlib.h "defined(__PIC__) || defined(__pic__) || defined(PIC)" && enable_weak pic
3499
3500 set_default $PATHS_LIST
3501 set_default nm
3502
3503 # we need to build at least one lib type
3504 if ! enabled_any static shared; then
3505     cat <<EOF
3506 At least one library type must be built.
3507 Specify --enable-static to build the static libraries or --enable-shared to
3508 build the shared libraries as well. To only build the shared libraries specify
3509 --disable-static in addition to --enable-shared.
3510 EOF
3511     exit 1;
3512 fi
3513
3514 die_license_disabled() {
3515     enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; }
3516 }
3517
3518 die_license_disabled gpl libcdio
3519 die_license_disabled gpl libx264
3520 die_license_disabled gpl libxavs
3521 die_license_disabled gpl libxvid
3522 die_license_disabled gpl x11grab
3523
3524 die_license_disabled nonfree libfaac
3525 die_license_disabled nonfree libfdk_aac
3526 die_license_disabled nonfree openssl
3527
3528 die_license_disabled version3 libopencore_amrnb
3529 die_license_disabled version3 libopencore_amrwb
3530 die_license_disabled version3 libvo_aacenc
3531 die_license_disabled version3 libvo_amrwbenc
3532
3533 enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; }
3534
3535 disabled optimizations || check_cflags -fomit-frame-pointer
3536
3537 enable_weak_pic() {
3538     disabled pic && return
3539     enable pic
3540     add_cppflags -DPIC
3541     case "$target_os" in
3542     mingw*|cygwin*)
3543         ;;
3544     *)
3545         add_cflags -fPIC
3546         ;;
3547     esac
3548     add_asflags  -fPIC
3549 }
3550
3551 enabled pic && enable_weak_pic
3552
3553 check_cc <<EOF || die "Symbol mangling check failed."
3554 int ff_extern;
3555 EOF
3556 sym=$($nm $TMPO | awk '/ff_extern/{ print substr($0, match($0, /[^ \t]*ff_extern/)) }')
3557 extern_prefix=${sym%%ff_extern*}
3558
3559 check_cc <<EOF && enable_weak inline_asm
3560 void foo(void) { __asm__ volatile ("" ::); }
3561 EOF
3562
3563 _restrict=
3564 for restrict_keyword in restrict __restrict__ __restrict; do
3565     check_cc <<EOF && _restrict=$restrict_keyword && break
3566 void foo(char * $restrict_keyword p);
3567 EOF
3568 done
3569
3570 check_cc <<EOF && enable pragma_deprecated
3571 void foo(void) { _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") }
3572 EOF
3573
3574 check_cc <<EOF && enable attribute_packed
3575 struct { int x; } __attribute__((packed)) x;
3576 EOF
3577
3578 check_cc <<EOF && enable attribute_may_alias
3579 union { int x; } __attribute__((may_alias)) x;
3580 EOF
3581
3582 check_cc <<EOF || die "endian test failed"
3583 unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
3584 EOF
3585 od -t x1 $TMPO | grep -q '42 *49 *47 *45' && enable bigendian
3586
3587 check_inline_asm inline_asm_labels '"1:\n"'
3588
3589 if enabled alpha; then
3590
3591     check_cflags -mieee
3592
3593 elif enabled arm; then
3594
3595     check_cpp_condition stddef.h "defined __thumb__" && enable_weak thumb
3596     enabled thumb && check_cflags -mthumb || check_cflags -marm
3597     nogas=die
3598
3599     if     check_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then
3600         enable vfp_args
3601     elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then
3602         case "${cross_prefix:-$cc}" in
3603             *hardfloat*)         enable vfp_args;   fpabi=vfp ;;
3604             *) check_ld <<EOF && enable vfp_args && fpabi=vfp || fpabi=soft ;;
3605 __asm__ (".eabi_attribute 28, 1");
3606 int main(void) { return 0; }
3607 EOF
3608         esac
3609         warn "Compiler does not indicate floating-point ABI, guessing $fpabi."
3610     fi
3611
3612     enabled armv5te && check_insn armv5te 'qadd r0, r0, r0'
3613     enabled armv6   && check_insn armv6   'sadd16 r0, r0, r0'
3614     enabled armv6t2 && check_insn armv6t2 'movt r0, #0'
3615     enabled neon    && check_insn neon    'vadd.i16 q0, q0, q0'
3616     enabled vfp     && check_insn vfp     'fadds s0, s0, s0'
3617     enabled vfpv3   && check_insn vfpv3   'vmov.f32 s0, #1.0'
3618
3619     [ $target_os = linux ] ||
3620         map 'enabled_any ${v}_external ${v}_inline || disable $v' \
3621             $ARCH_EXT_LIST_ARM
3622
3623     check_inline_asm asm_mod_q '"add r0, %Q0, %R0" :: "r"((long long)0)'
3624     check_inline_asm asm_mod_y '"vmul.i32 d0, d0, %y0" :: "x"(0)'
3625
3626     [ $target_os != win32 ] && enabled_all armv6t2 shared !pic && enable_weak_pic
3627
3628 elif enabled mips; then
3629
3630     check_inline_asm loongson '"dmult.g $1, $2, $3"'
3631
3632 elif enabled parisc; then
3633
3634     if enabled gcc; then
3635         case $($cc -dumpversion) in
3636             4.[3-8].*) check_cflags -fno-optimize-sibling-calls ;;
3637         esac
3638     fi
3639
3640 elif enabled ppc; then
3641
3642     enable local_aligned_8 local_aligned_16
3643
3644     check_inline_asm dcbzl     '"dcbzl 0, %0" :: "r"(0)'
3645     check_inline_asm ibm_asm   '"add 0, 0, 0"'
3646     check_inline_asm ppc4xx    '"maclhw r10, r11, r12"'
3647     check_inline_asm xform_asm '"lwzx %1, %y0" :: "Z"(*(int*)0), "r"(0)'
3648
3649     # AltiVec flags: The FSF version of GCC differs from the Apple version
3650     if enabled altivec; then
3651         nogas=warn
3652         check_cflags -maltivec -mabi=altivec &&
3653         { check_header altivec.h && inc_altivec_h="#include <altivec.h>" ; } ||
3654         check_cflags -faltivec
3655
3656         # check if our compiler supports Motorola AltiVec C API
3657         check_cc <<EOF || disable altivec
3658 $inc_altivec_h
3659 int main(void) {
3660     vector signed int v1 = (vector signed int) { 0 };
3661     vector signed int v2 = (vector signed int) { 1 };
3662     v1 = vec_add(v1, v2);
3663     return 0;
3664 }
3665 EOF
3666
3667         enabled altivec || warn "Altivec disabled, possibly missing --cpu flag"
3668     fi
3669
3670 elif enabled sparc; then
3671
3672     enabled vis && check_inline_asm vis '"pdist %f0, %f0, %f0"'
3673
3674 elif enabled x86; then
3675
3676     check_builtin rdtsc    intrin.h   "__rdtsc()"
3677     check_builtin mm_empty mmintrin.h "_mm_empty()"
3678
3679     enable local_aligned_8 local_aligned_16
3680
3681     # check whether EBP is available on x86
3682     # As 'i' is stored on the stack, this program will crash
3683     # if the base pointer is used to access it because the
3684     # base pointer is cleared in the inline assembly code.
3685     check_exec_crash <<EOF && enable ebp_available
3686 volatile int i=0;
3687 __asm__ volatile ("xorl %%ebp, %%ebp" ::: "%ebp");
3688 return i;
3689 EOF
3690
3691     # check whether EBX is available on x86
3692     check_inline_asm ebx_available '""::"b"(0)' &&
3693         check_inline_asm ebx_available '"":::"%ebx"'
3694
3695     # check whether xmm clobbers are supported
3696     check_inline_asm xmm_clobbers '"":::"%xmm0"'
3697
3698     # check whether binutils is new enough to compile SSSE3/MMXEXT
3699     enabled ssse3  && check_inline_asm ssse3_inline  '"pabsw %xmm0, %xmm0"'
3700     enabled mmxext && check_inline_asm mmxext_inline '"pmaxub %mm0, %mm1"'
3701
3702     if ! disabled_any asm mmx yasm; then
3703         if check_cmd $yasmexe --version; then
3704             enabled x86_64 && yasm_extra="-m amd64"
3705             yasm_debug="-g dwarf2"
3706         elif check_cmd nasm -v; then
3707             yasmexe=nasm
3708             yasm_debug="-g -F dwarf"
3709             enabled x86_64 && test "$objformat" = elf && objformat=elf64
3710         fi
3711
3712         YASMFLAGS="-f $objformat $yasm_extra"
3713         enabled pic               && append YASMFLAGS "-DPIC"
3714         test -n "$extern_prefix"  && append YASMFLAGS "-DPREFIX"
3715         case "$objformat" in
3716             elf*) enabled debug && append YASMFLAGS $yasm_debug ;;
3717         esac
3718
3719         check_yasm "movbe ecx, [5]" && enable yasm ||
3720             die "yasm/nasm not found or too old. Use --disable-yasm for a crippled build."
3721         check_yasm "vfmaddps ymm0, ymm1, ymm2, ymm3" || disable fma4_external
3722         check_yasm "CPU amdnop" && enable cpunop
3723     fi
3724
3725     case "$cpu" in
3726         athlon*|opteron*|k8*|pentium|pentium-mmx|prescott|nocona|atom|geode)
3727             disable fast_clz
3728         ;;
3729     esac
3730
3731 fi
3732
3733 if enabled asm; then
3734     as=${gas:=$as}
3735     check_as <<EOF && enable gnu_as || \
3736         $nogas "GNU assembler not found, install gas-preprocessor"
3737 .macro m n
3738 \n: .int 0
3739 .endm
3740 m x
3741 EOF
3742 fi
3743
3744 check_ldflags -Wl,--as-needed
3745
3746 if check_func dlopen; then
3747     ldl=
3748 elif check_func dlopen -ldl; then
3749     ldl=-ldl
3750 fi
3751
3752 if ! disabled network; then
3753     check_type "sys/types.h sys/socket.h" socklen_t
3754     check_type netdb.h "struct addrinfo"
3755     check_type netinet/in.h "struct group_source_req" -D_BSD_SOURCE
3756     check_type netinet/in.h "struct ip_mreq_source" -D_BSD_SOURCE
3757     check_type netinet/in.h "struct ipv6_mreq" -D_DARWIN_C_SOURCE
3758     check_type netinet/in.h "struct sockaddr_in6"
3759     check_type poll.h "struct pollfd"
3760     check_type "sys/types.h sys/socket.h" "struct sockaddr_storage"
3761     check_struct "sys/types.h sys/socket.h" "struct sockaddr" sa_len
3762     check_type netinet/sctp.h "struct sctp_event_subscribe"
3763     check_func getaddrinfo $network_extralibs
3764     check_func getservbyport $network_extralibs
3765     # Prefer arpa/inet.h over winsock2
3766     if check_header arpa/inet.h ; then
3767         check_func closesocket
3768     elif check_header winsock2.h ; then
3769         check_func_headers winsock2.h closesocket -lws2 &&
3770             network_extralibs="-lws2" ||
3771         { check_func_headers winsock2.h closesocket -lws2_32 &&
3772             network_extralibs="-lws2_32"; }
3773         check_func_headers ws2tcpip.h getaddrinfo $network_extralibs
3774         check_type ws2tcpip.h socklen_t
3775         check_type ws2tcpip.h "struct addrinfo"
3776         check_type ws2tcpip.h "struct group_source_req"
3777         check_type ws2tcpip.h "struct ip_mreq_source"
3778         check_type ws2tcpip.h "struct ipv6_mreq"
3779         check_type winsock2.h "struct pollfd"
3780         check_type ws2tcpip.h "struct sockaddr_in6"
3781         check_type ws2tcpip.h "struct sockaddr_storage"
3782         check_struct winsock2.h "struct sockaddr" sa_len
3783     else
3784         disable network
3785     fi
3786 fi
3787
3788 # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
3789 check_func nanosleep || { check_func nanosleep -lrt && add_extralibs -lrt; }
3790
3791 check_func  fcntl
3792 check_func  fork
3793 check_func_headers stdlib.h getenv
3794 check_func  gethrtime
3795 check_func  getopt
3796 check_func  getrusage
3797 check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
3798 check_func  gettimeofday
3799 check_func  inet_aton $network_extralibs
3800 check_func  isatty
3801 check_func  localtime_r
3802 check_func  ${malloc_prefix}memalign            && enable memalign
3803 check_func  mkstemp
3804 check_func  mmap
3805 check_func  mprotect
3806 check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
3807 check_func_headers malloc.h _aligned_malloc     && enable aligned_malloc
3808 check_func  setrlimit
3809 check_func  strerror_r
3810 check_func  strptime
3811 check_func  strtok_r
3812 check_func  sched_getaffinity
3813 check_builtin sync_val_compare_and_swap "" "int *ptr; int oldval, newval; __sync_val_compare_and_swap(ptr, oldval, newval)"
3814 check_builtin machine_rw_barrier mbarrier.h "__machine_rw_barrier()"
3815 check_builtin atomic_cas_ptr atomic.h "void **ptr; void *oldval, *newval; atomic_cas_ptr(ptr, oldval, newval)"
3816 check_builtin MemoryBarrier windows.h "MemoryBarrier()"
3817 check_func  sysconf
3818 check_func  sysctl
3819 check_func  usleep
3820 check_func_headers io.h setmode
3821 check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
3822 check_lib2 "windows.h wincrypt.h" CryptGenRandom -ladvapi32
3823 check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
3824 check_func_headers windows.h GetProcessAffinityMask
3825 check_func_headers windows.h GetProcessTimes
3826 check_func_headers windows.h GetSystemTimeAsFileTime
3827 check_func_headers windows.h MapViewOfFile
3828 check_func_headers windows.h SetConsoleTextAttribute
3829 check_func_headers windows.h Sleep
3830 check_func_headers windows.h VirtualAlloc
3831
3832 check_header direct.h
3833 check_header dlfcn.h
3834 check_header dxva.h
3835 check_header dxva2api.h
3836 check_header io.h
3837 check_header malloc.h
3838 check_header poll.h
3839 check_header sys/mman.h
3840 check_header sys/param.h
3841 check_header sys/resource.h
3842 check_header sys/select.h
3843 check_header sys/time.h
3844 check_header sys/un.h
3845 check_header unistd.h
3846 check_header vdpau/vdpau.h
3847 check_header vdpau/vdpau_x11.h
3848 check_header VideoDecodeAcceleration/VDADecoder.h
3849 check_header windows.h
3850 check_header X11/extensions/XvMClib.h
3851
3852 if ! disabled w32threads && ! enabled pthreads; then
3853     check_func_headers "windows.h process.h" _beginthreadex && enable w32threads
3854 fi
3855
3856 # check for some common methods of building with pthread support
3857 # do this before the optional library checks as some of them require pthreads
3858 if ! disabled pthreads && ! enabled w32threads; then
3859     enable pthreads
3860     if check_func pthread_join -pthread; then
3861         add_cflags -pthread
3862         add_extralibs -pthread
3863     elif check_func pthread_join -pthreads; then
3864         add_cflags -pthreads
3865         add_extralibs -pthreads
3866     elif check_func pthread_join -lpthreadGC2; then
3867         add_extralibs -lpthreadGC2
3868     elif check_lib pthread.h pthread_join -lpthread; then
3869         :
3870     elif ! check_func pthread_join; then
3871         disable pthreads
3872     fi
3873 fi
3874
3875 for thread in $THREADS_LIST; do
3876     if enabled $thread; then
3877         test -n "$thread_type" &&
3878             die "ERROR: Only one thread type must be selected." ||
3879             thread_type="$thread"
3880     fi
3881 done
3882
3883 disabled  zlib || check_lib   zlib.h      zlibVersion -lz   || disable  zlib
3884 disabled bzlib || check_lib2 bzlib.h BZ2_bzlibVersion -lbz2 || disable bzlib
3885
3886 check_lib math.h sin -lm && LIBM="-lm"
3887 enabled vaapi && require vaapi va/va.h vaInitialize -lva
3888
3889 atan2f_args=2
3890 ldexpf_args=2
3891 powf_args=2
3892
3893 for func in $MATH_FUNCS; do
3894     eval check_mathfunc $func \${${func}_args:-1}
3895 done
3896
3897 # these are off by default, so fail if requested and not available
3898 enabled avisynth          && { { check_header "avisynth/avisynth_c.h" && check_lib2 "windows.h" LoadLibrary; } ||
3899                                { check_header "avxsynth/avxsynth_c.h" && check_lib2 "dlfcn.h" dlopen -ldl; } ||
3900                                die "ERROR: LoadLibrary/dlopen not found, or avisynth header not found"; }
3901 enabled frei0r            && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
3902 enabled gnutls            && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
3903 enabled libfaac           && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
3904 enabled libfdk_aac        && require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac
3905 enabled libfreetype       && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType
3906 enabled libgsm            && { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do
3907                                    check_lib "${gsm_hdr}" gsm_create -lgsm && break;
3908                                done || die "ERROR: libgsm not found"; }
3909 enabled libilbc           && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
3910 enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
3911 enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
3912 enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
3913 enabled libopencv         && require_pkg_config opencv opencv/cv.h cvCreateImageHeader
3914 enabled libopenjpeg       && require libopenjpeg openjpeg.h opj_version -lopenjpeg
3915 enabled libopus           && require_pkg_config opus opus_multistream.h opus_multistream_decoder_create
3916 enabled libpulse          && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new
3917 enabled librtmp           && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
3918 enabled libschroedinger   && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init
3919 enabled libspeex          && require libspeex speex/speex.h speex_decoder_init -lspeex
3920 enabled libtheora         && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
3921 enabled libvo_aacenc      && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
3922 enabled libvo_amrwbenc    && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
3923 enabled libvorbis         && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
3924 enabled libvpx            && {
3925     enabled libvpx_vp8_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
3926                                     die "ERROR: libvpx decoder version must be >=0.9.1"; }
3927     enabled libvpx_vp8_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx ||
3928                                     die "ERROR: libvpx encoder version must be >=0.9.6"; }
3929     enabled libvpx_vp9_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" "vpx_codec_vp9_dx" -lvpx || disable libvpx_vp9_decoder; }
3930     enabled libvpx_vp9_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx" -lvpx || disable libvpx_vp9_encoder; } }
3931 enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput  -lwavpack
3932 enabled libwebp           && require_pkg_config libwebp webp/encode.h WebPGetEncoderVersion
3933 enabled libx264           && require libx264 x264.h x264_encoder_encode -lx264 &&
3934                              { check_cpp_condition x264.h "X264_BUILD >= 118" ||
3935                                die "ERROR: libx264 version must be >= 0.118."; }
3936 enabled libxavs           && require libxavs xavs.h xavs_encoder_encode -lxavs
3937 enabled libxvid           && require libxvid xvid.h xvid_global -lxvidcore
3938 enabled openssl           && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto ||
3939                                check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
3940                                check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
3941                                die "ERROR: openssl not found"; }
3942
3943 if enabled gnutls; then
3944     { check_lib nettle/bignum.h nettle_mpz_get_str_256 -lnettle -lhogweed -lgmp && enable nettle; } ||
3945     { check_lib gcrypt.h gcry_mpi_new -lgcrypt && enable gcrypt; }
3946 fi
3947
3948 # libdc1394 check
3949 if enabled libdc1394; then
3950     { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 &&
3951         enable libdc1394_2; } ||
3952     { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 &&
3953         enable libdc1394_1; } ||
3954     die "ERROR: No version of libdc1394 found "
3955 fi
3956
3957 if check_pkg_config sdl SDL_events.h SDL_PollEvent; then
3958     check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags &&
3959     check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x010300" $sdl_cflags &&
3960     enable sdl
3961 fi
3962
3963 pod2man --help     > /dev/null 2>&1 && enable pod2man   || disable pod2man
3964 texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html
3965
3966 check_header linux/fb.h
3967 check_header linux/videodev2.h
3968 check_struct linux/videodev2.h "struct v4l2_frmivalenum" discrete
3969
3970 check_header sys/videoio.h
3971
3972 check_func_headers "windows.h vfw.h" capCreateCaptureWindow "$vfwcap_indev_extralibs"
3973 # check that WM_CAP_DRIVER_CONNECT is defined to the proper value
3974 # w32api 3.12 had it defined wrong
3975 check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines
3976
3977 # check for ioctl_meteor.h, ioctl_bt848.h and alternatives
3978 { check_header dev/bktr/ioctl_meteor.h &&
3979   check_header dev/bktr/ioctl_bt848.h; } ||
3980 { check_header machine/ioctl_meteor.h &&
3981   check_header machine/ioctl_bt848.h; } ||
3982 { check_header dev/video/meteor/ioctl_meteor.h &&
3983   check_header dev/video/bktr/ioctl_bt848.h; } ||
3984 check_header dev/ic/bt8xx.h
3985
3986 check_header sndio.h
3987 check_header sys/soundcard.h
3988 check_header soundcard.h
3989
3990 enabled_any alsa_indev alsa_outdev &&
3991     check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound
3992
3993 enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack &&
3994     check_func jack_port_get_latency_range -ljack
3995
3996 enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio
3997
3998 if enabled libcdio; then
3999     check_lib2 "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio ||
4000     check_lib2 "cdio/paranoia/cdda.h cdio/paranoia/paranoia.h" cdio_cddap_open -lcdio_paranoia -lcdio_cdda -lcdio
4001 fi
4002
4003 check_lib X11/Xlib.h XOpenDisplay -lX11 && enable xlib
4004
4005 enabled x11grab                                           &&
4006 require Xext X11/extensions/XShm.h XShmCreateImage -lXext &&
4007 require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes &&
4008 { enabled xlib || die "ERROR: Xlib not found"; }
4009
4010 enabled vdpau &&
4011     check_cpp_condition vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" ||
4012     disable vdpau
4013
4014 enabled vdpau && enabled xlib &&
4015     check_lib2 "vdpau/vdpau.h vdpau/vdpau_x11.h" vdp_device_create_x11 -lvdpau &&
4016     enable vdpau_x11
4017
4018 enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel"
4019
4020 # add some useful compiler flags if supported
4021 check_cflags -Wdeclaration-after-statement