[FFmpeg-cvslog] Merge commit '7cb1d9e2dbbe5bf4652be5d78cdd68e956fa3d63'

James Almer git at videolan.org
Thu Oct 12 00:26:18 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Wed Oct 11 17:55:25 2017 -0300| [6dfcbd80ad446ff163b47f2bf432bbf706436ea8] | committer: James Almer

Merge commit '7cb1d9e2dbbe5bf4652be5d78cdd68e956fa3d63'

* commit '7cb1d9e2dbbe5bf4652be5d78cdd68e956fa3d63':
  build: Fine-grained link-time dependency settings

Also included are bug fix commits 5ff3b5cafcc685b6936d16602b0f80aa09a95870,
d9da7151eef7fc469787e7298196cea291acfd82 and
5e27ef800bfa2be17a6353ddedac6b7400e4624f.

Merged-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6dfcbd80ad446ff163b47f2bf432bbf706436ea8
---

 Makefile                |   3 +-
 configure               | 297 +++++++++++++++++++++++++++++-------------------
 ffbuild/common.mak      |   2 +-
 ffbuild/library.mak     |   2 +-
 tests/checkasm/Makefile |   2 +-
 5 files changed, 187 insertions(+), 119 deletions(-)

diff --git a/Makefile b/Makefile
index 642651d4cc..f964a770e6 100644
--- a/Makefile
+++ b/Makefile
@@ -45,12 +45,11 @@ FF_DEP_LIBS  := $(DEP_LIBS)
 FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
 
 $(TOOLS): %$(EXESUF): %.o
-	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
+	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(EXTRALIBS-$(*F)) $(EXTRALIBS) $(ELIBS)
 
 target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
 	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)
 
-tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
 tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
 tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
diff --git a/configure b/configure
index 259619cccd..dfbc251bb2 100755
--- a/configure
+++ b/configure
@@ -732,12 +732,11 @@ is_in(){
     return 1
 }
 
