From 1655001d851028d3ec53616bf8c7c7ffd8562139 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Sat, 13 Jul 2019 11:17:51 +0200 Subject: [PATCH] makefiles: Add Kconfig related targets and dependencies - The autoconf.h header file, generated with the current Kconfig configurations, is added as a build dependency. - autoconf.h depends on the proper tool (genconfig) and a Kconfig.dep which contains the dependencies for the given application and board, this is generated from $(USEMODULE). - The menuconfig target is added, to allow the configuration of modules using the Kconfig system. --- Makefile.base | 8 ++-- Makefile.include | 3 ++ makefiles/kconfig.mk | 88 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 makefiles/kconfig.mk diff --git a/Makefile.base b/Makefile.base index 5f7fd9f02d..d9dfbc00b0 100644 --- a/Makefile.base +++ b/Makefile.base @@ -96,19 +96,19 @@ CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS) $(OBJC_LTO): CFLAGS+=$(LTOFLAGS) -$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) +$(OBJC): $(BINDIR)/$(MODULE)/%.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) $(Q)$(CCACHE) $(CC) \ -DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \ -DRIOT_FILE_NOPATH=\"$(notdir $<)\" \ $(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $(abspath $<) -$(GENOBJC): %.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) +$(GENOBJC): %.o: %.c $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) $(Q) $(CCACHE) $(CC) \ -DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$<)\" \ -DRIOT_FILE_NOPATH=\"$(notdir $<)\" \ $(CFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $< -$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C) +$(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) $(Q)$(CCACHE) $(CXX) \ -DRIOT_FILE_RELATIVE=\"$(patsubst $(RIOTBASE)/%,%,$(abspath $<))\" \ -DRIOT_FILE_NOPATH=\"$(notdir $<)\" \ @@ -117,7 +117,7 @@ $(OBJCXX): $(BINDIR)/$(MODULE)/%.o: %.cpp $(RIOTBUILD_CONFIG_HEADER_C) $(ASMOBJ): $(BINDIR)/$(MODULE)/%.o: %.s $(Q)$(AS) $(ASFLAGS) -o $@ $(abspath $<) -$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S $(RIOTBUILD_CONFIG_HEADER_C) +$(ASSMOBJ): $(BINDIR)/$(MODULE)/%.o: %.S $(RIOTBUILD_CONFIG_HEADER_C) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) $(Q)$(CCAS) $(CCASFLAGS) $(INCLUDES) -MQ '$@' -MD -MP -c -o $@ $(abspath $<) # pull in dependency info for *existing* .o files diff --git a/Makefile.include b/Makefile.include index 805c23bffe..4a1ecaec2b 100644 --- a/Makefile.include +++ b/Makefile.include @@ -148,6 +148,9 @@ include $(RIOTMAKE)/scan-build.inc.mk export RIOTBUILD_CONFIG_HEADER_C = $(BINDIR)/riotbuild/riotbuild.h +# Include Kconfig functionalities +include $(RIOTMAKE)/kconfig.mk + ifeq ($(OS),Darwin) OPEN := open else diff --git a/makefiles/kconfig.mk b/makefiles/kconfig.mk new file mode 100644 index 0000000000..119ded8642 --- /dev/null +++ b/makefiles/kconfig.mk @@ -0,0 +1,88 @@ +# This is the root Kconfig +KCONFIG ?= $(RIOTBASE)/Kconfig + +# Include tools targets +include $(RIOTMAKE)/tools/kconfiglib.inc.mk + +# Generated dir will contain Kconfig generated configurations +GENERATED_DIR = $(BINDIR)/generated + +# This file will contain all generated configuration from kconfig +export KCONFIG_GENERATED_AUTOCONF_HEADER_C = $(GENERATED_DIR)/autoconf.h + +# Add configuration header to build dependencies +BUILDDEPS += $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) + +# Include configuration header when building +CFLAGS += -include '$(KCONFIG_GENERATED_AUTOCONF_HEADER_C)' + +# Header for the generated header file +define KCONFIG_AUTOHEADER_HEADER +/* RIOT Configuration File */ + +endef +export KCONFIG_AUTOHEADER_HEADER + +# This file will contain the calculated dependencies formated in Kconfig +export KCONFIG_GENERATED_DEPENDENCIES = $(GENERATED_DIR)/Kconfig.dep + +# This file will contain application default configurations +KCONFIG_APP_CONFIG = $(APPDIR)/app.config + +# Default and user overwritten configurations +KCONFIG_USER_CONFIG = $(APPDIR)/user.config + +# This file will contain merged configurations from MERGE_SOURCES and is the +# one that is used to generate the 'riotconf.h' header +KCONFIG_MERGED_CONFIG = $(GENERATED_DIR)/merged.config + +# Flag that indicates that the configuration has been edited +KCONFIG_EDITED_CONFIG = $(GENERATED_DIR)/.editedconfig + +# Add configurations to merge, in ascendent priority (i.e. a file overrides the +# previous ones) +MERGE_SOURCES += $(wildcard $(KCONFIG_APP_CONFIG)) +MERGE_SOURCES += $(wildcard $(KCONFIG_USER_CONFIG)) + +# Create directory to place generated files +$(GENERATED_DIR): $(CLEAN) + $(Q)mkdir -p $@ + +# Build a Kconfig file defining all used modules. This is done by defining +# symbols like 'MODULE_' which default to 'y'. Then, every module +# Kconfig menu will depend on that symbol being set to show its options. +$(KCONFIG_GENERATED_DEPENDENCIES): FORCE | $(GENERATED_DIR) + $(Q)printf "%s " $(USEMODULE) \ + | awk 'BEGIN {RS=" "}{ gsub("-", "_", $$0); \ + printf "config MODULE_%s\n\tbool\n\tdefault y\n", toupper($$0)}' \ + | $(LAZYSPONGE) $(LAZYSPONGE_FLAGS) $@ + +.PHONY: menuconfig + +# Opens the menuconfig interface for configuration of modules using the Kconfig +# system. +menuconfig: $(MENUCONFIG) $(KCONFIG_MERGED_CONFIG) $(KCONFIG_EDITED_CONFIG) + $(Q)KCONFIG_CONFIG=$(KCONFIG_MERGED_CONFIG) $(MENUCONFIG) $(KCONFIG) + +# Marks that the configuration file has been edited via some interface, such as +# menuconfig +$(KCONFIG_EDITED_CONFIG): FORCE + $(Q)touch $(KCONFIG_EDITED_CONFIG) + +# Generates a merged configuration file from the given sources. If the config +# file has been edited a '.editedconfig' file will be present. +# This is used to decide if the sources have to be merged or not. +$(KCONFIG_MERGED_CONFIG): $(MERGECONFIG) $(KCONFIG_GENERATED_DEPENDENCIES) FORCE + $(Q)\ + if ! test -f $(KCONFIG_EDITED_CONFIG); then \ + if ! test -z "$(strip $(MERGE_SOURCES))"; then \ + $(MERGECONFIG) $(KCONFIG) $@ $(MERGE_SOURCES); \ + else \ + rm -f $@; \ + fi \ + fi + +# Build a header file with all the Kconfig configurations. genconfig will avoid +# any unnecessary rewrites of the header file if no configurations changed. +$(KCONFIG_GENERATED_AUTOCONF_HEADER_C): $(KCONFIG_GENERATED_DEPENDENCIES) $(GENCONFIG) $(KCONFIG_MERGED_CONFIG) FORCE + $(Q)KCONFIG_CONFIG=$(KCONFIG_MERGED_CONFIG) $(GENCONFIG) --header-path $@ $(KCONFIG)