Previously, all link-time dependencies were added for all libraries, resulting in bogus link-time dependencies since not all dependencies are shared across libraries. Also, in some cases like libavutil, not all dependencies were taken into account, resulting in some cases of underlinking.
To address all this mess a machinery is added for tracking which dependency belongs to which library component and then leveraged to determine correct dependencies for all individual libraries. --- Rebased on top of the (do_)check_deps typo fix. Makefile | 2 +- avbuild/common.mak | 2 +- avbuild/library.mak | 2 +- configure | 165 +++++++++++++++++++++++++++++++++++------------- tests/checkasm/Makefile | 2 +- 5 files changed, 124 insertions(+), 49 deletions(-) diff --git a/Makefile b/Makefile index 98eb3ab..90caf0f 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ FF_STATIC_DEP_LIBS := $(STATIC_DEP_LIBS) all: $(AVPROGS) $(TOOLS): %$(EXESUF): %.o - $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(EXTRALIBS) $(ELIBS) + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $^ $(EXTRALIBS-$(*F)) $(EXTRALIBS) $(ELIBS) CONFIGURABLE_COMPONENTS = \ $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c)) \ diff --git a/avbuild/common.mak b/avbuild/common.mak index 236380e..a627dc0 100644 --- a/avbuild/common.mak +++ b/avbuild/common.mak @@ -8,7 +8,7 @@ OBJS += $(OBJS-yes) FFLIBS := $($(NAME)_FFLIBS) $(FFLIBS-yes) $(FFLIBS) TESTPROGS += $(TESTPROGS-yes) -FFEXTRALIBS := $(FFLIBS:%=$(LD_LIB)) $(EXTRALIBS) +FFEXTRALIBS := $(FFLIBS:%=$(LD_LIB)) $(foreach lib,EXTRALIBS-$(NAME) $(FFLIBS:%=EXTRALIBS-%),$($(lib))) $(EXTRALIBS) OBJS := $(sort $(OBJS:%=$(SUBDIR)%)) TESTOBJS := $(TESTOBJS:%=$(SUBDIR)tests/%) $(TESTPROGS:%=$(SUBDIR)tests/%.o) diff --git a/avbuild/library.mak b/avbuild/library.mak index e5f6d7d..be6098c 100644 --- a/avbuild/library.mak +++ b/avbuild/library.mak @@ -30,7 +30,7 @@ $(TOOLS): THISLIB = $(NAME:%=$(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)/avbuild/libversion.sh $(NAME) $$< > $$@ diff --git a/configure b/configure index bd35e49..b5a1c7d 100755 --- a/configure +++ b/configure @@ -610,7 +610,7 @@ is_in(){ return 1 } -do_check_deps(){ +check_deps(){ for cfg; do enabled ${cfg}_checking && die "Circular dependency for $cfg." disabled ${cfg}_checking && continue @@ -626,7 +626,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; } @@ -639,24 +639,17 @@ do_check_deps(){ 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 disable ${cfg}_checking done } -check_deps(){ - unset allopts - - do_check_deps "$@" - - for cfg in $allopts; do - enabled $cfg || continue - eval dep_extralibs="\$${cfg}_extralibs" - test -n "$dep_extralibs" && add_extralibs $dep_extralibs - done -} - print_config(){ pfx=$1 files=$2 @@ -711,6 +704,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 "$@" } @@ -747,6 +749,12 @@ add_extralibs(){ prepend extralibs $($ldflags_filter "$@") } +add_extralibs_component(){ + component=$1 + shift + prepend extralibs_${component} $($ldflags_filter "$@") +} + add_host_cppflags(){ append host_cppflags "$@" } @@ -1015,7 +1023,7 @@ check_lib(){ shift 3 disable $name check_func_headers "$headers" "$funcs" "$@" && - enable $name && add_extralibs "$@" + enable $name && eval ${name}_extralibs="\$@" } check_pkg_config(){ @@ -1142,7 +1150,7 @@ require_pkg_config(){ test "$name" = "" && name=$pkg check_pkg_config "$@" || die "ERROR: $pkg_version not found" add_cflags $(get_safe "${pkg}_cflags") - add_extralibs $(get_safe "${pkg}_extralibs") + eval $(sanitize_var_name ${name}_extralibs)="\$(get_safe ${pkg}_extralibs)" } hostcc_e(){ @@ -1255,6 +1263,12 @@ EXAMPLE_LIST=" transcode_aac_example " +# catchall list of things that require external libs to link +EXTRALIBS_LIST=" + cpu_init + cws2fws +" + HWACCEL_LIBRARY_NONFREE_LIST=" cuda libnpp @@ -2157,7 +2171,7 @@ 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" +vda_frameworks="-framework CoreFoundation -framework VideoDecodeAcceleration -framework QuartzCore" h263_vaapi_hwaccel_deps="vaapi" h263_vaapi_hwaccel_select="h263_decoder" @@ -2401,7 +2415,7 @@ xwma_demuxer_select="riffdec" alsa_indev_deps="alsa" alsa_outdev_deps="alsa" avfoundation_indev_deps="AVFoundation_AVFoundation_h objc_arc pthreads" -avfoundation_indev_extralibs="-framework Foundation -framework AVFoundation -framework CoreVideo -framework CoreMedia" +avfoundation_indev_frameworks="-framework Foundation -framework AVFoundation -framework CoreVideo -framework CoreMedia" 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" @@ -2495,6 +2509,10 @@ output_example_deps="avcodec avformat avresample avutil swscale" qsvdec_example_deps="avcodec avutil libmfx h264_qsv_decoder" transcode_aac_example_deps="avcodec avformat avresample" +# EXTRALIBS_LIST +cpu_init_extralibs="pthreads_extralibs" +cws2fws_extralibs="zlib_extralibs" + # libraries, in linking order avcodec_deps="avutil" avcodec_select="null_bsf" @@ -2505,15 +2523,21 @@ avformat_suggest="network" avresample_deps="avutil" swscale_deps="avutil" +avcodec_extralibs="pthreads_extralibs" +avfilter_extralibs="pthreads_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" + # 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 trim_filter" +avconv_suggest="dxva2_lib ole32 psapi shell32" avplay_deps="avcodec avfilter avformat avresample sdl" -avplay_extralibs='$sdl_extralibs' avplay_select="rdft format_filter transpose_filter hflip_filter vflip_filter" +avplay_suggest="shell32" avprobe_deps="avcodec avformat" +avprobe_suggest="shell32" # documentation pod2man_deps="doc" @@ -2571,6 +2595,9 @@ enable valgrind_backtrace # By default, enable only those hwaccels that have no external dependencies. enable d3d11va dxva2 vda vdpau +# internal components are enabled by default +enable $EXTRALIBS_LIST + # build settings SHFLAGS='-shared -Wl,-soname,$$(@F)' LIBPREF="lib" @@ -2662,20 +2689,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 @@ -4519,7 +4562,7 @@ 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 && LIBRT="-lrt"; } + check_lib clock_gettime time.h clock_gettime -lrt check_func fcntl check_func fork @@ -4632,14 +4675,14 @@ disabled bzlib || check_lib bzlib bzlib.h BZ2_bzlibVersion -lbz2 # 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 libm math.h sin -lm && LIBM="-lm" +check_lib libm math.h sin -lm atan2f_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 # these are off by default, so fail if requested and not available @@ -4719,13 +4762,13 @@ enabled mmal && { check_lib mmal interface/mmal/mmal.h mmal_port_co 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 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/ssl.h OPENSSL_init_ssl || - check_pkg_config openssl openssl/ssl.h SSL_library_init; } && { - add_cflags $openssl_cflags && add_extralibs $openssl_extralibs; } || + check_pkg_config openssl openssl/ssl.h SSL_library_init; } && + add_cflags $openssl_cflags || 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 || @@ -5076,6 +5119,42 @@ check_deps $CONFIG_LIST \ $HAVE_LIST \ $ALL_COMPONENTS \ +resolve_extralibs(){ + for v; do + resolve v + for tok in $v; do + case $tok in + *_extralibs) + eval resolve_extralibs $tok + ;; + *) + printf '%s ' $($ldflags_filter $tok) + ;; + esac + done + done +} + +for linkunit in $LIBRARY_LIST; do + unset current_extralibs + eval components=\$$(toupper ${linkunit})_COMPONENTS_LIST + for comp in ${components}; do + 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 + eval resolved_extralibs="\$(resolve_extralibs \$${linkunit}_extralibs)" + unique resolved_extralibs + eval extralibs_${linkunit}=\"\$resolved_extralibs\" +done + +# special-case -framework handling instead of costly iterating over all components +enabled vda && add_extralibs_component avcodec $vda_frameworks +enabled avfoundation_indev && add_extralibs_component avdevice $avfoundation_indev_frameworks + map 'enabled $v && intrinsics=${v#intrinsics_}' $INTRINSICS_LIST for thread in $THREADS_LIST; do @@ -5320,7 +5399,6 @@ TARGET_PATH=$target_path TARGET_SAMPLES=${target_samples:-\$(SAMPLES)} CFLAGS-avplay=$sdl_cflags CFLAGS_HEADERS=$CFLAGS_HEADERS -ZLIB=$($ldflags_filter -lz) LIB_INSTALL_EXTRA_CMD=$LIB_INSTALL_EXTRA_CMD EXTRALIBS=$extralibs COMPAT_OBJS=$compat_objs @@ -5342,12 +5420,9 @@ EOF map 'eval echo "${v}_FFLIBS=\$${v}_deps" >> avbuild/config.mak' $LIBRARY_LIST -print_program_extralibs(){ - eval "program_extralibs=\$${1}_extralibs" - eval echo "EXTRALIBS-${1}=${program_extralibs}" >> avbuild/config.mak -} - -map 'print_program_extralibs $v' $PROGRAM_LIST +for entry in $LIBRARY_LIST $PROGRAM_LIST $EXTRALIBS_LIST; do + eval echo "EXTRALIBS-${entry}=\$extralibs_${entry}" >> avbuild/config.mak +done cat > $TMPH <<EOF /* Automatically generated by configure - do not modify! */ @@ -5429,13 +5504,13 @@ incdir=$incdir 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_swscale="$LIBM" +extralibs_avutil="$extralibs_avutil" +extralibs_avcodec="$extralibs_avcodec" +extralibs_avformat="$extralibs_avformat" +extralibs_avdevice="$extralibs_avdevice" +extralibs_avfilter="$extralibs_avfilter" +extralibs_avresample="$extralibs_avresample" +extralibs_swscale="$extralibs_swscale" EOF for lib in $LIBRARY_LIST; do diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index 639a08e..87f92f4 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -35,7 +35,7 @@ OBJDIRS += $(CHECKASMDIRS) 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) checkasm: $(CHECKASM) -- 2.1.4 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel