diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2021-05-21 15:41:15 +0200 |
---|---|---|
committer | Thorsten Behrens <thorsten.behrens@allotropia.de> | 2022-01-12 11:12:46 +0100 |
commit | dc9ccf3d8f294cd7ae9d5bece7b6c16c3b22f6a5 (patch) | |
tree | 3e304e27dde75eab1f766894895049a757f99404 /solenv | |
parent | aaec6db548ef2fe4d1d1869491eea15571457f57 (diff) |
gbuild: build static LO / link static executables
This allows to build a complete static LibreOffice on Linux,
except for linked externals. Since LO's static build implies
disabled dynamic loading, one must select one VCL backend to
be compiled in.
See the (large) comment in solenv/gbuild/static.mk trying to
explain, why this implementation was chosen (spoiler: seems
there is no other way) and what is actually implemented.
This will collect all libraries, statics and externals of
executables. If the executable uses components, it will get
linked to all static components. While it works with any
Executable, it just makes sense for soffice.bin, because the
static component map sucks every dependency in, bloating most
other binaries.
In theory on could generate the dependencies based on the list
of used components (see gb_CppunitTest_use_components), then
generate a specific static constructor map, directly include it
in the exe's cxx code and then link the minimal dependencies.
The static LO should build on Linux with:
--enable-customtarget-components
--disable-dynamic-loading
Tested VCL plugin config is:
--disable-gtk3
--disable-gen
--enable-qt5
The partial build support is split into a 2nd patch.
Change-Id: Iafc95752fae9e88095f54a21f1e30a4f080815e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126790
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'solenv')
-rw-r--r-- | solenv/gbuild/LinkTarget.mk | 94 | ||||
-rw-r--r-- | solenv/gbuild/TargetLocations.mk | 3 | ||||
-rw-r--r-- | solenv/gbuild/gbuild.mk | 1 | ||||
-rw-r--r-- | solenv/gbuild/platform/unxgcc.mk | 8 | ||||
-rw-r--r-- | solenv/gbuild/static.mk | 207 |
5 files changed, 294 insertions, 19 deletions
diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk index ce60b462ecee..b7cada89523b 100644 --- a/solenv/gbuild/LinkTarget.mk +++ b/solenv/gbuild/LinkTarget.mk @@ -36,6 +36,13 @@ # gb_LinkTarget_INCLUDE # gb_YaccTarget__command(grammar-file, stem-for-message, source-target, include-target) +# Same happens for the gb_LinkTarget_add_libs calls from RepositoryExternal.mk. But we have no real +# way to separate for gbuild internal and external gb_LinkTarget_add_libs calls. +# So this flags these call parameters with an @ postfix. But now these must be filtered out, so this +# defines that filter, just in case we need to change it because it conflicts with some parameters. +# FYI: on Windows, gb_Library_use_system_win32_libs also calls gb_LinkTarget_add_libs; easy to miss. +gb_LinkTarget__syslib = %@ + # Detect whether symbols should be enabled for the given gbuild target. # enable if: no "-TARGET" defined AND [module is enabled OR "TARGET" defined] gb_LinkTarget__symbols_enabled = \ @@ -769,7 +776,7 @@ $(WORKDIR)/Clean/LinkTarget/% : # cat the deps of all objects in one file, then we need only open that one file # call gb_LinkTarget__command_dep,dep_target,linktargetname define gb_LinkTarget__command_dep -$(call gb_Output_announce,LNK:$(2),$(true),DEP,1) +$(call gb_Output_announce,LNK:$(2).d,$(true),DEP,1) $(call gb_Trace_StartRange,LNK:$(2),DEP) $(call gb_Helper_abbreviate_dirs,\ mkdir -p $(dir $(1)) && \ @@ -838,6 +845,11 @@ $(call gb_LinkTarget_get_target,$(1)) : $(call gb_LinkTarget_get_headers_target, endef +define gb_LinkTarget__add_linked_libs +$(call gb_LinkTarget_get_target,$(1)) : LINKED_LIBS += $(2) + +endef + # it's not possible to use a pattern rule for files in INSTDIR because # it would inevitably conflict with the pattern rule for Package # (especially since external libraries are delivered via Package) @@ -860,7 +872,7 @@ endef ifeq ($(gb_FULLDEPS),$(true)) $(call gb_LinkTarget_get_dep_target,%) : $(call gb_Executable_get_runtime_dependencies,concat-deps) $(call gb_LinkTarget__command_dep,$@,$*) -endif +endif # gb_FULLDEPS # Ok, this is some dark voodoo: When declaring a linktarget with # gb_LinkTarget_LinkTarget we set SELF in the headertarget to name of the @@ -1029,7 +1041,7 @@ $(call gb_LinkTarget_get_dep_target,$(1)) : GENOBJCXXOBJECTS := $(call gb_LinkTarget_get_dep_target,$(1)) : GENNASMOBJECTS := $(call gb_LinkTarget_get_dep_target,$(1)) : GENCXXCLROBJECTS := $(call gb_LinkTarget_get_dep_target,$(1)) : YACCOBJECTS := -endif +endif # gb_FULLDEPS gb_LinkTarget_CXX_SUFFIX_$(call gb_LinkTarget__get_workdir_linktargetname,$(1)) := cxx @@ -1038,7 +1050,7 @@ $(if $(findstring $(INSTDIR),$(1)),$(call gb_LinkTarget__make_installed_rule,$(1 $(call gb_PrecompiledHeader_generate_timestamp_rule,$(2)) -endef +endef # gb_LinkTarget_LinkTarget # call gb_LinkTarget_set_soversion_script,linktarget,soversionscript define gb_LinkTarget_set_soversion_script @@ -1124,6 +1136,11 @@ define gb_LinkTarget_add_libs $(call gb_LinkTarget_get_target,$(1)) : T_LIBS += $(2) $(if $(call gb_LinkTarget__is_merged,$(1)),\ $(call gb_Library_get_linktarget_target,merged) : T_LIBS += $(2)) +ifeq ($(ENABLE_CUSTOMTARGET_COMPONENTS),TRUE) +$(if $(gb_DEBUG_STATIC),$$(info $$(call gb_LinkTarget__get_all_libraries_var,$(1)) += $(filter-out $(call gb_LinkTarget__get_all_libraries,$(1)),$(patsubst %,$(gb_LinkTarget__syslib),$(2))))) +$$(eval $$(call gb_LinkTarget__get_all_libraries_var,$(1)) += $(filter-out $(call gb_LinkTarget__get_all_libraries,$(1)),$(patsubst %,$(gb_LinkTarget__syslib),$(2)))) +$(call gb_LinkTarget_get_target,$(1)) : LINKED_LIBS += $(filter-out $(call gb_LinkTarget__get_all_libraries,$(1)),$(patsubst %,$(gb_LinkTarget__syslib),$(2))) +endif endef @@ -1210,6 +1227,38 @@ $(call gb_Library_get_target,$(1)) :| $(call gb_Library_get_headers_target,$(1)) endef +define gb_LinkTarget__generate_all_x_accessors +gb_LinkTarget__get_all_$(1)_var = $$(call gb_LinkTarget__get_workdir_linktargetname,$$(1))<>ALL_$(2) +gb_LinkTarget__get_all_$(1) = $$($$(call gb_LinkTarget__get_all_$(1)_var,$$(1))) +gb_Library__get_all_$(1) = $$($$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_Library_get_linktarget,$$(1)))) +gb_Executable__get_all_$(1) = $$($$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_Executable_get_linktarget,$$(1)))) +gb_ExternalProject__get_all_$(1) = $$($$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_ExternalProject__get_workdir_linktargetname,$$(1)))) +gb_CppunitTest__get_all_$(1) = $$($$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_CppunitTest__get_workdir_linktargetname,$$(1)))) + +endef + +$(eval $(call gb_LinkTarget__generate_all_x_accessors,libraries,LIBRARIES)) +gb_LinkTarget__filter_lo_libraries = $(filter-out $(gb_LinkTarget__syslib),$(1)) +gb_LinkTarget__get_all_lo_libraries = $(call gb_LinkTarget__filter_lo_libraries,$(call gb_LinkTarget__get_all_libraries,$(1))) +gb_LinkTarget__filter_sys_libraries = $(filter $(gb_LinkTarget__syslib),$(1)) +gb_LinkTarget__get_all_sys_libraries = $(call gb_LinkTarget__filter_sys_libraries,$(call gb_LinkTarget__get_all_libraries,$(1))) +$(eval $(call gb_LinkTarget__generate_all_x_accessors,externals,EXTERNALS)) +$(eval $(call gb_LinkTarget__generate_all_x_accessors,statics,STATICS)) + +# call gb_LinkTarget__register_type,type,linktarget,type list +define gb_LinkTarget__register_type +ifeq ($(ENABLE_CUSTOMTARGET_COMPONENTS),TRUE) +ifeq (,$(DISABLE_DYNLOADING)) +$$(error ENABLE_CUSTOMTARGET_COMPONENTS just works with DISABLE_DYNLOADING) +endif +$(foreach type,$(3),$(if $(filter $(type),$(call gb_LinkTarget__get_all_$(1),$(2))),, \ + $(if $(gb_DEBUG_STATIC),$$(info $(call gb_LinkTarget__get_all_$(1)_var,$(2)) += $(type))) \ + $$(eval $(call gb_LinkTarget__get_all_$(1)_var,$(2)) += $(type)) \ +)) +endif + +endef + # call gb_LinkTarget__use_libraries,linktarget,requestedlibs,actuallibs,linktargetmakefilename define gb_LinkTarget__use_libraries @@ -1227,23 +1276,29 @@ ifeq (,$(DISABLE_DYNLOADING)) # depend on the exports of the library, not on the library itself # for faster incremental builds when the ABI is unchanged. # export files are created from the library, so this also ensures the library exists. -$(call gb_LinkTarget_get_target,$(1)) : \ - $(foreach lib,$(3),$(call gb_Library_get_exports_target,$(lib))) +$(foreach lib,$(call gb_LinkTarget__filter_lo_libraries,$(3)),$(if $(filter $(lib),$(gb_Library_KNOWNLIBS)), \ + $(eval $(call gb_LinkTarget_get_target,$(1)) : $(call gb_Library_get_exports_target,$(lib))) \ +)) else # DISABLE_DYNLOADING # depend on the now-static libraries themself, but only if the target actually links to it ifneq (,$(call gb_LinkTarget_does_real_link,$(1))) -$(foreach lib,$(3),$(if $(filter $(lib),$(gb_Library_KNOWNLIBS)), \ - $(eval $(call gb_LinkTarget_get_target,$(1)) : $(call gb_Library_get_linktarget_target,$(lib))) \ -)) +$(call gb_LinkTarget_get_target,$(1)) : T_LIBS += $(call gb_LinkTarget__filter_sys_libraries,$(3)) +$(if $(filter-out Library,gb_LinkTarget__get_workdir_linktargetclass,$(1)), \ + $(foreach lib,$(call gb_LinkTarget__filter_lo_libraries,$(3)),$(if $(filter $(lib),$(gb_Library_KNOWNLIBS)), \ + $(eval $(call gb_LinkTarget_get_target,$(1)) : $(call gb_Library_get_linktarget_target,$(lib))) \ + ))) endif endif # DISABLE_DYNLOADING -$(call gb_LinkTarget_get_headers_target,$(1)) : \ - $(foreach lib,$(2),$(call gb_Library_get_headers_target,$(lib))) -$(foreach lib,$(2),$(call gb_LinkTarget__lib_dummy_depend,$(lib))) +$(call gb_LinkTarget__register_type,libraries,$(1),$(3)) -endef +$(foreach lib,$(call gb_LinkTarget__filter_lo_libraries,$(2)),$(if $(filter $(lib),$(gb_Library_KNOWNLIBS)), \ + $(eval $(call gb_LinkTarget_get_headers_target,$(1)) : $(call gb_Library_get_headers_target,$(lib))) \ + $(call gb_LinkTarget__lib_dummy_depend,$(lib)) \ +)) + +endef # gb_LinkTarget__use_libraries # libraries which are merged but need to be built for gb_BUILD_HELPER_TOOLS gb_BUILD_HELPER_LIBS := $(foreach lib, \ @@ -1287,9 +1342,9 @@ endef # call gb_LinkTarget_use_libraries,linktarget,libs define gb_LinkTarget_use_libraries -ifneq (,$$(filter-out $(gb_Library_KNOWNLIBS),$(2))) +ifneq (,$$(filter-out $(gb_Library_KNOWNLIBS) $(gb_LinkTarget__syslib),$(2))) $$(eval $$(call gb_Output_info,currently known libraries are: $(sort $(gb_Library_KNOWNLIBS)),ALL)) -$$(eval $$(call gb_Output_error,Cannot link against library/libraries '$$(filter-out $(gb_Library_KNOWNLIBS),$(2))'. Libraries must be registered in Repository.mk or RepositoryExternal.mk)) +$$(eval $$(call gb_Output_error,Cannot link against library/libraries '$$(filter-out $(gb_Library_KNOWNLIBS) $(gb_LinkTarget__syslib),$(2))'. Libraries must be registered in Repository.mk or RepositoryExternal.mk)) endif ifneq (,$$(filter $(2),$(gb_Library_KNOWNPLUGINS))) ifneq (,$$(filter $(1),$$(foreach plugin,$(gb_Library_KNOWNPLUGINS),$(call gb_Library__get_workdir_linktargetname,$(plugin))))) @@ -1333,11 +1388,14 @@ ifneq (,$(call gb_LinkTarget_does_real_link,$(1))) $(foreach lib,$(2), \ $$(eval $(call gb_LinkTarget_get_target,$(1)): $(call gb_StaticLibrary_get_linktarget_target,$(lib)))) endif + +$(call gb_LinkTarget__register_type,statics,$(1),$(2)) + $(call gb_LinkTarget_get_headers_target,$(1)) : \ $(foreach lib,$(2),$(call gb_StaticLibrary_get_headers_target,$(lib))) $(foreach lib,$(2),$(call gb_LinkTarget__static_lib_dummy_depend,$(lib))) -endef +endef # gb_LinkTarget_use_static_libraries # call gb_LinkTarget_add_cobject,linktarget,sourcefile,cflags,linktargetmakefilename define gb_LinkTarget_add_cobject @@ -2038,6 +2096,9 @@ $(if $(filter undefined,$(origin gb_LinkTarget__use_$(2))),\ $(call gb_LinkTarget__use_$(2),$(call gb_Library_get_linktarget,merged)))) \ $(call gb_LinkTarget__use_$(2),$(1)) \ ) + +$(call gb_LinkTarget__register_type,externals,$(1),$(2)) + endef # $(call gb_LinkTarget_use_externals,library,externals) @@ -2156,6 +2217,7 @@ ifeq ($(call gb_LinkTarget__is_build_tool,$(1)),$(true)) $$(eval $$(call gb_Output_error,Plugin support for build tools not implemented)) endif +$(if $(filter $(2),$(gb_Library_KNOWNLOADERS)),,gb_Library_KNOWNLOADERS += $(2)) $(if $(3),,$(call gb_LinkTarget_use_libraries,$(1),$(2),,$(4))) endef diff --git a/solenv/gbuild/TargetLocations.mk b/solenv/gbuild/TargetLocations.mk index 2dd50de62b94..3e4b044d86b2 100644 --- a/solenv/gbuild/TargetLocations.mk +++ b/solenv/gbuild/TargetLocations.mk @@ -67,6 +67,7 @@ gb_GenCxxObject_get_dwo_target = $(WORKDIR)/GenCxxObject/$(1).dwo gb_GenNasmObject_get_target = $(WORKDIR)/GenNasmObject/$(1).o gb_GenNasmObject_get_dwo_target = $(WORKDIR)/GenNasmObject/$(1).dwo gb_Executable_get_headers_target = $(WORKDIR)/Headers/Executable/$(1) +gb_Executable_get_linktargetfile = $(call gb_LinkTarget_get_target,$(call gb_Executable_get_linktarget,$1)) gb_Executable_get_runtime_target = $(WORKDIR_FOR_BUILD)/Executable/$(1).run gb_Extension_get_target = $(WORKDIR)/Extension/$(1).oxt gb_Extension_get_rootdir = $(WORKDIR)/Extension/$(1)/root @@ -406,6 +407,8 @@ $(call gb_Executable__get_workdir_linktargetname,$(1))<>$(call gb_Executable_get endef gb_Executable_get_linktarget_target = $(call gb_LinkTarget_get_target,$(call gb_Executable_get_linktarget,$(1))) +gb_ExternalProject__get_workdir_linktargetname = ExternalProject/$(1) + define gb_Library__get_workdir_linktargetname Library/$(call gb_Library_get_filename,$(1)) endef diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk index 5f8dacfae841..98deb69c1a13 100644 --- a/solenv/gbuild/gbuild.mk +++ b/solenv/gbuild/gbuild.mk @@ -287,7 +287,6 @@ gb_TEST_ENV_VARS += SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION=1 ifeq (,$(SAL_USE_VCLPLUGIN)) gb_TEST_ENV_VARS += SAL_USE_VCLPLUGIN=svp endif -gb_TEST_ENV_VARS += UNO_HOME=file://$$I/program # This is used to detect whether LibreOffice is being built (as opposed to building # 3rd-party code). Used for tag deprecation for API we want to diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk index 684ab7695f77..b3efff76f892 100644 --- a/solenv/gbuild/platform/unxgcc.mk +++ b/solenv/gbuild/platform/unxgcc.mk @@ -65,10 +65,13 @@ gb_LinkTarget_LDFLAGS += \ -Wl,--sysroot=$(SYSBASE) endif +ifeq (,$(DISABLE_DYNLOADING)) gb_LinkTarget_LDFLAGS += \ -Wl,-rpath-link,$(SYSBASE)/lib:$(SYSBASE)/usr/lib \ -Wl,-z,combreloc \ +endif + ifeq ($(HAVE_LD_HASH_STYLE),TRUE) gb_LinkTarget_LDFLAGS += \ -Wl,--hash-style=$(WITH_LINKER_HASH_STYLE) \ @@ -112,7 +115,8 @@ $(if $(strip $(and \ )),$(true)) endef -gb_LinkTarget__NeedsCxxLinker = $(if $(CXXOBJECTS)$(GENCXXOBJECTS)$(EXTRAOBJECTLISTS)$(filter-out XTRUE,X$(ENABLE_RUNTIME_OPTIMIZATIONS)),$(true)) +# In theory would would need to track, if any of the linked objects is C++ code, so for the static build we assume yes :-( +gb_LinkTarget__NeedsCxxLinker = $(if $(CXXOBJECTS)$(GENCXXOBJECTS)$(EXTRAOBJECTLISTS)$(filter-out XTRUE,X$(ENABLE_RUNTIME_OPTIMIZATIONS)$(DISABLE_DYNLOADING)),$(true)) # note that `cat $(extraobjectlist)` is needed to build with older gcc versions, e.g. 4.1.2 on SLED10 # we want to use @$(extraobjectlist) in the long run @@ -146,7 +150,7 @@ $(call gb_Helper_abbreviate_dirs,\ -Wl$(COMMA)--start-group \ $(patsubst lib%.a,-l%,$(patsubst lib%.so,-l%,$(patsubst %.$(gb_Library_UDK_MAJORVER),%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib)))))) \ $(foreach lib,$(LINKED_STATIC_LIBS),$(call gb_StaticLibrary_get_target,$(lib))) \ - $(T_LIBS) \ + $(patsubst $(gb_LinkTarget__syslib),%,$(T_LIBS)) \ $(if $(call gb_LinkTarget__NeedsCxxLinker),$(T_STDLIBS_CXX)) \ -Wl$(COMMA)--end-group \ , \ diff --git a/solenv/gbuild/static.mk b/solenv/gbuild/static.mk new file mode 100644 index 000000000000..346a18991134 --- /dev/null +++ b/solenv/gbuild/static.mk @@ -0,0 +1,207 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +# "spezialgelagerter Sonderfall" :-( +# +# ******************************************* +# Use gb_DEBUG_STATIC=t to dump various debug info for the static build preparation! +# Use gb_DEBUG_STATIC=a to abort / error after the dump +# ******************************************* +# +# "Generic" comment from the author: +# My thought was: the dependency info is already there. Can't be too hard to use it for +# correct static linkage... well it took more then two weeks to hopefully identify all +# problems / edge cases. Now I can appreciate the usage bin/lo-all-static-libs even more. +# +# This code moved a few times to the various gbuild / make phases: Makefile / module +# setup (in use_(libraries|externals)), post parsing (like now), make "dependency" tree +# processing. It currently looks like this is the only working option. +# +# For static linking, we must collect all depending libraries, externals and statics to +# be available at link time. And Libraries and externals can use each other. This could +# be done "in-line", while make processes the dependency tree and would have the correct +# order, so no separate tree-walking would be needed. +# It can't be done while reading / processing the modules, as this happens in no order, so +# depending modules will be missing. +# +# Then there is the (gbuild new) concept of plugin libraries. These depend on some loader +# libraries, like vcl and vclplug_* or gie. For a shared library build, these plugins are +# just dlopen'ed, but for a static build, any linked binary must also link the plugins, which +# turns plugins + loaders into a dependency cycle. The implemented solution is to just add +# plugins to executables, if these depend on a loader library. This results in the additional +# rule: nothing non-plugin is allowed to depend on a plugins (see gb_Library_set_plugin_for). +# +# And we can't add these dependencies while make is already processing the Executables, +# because these contain additional eval'ed targets, which we can't create in make recipes. +# This is especially true for externals (see gb_LinkTarget__use_* in RepositoryExternal.mk). +# We also can't add all plugins to all executables, as we have multiple helper +# binaries, which are needed early and don't depend on plugins. +# +# So the only option left seems to be to walk the dependency tree ourself and expand all +# the libraries and externals and then add the plugins to the executables. Statics are +# handled after that, since these won't need extra dependencies not already known. +# It's a bit fragile in theory, as you can add "gbuild-undetectable" dependencies to any +# target in the modules, which would need some manual adjustment, but currently that +# doesn't seem to happen in any breaking way and it works to link multiple Executable +# with large and small expanded dependency lists. +# +# Then there is the special static "components" library, which simply depends on all build +# components. In theory these could be limited per-module (Writer, Calc, etc.), but currently +# this is not implemented and instead solenv/bin/native-code.py is used, so actually +# everything is build and "cleaned up" at link time, which is especially expensive for WASM. +# That library is currently just used for Emscripten, but could be used generally for +# static builds. +# +# There is already a lot of $(info ...) protected by the already mentioned $(gb_DEBUG_STATIC). + +ifeq ($(gb_FULLDEPS),$(true)) +ifeq (,$(gb_PARTIAL_BUILD)) + +$(foreach lib,$(gb_Library_KNOWNLIBS),$(if $(call gb_Library__get_component,$(lib)), \ + $(eval $(call gb_Library_use_libraries,components,$(lib))))) + +define gb_LinkTarget__add_x_template + +# call gb_LinkTarget__add_$(1),linktarget,objects +define gb_LinkTarget__add_$(1) +$$(foreach item,$$(2),$$(if $$(filter $$(item),GBUILD_TOUCHED $$(call gb_LinkTarget__get_all_$(1),$$(1))),, + $$(if $(gb_DEBUG_STATIC),$$(info $$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_LinkTarget__get_workdir_linktargetname,$$(1))) += $$(item))) + $$(eval $$(call gb_LinkTarget__get_all_$(1)_var,$$(call gb_LinkTarget__get_workdir_linktargetname,$$(1))) += $$(item)) +)) +endef + +endef # gb_LinkTarget__add_x_template + +ifneq (,$(gb_DEBUG_STATIC)) +$(info $(call gb_LinkTarget__add_x_template,libraries)) +$(info $(call gb_LinkTarget__add_x_template,externals)) +$(info $(call gb_LinkTarget__add_x_template,statics)) +endif +$(eval $(call gb_LinkTarget__add_x_template,libraries)) +$(eval $(call gb_LinkTarget__add_x_template,externals)) +$(eval $(call gb_LinkTarget__add_x_template,statics)) + +# call gb_LinkTarget__add_linktargets,linktarget,class,func,objects +define gb_LinkTarget__add_linktargets +$(call gb_LinkTarget__add_$(3),$(1),$(4)) +$(foreach item,$(foreach mapped,$(4),$(call gb_$(2)__get_workdir_linktargetname,$(mapped))), + $(call gb_LinkTarget__add_libraries,$(1),$(call gb_LinkTarget__get_all_libraries,$(item))) + $(call gb_LinkTarget__add_externals,$(1),$(call gb_LinkTarget__get_all_externals,$(item))) + $(call gb_LinkTarget__add_statics,$(1),$(call gb_LinkTarget__get_all_statics,$(item))) +) +endef + +# contains the list of all touched workdir_linktargetname(s) +gb_LinkTarget__ALL_TOUCHED = + +define gb_LinkTarget__add_touch +$(eval $(call gb_LinkTarget__get_all_libraries_var,$(call gb_LinkTarget__get_workdir_linktargetname,$(1))) += GBUILD_TOUCHED) +$(eval $(call gb_LinkTarget__get_all_externals_var,$(call gb_LinkTarget__get_workdir_linktargetname,$(1))) += GBUILD_TOUCHED) +$(eval $(call gb_LinkTarget__get_all_statics_var,$(call gb_LinkTarget__get_workdir_linktargetname,$(1))) += GBUILD_TOUCHED) +gb_LinkTarget__ALL_TOUCHED += $(1) + +endef + +define gb_LinkTarget__remove_touch +$(call gb_LinkTarget__get_all_libraries_var,$(1)) := $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_libraries,$(1))) +$(call gb_LinkTarget__get_all_externals_var,$(1)) := $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_externals,$(1))) +$(call gb_LinkTarget__get_all_statics_var,$(1)) := $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_statics,$(1))) + +endef + +# call gb_LinkTarget__fill_all_deps.linktargetname +define gb_LinkTarget__fill_all_deps +$(if $(filter GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_lo_libraries,$(1))),, + + # LO has quite a few dependency loops, so touch first to break them + $(call gb_LinkTarget__add_touch,$(1)) + + # Add lo libraries + $(foreach item,$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_lo_libraries,$(1))), + $(call gb_LinkTarget__fill_all_deps,$(call gb_Library_get_linktarget,$(item))) + $(call gb_LinkTarget__add_libraries,$(1),$(call gb_Library__get_all_libraries,$(item))) + $(call gb_LinkTarget__add_externals,$(1),$(call gb_Library__get_all_externals,$(item))) + $(call gb_LinkTarget__add_statics,$(1),$(call gb_Library__get_all_statics,$(item))) + ) + + # Add (win32) system libraries + $(call gb_LinkTarget__add_libraries,$(1),$(call gb_LinkTarget__get_all_sys_libraries,$(1))) + + # Add externals + $(foreach item,$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_externals,$(1))), + $(call gb_LinkTarget__fill_all_deps,$(call gb_ExternalProject__get_workdir_linktargetname,$(item))) + $(call gb_LinkTarget__add_libraries,$(1),$(call gb_ExternalProject__get_all_libraries,$(item))) + $(call gb_LinkTarget__add_externals,$(1),$(call gb_ExternalProject__get_all_externals,$(item))) + $(call gb_LinkTarget__add_statics,$(1),$(call gb_ExternalProject__get_all_statics,$(item))) + ) + + # Add statics + $(foreach item,$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_statics,$(1))), + $(call gb_LinkTarget__fill_all_deps,$(call gb_StaticLibrary_get_linktarget,$(item))) + $(call gb_LinkTarget__add_libraries,$(1),$(call gb_StaticLibrary__get_all_libraries,$(item))) + $(call gb_LinkTarget__add_externals,$(1),$(call gb_StaticLibrary__get_all_externals,$(item))) + $(call gb_LinkTarget__add_statics,$(1),$(call gb_StaticLibrary__get_all_statics,$(item))) + ) + + $(if $(gb_DEBUG_STATIC), + $(info gb_LinkTarget__fill_all_deps libraries for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)) out: $(call gb_LinkTarget__get_all_libraries,$(1))) + $(info gb_LinkTarget__fill_all_deps externals for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)) out: $(call gb_LinkTarget__get_all_externals,$(1))) + $(info gb_LinkTarget__fill_all_deps statics for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)) out: $(call gb_LinkTarget__get_all_statics,$(1))) + ) +) + +endef + + +# call gb_LinkTarget__expand_executable,linktarget +define gb_LinkTarget__expand_executable +$(call gb_LinkTarget__fill_all_deps,$(1)) + +# 1. Check if cppuhelper loader for components is requested and add the needed plugin dependences +# This is a *HACK*, so we don't have to recursively check loader libraries +# 2. Find any other loader libraries and add the needed plugin dependences +$(if $(filter cppuhelper,$(filter $(gb_Library_KNOWNLOADERS),$(call gb_LinkTarget__get_all_libraries,$(1)))), + $(call gb_LinkTarget__add_linktargets,$(1),Library,libraries,$(call gb_Library__get_plugins,cppuhelper))) +$(foreach loader,$(filter $(filter-out cppuhelper,$(gb_Library_KNOWNLOADERS)),$(call gb_LinkTarget__get_all_libraries,$(1))), + $(call gb_LinkTarget__add_linktargets,$(1),Library,libraries,$(call gb_Library__get_plugins,$(loader)))) + +$(if $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_libraries,$(1))), + $(eval $(call gb_LinkTarget_use_libraries,$(1),$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_libraries,$(1)))))) + +$(if $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_externals,$(1))), + $(eval $(call gb_LinkTarget_use_externals,$(1),$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_externals,$(1)))))) + +$(if $(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_statics,$(1))), + $(eval $(call gb_LinkTarget_use_static_libraries,$(1),$(filter-out GBUILD_TOUCHED,$(call gb_LinkTarget__get_all_statics,$(1)))))) + +# Some fixes for the _use_external_project(s) mess +$(if $(filter icui18n icuuc,$(call gb_LinkTarget__get_all_externals,$(1))), + $(call gb_LinkTarget_use_externals,$(1),icudata)) +$(if $(filter orcus-parser,$(call gb_LinkTarget__get_all_externals,$(1))), + $(call gb_LinkTarget_use_static_libraries,$(1),boost_filesystem)) + +$(if $(gb_DEBUG_STATIC), + $(info gb_LinkTarget__expand_executable libraries for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)): $(call gb_LinkTarget__get_all_libraries,$(1))) + $(info gb_LinkTarget__expand_executable externals for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)): $(call gb_LinkTarget__get_all_externals,$(1))) + $(info gb_LinkTarget__expand_executable statics for $(call gb_LinkTarget__get_workdir_linktargetname,$(1)): $(call gb_LinkTarget__get_all_statics,$(1))) +) + +endef + +$(foreach lib,$(gb_Library_KNOWNLIBS), \ + $(eval $(call gb_LinkTarget__fill_all_deps,$(call gb_Library_get_linktarget,$(lib))))) +$(foreach exec,$(gb_Executable_KNOWN), \ + $(eval $(call gb_LinkTarget__expand_executable,$(call gb_Executable_get_linktarget,$(exec))))) +$(foreach workdir_linktargetname,$(gb_LinkTarget__ALL_TOUCHED), \ + $(eval $(call gb_LinkTarget__remove_touch,$(workdir_linktargetname)))) + +endif # !gb_PARTIAL_BUILD +endif # gb_FULLDEPS + +# vim: set noet sw=4 ts=4: |