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