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