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