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