]> granicus.if.org Git - esp-idf/blob - make/project_config.mk
Merge branch 'feature/idf_version' into 'master'
[esp-idf] / make / project_config.mk
1 # Makefile support for the menuconfig system
2
3 #Find all Kconfig files for all components
4 COMPONENT_KCONFIGS := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig))
5 COMPONENT_KCONFIGS_PROJBUILD := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig.projbuild))
6
7 #For doing make menuconfig etc
8 KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig
9
10 # set SDKCONFIG to the project's sdkconfig,
11 # unless it's overriden (happens for bootloader)
12 SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
13
14 # SDKCONFIG_DEFAULTS is an optional file containing default
15 # overrides (usually used for esp-idf examples)
16 SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
17
18 # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
19 $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf:
20         MAKEFLAGS=$(ORIGINAL_MAKEFLAGS) CC=$(HOSTCC) LD=$(HOSTLD) \
21         $(MAKE) -C $(KCONFIG_TOOL_DIR)
22
23 # use a wrapper environment for where we run Kconfig tools
24 KCONFIG_TOOL_ENV=KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
25         COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
26         COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)"
27
28 menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(call prereq_if_explicit,defconfig)
29         $(summary) MENUCONFIG
30         $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
31
32 ifeq ("$(wildcard $(SDKCONFIG))","")
33 ifeq ("$(call prereq_if_explicit,defconfig)","")
34 # if not configuration is present and defconfig is not a target, run defconfig then menuconfig
35 $(SDKCONFIG): defconfig menuconfig
36 else
37 # otherwise, just defconfig
38 $(SDKCONFIG): defconfig
39 endif
40 endif
41
42 # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
43 defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE)
44         $(summary) DEFCONFIG
45 ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
46         cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG)  # append defaults to sdkconfig, will override existing values
47 endif
48         mkdir -p $(BUILD_DIR_BASE)/include/config
49         $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --olddefconfig $(IDF_PATH)/Kconfig
50
51 # Work out of whether we have to build the Kconfig makefile
52 # (auto.conf), or if we're in a situation where we don't need it
53 NON_CONFIG_TARGETS := clean %-clean help menuconfig defconfig
54 AUTO_CONF_REGEN_TARGET := $(SDKCONFIG_MAKEFILE)
55
56 # disable AUTO_CONF_REGEN_TARGET if all targets are non-config targets
57 # (and not building default target)
58 ifneq ("$(MAKECMDGOALS)","")
59 ifeq ($(filter $(NON_CONFIG_TARGETS), $(MAKECMDGOALS)),$(MAKECMDGOALS))
60 AUTO_CONF_REGEN_TARGET :=
61 # dummy target
62 $(SDKCONFIG_MAKEFILE):
63 endif
64 endif
65
66 $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(KCONFIG_TOOL_DIR)/conf $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD)
67         $(summary) GENCONFIG
68         mkdir -p $(BUILD_DIR_BASE)/include/config
69         cd $(BUILD_DIR_BASE); $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --silentoldconfig $(IDF_PATH)/Kconfig
70         touch $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h
71 # touch to ensure both output files are newer - as 'conf' can also update sdkconfig (a dependency). Without this,
72 # sometimes you can get an infinite make loop on Windows where sdkconfig always gets regenerated newer
73 # than the target(!)
74
75 .PHONY: config-clean
76 config-clean:
77         $(summary RM CONFIG)
78         $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
79         rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h