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