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