x86: custo support custo
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 8 Nov 2018 11:15:05 +0000 (12:15 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 8 Nov 2018 11:15:05 +0000 (12:15 +0100)
include/custo.mk [new file with mode: 0644]
include/target-custo.mk [new file with mode: 0644]
target/linux/x86/Makefile

diff --git a/include/custo.mk b/include/custo.mk
new file mode 100644 (file)
index 0000000..e1bea33
--- /dev/null
@@ -0,0 +1,176 @@
+define Build/Prepare
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+include $(INCLUDE_DIR)/target.mk
+
+# derive custo variables from packagename
+# CONFIG_CUSTO-* / CONFIG_CUSTO_MAPPINGS-*
+PKG_CUSTO_CONFIG_VAR?=$(patsubst mappings-%,CONFIG_CUSTO_MAPPINGS-%,$(patsubst conf-%,CONFIG_CUSTO-%,$(patsubst webui-%,CONFIG_CUSTO_WEBUI-%,$(patsubst cli-%,CONFIG_CUSTO_CLI-%,$(patsubst mib-%,CONFIG_CUSTO_MIB-%,$(PKG_NAME))))))
+# debug
+$(warning PKG_CUSTO_CONFIG_VAR = $(PKG_CUSTO_CONFIG_VAR))
+
+ifeq ($(strip $(PKG_CUSTO_CONFIG_VAR)),$(strip $(PKG_NAME)))
+  $(error PKG_CUSTO_CONFIG_VAR not explicitly set or PKG_NAME is not of the form conf-*, mappings-*, webui-*, cli-* or mib-*)
+endif
+
+ifeq ($($(PKG_CUSTO_CONFIG_VAR)),)
+  #only check when actually building
+  ifneq ($(strip $(BUILDNAME)),)
+    $(error $(PKG_CUSTO_CONFIG_VAR) not set. Run repowrt menuconfig to correct)
+  endif
+endif
+
+# if CONFIG_CUSTO-* / CONFIG_CUSTO_MAPPINGS-* is empty, replace by generic
+ifneq ($($(PKG_CUSTO_CONFIG_VAR)),"")
+  PKG_CUSTO_CONFIG_VALUE=$(patsubst "%",%,$($(PKG_CUSTO_CONFIG_VAR)))
+else
+  PKG_CUSTO_CONFIG_VALUE=generic
+endif
+
+# ensure PKG_CUSTO_FILE_PREFIXES is not empty
+ifeq ($(strip $(PKG_CUSTO_FILE_PREFIXES)),)
+  $(error PKG_CUSTO_FILE_PREFIXES not set)
+endif
+
+# ensure the CONFIG_CUSTO-* / CONFIG_CUSTO_MAPPINGS-* value is taken into account in the
+# decision to rebuild
+STAMP_PREPARED:=$(STAMP_PREPARED)_$(patsubst "%",%,$(PKG_CUSTO_CONFIG_VALUE))
+# debug
+$(warning STAMP_PREPARED = $(STAMP_PREPARED))
+
+# create config section
+# CUSTO- (for config)
+PKG_CUSTO_VAR?=$(patsubst conf-%,CUSTO-%,$(patsubst mappings-%,CUSTO_MAPPINGS-%,$(patsubst webui-%,CUSTO_WEBUI-%,$(patsubst cli-%,CUSTO_CLI-%,$(patsubst mib-%,CUSTO_MIB-%,$(PKG_NAME))))))
+#debug
+$(warning PKG_CUSTO_VAR = $(PKG_CUSTO_VAR))
+
+ifeq ($(strip $(PKG_CUSTO_VAR)),$(strip $(PKG_NAME)))
+  $(error PKG_CUSTO_VAR not explicitly set or PKG_NAME is not of the form conf-*, mappings-*, webui-*, cli-* or mib-*)
+endif
+
+define create_config
+  define Package/$(1)/config
+    config $(2)
+    depends on PACKAGE_$(1)
+    string "Name of the custo to use."
+    default "generic"
+    $$(Package/$(1)/additionalconfig)
+  endef
+endef
+
+$(eval $(call create_config,$(PKG_NAME),$(PKG_CUSTO_VAR)))
+
+# create list of CUSTO sources
+# $1 = PREFIX, $2 = PKG_CUSTO_CONFIG_VALUE , $3 = BOARDNAME
+define find_custos
+  $(1)_CUSTOS_$(3):=$(shell find -L . -regex './files/$(shell echo "$(3)" | tr '[:upper:]' '[:lower:]')/$(1)-$(2)' 2> /dev/null)
+  $(1)_CUSTOS_$(3)+=$(shell find -L . -regex './files/common/$(1)-$(2)' 2> /dev/null)
+  $(1)_CUSTOS_$(3)+=$(shell find -L . -regex './files/$(shell echo "$(3)" | tr '[:upper:]' '[:lower:]')/$(1)-generic' 2> /dev/null)
+  $(1)_CUSTOS_$(3)+=$(shell find -L . -regex './files/common/$(1)-generic' 2> /dev/null)
+endef
+
+#select first available CUSTO source from list
+define select_custo
+  $(1)_CUSTO_SELECTED_$(2):=$(firstword $($(1)_CUSTOS_$(2)))
+endef
+
+# if $(1)_CUSTO_SELECTED is a symlink to .remove, clear $(1)_CUSTO_SELECTED
+define remove_custo
+  $(1)_CUSTO_SELECTED_$(2):=$(if $($(1)_CUSTO_SELECTED_$(2)),$(if $(findstring .remove,$(shell readlink -f $($(1)_CUSTO_SELECTED_$(2)) 2> /dev/null)),,$($(1)_CUSTO_SELECTED_$(2))))
+endef
+
+define select_global_custo
+  $(1)_CUSTO_SELECTED:=$($(1)_CUSTO_SELECTED_$(2))
+endef
+
+# get current board family members, TARGET_FAMILY_MEMBERS looks like VDNT-O:PT VDNT-3:PA ..., strip the :xx to get VDNT-O VDNT-3
+FAMILY_MEMBERS:=$(if $(firstword $(TARGET_FAMILY_MEMBERS)),$(foreach MEMBER,$(TARGET_FAMILY_MEMBERS),$(shell echo "$(MEMBER)" | cut -d ':' -f 1)),$(BOARDNAME))
+# identify all possible "board" custo names
+POSSIBLE_CUSTO_NAMES:=$(sort $(FAMILY_MEMBERS) $(BOARDNAME))
+# find custo files for each member of the board family
+$(foreach CUSTO_NAME,$(POSSIBLE_CUSTO_NAMES),$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call find_custos,$(PREFIX),$(PKG_CUSTO_CONFIG_VALUE),$(CUSTO_NAME)))))
+# select correct custo from the retieved custo files for each member of the board family
+$(foreach CUSTO_NAME,$(POSSIBLE_CUSTO_NAMES),$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call select_custo,$(PREFIX),$(CUSTO_NAME)))))
+# handle .remove for the selected custo for each member of the board family
+$(foreach CUSTO_NAME,$(POSSIBLE_CUSTO_NAMES),$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call remove_custo,$(PREFIX),$(CUSTO_NAME)))))
+# select the custo applicable for the current BOARDNAME (for backwards compatibility)
+$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call select_global_custo,$(PREFIX),$(BOARDNAME))))
+
+# family installation
+# $(1) dst root path $(2) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_DIR
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(INSTALL_DIR) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(2)));),$(INSTALL_DIR) $(1)/$(patsubst /%,%,$(2));)
+endef
+
+# family installation
+# $(1) dst root path $(2) = PREFIX $(3) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_DATA
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(INSTALL_DATA) $($(2)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(3)));),$(INSTALL_DATA) $($(2)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(3));)
+endef
+
+# family installation
+# $(1) dst root path $(2) = PREFIX $(3) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_BIN
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(INSTALL_BIN) $($(2)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(3)));),$(INSTALL_BIN) $($(2)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(3));)
+endef
+
+# family installation, only proceed if source file exists
+# $(1) dst root path $(2) = PREFIX $(3) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_DATA_IF_EXISTS
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(if $($(2)_CUSTO_SELECTED_$(MEMBER)),$(INSTALL_DATA) $($(2)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(3)));)),$(INSTALL_DATA) $($(2)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(3));)
+endef
+
+# family installation, only proceed if source file exists
+# $(1) dst root path $(2) = PREFIX $(3) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_BIN_IF_EXISTS
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(if $($(2)_CUSTO_SELECTED_$(MEMBER)),$(INSTALL_BIN) $($(2)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(3)));)),$(if $($(2)_CUSTO_SELECTED),$(INSTALL_BIN) $($(2)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(3));))
+endef
+
+# conditional family installation, only install the dir if the file pointed to by CHECK_PREFIX contains the specified regexp 
+# $(1) dst root path $(2) = CHECK_PREFIX $(3) regexp  $(4) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_DIR_CONDITIONAL
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED_$(MEMBER))" 2> /dev/null)),$(INSTALL_DIR) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(4)));)),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED)" 2> /dev/null)),$(INSTALL_DIR) $(1)/$(patsubst /%,%,$(4));))
+endef
+
+# conditional family installation, only install the file referenced by INSTALL_PREFIX if the file pointed to by CHECK_PREFIX contains the specified regexp and file pointed to by INSTALL_PREFIX exists
+# $(1) dst root path $(2) = CHECK_PREFIX $(3) regexp  $(4) INSTALL_PREFIX $(5) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_DATA_CONDITIONAL
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED_$(MEMBER))" 2> /dev/null)),$(if $($(4)_CUSTO_SELECTED_$(MEMBER)),$(INSTALL_DATA) $($(4)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(5)));))),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED)" 2> /dev/null)),$(if $($(4)_CUSTO_SELECTED),$(INSTALL_DATA) $($(4)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(5));)))
+endef
+
+# conditional family installation, only install the file referenced by INSTALL_PREFIX if the file pointed to by CHECK_PREFIX contains the specified regexp and file pointed to by INSTALL_PREFIX exists
+# $(1) dst root path $(2) = CHECK_PREFIX $(3) regexp  $(4) INSTALL_PREFIX $(5) = dst subdir
+# if destination is /etc/custo/... then change to /etc/... if there is more than one family member
+define FAMILY_INSTALL_BIN_CONDITIONAL
+$(if $(filter-out $(BOARDNAME),$(FAMILY_MEMBERS)),$(foreach MEMBER,$(FAMILY_MEMBERS),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED_$(MEMBER))" 2> /dev/null)),$(if $($(4)_CUSTO_SELECTED_$(MEMBER)),$(INSTALL_BIN) $($(4)_CUSTO_SELECTED_$(MEMBER)) $(1)/etc/boards/$(MEMBER)/config/$(patsubst /%,%,$(patsubst /etc/custo/%,/etc/%,$(5)));))),$(if $(firstword $(shell grep "$(3)" "$($(2)_CUSTO_SELECTED)" 2> /dev/null)),$(if $($(4)_CUSTO_SELECTED),$(INSTALL_BIN) $($(4)_CUSTO_SELECTED) $(1)/$(patsubst /%,%,$(5));)))
+endef
+
+# reporting
+define report_custo_per_board
+$(shell echo "$(PKG_NAME): $(1)_CUSTOS_$(2) = $($(1)_CUSTOS_$(2)) $(1)_CUSTO_SELECTED_$(2) = $($(1)_CUSTO_SELECTED_$(2))" >> $(TMP_DIR)/.custo_$(PKG_NAME))
+endef
+
+define report_custo_global
+$(shell echo "$(PKG_NAME): BOARDNAME = $(BOARDNAME) $(1)_CUSTO_SELECTED = $($(1)_CUSTO_SELECTED)" >> $(TMP_DIR)/.custo_$(PKG_NAME))
+endef
+
+# remove existing report
+$(shell rm -f $(TMP_DIR)/.custo_$(PKG_NAME))
+
+# generate new report
+$(foreach MEMBER,$(FAMILY_MEMBERS),$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call report_custo_per_board,$(PREFIX),$(MEMBER)))))
+$(foreach PREFIX,$(PKG_CUSTO_FILE_PREFIXES),$(eval $(call report_custo_global,$(PREFIX))))
+
diff --git a/include/target-custo.mk b/include/target-custo.mk
new file mode 100644 (file)
index 0000000..f1d376d
--- /dev/null
@@ -0,0 +1,10 @@
+define target/ApplyCusto
+       #Install custom configuration if present
+       if [ -d $(TARGET_DIR)/etc/custo/ ]; then \
+               overrides=`find $(TARGET_DIR)/etc/custo/ -mindepth 1 -maxdepth 1 | xargs` ;\
+               for override in $$$$overrides ; do \
+                       cp -rf $$$$override $(TARGET_DIR)/etc/; \
+               done ;\
+               rm -r $(TARGET_DIR)/etc/custo/ ; \
+       fi
+endef
index 533c0e524807ec452175fbdafcedfc05e1c28c83..e5007aba52a2e44e4988833ecc192d21bfda20d7 100644 (file)
@@ -5,6 +5,7 @@
 # See /LICENSE for more information.
 #
 include $(TOPDIR)/rules.mk
+include $(INCLUDE_DIR)/target-custo.mk
 
 ARCH:=i386
 BOARD:=x86
@@ -21,6 +22,11 @@ include $(INCLUDE_DIR)/target.mk
 
 DEFAULT_PACKAGES += partx-utils mkf2fs e2fsprogs
 
+define Kernel/CompileImage
+       $(call target/ApplyCusto)
+       $(call Kernel/CompileImage/Default)
+endef
+
 $(eval $(call BuildTarget))
 
 $(eval $(call $(if $(CONFIG_TARGET_ROOTFS_ISO),RequireCommand,Ignore),mkisofs, \