1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

makefiles/kconfig: refactor targets and remove merged.config

Instead of the merged.config file, menuconfig operates directly on
out.config, which also is the destination of the merge of multiple
configuration sources.

Also, this introduces the autoconf.h.d file to track the Kconfig
dependencies and re-trigger the build of the header when any of the
Kconfig files change.
This commit is contained in:
Leandro Lanzieri 2020-08-07 09:28:30 +02:00
parent 9c10580ba4
commit 4803793418
No known key found for this signature in database
GPG Key ID: 13559905E2EBEAA5

View File

@ -29,24 +29,22 @@ 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
# This is the output of the generated configuration. It always mirrors the
# content of KCONFIG_GENERATED_AUTOCONF_HEADER_C, and it is used to load
# configuration symbols to the build system.
KCONFIG_OUT_CONFIG = $(GENERATED_DIR)/out.config
# This file is generated by the GENCONFIG tool. It is similar to the .d
# files generated by GCC, and the idea is the same. We want to re-trigger the
# generation of KCONFIG_OUT_CONFIG and KCONFIG_GENERATED_AUTOCONF_HEADER_C
# whenever a change occurs on one of the previously used Kconfig files.
KCONFIG_OUT_DEP = $(KCONFIG_OUT_CONFIG).d
# Include configuration symbols if available. This allows to check for Kconfig
# symbols in makefiles. Make tries to 'remake' all included files (see
# https://www.gnu.org/software/make/manual/html_node/Remaking-Makefiles.html).
-include $(KCONFIG_OUT_CONFIG)
# Flag that indicates that the configuration KCONFIG_MERGED_CONFIG 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))
@ -69,7 +67,10 @@ $(GENERATED_DIR): $(if $(MAKE_RESTARTS),,$(CLEAN))
# configuration via Kconfig is disabled by default). Should this change, the
# check would not longer be valid, and Kconfig would have to run on every
# build.
SHOULD_RUN_KCONFIG ?= $(or $(wildcard $(APPDIR)/*.config), $(wildcard $(APPDIR)/Kconfig), $(wildcard $(KCONFIG_MERGED_CONFIG)), $(filter menuconfig, $(MAKECMDGOALS)))
SHOULD_RUN_KCONFIG ?= $(or $(wildcard $(APPDIR)/*.config), \
$(wildcard $(APPDIR)/Kconfig), \
$(if $(CLEAN),,$(wildcard $(KCONFIG_OUT_CONFIG))), \
$(filter menuconfig, $(MAKECMDGOALS)))
ifneq (,$(SHOULD_RUN_KCONFIG))
@ -80,11 +81,24 @@ KCONFIG_SYNC_DEPS ?=
BUILDDEPS += $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
# Include configuration header when building
CFLAGS += -include '$(KCONFIG_GENERATED_AUTOCONF_HEADER_C)'
CFLAGS += -imacros '$(KCONFIG_GENERATED_AUTOCONF_HEADER_C)'
USEMODULE_W_PREFIX = $(addprefix MODULE_,$(USEMODULE))
USEPKG_W_PREFIX = $(addprefix PKG_,$(USEPKG))
.PHONY: menuconfig
# Opens the menuconfig interface for configuration of modules using the Kconfig
# system. It will try to update the autoconf.h, which will update if needed
# (i.e. out.config changed).
menuconfig: $(MENUCONFIG) $(KCONFIG_OUT_CONFIG)
$(Q)KCONFIG_CONFIG=$(KCONFIG_OUT_CONFIG) $(MENUCONFIG) $(KCONFIG)
$(MAKE) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
# These rules are not included when only calling `make clean` in
# order to keep the $(BINDIR) directory clean.
ifneq (clean, $(MAKECMDGOALS))
# Build a Kconfig file defining all used modules and packages. This is done by
# defining symbols like 'MODULE_<MODULE_NAME>' or PKG_<PACKAGE_NAME> which
# default to 'y'. Then, every module and package Kconfig menu will depend on
@ -95,43 +109,34 @@ $(KCONFIG_GENERATED_DEPENDENCIES): FORCE | $(GENERATED_DIR)
printf "config %s\n\tbool\n\tdefault y\n", toupper($$0)}' \
| $(LAZYSPONGE) $(LAZYSPONGE_FLAGS) $@
.PHONY: menuconfig
# Conditionally depend on KCONFIG_MERGED_CONFIG. Only trigger configuration
# merging process if there are configuration files to merge. This avoids the
# usage of aditional bash `if [ ]` in the target recipe.
MERGE_CONFIG_DEP = $(if $(strip $(MERGE_SOURCES)),$(KCONFIG_MERGED_CONFIG))
# Opens the menuconfig interface for configuration of modules using the Kconfig
# system.
menuconfig: $(MENUCONFIG) $(MERGE_CONFIG_DEP) $(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, only when the
# configuration has not been updated by some interface like menuconfig
$(KCONFIG_MERGED_CONFIG): $(MERGECONFIG) $(KCONFIG_GENERATED_DEPENDENCIES) $(MERGE_SOURCES)
$(Q)\
if ! test -f $(KCONFIG_EDITED_CONFIG); then \
$(MERGECONFIG) $(KCONFIG) $@ $(MERGE_SOURCES); \
fi
# Build a header file with all the Kconfig configurations. genconfig will avoid
# any unnecessary rewrites of the header file if no configurations changed.
# The rule is not included when only `make clean` is called in order to keep the
# $(BINDIR) folder clean
ifneq (clean,$(MAKECMDGOALS))
$(KCONFIG_OUT_CONFIG) $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) &: $(KCONFIG_GENERATED_DEPENDENCIES) $(GENCONFIG) $(MERGE_CONFIG_DEP)
$(Q) \
KCONFIG_CONFIG=$(KCONFIG_MERGED_CONFIG) $(GENCONFIG) \
# Generates a .config file by merging multiple sources specified in
# MERGE_SOURCES. This will also generate KCONFIG_OUT_DEP with the list of used
# Kconfig files.
$(KCONFIG_OUT_CONFIG): $(KCONFIG_GENERATED_DEPENDENCIES) $(GENCONFIG) $(MERGE_SOURCES) | $(GENERATED_DIR)
$(Q) $(GENCONFIG) \
--config-out=$(KCONFIG_OUT_CONFIG) \
--file-list $(KCONFIG_OUT_DEP) \
--kconfig-filename $(KCONFIG) \
--config-sources $(MERGE_SOURCES) && \
touch $(KCONFIG_OUT_CONFIG)
endif # eq (clean, $(MAKECMDGOALS))
# Generates the configuration header file which holds the same information
# as KCONFIG_OUT_CONFIG, and is used to inject the configurations during
# compilation.
#
# This will optionally generate the 'dummy' header files needed for incremental
# builds.
$(KCONFIG_GENERATED_AUTOCONF_HEADER_C): $(KCONFIG_OUT_CONFIG)
$(Q) $(GENCONFIG) \
--header-path $(KCONFIG_GENERATED_AUTOCONF_HEADER_C) \
$(if $(KCONFIG_SYNC_DEPS),--sync-deps $(KCONFIG_SYNC_DIR)) \
$(KCONFIG)
endif
--kconfig-filename $(KCONFIG) \
--config-sources $(KCONFIG_OUT_CONFIG) && \
touch $(KCONFIG_GENERATED_AUTOCONF_HEADER_C)
# Try to load the list of Kconfig files used
-include $(KCONFIG_OUT_DEP)
endif