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