-do_check_deps(){
+check_deps(){
     for cfg; do
         enabled ${cfg}_checking && die "Circular dependency for $cfg."
         disabled ${cfg}_checking && continue
         enable ${cfg}_checking
-        append allopts $cfg
 
         eval dep_all="\$${cfg}_deps"
         eval dep_any="\$${cfg}_deps_any"
@@ -748,7 +747,7 @@ do_check_deps(){
         eval dep_ifn="\$${cfg}_if_any"
 
         pushvar cfg dep_all dep_any dep_con dep_sel dep_sgs dep_ifa dep_ifn
-        do_check_deps $dep_all $dep_any $dep_con $dep_sel $dep_sgs $dep_ifa $dep_ifn
+        check_deps $dep_all $dep_any $dep_con $dep_sel $dep_sgs $dep_ifa $dep_ifn
         popvar cfg dep_all dep_any dep_con dep_sel dep_sgs dep_ifa dep_ifn
 
         [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
@@ -758,24 +757,15 @@ do_check_deps(){
         disabled_all $dep_con || { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but some conflicting dependencies are unsatisfied: $dep_con"; }
         disabled_any $dep_sel && { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but some selected dependency is unsatisfied: $dep_sel"; }
 
-        if enabled $cfg; then
-            enable_deep $dep_sel
-            enable_deep_weak $dep_sgs
-        fi
+        enabled $cfg && enable_deep_weak $dep_sel $dep_sgs
 
-        disable ${cfg}_checking
-    done
-}
-
-check_deps(){
-    unset allopts
-
-    do_check_deps "$@"
+        for dep in $dep_all $dep_any $dep_sel $dep_sgs; do
+            # filter out library deps, these do not belong in extralibs
+            is_in $dep $LIBRARY_LIST && continue
+            enabled $dep && eval append ${cfg}_extralibs ${dep}_extralibs
+        done
 
-    for cfg in $allopts; do
-        enabled $cfg || continue
-        eval dep_extralibs="\$${cfg}_extralibs"
-        test -n "$dep_extralibs" && add_extralibs $dep_extralibs
+        disable ${cfg}_checking
     done
 }
 
@@ -839,6 +829,15 @@ unique(){
     eval "$var=\"${uniq_list}\""
 }
 
+resolve(){
+    var=$1
+    tmpvar=
+    for entry in $(eval echo \$$var); do
+        tmpvar="$tmpvar $(eval echo \$${entry})"
+    done
+    eval "$var=\"${tmpvar}\""
+}
+
 add_cppflags(){
     append CPPFLAGS "$@"
 }
@@ -1135,7 +1134,8 @@ check_apple_framework(){
     name="$(tolower $framework)"
     header="${framework}/${framework}.h"
     disable $name
-    check_header_objcc $header && enable $name && add_extralibs "-framework $framework"
+    check_header_objcc $header &&
+        enable $name && eval ${name}_extralibs='"-framework $framework"'
 }
 
 check_func(){
@@ -1255,15 +1255,18 @@ check_lib(){
     shift 3
     disable $name
     check_func_headers "$headers" "$funcs" "$@" &&
-        enable $name && add_extralibs "$@"
+        enable $name && eval ${name}_extralibs="\$@"
 }
 
 check_lib_cpp(){
     log check_lib_cpp "$@"
-    headers="$1"
-    classes="$2"
-    shift 2
-    check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@"
+    name="$1"
+    headers="$2"
+    classes="$3"
+    shift 3
+    disable $name
+    check_class_headers_cpp "$headers" "$classes" "$@" &&
+        enable $name && eval ${name}_extralibs="\$@"
 }
 
 check_pkg_config(){
@@ -1280,8 +1283,8 @@ check_pkg_config(){
     pkg_libs=$($pkg_config --libs $pkg_config_flags $pkg)
     check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
         enable $name &&
-        set_safe "${pkg}_cflags"    $pkg_cflags &&
-        set_safe "${pkg}_extralibs" $pkg_libs
+        set_safe "${name}_cflags"    $pkg_cflags &&
+        set_safe "${name}_extralibs" $pkg_libs
 }
 
 check_exec(){
@@ -1394,10 +1397,9 @@ require_cpp_condition(){
 
 use_pkg_config(){
     log use_pkg_config "$@"
-    pkg="${2%% *}"
+    name="$1"
     check_pkg_config "$@" || return 1
-    add_cflags    $(get_safe "${pkg}_cflags")
-    add_extralibs $(get_safe "${pkg}_extralibs")
+    add_cflags    $(get_safe "${name}_cflags")
 }
 
 require_pkg_config(){
@@ -1578,7 +1580,6 @@ EXTERNAL_LIBRARY_GPLV3_LIST="
 "
 
 EXTERNAL_LIBRARY_LIST="
-    $EXTERNAL_AUTODETECT_LIBRARY_LIST
     $EXTERNAL_LIBRARY_GPL_LIST
     $EXTERNAL_LIBRARY_NONFREE_LIST
     $EXTERNAL_LIBRARY_VERSION3_LIST
@@ -1656,13 +1657,18 @@ HWACCEL_AUTODETECT_LIBRARY_LIST="
     xvmc
 "
 
+# catchall list of things that require external libs to link
+EXTRALIBS_LIST="
+    cpu_init
+    cws2fws
+"
+
 HWACCEL_LIBRARY_NONFREE_LIST="
     cuda_sdk
     libnpp
 "
 
 HWACCEL_LIBRARY_LIST="
-    $HWACCEL_AUTODETECT_LIBRARY_LIST
     $HWACCEL_LIBRARY_NONFREE_LIST
     libmfx
     mmal
@@ -1735,7 +1741,9 @@ CONFIG_LIST="
     $DOCUMENT_LIST
     $EXAMPLE_LIST
     $EXTERNAL_LIBRARY_LIST
+    $EXTERNAL_AUTODETECT_LIBRARY_LIST
     $HWACCEL_LIBRARY_LIST
+    $HWACCEL_AUTODETECT_LIBRARY_LIST
     $FEATURE_LIST
     $LICENSE_LIST
     $LIBRARY_LIST
@@ -2649,12 +2657,11 @@ crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 cuda_deps_any="libdl LoadLibrary"
 cuvid_deps="cuda"
 d3d11va_deps="d3d11_h dxva_h ID3D11VideoDecoder ID3D11VideoContext"
-dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32"
-dxva2_extralibs="-luser32"
+dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 vda_framework_deps="VideoDecodeAcceleration_VDADecoder_h blocks_extension"
 vda_framework_extralibs="-framework VideoDecodeAcceleration"
-vda_deps="vda_framework pthreads"
-vda_extralibs="-framework CoreFoundation -framework QuartzCore"
+vda_deps="vda_framework pthreads corefoundation"
+vda_extralibs="-framework QuartzCore"
 videotoolbox_hwaccel_deps="videotoolbox pthreads"
 videotoolbox_hwaccel_extralibs="-framework QuartzCore"
 xvmc_deps="X11_extensions_XvMClib_h"
@@ -2976,7 +2983,7 @@ libtheora_encoder_deps="libtheora"
 libtwolame_encoder_deps="libtwolame"
 libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
 libvorbis_decoder_deps="libvorbis"
-libvorbis_encoder_deps="libvorbis"
+libvorbis_encoder_deps="libvorbis libvorbisenc"
 libvorbis_encoder_select="audio_frame_queue"
 libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
@@ -2994,7 +3001,8 @@ libx265_encoder_deps="libx265"
 libxavs_encoder_deps="libxavs"
 libxvid_encoder_deps="libxvid"
 libzvbi_teletext_decoder_deps="libzvbi"
-videotoolbox_extralibs="-framework CoreFoundation -framework VideoToolbox -framework CoreMedia -framework CoreVideo"
+videotoolbox_suggest="coreservices"
+videotoolbox_deps="corefoundation coremedia corevideo"
 videotoolbox_encoder_deps="videotoolbox VTCompressionSessionPrepareToEncodeFrames"
 videotoolbox_encoder_suggest="vda_framework"
 
@@ -3080,8 +3088,9 @@ xwma_demuxer_select="riffdec"
 # indevs / outdevs
 alsa_indev_deps="alsa"
 alsa_outdev_deps="alsa"
-avfoundation_indev_deps="avfoundation pthreads"
-avfoundation_indev_extralibs="-framework Foundation -framework CoreVideo -framework CoreMedia"
+avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
+avfoundation_indev_suggest="coregraphics applicationservices"
+avfoundation_indev_extralibs="-framework Foundation"
 bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
 caca_outdev_deps="libcaca"
 decklink_deps_any="libdl LoadLibrary"
@@ -3121,6 +3130,7 @@ v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
 v4l2_outdev_deps_any="linux_videodev2_h sys_videoio_h"
 vfwcap_indev_deps="vfw32 vfwcap_defines"
 xcbgrab_indev_deps="libxcb"
+xcbgrab_indev_suggest="libxcb_shm libxcb_shape libxcb_xfixes"
 xv_outdev_deps="X11_extensions_Xvlib_h XvGetPortAttribute"
 xv_outdev_extralibs="-lXv -lX11 -lXext"
 
@@ -3135,8 +3145,11 @@ ffrtmphttp_protocol_select="http_protocol"
 ftp_protocol_select="tcp_protocol"
 gopher_protocol_select="network"
 http_protocol_select="tcp_protocol"
+http_protocol_suggest="zlib"
 httpproxy_protocol_select="tcp_protocol"
+httpproxy_protocol_suggest="zlib"
 https_protocol_select="tls_protocol"
+https_protocol_suggest="zlib"
 icecast_protocol_select="http_protocol"
 librtmp_protocol_deps="librtmp"
 librtmpe_protocol_deps="librtmp"
@@ -3149,12 +3162,18 @@ mmsh_protocol_select="http_protocol"
 mmst_protocol_select="network"
 rtmp_protocol_conflict="librtmp_protocol"
 rtmp_protocol_select="tcp_protocol"
+rtmp_protocol_suggest="zlib"
 rtmpe_protocol_select="ffrtmpcrypt_protocol"
+rtmpe_protocol_suggest="zlib"
 rtmps_protocol_conflict="librtmp_protocol"
 rtmps_protocol_select="tls_protocol"
+rtmps_protocol_suggest="zlib"
 rtmpt_protocol_select="ffrtmphttp_protocol"
+rtmpt_protocol_suggest="zlib"
 rtmpte_protocol_select="ffrtmpcrypt_protocol ffrtmphttp_protocol"
+rtmpte_protocol_suggest="zlib"
 rtmpts_protocol_select="ffrtmphttp_protocol https_protocol"
+rtmpts_protocol_suggest="zlib"
 rtp_protocol_select="udp_protocol"
 sctp_protocol_deps="struct_sctp_event_subscribe struct_msghdr_msg_flags"
 sctp_protocol_select="network"
@@ -3201,7 +3220,9 @@ deinterlace_qsv_filter_deps="libmfx"
 deinterlace_vaapi_filter_deps="vaapi"
 delogo_filter_deps="gpl"
 deshake_filter_select="pixelutils"
+deshake_filter_suggest="opencl"
 drawtext_filter_deps="libfreetype"
+drawtext_filter_suggest="libfontconfig"
 elbg_filter_deps="avcodec"
 eq_filter_deps="gpl"
 fftfilt_filter_deps="avcodec"
@@ -3270,6 +3291,7 @@ tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
 tonemap_filter_deps="const_nan"
 uspp_filter_deps="gpl avcodec"
+unsharp_filter_suggest="opencl"
 vaguedenoiser_filter_deps="gpl"
 vidstabdetect_filter_deps="libvidstab"
 vidstabtransform_filter_deps="libvidstab"
@@ -3302,27 +3324,45 @@ scaling_video_example_deps="avutil swscale"
 transcode_aac_example_deps="avcodec avformat swresample"
 transcoding_example_deps="avfilter avcodec avformat avutil"
 
+# EXTRALIBS_LIST
+cpu_init_extralibs="pthreads_extralibs"
+cws2fws_extralibs="zlib_extralibs"
+
 # libraries, in linking order
 avcodec_deps="avutil"
+avcodec_suggest="libm"
 avcodec_select="null_bsf"
 avdevice_deps="avformat avcodec avutil"
+avdevice_suggest="libm"
 avfilter_deps="avutil"
+avfilter_suggest="libm"
 avformat_deps="avcodec avutil"
-avformat_suggest="network"
+avformat_suggest="libm network"
 avresample_deps="avutil"
+avresample_suggest="libm"
+avutil_suggest="libm libdrm libmfx user32 vaapi videotoolbox wincrypt"
 postproc_deps="avutil gpl"
+postproc_suggest="libm"
 swresample_deps="avutil"
+swresample_suggest="libm libsoxr"
 swscale_deps="avutil"
+swscale_suggest="libm"
+
+avcodec_extralibs="pthreads_extralibs iconv_extralibs"
+avfilter_extralibs="pthreads_extralibs"
+avutil_extralibs="clock_gettime_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vdpau_x11_extralibs"
 
 # programs
 ffmpeg_deps="avcodec avfilter avformat swresample"
 ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
                null_filter
                trim_filter"
+ffmpeg_suggest="ole32 psapi shell32"
 ffplay_deps="avcodec avformat swscale swresample sdl2"
-ffplay_extralibs='$sdl2_extralibs'
 ffplay_select="rdft crop_filter transpose_filter hflip_filter vflip_filter rotate_filter"
+ffplay_suggest="shell32"
 ffprobe_deps="avcodec avformat"
+ffprobe_suggest="shell32"
 ffserver_deps="avformat fork sarestart"
 ffserver_select="ffm_muxer rtp_protocol rtsp_demuxer"
 
@@ -3401,6 +3441,12 @@ enable valgrind_backtrace
 sws_max_filter_size_default=256
 set_default sws_max_filter_size
 
+# internal components are enabled by default
+enable $EXTRALIBS_LIST
+
+# Avoid external, non-system, libraries getting enabled by dependency resolution
+disable $EXTERNAL_LIBRARY_LIST $HWACCEL_LIBRARY_LIST
+
 # build settings
 SHFLAGS='-shared -Wl,-soname,$$(@F)'
 LIBPREF="lib"
@@ -3501,20 +3547,36 @@ find_things_extern(){
 BSF_LIST=$(find_things_extern bsf AVBitStreamFilter libavcodec/bitstream_filters.c)
 PROTOCOL_LIST=$(find_things_extern protocol URLProtocol libavformat/protocols.c)
 
-ALL_COMPONENTS="
+AVCODEC_COMPONENTS_LIST="
     $BSF_LIST
     $DECODER_LIST
-    $DEMUXER_LIST
     $ENCODER_LIST
-    $FILTER_LIST
     $HWACCEL_LIST
+    $PARSER_LIST
+"
+
+AVDEVICE_COMPONENTS_LIST="
     $INDEV_LIST
-    $MUXER_LIST
     $OUTDEV_LIST
-    $PARSER_LIST
+"
+
+AVFILTER_COMPONENTS_LIST="
+    $FILTER_LIST
+"
+
+AVFORMAT_COMPONENTS_LIST="
+    $DEMUXER_LIST
+    $MUXER_LIST
     $PROTOCOL_LIST
 "
 
+ALL_COMPONENTS="
+    $AVCODEC_COMPONENTS_LIST
+    $AVDEVICE_COMPONENTS_LIST
+    $AVFILTER_COMPONENTS_LIST
+    $AVFORMAT_COMPONENTS_LIST
+"
+
 for n in $COMPONENT_LIST; do
     v=$(toupper ${n%s})_LIST
     eval enable \$$v
@@ -5711,8 +5773,7 @@ check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
 
 check_func  access
 check_func_headers stdlib.h arc4random
-check_func_headers time.h clock_gettime ||
-    { check_lib clock_gettime time.h clock_gettime -lrt && LIBRT="-lrt"; }
+check_func_headers time.h clock_gettime || check_lib clock_gettime time.h clock_gettime -lrt
 check_func  fcntl
 check_func  fork
 check_func  gethrtime
@@ -5725,8 +5786,7 @@ check_func  mkstemp
 check_func  mmap
 check_func  mprotect
 # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
-check_func_headers time.h nanosleep ||
-    { check_lib nanosleep time.h nanosleep -lrt && LIBRT="-lrt"; }
+check_func_headers time.h nanosleep || check_lib nanosleep time.h nanosleep -lrt
 check_func  sched_getaffinity
 check_func  setrlimit
 check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
@@ -5800,9 +5860,14 @@ enabled avfoundation && check_apple_framework AVFoundation
 enabled coreimage    && check_apple_framework CoreImage
 enabled videotoolbox && check_apple_framework VideoToolbox
 
+check_apple_framework CoreFoundation
+check_apple_framework CoreMedia
+check_apple_framework CoreVideo
+
 enabled avfoundation && {
-    check_lib avfoundation CoreGraphics/CoreGraphics.h               CGGetActiveDisplayList "-framework CoreGraphics" ||
-    check_lib avfoundation ApplicationServices/ApplicationServices.h CGGetActiveDisplayList "-framework ApplicationServices"; }
+    disable coregraphics applicationservices
+    check_lib CoreGraphics        CoreGraphics/CoreGraphics.h               CGGetActiveDisplayList "-framework CoreGraphics" ||
+    check_lib applicationservices ApplicationServices/ApplicationServices.h CGGetActiveDisplayList "-framework ApplicationServices"; }
 
 enabled videotoolbox && {
     check_lib coreservices CoreServices/CoreServices.h UTGetOSTypeFromString "-framework CoreServices"
@@ -5879,7 +5944,7 @@ enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzma
 # On some systems dynamic loading requires no extra linker flags
 check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
 
-check_lib libm math.h sin -lm && LIBM="-lm"
+check_lib libm math.h sin -lm
 
 atan2f_args=2
 copysign_args=2
@@ -5888,7 +5953,7 @@ ldexpf_args=2
 powf_args=2
 
 for func in $MATH_FUNCS; do
-    eval check_mathfunc $func \${${func}_args:-1} $LIBM
+    eval check_mathfunc $func \${${func}_args:-1} $libm_extralibs
 done
 
 for func in $COMPLEX_FUNCS; do
@@ -5925,7 +5990,7 @@ flite_extralibs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lfl
 enabled libflite          && require libflite "flite/flite.h" flite_init $flite_extralibs
 enabled fontconfig        && enable libfontconfig
 enabled libfontconfig     && require_pkg_config libfontconfig fontconfig "fontconfig/fontconfig.h" FcInit
-enabled libfreetype       && require_pkg_config libfreetype2 freetype2 "ft2build.h FT_FREETYPE_H" FT_Init_FreeType
+enabled libfreetype       && require_pkg_config libfreetype freetype2 "ft2build.h FT_FREETYPE_H" FT_Init_FreeType
 enabled libfribidi        && require_pkg_config libfribidi fribidi fribidi.h fribidi_version_info
 enabled libgme            && { use_pkg_config libgme libgme gme/gme.h gme_new_emu ||
                                require libgme gme/gme.h gme_new_emu -lgme -lstdc++; }
@@ -5952,7 +6017,7 @@ enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec
 enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
 enabled libopencv         && { check_header opencv2/core/core_c.h &&
                                { use_pkg_config libopencv opencv opencv2/core/core_c.h cvCreateImageHeader ||
-                                 require opencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
+                                 require libopencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
                                require_pkg_config libopencv opencv opencv/cxcore.h cvCreateImageHeader; }
 enabled libopenh264       && require_pkg_config libopenh264 openh264 wels/codec_api.h WelsGetCodecVersion
 enabled libopenjpeg       && { { check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
@@ -5980,9 +6045,9 @@ enabled librtmp           && require_pkg_config librtmp librtmp librtmp/rtmp.h R
 enabled librubberband     && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
 enabled libshine          && require_pkg_config libshine shine shine/layer3.h shine_encode_buffer
 enabled libsmbclient      && { use_pkg_config libsmbclient smbclient libsmbclient.h smbc_init ||
-                               require smbclient libsmbclient.h smbc_init -lsmbclient; }
+                               require libsmbclient libsmbclient.h smbc_init -lsmbclient; }
 enabled libsnappy         && require libsnappy snappy-c.h snappy_compress -lsnappy
-enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr && LIBSOXR="-lsoxr"
+enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr
 enabled libssh            && require_pkg_config libssh libssh libssh/sftp.h sftp_init
 enabled libspeex          && require_pkg_config libspeex speex speex/speex.h speex_decoder_init -lspeex
 enabled libtesseract      && require_pkg_config libtesseract tesseract tesseract/capi.h TessBaseAPICreate
@@ -6066,17 +6131,17 @@ enabled opengl            && { check_lib opengl GL/glx.h glXGetProcAddress "-lGL
                                check_lib opengl ES2/gl.h glGetError "-isysroot=${sysroot} -Wl,-framework,OpenGLES" ||
                                die "ERROR: opengl not found."
                              }
+enabled omx               && require_header OMX_Core.h
 enabled omx_rpi           && { check_header OMX_Core.h ||
                                { ! enabled cross_compile && add_cflags -isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
-                               die "ERROR: OpenMAX IL headers not found"; }
-enabled omx               && require_header OMX_Core.h
+                               die "ERROR: OpenMAX IL headers not found"; } && enable omx
 enabled openssl           && { use_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
                                use_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                                check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                                die "ERROR: openssl not found"; }
-enabled rkmpp             && { { require_pkg_config rockchip_mpp rockchip_mpp rockchip/rk_mpi.h mpp_create ||
+enabled rkmpp             && { { require_pkg_config rkmpp rockchip_mpp rockchip/rk_mpi.h mpp_create ||
                                  die "ERROR : Rockchip MPP was not found."; } &&
                                { check_func_headers rockchip/rk_mpi_cmd.h "MPP_DEC_GET_FREE_PACKET_SLOT_COUNT" ||
                                  die "ERROR: Rockchip MPP is outdated, please get a more recent one."; } &&
@@ -6091,7 +6156,7 @@ if enabled gcrypt; then
         gcrypt_extralibs=$("${GCRYPT_CONFIG}" --libs)
         check_func_headers gcrypt.h gcry_mpi_new $gcrypt_cflags $gcrypt_extralibs ||
             die "ERROR: gcrypt not found"
-        add_cflags $gcrypt_cflags && add_extralibs $gcrypt_extralibs
+        add_cflags $gcrypt_cflags
     else
         require gcrypt gcrypt.h gcry_mpi_new -lgcrypt
     fi
@@ -6114,7 +6179,6 @@ if enabled sdl2; then
         sdl2_extralibs=$(filter_out '-mwindows' $sdl2_extralibs)
     fi
 fi
-enabled sdl2 && add_cflags $(filter_out '-Dmain=SDL_main' $sdl2_cflags) && add_extralibs $sdl2_extralibs
 
 if enabled decklink; then
     case $target_os in
@@ -6133,7 +6197,7 @@ enabled securetransport &&
 enabled schannel &&
     check_func_headers "windows.h security.h" InitializeSecurityContext -DSECURITY_WIN32 -lsecur32 &&
     check_cpp_condition winerror.h "defined(SEC_I_CONTEXT_EXPIRED)" &&
-    add_extralibs -lsecur32 ||
+    schannel_extralibs="-lsecur32" ||
         disable schannel
 
 makeinfo --version > /dev/null 2>&1 && enable makeinfo  || disable makeinfo
@@ -6203,16 +6267,13 @@ if enabled libcdio; then
     die "ERROR: No usable libcdio/cdparanoia found"
 fi
 
-enabled libxcb && check_pkg_config libxcb "xcb >= 1.4" xcb/xcb.h xcb_connect ||
+enabled libxcb && use_pkg_config libxcb "xcb >= 1.4" xcb/xcb.h xcb_connect ||
     disable libxcb_shm libxcb_shape libxcb_xfixes
 
 if enabled libxcb; then
-    enabled libxcb_shm    && check_pkg_config libxcb_shm    xcb-shm    xcb/shm.h    xcb_shm_attach
-    enabled libxcb_shape  && check_pkg_config libxcb_shape  xcb-shape  xcb/shape.h  xcb_shape_get_rectangles
-    enabled libxcb_xfixes && check_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
-
-    add_cflags $xcb_cflags $xcb_shm_cflags $xcb_xfixes_cflags $xcb_shape_cflags
-    add_extralibs $xcb_extralibs $xcb_shm_extralibs $xcb_xfixes_extralibs $xcb_shape_extralibs
+    enabled libxcb_shm    && use_pkg_config libxcb_shm    xcb-shm    xcb/shm.h    xcb_shm_attach
+    enabled libxcb_shape  && use_pkg_config libxcb_shape  xcb-shape  xcb/shape.h  xcb_shape_get_rectangles
+    enabled libxcb_xfixes && use_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
 fi
 
 check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
@@ -6591,32 +6652,42 @@ if test $target_os = "haiku"; then
     disable posix_memalign
 fi
 
-# add_dep lib dep
-# -> enable ${lib}_deps_${dep}
-# -> add $dep to ${lib}_deps only once
-add_dep() {
-    lib=$1
-    dep=$2
-    enabled "${lib}_deps_${dep}" && return 0
-    enable  "${lib}_deps_${dep}"
-    prepend "${lib}_deps" $dep
-}
-
-# merge deps lib components
-# merge all ${component}_deps into ${lib}_deps and ${lib}_deps_*
-merge_deps() {
-    lib=$1
-    shift
-    for comp in $*; do
-        enabled $comp || continue
-        eval "dep=\"\$${comp}_deps\""
-        for d in $dep; do
-            add_dep $lib $d
-        done
+flatten_extralibs(){
+    unset nested_entries
+    list_name=$1
+    eval list=\$${1}
+    for entry in $list; do
+        entry_copy=$entry
+        resolve entry_copy
+        append nested_entries $(filter '*_extralibs' $entry_copy)
+        flat_entries=$(filter_out '*_extralibs' $entry_copy)
+        eval $entry="\$flat_entries"
     done
+    append $list_name "$nested_entries"
+
+    resolve nested_entries
+    if test -n "$(filter '*_extralibs' $nested_entries)"; then
+        flatten_extralibs $list_name
+    fi
 }
 
-merge_deps libavfilter $FILTER_LIST
+for linkunit in $LIBRARY_LIST; do
+    unset current_extralibs
+    eval components=\$$(toupper ${linkunit})_COMPONENTS_LIST
+    for comp in ${components}; do
+        enabled $comp || continue
+        comp_extralibs="${comp}_extralibs"
+        append current_extralibs $comp_extralibs
+    done
+    eval prepend ${linkunit}_extralibs $current_extralibs
+done
+
+for linkunit in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
+    flatten_extralibs ${linkunit}_extralibs
+    unique  ${linkunit}_extralibs
+    resolve ${linkunit}_extralibs
+    eval ${linkunit}_extralibs=\$\(\$ldflags_filter \$${linkunit}_extralibs\)
+done
 
 map 'enabled $v && intrinsics=${v#intrinsics_}' $INTRINSICS_LIST
 
@@ -6686,6 +6757,9 @@ enabled zoompan_filter      && prepend avfilter_deps "swscale"
 
 enabled lavfi_indev         && prepend avdevice_deps "avfilter"
 
+#FIXME
+enabled sdl2_outdev     && add_cflags $(filter_out '-Dmain=SDL_main' $sdl2_cflags)
+
 enabled opus_decoder    && prepend avcodec_deps "swresample"
 
 expand_deps(){
@@ -6799,11 +6873,11 @@ test -n "$random_seed" &&
 echo
 
 echo "External libraries:"
-print_enabled '' $EXTERNAL_LIBRARY_LIST | print_in_columns
+print_enabled '' $EXTERNAL_LIBRARY_LIST $EXTERNAL_AUTODETECT_LIBRARY_LIST | print_in_columns
 echo
 
 echo "External libraries providing hardware acceleration:"
-print_enabled '' $HWACCEL_LIBRARY_LIST | print_in_columns
+print_enabled '' $HWACCEL_LIBRARY_LIST $HWACCEL_AUTODETECT_LIBRARY_LIST | print_in_columns
 echo
 
 echo "Libraries:"
@@ -6957,7 +7031,6 @@ TARGET_PATH=$target_path
 TARGET_SAMPLES=${target_samples:-\$(SAMPLES)}
 CFLAGS-ffplay=${sdl2_cflags}
 CFLAGS_HEADERS=$CFLAGS_HEADERS
-ZLIB=$($ldflags_filter -lz)
 LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
 EXTRALIBS=$extralibs
 COMPAT_OBJS=$compat_objs
@@ -6981,12 +7054,9 @@ EOF
 
 map 'eval echo "${v}_FFLIBS=\$${v}_deps" >> ffbuild/config.mak' $LIBRARY_LIST
 
-print_program_extralibs(){
-    eval "program_extralibs=\$${1}_extralibs"
-    eval echo "EXTRALIBS-${1}=${program_extralibs}" >> ffbuild/config.mak
-}
-
-map 'print_program_extralibs $v' $PROGRAM_LIST
+for entry in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
+    eval echo "EXTRALIBS-${entry}=\$${entry}_extralibs" >> ffbuild/config.mak
+done
 
 cat > $TMPH <<EOF
 /* Automatically generated by configure - do not modify! */
@@ -7088,16 +7158,15 @@ rpath=$(enabled rpath && echo "-Wl,-rpath,\${libdir}")
 source_path=${source_path}
 LIBPREF=${LIBPREF}
 LIBSUF=${LIBSUF}
-
-extralibs_avutil="$LIBRT $LIBM"
-extralibs_avcodec="$extralibs"
-extralibs_avformat="$extralibs"
-extralibs_avdevice="$extralibs"
-extralibs_avfilter="$extralibs"
-extralibs_avresample="$LIBM"
-extralibs_postproc=""
-extralibs_swscale="$LIBM"
-extralibs_swresample="$LIBM $LIBSOXR"
+extralibs_avutil="$avutil_extralibs"
+extralibs_avcodec="$avcodec_extralibs"
+extralibs_avformat="$avformat_extralibs"
+extralibs_avdevice="$avdevice_extralibs"
+extralibs_avfilter="$avfilter_extralibs"
+extralibs_avresample="$avresample_extralibs"
+extralibs_postproc="$postproc_extralibs"
+extralibs_swscale="$swscale_extralibs"
+extralibs_swresample="$swresample_extralibs"
 EOF
 
 for lib in $LIBRARY_LIST; do
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index e168fb2cfd..a6b23e029f 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -119,7 +119,7 @@ FFLIBS    := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
 TESTPROGS += $(TESTPROGS-yes)
 
 LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
-FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
+FFEXTRALIBS := $(FFLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS)
 
 OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
 SLIBOBJS  := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 4191edcf9c..430da3f72a 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -32,7 +32,7 @@ $(TOOLS):     THISLIB = $(FULLNAME:%=$(LD_LIB))
 $(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
 
 $(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
-	$$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(ELIBS)
+	$$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(EXTRALIBS-$$(*F)) $$(ELIBS)
 
 $(SUBDIR)lib$(NAME).version: $(SUBDIR)version.h | $(SUBDIR)
 	$$(M) $$(SRC_PATH)/ffbuild/libversion.sh $(NAME) $$< > $$@
diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 14916e5100..74f07f11cd 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -56,7 +56,7 @@ tests/checkasm/checkasm.o: CFLAGS += -Umain
 CHECKASM := tests/checkasm/checkasm$(EXESUF)
 
 $(CHECKASM): $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS)
-	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS)
+	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avutil) $(EXTRALIBS)
 
 checkasm: $(CHECKASM)
 


======================================================================

diff --cc Makefile
index 642651d4cc,80d50d8253..f964a770e6
--- a/Makefile
+++ b/Makefile
@@@ -45,17 -97,8 +45,16 @@@ FF_DEP_LIBS  := $(DEP_LIBS
  FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS)
  
  $(TOOLS): %$(EXESUF): %.o
- 	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS)
+ 	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(EXTRALIBS-$(*F)) $(EXTRALIBS) $(ELIBS)
  
 +target_dec_%_fuzzer$(EXESUF): target_dec_%_fuzzer.o $(FF_DEP_LIBS)
 +	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(ELIBS) $(FF_EXTRALIBS) $(LIBFUZZER_PATH)
 +
- tools/cws2fws$(EXESUF): ELIBS = $(ZLIB)
 +tools/sofa2wavs$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 +tools/uncoded_frame$(EXESUF): $(FF_DEP_LIBS)
 +tools/uncoded_frame$(EXESUF): ELIBS = $(FF_EXTRALIBS)
 +tools/target_dec_%_fuzzer$(EXESUF): $(FF_DEP_LIBS)
 +
  CONFIGURABLE_COMPONENTS =                                           \
      $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c))                 \
      $(SRC_PATH)/libavcodec/bitstream_filters.c                      \
diff --cc configure
index 259619cccd,5af7df3057..dfbc251bb2
--- a/configure
+++ b/configure
@@@ -737,7 -615,7 +737,6 @@@ check_deps()
          enabled ${cfg}_checking && die "Circular dependency for $cfg."
          disabled ${cfg}_checking && continue
          enable ${cfg}_checking
--        append allopts $cfg
  
          eval dep_all="\$${cfg}_deps"
          eval dep_any="\$${cfg}_deps_any"
@@@ -753,29 -631,22 +752,20 @@@
  
          [ -n "$dep_ifa" ] && { enabled_all $dep_ifa && enable_weak $cfg; }
          [ -n "$dep_ifn" ] && { enabled_any $dep_ifn && enable_weak $cfg; }
 -        enabled_all  $dep_all || disable $cfg
 -        enabled_any  $dep_any || disable $cfg
 -        disabled_all $dep_con || disable $cfg
 -        disabled_any $dep_sel && disable $cfg
 -
 -        if enabled $cfg; then
 -            enable_deep $dep_sel
 -            enable_deep_weak $dep_sgs
 -            for dep in $dep_all $dep_any $dep_sgs; do
 -                # filter out library deps, these do not belong in extralibs
 -                is_in $dep $LIBRARY_LIST && continue
 -                enabled $dep && eval append ${cfg}_extralibs ${dep}_extralibs
 -            done
 -        fi
 +        enabled_all  $dep_all || { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but not all dependencies are satisfied: $dep_all"; }
 +        enabled_any  $dep_any || { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but not any dependency is satisfied: $dep_any"; }
 +        disabled_all $dep_con || { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but some conflicting dependencies are unsatisfied: $dep_con"; }
 +        disabled_any $dep_sel && { disable $cfg && requested $cfg && die "ERROR: $cfg requested, but some selected dependency is unsatisfied: $dep_sel"; }
 +
-         if enabled $cfg; then
-             enable_deep $dep_sel
-             enable_deep_weak $dep_sgs
-         fi
++        enabled $cfg && enable_deep_weak $dep_sel $dep_sgs
 +
-         disable ${cfg}_checking
-     done
- }
- 
- check_deps(){
-     unset allopts
- 
-     do_check_deps "$@"
++        for dep in $dep_all $dep_any $dep_sel $dep_sgs; do
++            # filter out library deps, these do not belong in extralibs
++            is_in $dep $LIBRARY_LIST && continue
++            enabled $dep && eval append ${cfg}_extralibs ${dep}_extralibs
++        done
  
-     for cfg in $allopts; do
-         enabled $cfg || continue
-         eval dep_extralibs="\$${cfg}_extralibs"
-         test -n "$dep_extralibs" && add_extralibs $dep_extralibs
+         disable ${cfg}_checking
      done
  }
  
@@@ -1117,27 -942,6 +1116,28 @@@ int x
  EOF
  }
  
 +check_header_objcc(){
 +    log check_header_objcc "$@"
 +    rm -f -- "$TMPO"
 +    header=$1
 +    shift
 +    disable_safe $header
 +    {
 +       echo "#include <$header>"
 +       echo "int main(void) { return 0; }"
 +    } | check_objcc && check_stat "$TMPO" && enable_safe $header
 +}
 +
 +check_apple_framework(){
 +    log check_apple_framework "$@"
 +    framework="$1"
 +    name="$(tolower $framework)"
 +    header="${framework}/${framework}.h"
 +    disable $name
-     check_header_objcc $header && enable $name && add_extralibs "-framework $framework"
++    check_header_objcc $header &&
++        enable $name && eval ${name}_extralibs='"-framework $framework"'
 +}
 +
  check_func(){
      log check_func "$@"
      func=$1
@@@ -1255,17 -1017,9 +1255,20 @@@ check_lib()
      shift 3
      disable $name
      check_func_headers "$headers" "$funcs" "$@" &&
-         enable $name && add_extralibs "$@"
+         enable $name && eval ${name}_extralibs="\$@"
  }
  
 +check_lib_cpp(){
 +    log check_lib_cpp "$@"
-     headers="$1"
-     classes="$2"
-     shift 2
-     check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@"
++    name="$1"
++    headers="$2"
++    classes="$3"
++    shift 3
++    disable $name
++    check_class_headers_cpp "$headers" "$classes" "$@" &&
++        enable $name && eval ${name}_extralibs="\$@"
 +}
 +
  check_pkg_config(){
      log check_pkg_config "$@"
      name="$1"
@@@ -1280,8 -1034,8 +1283,8 @@@
      pkg_libs=$($pkg_config --libs $pkg_config_flags $pkg)
      check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
          enable $name &&
-         set_safe "${pkg}_cflags"    $pkg_cflags &&
-         set_safe "${pkg}_extralibs" $pkg_libs
 -        add_cflags    "$pkg_cflags" &&
 -        eval $(sanitize_var_name ${name}_extralibs)="\$pkg_libs"
++        set_safe "${name}_cflags"    $pkg_cflags &&
++        set_safe "${name}_extralibs" $pkg_libs
  }
  
  check_exec(){
@@@ -1392,14 -1138,6 +1395,13 @@@ require_cpp_condition()
      check_cpp_condition "$header" "$condition" "$@" || die "ERROR: $condition not satisfied"
  }
  
 +use_pkg_config(){
 +    log use_pkg_config "$@"
-     pkg="${2%% *}"
++    name="$1"
 +    check_pkg_config "$@" || return 1
-     add_cflags    $(get_safe "${pkg}_cflags")
-     add_extralibs $(get_safe "${pkg}_extralibs")
++    add_cflags    $(get_safe "${name}_cflags")
 +}
 +
  require_pkg_config(){
      log require_pkg_config "$@"
      pkg_version="$2"
@@@ -1630,51 -1331,14 +1631,56 @@@ EXTERNAL_LIBRARY_LIST=
      libvpx
      libwavpack
      libwebp
 -    libxcb
 -    libxcb_shm
 -    libxcb_xfixes
 +    libxml2
 +    libzimg
 +    libzmq
 +    libzvbi
 +    mediacodec
 +    openal
 +    opencl
 +    opengl
  "
  
 -SYSTEM_LIBRARY_LIST="
 -    bzlib
 -    zlib
 +HWACCEL_AUTODETECT_LIBRARY_LIST="
 +    audiotoolbox
 +    crystalhd
 +    cuda
 +    cuvid
 +    d3d11va
 +    dxva2
 +    nvenc
 +    vaapi
 +    vda
 +    vdpau
 +    videotoolbox
 +    v4l2_m2m
 +    xvmc
 +"
 +
++# catchall list of things that require external libs to link
++EXTRALIBS_LIST="
++    cpu_init
++    cws2fws
++"
++
 +HWACCEL_LIBRARY_NONFREE_LIST="
 +    cuda_sdk
 +    libnpp
 +"
 +
 +HWACCEL_LIBRARY_LIST="
-     $HWACCEL_AUTODETECT_LIBRARY_LIST
 +    $HWACCEL_LIBRARY_NONFREE_LIST
 +    libmfx
 +    mmal
 +    omx
 +"
 +
 +DOCUMENT_LIST="
 +    doc
 +    htmlpages
 +    manpages
 +    podpages
 +    txtpages
  "
  
  FEATURE_LIST="
@@@ -1732,10 -1391,9 +1738,12 @@@ SUBSYSTEM_LIST=
  
  # COMPONENT_LIST needs to come last to ensure correct dependency checking
  CONFIG_LIST="
 +    $DOCUMENT_LIST
      $EXAMPLE_LIST
      $EXTERNAL_LIBRARY_LIST
++    $EXTERNAL_AUTODETECT_LIBRARY_LIST
      $HWACCEL_LIBRARY_LIST
++    $HWACCEL_AUTODETECT_LIBRARY_LIST
      $FEATURE_LIST
      $LICENSE_LIST
      $LIBRARY_LIST
@@@ -2636,28 -2156,18 +2644,27 @@@ wmv2_decoder_select="blockdsp error_res
  wmv2_encoder_select="h263_encoder wmv2dsp"
  wmv3_decoder_select="vc1_decoder"
  wmv3image_decoder_select="wmv3_decoder"
 -zerocodec_decoder_deps="zlib"
 -zlib_decoder_deps="zlib"
 -zlib_encoder_deps="zlib"
 -zmbv_decoder_deps="zlib"
 -zmbv_encoder_deps="zlib"
 +xma1_decoder_select="wmapro_decoder"
 +xma2_decoder_select="wmapro_decoder"
 +zerocodec_decoder_select="zlib"
 +zlib_decoder_select="zlib"
 +zlib_encoder_select="zlib"
 +zmbv_decoder_select="zlib"
 +zmbv_encoder_select="zlib"
  
  # hardware accelerators
 -d3d11va_deps="d3d11_h dxva_h ID3D11VideoDecoder"
 -dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode"
 -dxva2_lib_deps="dxva2"
 -vda_deps="VideoDecodeAcceleration_VDADecoder_h blocks_extension pthreads"
 -vda_extralibs="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore"
 +crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
 +cuda_deps_any="libdl LoadLibrary"
 +cuvid_deps="cuda"
 +d3d11va_deps="d3d11_h dxva_h ID3D11VideoDecoder ID3D11VideoContext"
- dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32"
- dxva2_extralibs="-luser32"
++dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode ole32 user32"
 +vda_framework_deps="VideoDecodeAcceleration_VDADecoder_h blocks_extension"
 +vda_framework_extralibs="-framework VideoDecodeAcceleration"
- vda_deps="vda_framework pthreads"
- vda_extralibs="-framework CoreFoundation -framework QuartzCore"
++vda_deps="vda_framework pthreads corefoundation"
++vda_extralibs="-framework QuartzCore"
 +videotoolbox_hwaccel_deps="videotoolbox pthreads"
 +videotoolbox_hwaccel_extralibs="-framework QuartzCore"
 +xvmc_deps="X11_extensions_XvMClib_h"
  
  h263_vaapi_hwaccel_deps="vaapi"
  h263_vaapi_hwaccel_select="h263_decoder"
@@@ -2974,9 -2326,10 +2981,9 @@@ libspeex_encoder_deps="libspeex
  libspeex_encoder_select="audio_frame_queue"
  libtheora_encoder_deps="libtheora"
  libtwolame_encoder_deps="libtwolame"
 -libvo_aacenc_encoder_deps="libvo_aacenc"
 -libvo_aacenc_encoder_select="audio_frame_queue"
  libvo_amrwbenc_encoder_deps="libvo_amrwbenc"
 -libvorbis_encoder_deps="libvorbis"
 +libvorbis_decoder_deps="libvorbis"
- libvorbis_encoder_deps="libvorbis"
++libvorbis_encoder_deps="libvorbis libvorbisenc"
  libvorbis_encoder_select="audio_frame_queue"
  libvpx_vp8_decoder_deps="libvpx"
  libvpx_vp8_encoder_deps="libvpx"
@@@ -2985,18 -2338,11 +2992,19 @@@ libvpx_vp9_encoder_deps="libvpx
  libwavpack_encoder_deps="libwavpack"
  libwavpack_encoder_select="audio_frame_queue"
  libwebp_encoder_deps="libwebp"
 +libwebp_anim_encoder_deps="libwebp"
  libx262_encoder_deps="libx262"
  libx264_encoder_deps="libx264"
 +libx264rgb_encoder_deps="libx264 x264_csp_bgr"
 +libx264rgb_encoder_select="libx264_encoder"
  libx265_encoder_deps="libx265"
  libxavs_encoder_deps="libxavs"
 -libxvid_encoder_deps="libxvid mkstemp"
 +libxvid_encoder_deps="libxvid"
 +libzvbi_teletext_decoder_deps="libzvbi"
- videotoolbox_extralibs="-framework CoreFoundation -framework VideoToolbox -framework CoreMedia -framework CoreVideo"
++videotoolbox_suggest="coreservices"
++videotoolbox_deps="corefoundation coremedia corevideo"
 +videotoolbox_encoder_deps="videotoolbox VTCompressionSessionPrepareToEncodeFrames"
 +videotoolbox_encoder_suggest="vda_framework"
  
  # demuxers / muxers
  ac3_demuxer_select="ac3_parser"
@@@ -3080,36 -2410,16 +3088,37 @@@ xwma_demuxer_select="riffdec
  # indevs / outdevs
  alsa_indev_deps="alsa"
  alsa_outdev_deps="alsa"
- avfoundation_indev_deps="avfoundation pthreads"
- avfoundation_indev_extralibs="-framework Foundation -framework CoreVideo -framework CoreMedia"
 -avfoundation_indev_deps="AVFoundation_AVFoundation_h objc_arc pthreads"
 -avfoundation_indev_extralibs="-framework Foundation -framework AVFoundation -framework CoreVideo -framework CoreMedia"
++avfoundation_indev_deps="avfoundation corevideo coremedia pthreads"
++avfoundation_indev_suggest="coregraphics applicationservices"
++avfoundation_indev_extralibs="-framework Foundation"
  bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
 -dv1394_indev_deps="dv1394"
 -dv1394_indev_select="dv_demuxer"
 +caca_outdev_deps="libcaca"
 +decklink_deps_any="libdl LoadLibrary"
 +decklink_indev_deps="decklink threads"
 +decklink_indev_extralibs="-lstdc++"
 +decklink_outdev_deps="decklink threads"
 +decklink_outdev_extralibs="-lstdc++"
 +libndi_newtek_indev_deps="libndi_newtek"
 +libndi_newtek_indev_extralibs="-lndi"
 +libndi_newtek_outdev_deps="libndi_newtek"
 +libndi_newtek_outdev_extralibs="-lndi"
 +dshow_indev_deps="IBaseFilter"
 +dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi"
  fbdev_indev_deps="linux_fb_h"
 +fbdev_outdev_deps="linux_fb_h"
 +gdigrab_indev_deps="CreateDIBSection"
 +gdigrab_indev_extralibs="-lgdi32"
 +gdigrab_indev_select="bmp_decoder"
 +iec61883_indev_deps="libiec61883"
  jack_indev_deps="jack"
  jack_indev_deps_any="sem_timedwait dispatch_dispatch_h"
 +kmsgrab_indev_deps="libdrm"
 +lavfi_indev_deps="avfilter"
  libcdio_indev_deps="libcdio"
  libdc1394_indev_deps="libdc1394"
 +libv4l2_indev_deps="libv4l2"
 +openal_indev_deps="openal"
 +opengl_outdev_deps="opengl"
  oss_indev_deps_any="soundcard_h sys_soundcard_h"
  oss_outdev_deps_any="soundcard_h sys_soundcard_h"
  pulse_indev_deps="libpulse"
@@@ -3118,25 -2426,20 +3127,29 @@@ sdl2_outdev_deps="sdl2
  sndio_indev_deps="sndio"
  sndio_outdev_deps="sndio"
  v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h"
 +v4l2_outdev_deps_any="linux_videodev2_h sys_videoio_h"
  vfwcap_indev_deps="vfw32 vfwcap_defines"
 -xcbgrab_indev_deps="libxcb libxcb_shape"
 -xcbgrab_indev_suggest="libxcb_shm libxcb_xfixes"
 +xcbgrab_indev_deps="libxcb"
++xcbgrab_indev_suggest="libxcb_shm libxcb_shape libxcb_xfixes"
 +xv_outdev_deps="X11_extensions_Xvlib_h XvGetPortAttribute"
 +xv_outdev_extralibs="-lXv -lX11 -lXext"
  
  # protocols
 +async_protocol_deps="threads"
 +bluray_protocol_deps="libbluray"
  ffrtmpcrypt_protocol_conflict="librtmp_protocol"
 -ffrtmpcrypt_protocol_deps_any="gmp openssl"
 +ffrtmpcrypt_protocol_deps_any="gcrypt gmp openssl"
  ffrtmpcrypt_protocol_select="tcp_protocol"
  ffrtmphttp_protocol_conflict="librtmp_protocol"
  ffrtmphttp_protocol_select="http_protocol"
 +ftp_protocol_select="tcp_protocol"
  gopher_protocol_select="network"
  http_protocol_select="tcp_protocol"
++http_protocol_suggest="zlib"
  httpproxy_protocol_select="tcp_protocol"
++httpproxy_protocol_suggest="zlib"
  https_protocol_select="tls_protocol"
++https_protocol_suggest="zlib"
  icecast_protocol_select="http_protocol"
  librtmp_protocol_deps="librtmp"
  librtmpe_protocol_deps="librtmp"
@@@ -3149,14 -2450,14 +3162,20 @@@ mmsh_protocol_select="http_protocol
  mmst_protocol_select="network"
  rtmp_protocol_conflict="librtmp_protocol"
  rtmp_protocol_select="tcp_protocol"
++rtmp_protocol_suggest="zlib"
  rtmpe_protocol_select="ffrtmpcrypt_protocol"
++rtmpe_protocol_suggest="zlib"
  rtmps_protocol_conflict="librtmp_protocol"
  rtmps_protocol_select="tls_protocol"
++rtmps_protocol_suggest="zlib"
  rtmpt_protocol_select="ffrtmphttp_protocol"
++rtmpt_protocol_suggest="zlib"
  rtmpte_protocol_select="ffrtmpcrypt_protocol ffrtmphttp_protocol"
++rtmpte_protocol_suggest="zlib"
  rtmpts_protocol_select="ffrtmphttp_protocol https_protocol"
++rtmpts_protocol_suggest="zlib"
  rtp_protocol_select="udp_protocol"
 -sctp_protocol_deps="struct_sctp_event_subscribe"
 +sctp_protocol_deps="struct_sctp_event_subscribe struct_msghdr_msg_flags"
  sctp_protocol_select="network"
  srtp_protocol_select="rtp_protocol srtp"
  tcp_protocol_select="network"
@@@ -3200,139 -2480,68 +3219,160 @@@ cropdetect_filter_deps="gpl
  deinterlace_qsv_filter_deps="libmfx"
  deinterlace_vaapi_filter_deps="vaapi"
  delogo_filter_deps="gpl"
 +deshake_filter_select="pixelutils"
++deshake_filter_suggest="opencl"
  drawtext_filter_deps="libfreetype"
+ drawtext_filter_suggest="libfontconfig"
 +elbg_filter_deps="avcodec"
 +eq_filter_deps="gpl"
 +fftfilt_filter_deps="avcodec"
 +fftfilt_filter_select="rdft"
 +find_rect_filter_deps="avcodec avformat gpl"
 +firequalizer_filter_deps="avcodec"
 +firequalizer_filter_select="rdft"
 +flite_filter_deps="libflite"
 +framerate_filter_select="pixelutils"
  frei0r_filter_deps="frei0r libdl"
  frei0r_src_filter_deps="frei0r libdl"
 -hdcd_filter_deps="libhdcd"
 +fspp_filter_deps="gpl"
 +geq_filter_deps="gpl"
 +histeq_filter_deps="gpl"
  hqdn3d_filter_deps="gpl"
  interlace_filter_deps="gpl"
 +kerndeint_filter_deps="gpl"
 +ladspa_filter_deps="ladspa libdl"
 +mcdeint_filter_deps="avcodec gpl"
  movie_filter_deps="avcodec avformat"
 +mpdecimate_filter_deps="gpl"
 +mpdecimate_filter_select="pixelutils"
 +mptestsrc_filter_deps="gpl"
 +negate_filter_deps="lut_filter"
 +nnedi_filter_deps="gpl"
 +ocr_filter_deps="libtesseract"
  ocv_filter_deps="libopencv"
 +owdenoise_filter_deps="gpl"
 +pan_filter_deps="swresample"
 +perspective_filter_deps="gpl"
 +phase_filter_deps="gpl"
 +pp7_filter_deps="gpl"
 +pp_filter_deps="gpl postproc"
 +pullup_filter_deps="gpl"
 +removelogo_filter_deps="avcodec avformat swscale"
 +repeatfields_filter_deps="gpl"
  resample_filter_deps="avresample"
 +rubberband_filter_deps="librubberband"
 +sab_filter_deps="gpl swscale"
 +scale2ref_filter_deps="swscale"
  scale_filter_deps="swscale"
  scale_qsv_filter_deps="libmfx"
 +select_filter_select="pixelutils"
 +showcqt_filter_deps="avcodec avformat swscale"
 +showcqt_filter_select="fft"
 +showfreqs_filter_deps="avcodec"
 +showfreqs_filter_select="fft"
 +showspectrum_filter_deps="avcodec"
 +showspectrum_filter_select="fft"
 +showspectrumpic_filter_deps="avcodec"
 +showspectrumpic_filter_select="fft"
 +signature_filter_deps="gpl avcodec avformat"
 +smartblur_filter_deps="gpl swscale"
 +sofalizer_filter_deps="libmysofa avcodec"
 +sofalizer_filter_select="fft"
 +spectrumsynth_filter_deps="avcodec"
 +spectrumsynth_filter_select="fft"
 +spp_filter_deps="gpl avcodec"
 +spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 +stereo3d_filter_deps="gpl"
 +subtitles_filter_deps="avformat avcodec libass"
 +super2xsai_filter_deps="gpl"
 +pixfmts_super2xsai_test_deps="super2xsai_filter"
 +tinterlace_filter_deps="gpl"
 +tinterlace_merge_test_deps="tinterlace_filter"
 +tinterlace_pad_test_deps="tinterlace_filter"
 +tonemap_filter_deps="const_nan"
 +uspp_filter_deps="gpl avcodec"
++unsharp_filter_suggest="opencl"
 +vaguedenoiser_filter_deps="gpl"
 +vidstabdetect_filter_deps="libvidstab"
 +vidstabtransform_filter_deps="libvidstab"
 +libvmaf_filter_deps="libvmaf"
 +zmq_filter_deps="libzmq"
 +zoompan_filter_deps="swscale"
 +zscale_filter_deps="libzimg const_nan"
  scale_vaapi_filter_deps="vaapi VAProcPipelineParameterBuffer"
  
  # examples
 +avio_dir_cmd_deps="avformat avutil"
 +avio_reading_deps="avformat avcodec avutil"
  decode_audio_example_deps="avcodec avutil"
  decode_video_example_deps="avcodec avutil"
 +demuxing_decoding_example_deps="avcodec avformat avutil"
  encode_audio_example_deps="avcodec avutil"
  encode_video_example_deps="avcodec avutil"
 +extract_mvs_example_deps="avcodec avformat avutil"
  filter_audio_example_deps="avfilter avutil"
 +filtering_audio_example_deps="avfilter avcodec avformat avutil"
 +filtering_video_example_deps="avfilter avcodec avformat avutil"
 +http_multiclient_example_deps="avformat avutil fork"
 +hw_decode_example_deps="avcodec avformat avutil"
  metadata_example_deps="avformat avutil"
 -output_example_deps="avcodec avformat avresample avutil swscale"
 +muxing_example_deps="avcodec avformat avutil swscale"
  qsvdec_example_deps="avcodec avutil libmfx h264_qsv_decoder"
 -transcode_aac_example_deps="avcodec avformat avresample"
 +remuxing_example_deps="avcodec avformat avutil"
 +resampling_audio_example_deps="avutil swresample"
 +scaling_video_example_deps="avutil swscale"
 +transcode_aac_example_deps="avcodec avformat swresample"
 +transcoding_example_deps="avfilter avcodec avformat avutil"
  
+ # EXTRALIBS_LIST
+ cpu_init_extralibs="pthreads_extralibs"
+ cws2fws_extralibs="zlib_extralibs"
+ 
  # libraries, in linking order
  avcodec_deps="avutil"
++avcodec_suggest="libm"
  avcodec_select="null_bsf"
  avdevice_deps="avformat avcodec avutil"
++avdevice_suggest="libm"
  avfilter_deps="avutil"
++avfilter_suggest="libm"
  avformat_deps="avcodec avutil"
--avformat_suggest="network"
++avformat_suggest="libm network"
  avresample_deps="avutil"
++avresample_suggest="libm"
++avutil_suggest="libm libdrm libmfx user32 vaapi videotoolbox wincrypt"
 +postproc_deps="avutil gpl"
++postproc_suggest="libm"
 +swresample_deps="avutil"
++swresample_suggest="libm libsoxr"
  swscale_deps="avutil"
++swscale_suggest="libm"
+ 
 -avcodec_extralibs="pthreads_extralibs libm_extralibs"
 -avdevice_extralibs="libm_extralibs"
 -avformat_extralibs="libm_extralibs"
 -avfilter_extralibs="pthreads_extralibs libm_extralibs"
 -avresample_extralibs="libm_extralibs"
 -avutil_extralibs="clock_gettime_extralibs cuda_extralibs libm_extralibs libmfx_extralibs nanosleep_extralibs user32_extralibs vaapi_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vdpau_x11_extralibs wincrypt_extralibs"
 -swscale_extralibs="libm_extralibs"
++avcodec_extralibs="pthreads_extralibs iconv_extralibs"
++avfilter_extralibs="pthreads_extralibs"
++avutil_extralibs="clock_gettime_extralibs nanosleep_extralibs pthreads_extralibs vaapi_drm_extralibs vaapi_x11_extralibs vdpau_x11_extralibs"
  
  # programs
 -avconv_deps="avcodec avfilter avformat avresample swscale"
 -avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_filter
 -               fps_filter null_filter resample_filter scale_filter
 +ffmpeg_deps="avcodec avfilter avformat swresample"
 +ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter
 +               null_filter
                 trim_filter"
 -avconv_suggest="dxva2_lib ole32 psapi shell32"
 -avplay_deps="avcodec avfilter avformat avresample sdl"
 -avplay_select="rdft format_filter transpose_filter hflip_filter vflip_filter"
 -avplay_suggest="shell32"
 -avprobe_deps="avcodec avformat"
 -avprobe_suggest="shell32"
++ffmpeg_suggest="ole32 psapi shell32"
 +ffplay_deps="avcodec avformat swscale swresample sdl2"
- ffplay_extralibs='$sdl2_extralibs'
 +ffplay_select="rdft crop_filter transpose_filter hflip_filter vflip_filter rotate_filter"
++ffplay_suggest="shell32"
 +ffprobe_deps="avcodec avformat"
++ffprobe_suggest="shell32"
 +ffserver_deps="avformat fork sarestart"
 +ffserver_select="ffm_muxer rtp_protocol rtsp_demuxer"
  
  # documentation
 -pod2man_deps="doc"
 -texi2html_deps="doc"
 +podpages_deps="perl"
 +manpages_deps="perl pod2man"
 +htmlpages_deps="perl"
 +htmlpages_deps_any="makeinfo_html texi2html"
 +txtpages_deps="perl makeinfo"
 +doc_deps_any="manpages htmlpages podpages txtpages"
  
  # default parameters
  
@@@ -3398,9 -2592,15 +3438,15 @@@ enable stati
  enable swscale_alpha
  enable valgrind_backtrace
  
 -# By default, enable only those hwaccels that have no external dependencies.
 -enable d3d11va dxva2 vda vdpau
 +sws_max_filter_size_default=256
 +set_default sws_max_filter_size
  
+ # internal components are enabled by default
+ enable $EXTRALIBS_LIST
+ 
+ # Avoid external, non-system, libraries getting enabled by dependency resolution
 -disable $EXTERNAL_LIBRARY_LIST
++disable $EXTERNAL_LIBRARY_LIST $HWACCEL_LIBRARY_LIST
+ 
  # build settings
  SHFLAGS='-shared -Wl,-soname,$$(@F)'
  LIBPREF="lib"
@@@ -5709,10 -4564,10 +5771,9 @@@ check_func_headers malloc.h _aligned_ma
  check_func  ${malloc_prefix}memalign            && enable memalign
  check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
  
 -check_cpp_condition unistd.h "defined(_POSIX_MONOTONIC_CLOCK)" &&
 -    check_func_headers time.h clock_gettime ||
 -        check_lib clock_gettime time.h clock_gettime -lrt
 -
 +check_func  access
 +check_func_headers stdlib.h arc4random
- check_func_headers time.h clock_gettime ||
-     { check_lib clock_gettime time.h clock_gettime -lrt && LIBRT="-lrt"; }
++check_func_headers time.h clock_gettime || check_lib clock_gettime time.h clock_gettime -lrt
  check_func  fcntl
  check_func  fork
  check_func  gethrtime
@@@ -5725,11 -4582,9 +5786,10 @@@ check_func  mkstem
  check_func  mmap
  check_func  mprotect
  # Solaris has nanosleep in -lrt, OpenSolaris no longer needs that
- check_func_headers time.h nanosleep ||
-     { check_lib nanosleep time.h nanosleep -lrt && LIBRT="-lrt"; }
+ check_func_headers time.h nanosleep || check_lib nanosleep time.h nanosleep -lrt
  check_func  sched_getaffinity
  check_func  setrlimit
 +check_struct "sys/stat.h" "struct stat" st_mtim.tv_nsec -D_BSD_SOURCE
  check_func  strerror_r
  check_func  sysconf
  check_func  sysctl
@@@ -5794,21 -4633,6 +5854,26 @@@ check_lib shell32  "windows.h shellapi.
  check_lib wincrypt "windows.h wincrypt.h" CryptGenRandom       -ladvapi32
  check_lib psapi    "windows.h psapi.h"    GetProcessMemoryInfo -lpsapi
  
 +enabled appkit       && check_apple_framework AppKit
 +enabled audiotoolbox && check_apple_framework AudioToolbox
 +enabled avfoundation && check_apple_framework AVFoundation
 +enabled coreimage    && check_apple_framework CoreImage
 +enabled videotoolbox && check_apple_framework VideoToolbox
 +
++check_apple_framework CoreFoundation
++check_apple_framework CoreMedia
++check_apple_framework CoreVideo
++
 +enabled avfoundation && {
-     check_lib avfoundation CoreGraphics/CoreGraphics.h               CGGetActiveDisplayList "-framework CoreGraphics" ||
-     check_lib avfoundation ApplicationServices/ApplicationServices.h CGGetActiveDisplayList "-framework ApplicationServices"; }
++    disable coregraphics applicationservices
++    check_lib CoreGraphics        CoreGraphics/CoreGraphics.h               CGGetActiveDisplayList "-framework CoreGraphics" ||
++    check_lib applicationservices ApplicationServices/ApplicationServices.h CGGetActiveDisplayList "-framework ApplicationServices"; }
 +
 +enabled videotoolbox && {
 +    check_lib coreservices CoreServices/CoreServices.h UTGetOSTypeFromString "-framework CoreServices"
 +    check_func_headers CoreMedia/CMFormatDescription.h kCMVideoCodecType_HEVC "-framework CoreMedia"
 +}
 +
  check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
  
  check_type "windows.h dxva.h" "DXVA_PicParams_HEVC" -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -D_CRT_BUILD_DESKTOP_APP=0
@@@ -5872,162 -4673,76 +5937,162 @@@ f
  enabled pthreads &&
      check_builtin sem_timedwait semaphore.h "sem_t *s; sem_init(s,0,0); sem_timedwait(s,0); sem_destroy(s)"
  
 -disabled  zlib || check_lib  zlib  zlib.h      zlibVersion -lz
 -disabled bzlib || check_lib bzlib bzlib.h BZ2_bzlibVersion -lbz2
 +enabled  zlib && check_lib zlib   zlib.h      zlibVersion    -lz
 +enabled bzlib && check_lib bzlib bzlib.h BZ2_bzlibVersion    -lbz2
 +enabled  lzma && check_lib lzma   lzma.h lzma_version_number -llzma
  
  # On some systems dynamic loading requires no extra linker flags
 -check_lib libdl dlfcn.h dlopen || check_lib libdl dlfcn.h dlopen -ldl
 +check_lib libdl dlfcn.h "dlopen dlsym" || check_lib libdl dlfcn.h "dlopen dlsym" -ldl
  
- check_lib libm math.h sin -lm && LIBM="-lm"
+ check_lib libm math.h sin -lm
  
  atan2f_args=2
 +copysign_args=2
 +hypot_args=2
  ldexpf_args=2
  powf_args=2
  
  for func in $MATH_FUNCS; do
-     eval check_mathfunc $func \${${func}_args:-1} $LIBM
+     eval check_mathfunc $func \${${func}_args:-1} $libm_extralibs
  done
  
 +for func in $COMPLEX_FUNCS; do
 +    eval check_complexfunc $func \${${func}_args:-1}
 +done
 +
  # these are off by default, so fail if requested and not available
 -enabled avisynth          && require_header avisynth/avisynth_c.h
 -enabled avxsynth          && require_header avxsynth/avxsynth_c.h
 -enabled cuda              && require cuda cuda.h cuInit -lcuda
 +enabled cuda_sdk          && require cuda_sdk cuda.h cuCtxCreate -lcuda
 +enabled cuvid             && { enabled cuda ||
 +                               die "ERROR: CUVID requires CUDA"; }
 +enabled chromaprint       && require chromaprint chromaprint.h chromaprint_get_version -lchromaprint
 +enabled decklink          && { require_header DeckLinkAPI.h &&
 +                               { check_cpp_condition DeckLinkAPIVersion.h "BLACKMAGIC_DECKLINK_API_VERSION >= 0x0a060100" || die "ERROR: Decklink API version must be >= 10.6.1."; } }
 +enabled libndi_newtek     && require_header Processing.NDI.Lib.h
  enabled frei0r            && require_header frei0r.h
 +enabled gmp               && require gmp gmp.h mpz_export -lgmp
  enabled gnutls            && require_pkg_config gnutls gnutls gnutls/gnutls.h gnutls_global_init
 +enabled jni               && { [ $target_os = "android" ] && check_header jni.h && enabled pthreads || die "ERROR: jni not found"; }
 +enabled ladspa            && require_header ladspa.h
 +enabled libiec61883       && require libiec61883 libiec61883/iec61883.h iec61883_cmp_connect -lraw1394 -lavc1394 -lrom1394 -liec61883
 +enabled libass            && require_pkg_config libass libass ass/ass.h ass_library_init
 +enabled libbluray         && require_pkg_config libbluray libbluray libbluray/bluray.h bd_open
  enabled libbs2b           && require_pkg_config libbs2b libbs2b bs2b.h bs2b_open
 +enabled libcelt           && require libcelt celt/celt.h celt_decode -lcelt0 &&
 +                             { check_lib libcelt celt/celt.h celt_decoder_create_custom -lcelt0 ||
 +                               die "ERROR: libcelt must be installed and version must be >= 0.11.0."; }
 +enabled libcaca           && require_pkg_config libcaca caca caca.h caca_create_canvas
  enabled libdc1394         && require_pkg_config libdc1394 libdc1394-2 dc1394/dc1394.h dc1394_new
 -enabled libdcadec         && require libdcadec libdcadec/dca_context.h dcadec_context_create -ldcadec
 -enabled libfaac           && require libfaac "stdint.h faac.h" faacEncGetVersion -lfaac
 -enabled libfdk_aac        && require_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen
 +enabled libdrm            && require_pkg_config libdrm libdrm xf86drm.h drmGetVersion
 +enabled libfdk_aac        && { use_pkg_config libfdk_aac fdk-aac "fdk-aac/aacenc_lib.h" aacEncOpen ||
 +                               { require libfdk_aac fdk-aac/aacenc_lib.h aacEncOpen -lfdk-aac &&
 +                                 warn "using libfdk without pkg-config"; } }
 +flite_extralibs="-lflite_cmu_time_awb -lflite_cmu_us_awb -lflite_cmu_us_kal -lflite_cmu_us_kal16 -lflite_cmu_us_rms -lflite_cmu_us_slt -lflite_usenglish -lflite_cmulex -lflite"
 +enabled libflite          && require libflite "flite/flite.h" flite_init $flite_extralibs
 +enabled fontconfig        && enable libfontconfig
  enabled libfontconfig     && require_pkg_config libfontconfig fontconfig "fontconfig/fontconfig.h" FcInit
- enabled libfreetype       && require_pkg_config libfreetype2 freetype2 "ft2build.h FT_FREETYPE_H" FT_Init_FreeType
+ enabled libfreetype       && require_pkg_config libfreetype freetype2 "ft2build.h FT_FREETYPE_H" FT_Init_FreeType
 +enabled libfribidi        && require_pkg_config libfribidi fribidi fribidi.h fribidi_version_info
 +enabled libgme            && { use_pkg_config libgme libgme gme/gme.h gme_new_emu ||
 +                               require libgme gme/gme.h gme_new_emu -lgme -lstdc++; }
  enabled libgsm            && { for gsm_hdr in "gsm.h" "gsm/gsm.h"; do
                                     check_lib libgsm "${gsm_hdr}" gsm_create -lgsm && break;
                                 done || die "ERROR: libgsm not found"; }
 -enabled libhdcd           && require_pkg_config libhdcd libhdcd "hdcd/hdcd_simple.h" hdcd_new
  enabled libilbc           && require libilbc ilbc.h WebRtcIlbcfix_InitDecode -lilbc
  enabled libkvazaar        && require_pkg_config libkvazaar "kvazaar >= 0.8.1" kvazaar.h kvz_api_get
 -enabled libmfx            && require_pkg_config libmfx libmfx "mfx/mfxvideo.h" MFXInit
 +# While it may appear that require is being used as a pkg-config
 +# fallback for libmfx, it is actually being used to detect a different
 +# installation route altogether.  If libmfx is installed via the Intel
 +# Media SDK or Intel Media Server Studio, these don't come with
 +# pkg-config support.  Instead, users should make sure that the build
 +# can find the libraries and headers through other means.
 +enabled libmfx            && { use_pkg_config libmfx libmfx "mfx/mfxvideo.h" MFXInit ||
 +                               { require libmfx "mfx/mfxvideo.h" MFXInit -llibmfx && warn "using libmfx without pkg-config"; } }
 +enabled libmodplug        && require_pkg_config libmodplug libmodplug libmodplug/modplug.h ModPlug_Load
  enabled libmp3lame        && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame
 -enabled libnpp            && require libnpp npp.h nppGetLibVersion -lnppi -lnppc
 +enabled libmysofa         && require libmysofa "mysofa.h" mysofa_load -lmysofa
 +enabled libnpp            && { check_lib libnpp npp.h nppGetLibVersion -lnppig -lnppicc -lnppc ||
 +                               check_lib libnpp npp.h nppGetLibVersion -lnppi -lnppc ||
 +                               die "ERROR: libnpp not found"; }
  enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb
  enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb
 -enabled libopencv         && require_pkg_config libopencv opencv opencv/cv.h cvCreateImageHeader
 +enabled libopencv         && { check_header opencv2/core/core_c.h &&
 +                               { use_pkg_config libopencv opencv opencv2/core/core_c.h cvCreateImageHeader ||
-                                  require opencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
++                                 require libopencv opencv2/core/core_c.h cvCreateImageHeader -lopencv_core -lopencv_imgproc; } ||
 +                               require_pkg_config libopencv opencv opencv/cxcore.h cvCreateImageHeader; }
  enabled libopenh264       && require_pkg_config libopenh264 openh264 wels/codec_api.h WelsGetCodecVersion
 -enabled libopenjpeg       && { check_lib libopenjpeg openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC ||
 -                               require_pkg_config libopenjpeg libopenjpeg1 openjpeg.h opj_version -DOPJ_STATIC; }
 -enabled libopus           && require_pkg_config libopus opus opus_multistream.h opus_multistream_decoder_create
 -enabled libpulse          && require_pkg_config libpulse libpulse-simple pulse/simple.h pa_simple_new
 +enabled libopenjpeg       && { { check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               check_lib libopenjpeg openjpeg-2.3/openjpeg.h opj_version -lopenjp2 ||
 +                               { check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               check_lib libopenjpeg openjpeg-2.2/openjpeg.h opj_version -lopenjp2 ||
 +                               { check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               check_lib libopenjpeg openjpeg-2.1/openjpeg.h opj_version -lopenjp2 ||
 +                               { check_lib libopenjpeg openjpeg-2.0/openjpeg.h opj_version -lopenjp2 -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               { check_lib libopenjpeg openjpeg-1.5/openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               { check_lib libopenjpeg openjpeg.h opj_version -lopenjpeg -DOPJ_STATIC && add_cppflags -DOPJ_STATIC; } ||
 +                               die "ERROR: libopenjpeg not found"; }
 +enabled libopenmpt        && require_pkg_config libopenmpt "libopenmpt >= 0.2.6557" libopenmpt/libopenmpt.h openmpt_module_create
 +enabled libopus           && {
 +    enabled libopus_decoder && {
 +        require_pkg_config libopus opus opus_multistream.h opus_multistream_decoder_create
 +    }
 +    enabled libopus_encoder && {
 +        require_pkg_config libopus opus opus_multistream.h opus_multistream_surround_encoder_create
 +    }
 +}
 +enabled libpulse          && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new
 +enabled librsvg           && require_pkg_config librsvg librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo
  enabled librtmp           && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket
 -enabled libschroedinger   && require_pkg_config libschroedinger schroedinger-1.0 schroedinger/schro.h schro_init
 +enabled librubberband     && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new
 +enabled libshine          && require_pkg_config libshine shine shine/layer3.h shine_encode_buffer
 +enabled libsmbclient      && { use_pkg_config libsmbclient smbclient libsmbclient.h smbc_init ||
-                                require smbclient libsmbclient.h smbc_init -lsmbclient; }
++                               require libsmbclient libsmbclient.h smbc_init -lsmbclient; }
  enabled libsnappy         && require libsnappy snappy-c.h snappy_compress -lsnappy
- enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr && LIBSOXR="-lsoxr"
++enabled libsoxr           && require libsoxr soxr.h soxr_create -lsoxr
 +enabled libssh            && require_pkg_config libssh libssh libssh/sftp.h sftp_init
  enabled libspeex          && require_pkg_config libspeex speex speex/speex.h speex_decoder_init -lspeex
 +enabled libtesseract      && require_pkg_config libtesseract tesseract tesseract/capi.h TessBaseAPICreate
  enabled libtheora         && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg
 -enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame
 -enabled libvo_aacenc      && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc
 +enabled libtwolame        && require libtwolame twolame.h twolame_init -ltwolame &&
 +                             { check_lib libtwolame twolame.h twolame_encode_buffer_float32_interleaved -ltwolame ||
 +                               die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; }
 +enabled libv4l2           && require_pkg_config libv4l2 libv4l2 libv4l2.h v4l2_ioctl
 +enabled libvidstab        && require_pkg_config libvidstab "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit
 +enabled libvmaf           && require_pkg_config libvmaf libvmaf libvmaf.h compute_vmaf
  enabled libvo_amrwbenc    && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc
 -enabled libvorbis         && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg
 -enabled libvpx            && require_pkg_config libvpx "vpx >= 1.3.0" vpx/vpx_codec.h vpx_codec_version &&
 -                             { enabled libvpx_vp8_decoder &&
 -                                   check_pkg_config libvpx_vp8_decoder vpx "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp8_dx
 -                               enabled libvpx_vp8_encoder &&
 -                                   check_pkg_config libvpx_vp8_encoder vpx "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp8_cx
 -                               enabled libvpx_vp9_decoder &&
 -                                   check_pkg_config libvpx_vp9_decoder vpx "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp9_dx
 -                               enabled libvpx_vp9_encoder &&
 -                                   check_pkg_config libvpx_vp9_encoder vpx "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp9_cx
 -                               disabled_all libvpx_vp8_decoder libvpx_vp9_decoder libvpx_vp8_encoder libvpx_vp9_encoder &&
 -                                   die "libvpx enabled but no supported decoders/encoders found"
 -                             }
 +enabled libvorbis         && require_pkg_config libvorbis vorbis vorbis/codec.h vorbis_info_init &&
 +                             require_pkg_config libvorbisenc vorbisenc vorbis/vorbisenc.h vorbis_encode_init
 +
 +enabled libvpx            && {
 +    enabled libvpx_vp8_decoder && {
 +        use_pkg_config libvpx_vp8_decoder "vpx >= 0.9.1" "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp8_dx ||
 +            check_lib libvpx_vp8_decoder "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx ||
 +                die "ERROR: libvpx decoder version must be >=0.9.1";
 +    }
 +    enabled libvpx_vp8_encoder && {
 +        use_pkg_config libvpx_vp8_encoder "vpx >= 0.9.7" "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp8_cx ||
 +            check_lib libvpx_vp8_encoder "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VP8E_SET_MAX_INTRA_BITRATE_PCT" -lvpx ||
 +                die "ERROR: libvpx encoder version must be >=0.9.7";
 +    }
 +    enabled libvpx_vp9_decoder && {
 +        use_pkg_config libvpx_vp9_decoder "vpx >= 1.3.0" "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_vp9_dx ||
 +            check_lib libvpx_vp9_decoder "vpx/vpx_decoder.h vpx/vp8dx.h" "vpx_codec_vp9_dx" -lvpx
 +    }
 +    enabled libvpx_vp9_encoder && {
 +        use_pkg_config libvpx_vp9_encoder "vpx >= 1.3.0" "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_vp9_cx ||
 +            check_lib libvpx_vp9_encoder "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_vp9_cx VP9E_SET_AQ_MODE" -lvpx
 +    }
 +    if disabled_all libvpx_vp8_decoder libvpx_vp9_decoder libvpx_vp8_encoder libvpx_vp9_encoder; then
 +        die "libvpx enabled but no supported decoders found"
 +    fi
 +}
 +
  enabled libwavpack        && require libwavpack wavpack/wavpack.h WavpackOpenFileOutput  -lwavpack
 -enabled libwebp           && require_pkg_config libwebp libwebp webp/encode.h WebPGetEncoderVersion
 -enabled libx264           && require_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode &&
 +enabled libwebp           && {
 +    enabled libwebp_encoder      && require_pkg_config libwebp "libwebp >= 0.2.0" webp/encode.h WebPGetEncoderVersion
 +    enabled libwebp_anim_encoder && use_pkg_config libwebp_anim_encoder "libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
 +enabled libx264           && { use_pkg_config libx264 x264 "stdint.h x264.h" x264_encoder_encode ||
 +                               { require libx264 "stdint.h x264.h" x264_encoder_encode -lx264 &&
 +                                 warn "using libx264 without pkg-config"; } } &&
                               require_cpp_condition x264.h "X264_BUILD >= 118" &&
                               { check_cpp_condition x264.h "X264_MPEG2" &&
                                 enable libx262; }
@@@ -6049,119 -4757,36 +6114,118 @@@ enabled mmal              && { check_li
                                   check_lib mmal interface/mmal/mmal.h mmal_port_connect -lmmal_core -lmmal_util -lmmal_vc_client -lbcm_host; } ||
                                 die "ERROR: mmal not found" &&
                                 check_func_headers interface/mmal/mmal.h "MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS"; }
 +enabled openal            && { { for al_extralibs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do
 +                               check_lib openal 'AL/al.h' alGetError "${al_extralibs}" && break; done } ||
 +                               die "ERROR: openal not found"; } &&
 +                             { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" ||
 +                               die "ERROR: openal must be installed and version must be 1.1 or compatible"; }
 +enabled opencl            && { check_lib opencl OpenCL/cl.h clEnqueueNDRangeKernel -Wl,-framework,OpenCL ||
 +                               check_lib opencl CL/cl.h clEnqueueNDRangeKernel -lOpenCL ||
 +                               die "ERROR: opencl not found"; } &&
 +                             { check_cpp_condition "OpenCL/cl.h" "defined(CL_VERSION_1_2)" ||
 +                               check_cpp_condition "CL/cl.h" "defined(CL_VERSION_1_2)" ||
 +                               die "ERROR: opencl must be installed and version must be 1.2 or compatible"; }
 +enabled opengl            && { check_lib opengl GL/glx.h glXGetProcAddress "-lGL" ||
 +                               check_lib opengl windows.h wglGetProcAddress "-lopengl32 -lgdi32" ||
 +                               check_lib opengl OpenGL/gl3.h glGetError "-Wl,-framework,OpenGL" ||
 +                               check_lib opengl ES2/gl.h glGetError "-isysroot=${sysroot} -Wl,-framework,OpenGLES" ||
 +                               die "ERROR: opengl not found."
 +                             }
+ enabled omx               && require_header OMX_Core.h
  enabled omx_rpi           && { check_header OMX_Core.h ||
                                 { ! enabled cross_compile && add_cflags -isystem/opt/vc/include/IL && check_header OMX_Core.h ; } ||
-                                die "ERROR: OpenMAX IL headers not found"; }
- enabled omx               && require_header OMX_Core.h
+                                die "ERROR: OpenMAX IL headers not found"; } && enable omx
 -enabled openssl           && { { check_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
 -                                 check_pkg_config openssl openssl openssl/ssl.h SSL_library_init; } ||
 +enabled openssl           && { use_pkg_config openssl openssl openssl/ssl.h OPENSSL_init_ssl ||
 +                               use_pkg_config openssl openssl openssl/ssl.h SSL_library_init ||
                                 check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto ||
                                 check_lib openssl openssl/ssl.h SSL_library_init -lssl32 -leay32 ||
                                 check_lib openssl openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
                                 die "ERROR: openssl not found"; }
- enabled rkmpp             && { { require_pkg_config rockchip_mpp rockchip_mpp rockchip/rk_mpi.h mpp_create ||
++enabled rkmpp             && { { require_pkg_config rkmpp rockchip_mpp rockchip/rk_mpi.h mpp_create ||
 +                                 die "ERROR : Rockchip MPP was not found."; } &&
 +                               { check_func_headers rockchip/rk_mpi_cmd.h "MPP_DEC_GET_FREE_PACKET_SLOT_COUNT" ||
 +                                 die "ERROR: Rockchip MPP is outdated, please get a more recent one."; } &&
 +                               { enabled libdrm ||
 +                                 die "ERROR: rkmpp requires --enable-libdrm"; }
 +                             }
  
 -enabled gnutls            && check_lib gmp gmp.h mpz_export -lgmp
 -
 -if enabled nvenc; then
 -    require_header nvEncodeAPI.h
 -    require_cpp_condition nvEncodeAPI.h "NVENCAPI_MAJOR_VERSION >= 6"
 +if enabled gcrypt; then
 +    GCRYPT_CONFIG="${cross_prefix}libgcrypt-config"
 +    if "${GCRYPT_CONFIG}" --version > /dev/null 2>&1; then
 +        gcrypt_cflags=$("${GCRYPT_CONFIG}" --cflags)
 +        gcrypt_extralibs=$("${GCRYPT_CONFIG}" --libs)
 +        check_func_headers gcrypt.h gcry_mpi_new $gcrypt_cflags $gcrypt_extralibs ||
 +            die "ERROR: gcrypt not found"
-         add_cflags $gcrypt_cflags && add_extralibs $gcrypt_extralibs
++        add_cflags $gcrypt_cflags
 +    else
 +        require gcrypt gcrypt.h gcry_mpi_new -lgcrypt
 +    fi
  fi
  
 -check_pkg_config sdl "sdl >= 1.2.1 sdl < 1.3.0" SDL_events.h SDL_PollEvent
 +if enabled sdl2; then
 +    SDL2_CONFIG="${cross_prefix}sdl2-config"
 +    if check_pkg_config sdl2 "sdl2 >= 2.0.1 sdl2 < 2.1.0" SDL_events.h SDL_PollEvent; then
 +        check_func SDL_Init $sdl2_extralibs $sdl2_cflags ||
 +            disable sdl2
 +    elif "${SDL2_CONFIG}" --version > /dev/null 2>&1; then
 +        sdl2_cflags=$("${SDL2_CONFIG}" --cflags)
 +        sdl2_extralibs=$("${SDL2_CONFIG}" --libs)
 +        check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x020001" $sdl2_cflags &&
 +        check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) < 0x020100" $sdl2_cflags &&
 +        check_func SDL_Init $sdl2_extralibs $sdl2_cflags &&
 +            enable sdl2
 +    fi
 +    if test $target_os = "mingw32"; then
 +        sdl2_extralibs=$(filter_out '-mwindows' $sdl2_extralibs)
 +    fi
 +fi
- enabled sdl2 && add_cflags $(filter_out '-Dmain=SDL_main' $sdl2_cflags) && add_extralibs $sdl2_extralibs
  
 -! disabled pod2man   && check_cmd pod2man --help     && enable pod2man   || disable pod2man
 -! disabled texi2html && check_cmd texi2html -version && enable texi2html || disable texi2html
 +if enabled decklink; then
 +    case $target_os in
 +        mingw32*|mingw64*|win32|win64)
 +            decklink_outdev_extralibs="$decklink_outdev_extralibs -lole32 -loleaut32"
 +            decklink_indev_extralibs="$decklink_indev_extralibs -lole32 -loleaut32"
 +            ;;
 +    esac
 +fi
  
 +enabled securetransport &&
 +    check_func SecIdentityCreate "-Wl,-framework,CoreFoundation -Wl,-framework,Security" &&
 +    check_lib securetransport "Security/SecureTransport.h Security/Security.h" "SSLCreateContext SecItemImport" "-Wl,-framework,CoreFoundation -Wl,-framework,Security" ||
 +        disable securetransport
 +
 +enabled schannel &&
 +    check_func_headers "windows.h security.h" InitializeSecurityContext -DSECURITY_WIN32 -lsecur32 &&
 +    check_cpp_condition winerror.h "defined(SEC_I_CONTEXT_EXPIRED)" &&
-     add_extralibs -lsecur32 ||
++    schannel_extralibs="-lsecur32" ||
 +        disable schannel
 +
 +makeinfo --version > /dev/null 2>&1 && enable makeinfo  || disable makeinfo
 +enabled makeinfo \
 +    && [ 0$(makeinfo --version | grep "texinfo" | sed 's/.*texinfo[^0-9]*\([0-9]*\)\..*/\1/') -ge 5 ] \
 +    && enable makeinfo_html || disable makeinfo_html
 +disabled makeinfo_html && texi2html --help 2> /dev/null | grep -q 'init-file' && enable texi2html || disable texi2html
 +perl -v            > /dev/null 2>&1 && enable perl      || disable perl
 +pod2man --help     > /dev/null 2>&1 && enable pod2man   || disable pod2man
 +rsync --help 2> /dev/null | grep -q 'contimeout' && enable rsync_contimeout || disable rsync_contimeout
 +
 +# check V4L2 codecs available in the API
  check_header linux/fb.h
  check_header linux/videodev2.h
 -check_struct linux/videodev2.h "struct v4l2_frmivalenum" discrete
 -
 -check_header AVFoundation/AVFoundation.h
 +check_code cc linux/videodev2.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_safe struct_v4l2_frmivalenum_discrete
 +check_code cc linux/videodev2.h "int i = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_VIDEO_M2M | V4L2_BUF_FLAG_LAST;" || disable v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_VC1_ANNEX_G;" && enable vc1_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG1;" && enable mpeg1_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG2;" && enable mpeg2_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_MPEG4;" && enable mpeg4_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_HEVC;" && enable hevc_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_H263;" && enable h263_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_H264;" && enable h264_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_VP8;" && enable vp8_v4l2_m2m
 +check_code cc linux/videodev2.h "int i = V4L2_PIX_FMT_VP9;" && enable vp9_v4l2_m2m
  
  check_header sys/videoio.h
 +check_code cc sys/videoio.h "struct v4l2_frmsizeenum vfse; vfse.discrete.width = 0;" && enable_safe struct_v4l2_frmivalenum_discrete
  
  check_lib user32 "windows.h winuser.h" GetShellWindow -luser32
  check_lib vfw32 "windows.h vfw.h" capCreateCaptureWindow -lvfw32
@@@ -6203,37 -4820,19 +6267,34 @@@ if enabled libcdio; the
      die "ERROR: No usable libcdio/cdparanoia found"
  fi
  
- enabled libxcb && check_pkg_config libxcb "xcb >= 1.4" xcb/xcb.h xcb_connect ||
++enabled libxcb && use_pkg_config libxcb "xcb >= 1.4" xcb/xcb.h xcb_connect ||
 +    disable libxcb_shm libxcb_shape libxcb_xfixes
 +
  if enabled libxcb; then
-     enabled libxcb_shm    && check_pkg_config libxcb_shm    xcb-shm    xcb/shm.h    xcb_shm_attach
-     enabled libxcb_shape  && check_pkg_config libxcb_shape  xcb-shape  xcb/shape.h  xcb_shape_get_rectangles
-     enabled libxcb_xfixes && check_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
- 
-     add_cflags $xcb_cflags $xcb_shm_cflags $xcb_xfixes_cflags $xcb_shape_cflags
-     add_extralibs $xcb_extralibs $xcb_shm_extralibs $xcb_xfixes_extralibs $xcb_shape_extralibs
 -    require_pkg_config libxcb xcb xcb/xcb.h xcb_connect
 -    require_pkg_config libxcb_shape xcb-shape xcb/shape.h xcb_shape_rectangles
 -    disabled libxcb_shm ||
 -        check_pkg_config libxcb_shm xcb-shm xcb/shm.h xcb_shm_attach
 -    disabled libxcb_xfixes ||
 -        check_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
++    enabled libxcb_shm    && use_pkg_config libxcb_shm    xcb-shm    xcb/shm.h    xcb_shm_attach
++    enabled libxcb_shape  && use_pkg_config libxcb_shape  xcb-shape  xcb/shape.h  xcb_shape_get_rectangles
++    enabled libxcb_xfixes && use_pkg_config libxcb_xfixes xcb-xfixes xcb/xfixes.h xcb_xfixes_get_cursor_image
  fi
  
 -enabled dxva2 &&
 -    check_lib dxva2_lib windows.h CoTaskMemFree -lole32
 +check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
 +
 +# d3d11va requires linking directly to dxgi and d3d11 if not building for
 +# the desktop api partition
 +check_cpp <<EOF && enable uwp && d3d11va_extralibs="-ldxgi -ld3d11"
 +#ifdef WINAPI_FAMILY
 +#include <winapifamily.h>
 +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
 +#error desktop, not uwp
 +#else
 +// WINAPI_FAMILY_APP, WINAPI_FAMILY_PHONE_APP => UWP
 +#endif
 +#else
 +#error no family set
 +#endif
 +EOF
  
 -enabled vaapi && require vaapi va/va.h vaInitialize -lva
 +enabled vaapi &&
 +    check_lib vaapi va/va.h vaInitialize -lva
  
  enabled vaapi &&
      check_code cc "va/va.h" "vaCreateSurfaces(0, 0, 0, 0, 0, 0, 0, 0)" ||
@@@ -6583,40 -5110,42 +6644,50 @@@ check_deps $CONFIG_LIST       
             $HAVE_LIST         \
             $ALL_COMPONENTS    \
  
 +enabled threads && ! enabled pthreads && ! enabled atomics_native && die "non pthread threading without atomics not supported, try adding --enable-pthreads or --cpu=i486 or higher if you are on x86"
 +
 +
 +if test $target_os = "haiku"; then
 +    disable memalign
 +    disable posix_memalign
 +fi
 +
- # add_dep lib dep
- # -> enable ${lib}_deps_${dep}
- # -> add $dep to ${lib}_deps only once
- add_dep() {
-     lib=$1
-     dep=$2
-     enabled "${lib}_deps_${dep}" && return 0
-     enable  "${lib}_deps_${dep}"
-     prepend "${lib}_deps" $dep
- }
- 
- # merge deps lib components
- # merge all ${component}_deps into ${lib}_deps and ${lib}_deps_*
- merge_deps() {
-     lib=$1
-     shift
-     for comp in $*; do
-         enabled $comp || continue
-         eval "dep=\"\$${comp}_deps\""
-         for d in $dep; do
-             add_dep $lib $d
-         done
+ flatten_extralibs(){
+     unset nested_entries
+     list_name=$1
+     eval list=\$${1}
+     for entry in $list; do
+         entry_copy=$entry
+         resolve entry_copy
+         append nested_entries $(filter '*_extralibs' $entry_copy)
+         flat_entries=$(filter_out '*_extralibs' $entry_copy)
+         eval $entry="\$flat_entries"
      done
+     append $list_name "$nested_entries"
+ 
+     resolve nested_entries
+     if test -n "$(filter '*_extralibs' $nested_entries)"; then
+         flatten_extralibs $list_name
+     fi
  }
  
- merge_deps libavfilter $FILTER_LIST
+ for linkunit in $LIBRARY_LIST; do
+     unset current_extralibs
+     eval components=\$$(toupper ${linkunit})_COMPONENTS_LIST
+     for comp in ${components}; do
+         enabled $comp || continue
+         comp_extralibs="${comp}_extralibs"
+         append current_extralibs $comp_extralibs
+     done
+     eval prepend ${linkunit}_extralibs $current_extralibs
+ done
+ 
+ for linkunit in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
+     flatten_extralibs ${linkunit}_extralibs
+     unique  ${linkunit}_extralibs
+     resolve ${linkunit}_extralibs
+     eval ${linkunit}_extralibs=\$\(\$ldflags_filter \$${linkunit}_extralibs\)
+ done
  
  map 'enabled $v && intrinsics=${v#intrinsics_}' $INTRINSICS_LIST
  
@@@ -6652,41 -5176,12 +6723,44 @@@ don
  enabled zlib && add_cppflags -DZLIB_CONST
  
  # conditional library dependencies, in linking order
 +enabled afftfilt_filter     && prepend avfilter_deps "avcodec"
 +enabled afir_filter         && prepend avfilter_deps "avcodec"
 +enabled amovie_filter       && prepend avfilter_deps "avformat avcodec"
 +enabled aresample_filter    && prepend avfilter_deps "swresample"
 +enabled atempo_filter       && prepend avfilter_deps "avcodec"
 +enabled cover_rect_filter   && prepend avfilter_deps "avformat avcodec"
 +enabled ebur128_filter && enabled swresample && prepend avfilter_deps "swresample"
 +enabled elbg_filter         && prepend avfilter_deps "avcodec"
 +enabled fftfilt_filter      && prepend avfilter_deps "avcodec"
 +enabled find_rect_filter    && prepend avfilter_deps "avformat avcodec"
 +enabled firequalizer_filter && prepend avfilter_deps "avcodec"
 +enabled mcdeint_filter      && prepend avfilter_deps "avcodec"
  enabled movie_filter    && prepend avfilter_deps "avformat avcodec"
 -enabled_any asyncts_filter resample_filter &&
 -                           prepend avfilter_deps "avresample"
 +enabled pan_filter          && prepend avfilter_deps "swresample"
 +enabled pp_filter           && prepend avfilter_deps "postproc"
 +enabled removelogo_filter   && prepend avfilter_deps "avformat avcodec swscale"
 +enabled resample_filter && prepend avfilter_deps "avresample"
 +enabled sab_filter          && prepend avfilter_deps "swscale"
  enabled scale_filter    && prepend avfilter_deps "swscale"
 -
 -enabled opus_decoder    && prepend avcodec_deps "avresample"
 +enabled scale2ref_filter    && prepend avfilter_deps "swscale"
 +enabled sofalizer_filter    && prepend avfilter_deps "avcodec"
 +enabled showcqt_filter      && prepend avfilter_deps "avformat avcodec swscale"
 +enabled showfreqs_filter    && prepend avfilter_deps "avcodec"
 +enabled showspectrum_filter && prepend avfilter_deps "avcodec"
 +enabled signature_filter    && prepend avfilter_deps "avcodec avformat"
 +enabled smartblur_filter    && prepend avfilter_deps "swscale"
 +enabled spectrumsynth_filter && prepend avfilter_deps "avcodec"
 +enabled spp_filter          && prepend avfilter_deps "avcodec"
 +enabled subtitles_filter    && prepend avfilter_deps "avformat avcodec"
 +enabled uspp_filter         && prepend avfilter_deps "avcodec"
 +enabled zoompan_filter      && prepend avfilter_deps "swscale"
 +
 +enabled lavfi_indev         && prepend avdevice_deps "avfilter"
 +
++#FIXME
++enabled sdl2_outdev     && add_cflags $(filter_out '-Dmain=SDL_main' $sdl2_cflags)
++
 +enabled opus_decoder    && prepend avcodec_deps "swresample"
  
  expand_deps(){
      lib_deps=${1}_deps
@@@ -6799,11 -5256,10 +6873,11 @@@ test -n "$random_seed" &
  echo
  
  echo "External libraries:"
- print_enabled '' $EXTERNAL_LIBRARY_LIST | print_in_columns
 -print_enabled '' $EXTERNAL_LIBRARY_LIST | print_3_columns
++print_enabled '' $EXTERNAL_LIBRARY_LIST $EXTERNAL_AUTODETECT_LIBRARY_LIST | print_in_columns
  echo
 +
  echo "External libraries providing hardware acceleration:"
- print_enabled '' $HWACCEL_LIBRARY_LIST | print_in_columns
 -print_enabled '' $HWACCEL_LIBRARY_LIST | print_3_columns
++print_enabled '' $HWACCEL_LIBRARY_LIST $HWACCEL_AUTODETECT_LIBRARY_LIST | print_in_columns
  echo
  
  echo "Libraries:"
@@@ -6955,9 -5389,8 +7029,8 @@@ HOSTLD_O=$HOSTLD_
  TARGET_EXEC=$target_exec $target_exec_args
  TARGET_PATH=$target_path
  TARGET_SAMPLES=${target_samples:-\$(SAMPLES)}
 -CFLAGS-avplay=$sdl_cflags
 +CFLAGS-ffplay=${sdl2_cflags}
  CFLAGS_HEADERS=$CFLAGS_HEADERS
- ZLIB=$($ldflags_filter -lz)
  LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD
  EXTRALIBS=$extralibs
  COMPAT_OBJS=$compat_objs
@@@ -6979,14 -5410,11 +7052,11 @@@ LIBFUZZER_PATH=$libfuzzer_pat
  IGNORE_TESTS=$ignore_tests
  EOF
  
 -map 'eval echo "${v}_FFLIBS=\$${v}_deps" >> avbuild/config.mak' $LIBRARY_LIST
 +map 'eval echo "${v}_FFLIBS=\$${v}_deps" >> ffbuild/config.mak' $LIBRARY_LIST
  
- print_program_extralibs(){
-     eval "program_extralibs=\$${1}_extralibs"
-     eval echo "EXTRALIBS-${1}=${program_extralibs}" >> ffbuild/config.mak
- }
- 
- map 'print_program_extralibs $v' $PROGRAM_LIST
+ for entry in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do
 -    eval echo "EXTRALIBS-${entry}=\$${entry}_extralibs" >> avbuild/config.mak
++    eval echo "EXTRALIBS-${entry}=\$${entry}_extralibs" >> ffbuild/config.mak
+ done
  
  cat > $TMPH <<EOF
  /* Automatically generated by configure - do not modify! */
@@@ -7088,16 -5496,13 +7158,15 @@@ rpath=$(enabled rpath && echo "-Wl,-rpa
  source_path=${source_path}
  LIBPREF=${LIBPREF}
  LIBSUF=${LIBSUF}
- 
- extralibs_avutil="$LIBRT $LIBM"
- extralibs_avcodec="$extralibs"
- extralibs_avformat="$extralibs"
- extralibs_avdevice="$extralibs"
- extralibs_avfilter="$extralibs"
- extralibs_avresample="$LIBM"
- extralibs_postproc=""
- extralibs_swscale="$LIBM"
- extralibs_swresample="$LIBM $LIBSOXR"
+ extralibs_avutil="$avutil_extralibs"
+ extralibs_avcodec="$avcodec_extralibs"
+ extralibs_avformat="$avformat_extralibs"
+ extralibs_avdevice="$avdevice_extralibs"
+ extralibs_avfilter="$avfilter_extralibs"
+ extralibs_avresample="$avresample_extralibs"
++extralibs_postproc="$postproc_extralibs"
+ extralibs_swscale="$swscale_extralibs"
++extralibs_swresample="$swresample_extralibs"
  EOF
  
  for lib in $LIBRARY_LIST; do
diff --cc ffbuild/common.mak
index e168fb2cfd,0000000000..a6b23e029f
mode 100644,000000..100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@@ -1,177 -1,0 +1,177 @@@
 +#
 +# common bits used by all libraries
 +#
 +
 +DEFAULT_X86ASMD=.dbg
 +
 +ifeq ($(DBG),1)
 +X86ASMD=$(DEFAULT_X86ASMD)
 +else
 +X86ASMD=
 +endif
 +
 +ifndef SUBDIR
 +
 +ifndef V
 +Q      = @
 +ECHO   = printf "$(1)\t%s\n" $(2)
 +BRIEF  = CC CXX OBJCC HOSTCC HOSTLD AS X86ASM AR LD STRIP CP WINDRES NVCC
 +SILENT = DEPCC DEPHOSTCC DEPAS DEPX86ASM RANLIB RM
 +
 +MSG    = $@
 +M      = @$(call ECHO,$(TAG),$@);
 +$(foreach VAR,$(BRIEF), \
 +    $(eval override $(VAR) = @$$(call ECHO,$(VAR),$$(MSG)); $($(VAR))))
 +$(foreach VAR,$(SILENT),$(eval override $(VAR) = @$($(VAR))))
 +$(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL))
 +endif
 +
 +ALLFFLIBS = avcodec avdevice avfilter avformat avresample avutil postproc swscale swresample
 +
 +# NASM requires -I path terminated with /
 +IFLAGS     := -I. -I$(SRC_LINK)/
 +CPPFLAGS   := $(IFLAGS) $(CPPFLAGS)
 +CFLAGS     += $(ECFLAGS)
 +CCFLAGS     = $(CPPFLAGS) $(CFLAGS)
 +OBJCFLAGS  += $(EOBJCFLAGS)
 +OBJCCFLAGS  = $(CPPFLAGS) $(CFLAGS) $(OBJCFLAGS)
 +ASFLAGS    := $(CPPFLAGS) $(ASFLAGS)
 +CXXFLAGS   := $(CPPFLAGS) $(CFLAGS) $(CXXFLAGS)
 +X86ASMFLAGS += $(IFLAGS:%=%/) -I$(<D)/ -Pconfig.asm
 +NVCCFLAGS  += -ptx
 +
 +HOSTCCFLAGS = $(IFLAGS) $(HOSTCPPFLAGS) $(HOSTCFLAGS)
 +LDFLAGS    := $(ALLFFLIBS:%=$(LD_PATH)lib%) $(LDFLAGS)
 +
 +define COMPILE
 +       $(call $(1)DEP,$(1))
 +       $($(1)) $($(1)FLAGS) $($(1)_DEPFLAGS) $($(1)_C) $($(1)_O) $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<)
 +endef
 +
 +COMPILE_C = $(call COMPILE,CC)
 +COMPILE_CXX = $(call COMPILE,CXX)
 +COMPILE_S = $(call COMPILE,AS)
 +COMPILE_M = $(call COMPILE,OBJCC)
 +COMPILE_X86ASM = $(call COMPILE,X86ASM)
 +COMPILE_HOSTC = $(call COMPILE,HOSTCC)
 +COMPILE_NVCC = $(call COMPILE,NVCC)
 +
 +%.o: %.c
 +	$(COMPILE_C)
 +
 +%.o: %.cpp
 +	$(COMPILE_CXX)
 +
 +%.o: %.m
 +	$(COMPILE_M)
 +
 +%.s: %.c
 +	$(CC) $(CCFLAGS) -S -o $@ $<
 +
 +%.o: %.S
 +	$(COMPILE_S)
 +
 +%_host.o: %.c
 +	$(COMPILE_HOSTC)
 +
 +%$(DEFAULT_X86ASMD).asm: %.asm
 +	$(DEPX86ASM) $(X86ASMFLAGS) -M -o $@ $< > $(@:.asm=.d)
 +	$(X86ASM) $(X86ASMFLAGS) -e $< | sed '/^%/d;/^$$/d;' > $@
 +
 +%.o: %.asm
 +	$(COMPILE_X86ASM)
 +	-$(if $(ASMSTRIPFLAGS), $(STRIP) $(ASMSTRIPFLAGS) $@)
 +
 +%.o: %.rc
 +	$(WINDRES) $(IFLAGS) --preprocessor "$(DEPWINDRES) -E -xc-header -DRC_INVOKED $(CC_DEPFLAGS)" -o $@ $<
 +
 +%.i: %.c
 +	$(CC) $(CCFLAGS) $(CC_E) $<
 +
 +%.h.c:
 +	$(Q)echo '#include "$*.h"' >$@
 +
 +%.ptx: %.cu
 +	$(COMPILE_NVCC)
 +
 +%.ptx.c: %.ptx
 +	$(Q)sh $(SRC_PATH)/compat/cuda/ptx2c.sh $@ $(patsubst $(SRC_PATH)/%,$(SRC_LINK)/%,$<)
 +
 +%.c %.h %.pc %.ver %.version: TAG = GEN
 +
 +# Dummy rule to stop make trying to rebuild removed or renamed headers
 +%.h:
 +	@:
 +
 +# Disable suffix rules.  Most of the builtin rules are suffix rules,
 +# so this saves some time on slow systems.
 +.SUFFIXES:
 +
 +# Do not delete intermediate files from chains of implicit rules
 +$(OBJS):
 +endif
 +
 +include $(SRC_PATH)/ffbuild/arch.mak
 +
 +OBJS      += $(OBJS-yes)
 +SLIBOBJS  += $(SLIBOBJS-yes)
 +FFLIBS    := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS)
 +TESTPROGS += $(TESTPROGS-yes)
 +
 +LDLIBS       = $(FFLIBS:%=%$(BUILDSUF))
- FFEXTRALIBS := $(LDLIBS:%=$(LD_LIB)) $(EXTRALIBS)
++FFEXTRALIBS := $(FFLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS)
 +
 +OBJS      := $(sort $(OBJS:%=$(SUBDIR)%))
 +SLIBOBJS  := $(sort $(SLIBOBJS:%=$(SUBDIR)%))
 +TESTOBJS  := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o)
 +TESTPROGS := $(TESTPROGS:%=$(SUBDIR)tests/%$(EXESUF))
 +HOSTOBJS  := $(HOSTPROGS:%=$(SUBDIR)%.o)
 +HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
 +TOOLS     += $(TOOLS-yes)
 +TOOLOBJS  := $(TOOLS:%=tools/%.o)
 +TOOLS     := $(TOOLS:%=tools/%$(EXESUF))
 +HEADERS   += $(HEADERS-yes)
 +
 +PATH_LIBNAME = $(foreach NAME,$(1),lib$(NAME)/$($(2)LIBNAME))
 +DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib),$(CONFIG_SHARED:yes=S)))
 +STATIC_DEP_LIBS := $(foreach lib,$(FFLIBS),$(call PATH_LIBNAME,$(lib)))
 +
 +SRC_DIR    := $(SRC_PATH)/lib$(NAME)
 +ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
 +SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
 +SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
 +HOBJS        = $(filter-out $(SKIPHEADERS:.h=.h.o),$(ALLHEADERS:.h=.h.o))
 +PTXOBJS      = $(filter %.ptx.o,$(OBJS))
 +$(HOBJS):     CCFLAGS += $(CFLAGS_HEADERS)
 +checkheaders: $(HOBJS)
 +.SECONDARY:   $(HOBJS:.o=.c) $(PTXOBJS:.o=.c) $(PTXOBJS:.o=)
 +
 +alltools: $(TOOLS)
 +
 +$(HOSTOBJS): %.o: %.c
 +	$(COMPILE_HOSTC)
 +
 +$(HOSTPROGS): %$(HOSTEXESUF): %.o
 +	$(HOSTLD) $(HOSTLDFLAGS) $(HOSTLD_O) $^ $(HOSTEXTRALIBS)
 +
 +$(OBJS):     | $(sort $(dir $(OBJS)))
 +$(HOBJS):    | $(sort $(dir $(HOBJS)))
 +$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
 +$(SLIBOBJS): | $(sort $(dir $(SLIBOBJS)))
 +$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
 +$(TOOLOBJS): | tools
 +
 +OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) $(TESTOBJS))
 +
 +CLEANSUFFIXES     = *.d *.o *~ *.h.c *.gcda *.gcno *.map *.ver *.version *.ho *$(DEFAULT_X86ASMD).asm *.ptx *.ptx.c
 +DISTCLEANSUFFIXES = *.pc
 +LIBSUFFIXES       = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
 +
 +define RULES
 +clean::
 +	$(RM) $(HOSTPROGS) $(TESTPROGS) $(TOOLS)
 +endef
 +
 +$(eval $(RULES))
 +
 +-include $(wildcard $(OBJS:.o=.d) $(HOSTOBJS:.o=.d) $(TESTOBJS:.o=.d) $(HOBJS:.o=.d) $(SLIBOBJS:.o=.d)) $(OBJS:.o=$(DEFAULT_X86ASMD).d)
diff --cc ffbuild/library.mak
index 4191edcf9c,0000000000..430da3f72a
mode 100644,000000..100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@@ -1,107 -1,0 +1,107 @@@
 +include $(SRC_PATH)/ffbuild/common.mak
 +
 +ifeq (,$(filter %clean,$(MAKECMDGOALS)))
 +-include $(SUBDIR)lib$(NAME).version
 +endif
 +
 +LIBVERSION := $(lib$(NAME)_VERSION)
 +LIBMAJOR   := $(lib$(NAME)_VERSION_MAJOR)
 +LIBMINOR   := $(lib$(NAME)_VERSION_MINOR)
 +INCINSTDIR := $(INCDIR)/lib$(NAME)
 +
 +INSTHEADERS := $(INSTHEADERS) $(HEADERS:%=$(SUBDIR)%)
 +
 +all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME)  $(SUBDIR)lib$(FULLNAME).pc
 +all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) $(SUBDIR)lib$(FULLNAME).pc
 +
 +LIBOBJS := $(OBJS) $(SUBDIR)%.h.o $(TESTOBJS)
 +$(LIBOBJS) $(LIBOBJS:.o=.s) $(LIBOBJS:.o=.i):   CPPFLAGS += -DHAVE_AV_CONFIG_H
 +
 +$(SUBDIR)$(LIBNAME): $(OBJS)
 +	$(RM) $@
 +	$(AR) $(ARFLAGS) $(AR_O) $^
 +	$(RANLIB) $@
 +
 +install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
 +
 +install-libs-$(CONFIG_STATIC): install-lib$(NAME)-static
 +install-libs-$(CONFIG_SHARED): install-lib$(NAME)-shared
 +
 +define RULES
 +$(TOOLS):     THISLIB = $(FULLNAME:%=$(LD_LIB))
 +$(TESTPROGS): THISLIB = $(SUBDIR)$(LIBNAME)
 +
 +$(TESTPROGS) $(TOOLS): %$(EXESUF): %.o
- 	$$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(ELIBS)
++	$$(LD) $(LDFLAGS) $(LDEXEFLAGS) $$(LD_O) $$(filter %.o,$$^) $$(THISLIB) $(FFEXTRALIBS) $$(EXTRALIBS-$$(*F)) $$(ELIBS)
 +
 +$(SUBDIR)lib$(NAME).version: $(SUBDIR)version.h | $(SUBDIR)
 +	$$(M) $$(SRC_PATH)/ffbuild/libversion.sh $(NAME) $$< > $$@
 +
 +$(SUBDIR)lib$(FULLNAME).pc: $(SUBDIR)version.h | $(SUBDIR)
 +	$$(M) $$(SRC_PATH)/ffbuild/pkgconfig_generate.sh $(NAME) "$(DESC)"
 +
 +$(SUBDIR)lib$(NAME).ver: $(SUBDIR)lib$(NAME).v $(OBJS)
 +	$$(M)sed 's/MAJOR/$(lib$(NAME)_VERSION_MAJOR)/' $$< | $(VERSION_SCRIPT_POSTPROCESS_CMD) > $$@
 +
 +$(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
 +	$(Q)cd ./$(SUBDIR) && $(LN_S) $(SLIBNAME_WITH_MAJOR) $(SLIBNAME)
 +
 +$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SLIBOBJS) $(SUBDIR)lib$(NAME).ver
 +	$(SLIB_CREATE_DEF_CMD)
 +	$$(LD) $(SHFLAGS) $(LDFLAGS) $(LDLIBFLAGS) $$(LD_O) $$(filter %.o,$$^) $(FFEXTRALIBS)
 +	$(SLIB_EXTRA_CMD)
 +
 +ifdef SUBDIR
 +$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
 +endif
 +
 +clean::
 +	$(RM) $(addprefix $(SUBDIR),$(CLEANFILES) $(CLEANSUFFIXES) $(LIBSUFFIXES)) \
 +	    $(CLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) $(CLEANSUFFIXES:%=$(SUBDIR)tests/%)
 +
 +distclean:: clean
 +	$(RM) $(DISTCLEANSUFFIXES:%=$(SUBDIR)%) $(DISTCLEANSUFFIXES:%=$(SUBDIR)$(ARCH)/%) \
 +            $(DISTCLEANSUFFIXES:%=$(SUBDIR)tests/%)
 +
 +install-lib$(NAME)-shared: $(SUBDIR)$(SLIBNAME)
 +	$(Q)mkdir -p "$(SHLIBDIR)"
 +	$$(INSTALL) -m 755 $$< "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
 +	$$(STRIP) "$(SHLIBDIR)/$(SLIB_INSTALL_NAME)"
 +	$(Q)$(foreach F,$(SLIB_INSTALL_LINKS),(cd "$(SHLIBDIR)" && $(LN_S) $(SLIB_INSTALL_NAME) $(F));)
 +	$(if $(SLIB_INSTALL_EXTRA_SHLIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_SHLIB:%=$(SUBDIR)%) "$(SHLIBDIR)")
 +	$(if $(SLIB_INSTALL_EXTRA_LIB),$(Q)mkdir -p "$(LIBDIR)")
 +	$(if $(SLIB_INSTALL_EXTRA_LIB),$$(INSTALL) -m 644 $(SLIB_INSTALL_EXTRA_LIB:%=$(SUBDIR)%) "$(LIBDIR)")
 +
 +install-lib$(NAME)-static: $(SUBDIR)$(LIBNAME)
 +	$(Q)mkdir -p "$(LIBDIR)"
 +	$$(INSTALL) -m 644 $$< "$(LIBDIR)"
 +	$(LIB_INSTALL_EXTRA_CMD)
 +
 +install-lib$(NAME)-headers: $(addprefix $(SUBDIR),$(HEADERS) $(BUILT_HEADERS))
 +	$(Q)mkdir -p "$(INCINSTDIR)"
 +	$$(INSTALL) -m 644 $$^ "$(INCINSTDIR)"
 +
 +install-lib$(NAME)-pkgconfig: $(SUBDIR)lib$(FULLNAME).pc
 +	$(Q)mkdir -p "$(PKGCONFIGDIR)"
 +	$$(INSTALL) -m 644 $$^ "$(PKGCONFIGDIR)"
 +
 +uninstall-libs::
 +	-$(RM) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \
 +	       "$(SHLIBDIR)/$(SLIBNAME)"            \
 +	       "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)"
 +	-$(RM)  $(SLIB_INSTALL_EXTRA_SHLIB:%="$(SHLIBDIR)/%")
 +	-$(RM)  $(SLIB_INSTALL_EXTRA_LIB:%="$(LIBDIR)/%")
 +	-$(RM) "$(LIBDIR)/$(LIBNAME)"
 +
 +uninstall-headers::
 +	$(RM) $(addprefix "$(INCINSTDIR)/",$(HEADERS) $(BUILT_HEADERS))
 +	$(RM) "$(PKGCONFIGDIR)/lib$(FULLNAME).pc"
 +	-rmdir "$(INCINSTDIR)"
 +endef
 +
 +$(eval $(RULES))
 +
 +$(TOOLS):     $(DEP_LIBS) $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME)
 +$(TESTPROGS): $(DEP_LIBS) $(SUBDIR)$(LIBNAME)
 +
 +testprogs: $(TESTPROGS)
diff --cc tests/checkasm/Makefile
index 14916e5100,87f92f4a89..74f07f11cd
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@@ -56,7 -35,7 +56,7 @@@ tests/checkasm/checkasm.o: CFLAGS += -U
  CHECKASM := tests/checkasm/checkasm$(EXESUF)
  
  $(CHECKASM): $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS)
- 	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS)
 -	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avutil) $(EXTRALIBS)
++	$(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(CHECKASMOBJS) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avutil) $(EXTRALIBS)
  
  checkasm: $(CHECKASM)
  



More information about the ffmpeg-cvslog mailing list