[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] build: Extensible build rules



Replaces the hard-coded switch case that selects the build rule
definitions with an extensible system: For each source file, the build
system searches for a Make function in the form of:
  buildrule_<extension of source file> (e.g., buildrule_cpp)

When such a function was never defined (e.g., by an external
`Makefile.rules` as part of an external language library) the build
system throws an error.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 Makefile                     |  1 +
 support/build/Makefile.rules | 51 +++++++++++++++++++++---------------
 2 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 725b012a..81a07a29 100644
--- a/Makefile
+++ b/Makefile
@@ -57,6 +57,7 @@ qstrip = $(strip $(subst ",,$(1)))
 comma := ,
 empty :=
 space := $(empty) $(empty)
+plus  := $(call qstrip,"+")
 
 # bash prints the name of the directory on 'cd <dir>' if CDPATH is
 # set, so unset it here to not cause problems. Notice that the export
diff --git a/support/build/Makefile.rules b/support/build/Makefile.rules
index a13180a8..16a55674 100644
--- a/support/build/Makefile.rules
+++ b/support/build/Makefile.rules
@@ -55,6 +55,9 @@ endef
 
 sub_build_dir = $(addprefix $(BUILD_DIR)/,$(notdir $(1)))
 
+# Returns the file extension
+fileext = $(subst .,,$(suffix $(1)))
+
 # converts a list of library names to paths pointing to their corresponding 
object library file
 # libname2olib $libname
 libname2olib = $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(1)))
@@ -374,7 +377,7 @@ endef
 #
 # buildrule_* $libname,$source,$target,$extraflags(optional)
 
-define buildrule_S =
+define buildrule_S_ =
 $(3): $(2) | prepare
        $(call build_cmd_fixdep,AS,$(1),$(3),\
                $(AS)  $(ASINCLUDES) $(ASINCLUDES-y) \
@@ -392,6 +395,8 @@ $(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
 $(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call 
out2dep,$(3)))
 endef
 
+buildrule_sx = $(call buildrule_S_,$(1),$(2),$(3),$(4))
+
 define buildrule_s =
 $(3): $(2) | prepare
        $(call build_cmd,AS,$(1),$(3),\
@@ -446,6 +451,14 @@ $(eval $(call vprefix_lib,$(1),OBJS-y) += $(3))
 $(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call build_clean,$(3)) $(call 
out2dep,$(3)))
 endef
 
+# Aliases for C++ sources
+buildrule_cp  = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+buildrule_cxx = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+buildrule_cpp = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+buildrule_CPP = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+buildrule_C   = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+buildrule_c$(plus)$(plus) = $(call buildrule_cc,$(1),$(2),$(3),$(4))
+
 define buildrule_go =
 $(3): $(2) | prepare
        $(call build_cmd,GOC,$(1),$(3),\
@@ -472,7 +485,7 @@ define add_lds_to_lib =
 $(eval EXTRA_LD_SCRIPT-y += $(1))
 endef
 
-define buildrule_lds =
+define buildrule_S_lds =
 $(3): $(2) | prepare
        $(call build_cmd_fixdep,LDS,$(1),$(3),\
                $(AS)  -E -P -x assembler-with-cpp $(ASINCLUDES) 
$(ASINCLUDES-y) \
@@ -498,6 +511,13 @@ $(if $(strip $($(call uc,$(1))_PLATS)),\
 )
 endef
 
+# buildrule for *.S files: differentiate between *.lds.S, *.S
+define buildrule_S =
+$(if $(filter %.lds.S,$(2)),$(call buildrule_S_lds,$(1),$(2),$(3),$(4)),\
+$(call buildrule_S_,$(1),$(2),$(3),$(4))
+)
+endef
+
 ## Add the linker file to the common variable used for linker script
 define buildrule_ld  =
 $(2): | prepare
@@ -525,29 +545,18 @@ $(eval $(call vprefix_lib,$(1),CLEAN-y) += $(call 
build_clean,$(3)))
 endef
 
 # wrapper for buildrule_*,
-# selects appropriate buildrule depending on file extension
+# selects appropriate buildrule depending on file extension,
+# if there is no such buildrule available, we throw an error.
 #
 # buildrule $libname,$source,$target,$extraflags(optional)
+buildrule_ = $(error $(1): Failed to derive source type from $(2))
+
 define buildrule =
-$(if $(filter %.lds.S,$(2)),$(call buildrule_lds,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.ld   ,$(2)),$(call buildrule_ld ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.dts,  $(2)),$(call buildrule_dts,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.S,    $(2)),$(call buildrule_S  ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.sx,   $(2)),$(call buildrule_S  ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.s,    $(2)),$(call buildrule_s  ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.c,    $(2)),$(call buildrule_c  ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.cc,   $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.cp,   $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.cxx,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.cpp,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.CPP,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.c++,  $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.C,    $(2)),$(call buildrule_cc ,$(1),$(2),$(3),$(4)),\
-$(if $(filter %.go,   $(2)),$(call buildrule_go ,$(1),$(2),$(3),$(4)),\
-$(error $(3): missing build rule for source type $(suffix $(2))) \
-)))))))))))))))
-endef
+$(if $(filter buildrule_$(call fileext,$(2)),$(.VARIABLES)),,\
+$(error buildrule_$(call fileext,$(2)) is not defined: Failed to install rule 
for $(2)))
 
+$(call buildrule_$(call fileext,$(2)),$(1),$(2),$(3),$(4))
+endef
 
 #################################################
 #
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.