]> granicus.if.org Git - esp-idf/blob - make/project_config.mk
Merge branch 'driver/spi' 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 | 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 $(wildcard $(PROJECT_PATH)/sdkconfig.defaults): | menuconfig defconfig
43         cp $< $@
44
45 # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
46 defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE)
47         $(summary) DEFCONFIG
48 ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
49         cp $(SDKCONFIG_DEFAULTS) $(SDKCONFIG)
50 endif
51         mkdir -p $(BUILD_DIR_BASE)/include/config
52         $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --olddefconfig $(IDF_PATH)/Kconfig
53
54 # Work out of whether we have to build the Kconfig makefile
55 # (auto.conf), or if we're in a situation where we don't need it
56 NON_CONFIG_TARGETS := clean %-clean help menuconfig defconfig
57 AUTO_CONF_REGEN_TARGET := $(SDKCONFIG_MAKEFILE)
58
59 # disable AUTO_CONF_REGEN_TARGET if all targets are non-config targets
60 # (and not building default target)
61 ifneq ("$(MAKECMDGOALS)","")
62 ifeq ($(filter $(NON_CONFIG_TARGETS), $(MAKECMDGOALS)),$(MAKECMDGOALS))
63 AUTO_CONF_REGEN_TARGET :=
64 # dummy target
65 $(SDKCONFIG_MAKEFILE):
66 endif
67 endif
68
69 $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(KCONFIG_TOOL_DIR)/conf $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD)
70         $(summary) GENCONFIG
71         mkdir -p $(BUILD_DIR_BASE)/include/config
72         cd $(BUILD_DIR_BASE); $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --silentoldconfig $(IDF_PATH)/Kconfig
73         touch $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h
74 # touch to ensure both output files are newer - as 'conf' can also update sdkconfig (a dependency). Without this,
75 # sometimes you can get an infinite make loop on Windows where sdkconfig always gets regenerated newer
76 # than the target(!)
77
78 .PHONY: config-clean
79 config-clean:
80         $(summary RM CONFIG)
81         $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
82         rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h