[CRIU] [PATCH 07/15] build/nmk: add -obj-uniq and -lib-uniq

Dmitry Safonov dsafonov at virtuozzo.com
Mon Apr 11 05:19:21 PDT 2016


We need possibility to build one source file with different
CFLAGS, LDFLAGS, ASFLAGS for different Makefile-targets.
For example, I need to build pie for x86_64 and i386 both for
compatible task seizing. For that I need all pie's objects
to be built with both -m32 and -m64.
So, now I may use:
$(target-name)-obj-uniq += somefile.o
CFLAGS_$(target-name) += -m32
ASFLAGS_$(target-name) += -m32 -fno-pic
to built object with needed {C,AS}FLAGS and add link rule
for the $(target-name).

Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 scripts/nmk/scripts/build.mk | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/scripts/nmk/scripts/build.mk b/scripts/nmk/scripts/build.mk
index cac72919a9df..cfa80e22f261 100644
--- a/scripts/nmk/scripts/build.mk
+++ b/scripts/nmk/scripts/build.mk
@@ -206,6 +206,40 @@ define gen-custom-target-rule
         endif
 endef
 
+# for target $(1) compile source file that implicit object name is $(2)
+# with a new target-depended object name and add it to obj-y/lib-y $(3)
+# use CFLAGS, AFLAGS specified for target
+define gen-obj-uniq-rule
+        ifneq ($(wildcard $(call objectify,$(patsubst %.o,%.S,$(2)))),)
+                $$(eval $$(call gen-rule-o-from-S-by-name,		\
+                        $(basename $(call objectify,$(2)))-$(1),	\
+                        $(basename $(call objectify,$(2)))))
+        endif
+        ifneq ($(wildcard $(call objectify,$(patsubst %.o,%.c,$(2)))),)
+                $$(eval $$(call gen-rule-o-from-c-by-name,		\
+                        $(basename $(call objectify,$(2)))-$(1),	\
+                        $(basename $(call objectify,$(2)))))
+        endif
+        CFLAGS_$(basename $(2))-$(1).o += $$(CFLAGS_$(1))
+        AFLAGS_$(basename $(2))-$(1).o += $$(AFLAGS_$(1))
+        $(1)-$(3) += $(basename $(2))-$(1).o
+endef
+
+#
+# Generate unique object rules for a target.
+define gen-uniq-target-rule
+        ifneq ($($(1)-obj-uniq),)
+                $$(foreach t,$($(1)-obj-uniq),				\
+                        $$(eval $$(call gen-obj-uniq-rule,$(1),$$(t),obj-y)))
+        endif
+        ifneq ($($(1)-lib-uniq),)
+                $$(foreach t,$($(1)-lib-uniq),				\
+                        $$(eval $$(call gen-obj-uniq-rule,$(1),$$(t),lib-y)))
+        endif
+endef
+
+
+$(foreach t,$(target),$(eval $(call gen-uniq-target-rule,$(t))))
 $(foreach t,$(target),$(eval $(call gen-custom-target-rule,$(t))))
 
 #
-- 
2.8.0



More information about the CRIU mailing list