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