make/: Showing GENCONFIG even with V=1 is useful
[apeos.git] / make / project_config.mk
blob11a3cce87ca17e919060b081223bb22a49ccb08c
1 # Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
2 # Copyright 2018 apeos contributors
4 # Makefile support for the menuconfig system
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 #Find all Kconfig files for all components
19 COMPONENT_KCONFIGS := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig))
20 COMPONENT_KCONFIGS_PROJBUILD := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig.projbuild))
22 #For doing make menuconfig etc
23 KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig
25 # set SDKCONFIG to the project's sdkconfig,
26 # unless it's overriden (happens for bootloader)
27 SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
29 # SDKCONFIG_DEFAULTS is an optional file containing default
30 # overrides (usually used for esp-idf examples)
31 SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
33 # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
34 $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf: $(wildcard $(KCONFIG_TOOL_DIR)/*.c)
35 MAKEFLAGS="" CC=$(HOSTCC) LD=$(HOSTLD) \
36 $(MAKE) -C $(KCONFIG_TOOL_DIR)
38 ifeq ("$(wildcard $(SDKCONFIG))","")
39 ifeq ("$(filter defconfig clean% %clean, $(MAKECMDGOALS))","")
40 # if no configuration file is present and defconfig or clean
41 # is not a named target, run defconfig then menuconfig to get the initial config
42 $(SDKCONFIG): menuconfig
43 menuconfig: defconfig
44 else
45 # otherwise, just run defconfig
46 $(SDKCONFIG): defconfig
47 endif
48 endif
50 # macro for the commands to run kconfig tools conf or mconf.
51 # $1 is the name (& args) of the conf tool to run
52 define RunConf
53 mkdir -p $(BUILD_DIR_BASE)/include/config
54 cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
55 COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
56 COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)" \
57 $(KCONFIG_TOOL_DIR)/$1 $(IDF_PATH)/Kconfig
58 endef
60 ifndef MAKE_RESTARTS
61 # menuconfig, defconfig and "GENCONFIG" configuration generation only
62 # ever run on the first make pass, subsequent passes don't run these
63 # (make often wants to re-run them as the conf tool can regenerate the
64 # sdkconfig input file as an output file, but this is not what the
65 # user wants - a single config pass is enough to produce all output
66 # files.)
68 # To prevent problems missing genconfig, ensure none of these targets
69 # depend on any prerequisite that may cause a make restart as part of
70 # the prerequisite's own recipe.
72 menuconfig: $(KCONFIG_TOOL_DIR)/mconf
73 $(summary) MENUCONFIG
74 ifdef BATCH_BUILD
75 @echo "Can't run interactive configuration inside non-interactive build process."
76 @echo ""
77 @echo "Open a command line terminal and run 'make menuconfig' from there."
78 @echo "See esp-idf documentation for more details."
79 @exit 1
80 else
81 $(call RunConf,mconf)
82 endif
84 # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
85 defconfig: $(KCONFIG_TOOL_DIR)/conf
86 $(summary) DEFCONFIG
87 ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
88 cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG) # append defaults to sdkconfig, will override existing values
89 endif
90 $(call RunConf,conf --olddefconfig)
92 # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
93 # ensure generated config files are up to date
94 $(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)
95 @echo GENCONFIG
96 ifdef BATCH_BUILD # can't prompt for new config values like on terminal
97 $(call RunConf,conf --olddefconfig)
98 endif
99 $(call RunConf,conf --silentoldconfig)
100 touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
102 else # "$(MAKE_RESTARTS)" != ""
103 # on subsequent make passes, skip config generation entirely
104 defconfig:
105 menuconfig:
106 endif
108 .PHONY: config-clean defconfig menuconfig
109 config-clean:
110 $(summary) RM CONFIG
111 MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
112 rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h