gmake: CXXFLAGS override gb_Library_add_cxxflags
David Tardon
dtardon at redhat.com
Thu Jan 10 21:59:42 PST 2013
Hi,
On Wed, Jan 09, 2013 at 03:41:38PM +0100, Petr Mladek wrote:
> PS: I have troubles to understand the related gbuild code. It seems that
> both CXXFLAGS and gb_Library_add_cxxflags are added to the T_CXXFLAGS
> variable, see:
>
> --- cut solenv/gbuild/LinkTarget.mk ---
> $(call gb_LinkTarget_get_dep_target,$(1)) : T_CXXFLAGS :=
> $$(gb_LinkTarget_CXXFLAGS)
> [...]
> define gb_LinkTarget_add_cxxflags
> $(call gb_LinkTarget_get_headers_target,$(1)) \
> $(call gb_LinkTarget_get_target,$(1)) : T_CXXFLAGS += $(2)
> ifeq ($(gb_FULLDEPS),$(true))
> $(call gb_LinkTarget_get_dep_target,$(1)) : T_CXXFLAGS += $(2)
> endif
> endef
> --- cut ---
>
> It looks like T_CXXFLAGS is initialized with CXXFLAGS and
> gb_LinkTarget_add_cxxflags is added at the end. Though, in reality, they
> are listed in the opposite order. So, I am lost :-)
The problem is in variable inheritance. gb_LinkTarget_add_cxxobject
contains:
$(call gb_CxxObject_get_target,$(2)) : T_CXXFLAGS += $(3)
but there is _no_ T_CXXFLAGS variable defined on the target yet,
therefore make creates a new _recursive_ variable. When it is expanded,
it uses the current T_CXXFLAGS variable visible at the expansion point,
which is the one inherited from the CxxObject's LinkTarget. This is why
T_CXXFLAGS set on LinkTarget end up _before_ the flags passed to
gb_LinkTarget_add_cxxobject (these contain $(CXXFLAGS)).
I think all that is needed is
-$(call gb_CxxObject_get_target,$(2)) : T_CXXFLAGS += $(3)
+$(call gb_CxxObject_get_target,$(2)) : T_OBJECT_CXXFLAGS := $(3)
and then use both T_CXXFLAGS and T_OBJECT_CXXFLAGS in
gb_CxxObject__command. (The same think must then be done for other types
of objects--C, ObjC etc.)
There is still a problem with this: gb_LinkTarget_add_cxxobject can be
used directly in makefiles, in which case the passed flags are specific
for one or more cxx files and should (IMHO) override the LinkTarget
flags, which would not be the case here. On the other side,
gb_LinkTarget_add_cxxobject is mainly used to avoid passing optimization
flags, so hopefully this would not cause a problem.
D.
More information about the LibreOffice
mailing list