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