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