Import GNU make build system from esp-idf v3
[apeos.git] / make / project_config.mk
blob0a212cd287c966322bd5d952b52a6b99f49614dc
1 # Makefile support for the menuconfig system
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))
7 #For doing make menuconfig etc
8 KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig
10 # set SDKCONFIG to the project's sdkconfig,
11 # unless it's overriden (happens for bootloader)
12 SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
14 # SDKCONFIG_DEFAULTS is an optional file containing default
15 # overrides (usually used for esp-idf examples)
16 SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
18 # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
19 $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf: $(wildcard $(KCONFIG_TOOL_DIR)/*.c)
20 MAKEFLAGS="" CC=$(HOSTCC) LD=$(HOSTLD) \
21 $(MAKE) -C $(KCONFIG_TOOL_DIR)
23 ifeq ("$(wildcard $(SDKCONFIG))","")
24 ifeq ("$(filter defconfig clean% %clean, $(MAKECMDGOALS))","")
25 # if no configuration file is present and defconfig or clean
26 # is not a named target, run defconfig then menuconfig to get the initial config
27 $(SDKCONFIG): menuconfig
28 menuconfig: defconfig
29 else
30 # otherwise, just run defconfig
31 $(SDKCONFIG): defconfig
32 endif
33 endif
35 # macro for the commands to run kconfig tools conf or mconf.
36 # $1 is the name (& args) of the conf tool to run
37 define RunConf
38 mkdir -p $(BUILD_DIR_BASE)/include/config
39 cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
40 COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
41 COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)" \
42 $(KCONFIG_TOOL_DIR)/$1 $(IDF_PATH)/Kconfig
43 endef
45 ifndef MAKE_RESTARTS
46 # menuconfig, defconfig and "GENCONFIG" configuration generation only
47 # ever run on the first make pass, subsequent passes don't run these
48 # (make often wants to re-run them as the conf tool can regenerate the
49 # sdkconfig input file as an output file, but this is not what the
50 # user wants - a single config pass is enough to produce all output
51 # files.)
53 # To prevent problems missing genconfig, ensure none of these targets
54 # depend on any prerequisite that may cause a make restart as part of
55 # the prerequisite's own recipe.
57 menuconfig: $(KCONFIG_TOOL_DIR)/mconf
58 $(summary) MENUCONFIG
59 ifdef BATCH_BUILD
60 @echo "Can't run interactive configuration inside non-interactive build process."
61 @echo ""
62 @echo "Open a command line terminal and run 'make menuconfig' from there."
63 @echo "See esp-idf documentation for more details."
64 @exit 1
65 else
66 $(call RunConf,mconf)
67 endif
69 # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
70 defconfig: $(KCONFIG_TOOL_DIR)/conf
71 $(summary) DEFCONFIG
72 ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
73 cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG) # append defaults to sdkconfig, will override existing values
74 endif
75 $(call RunConf,conf --olddefconfig)
77 # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
78 # ensure generated config files are up to date
79 $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(KCONFIG_TOOL_DIR)/conf $(SDKCONFIG) $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD) | $(call prereq_if_explicit,defconfig) $(call prereq_if_explicit,menuconfig)
80 $(summary) GENCONFIG
81 ifdef BATCH_BUILD # can't prompt for new config values like on terminal
82 $(call RunConf,conf --olddefconfig)
83 endif
84 $(call RunConf,conf --silentoldconfig)
85 touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
87 else # "$(MAKE_RESTARTS)" != ""
88 # on subsequent make passes, skip config generation entirely
89 defconfig:
90 menuconfig:
91 endif
93 .PHONY: config-clean defconfig menuconfig
94 config-clean:
95 $(summary) RM CONFIG
96 MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
97 rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h