1# Makefile support for the menuconfig system 2 3#Find all Kconfig files for all components 4COMPONENT_KCONFIGS := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig)) 5COMPONENT_KCONFIGS_PROJBUILD := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig.projbuild)) 6COMPONENT_SDKCONFIG_RENAMES := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/sdkconfig.rename)) 7COMPONENT_KCONFIGS_SOURCE_FILE:=$(BUILD_DIR_BASE)/kconfigs.in 8COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE:=$(BUILD_DIR_BASE)/kconfigs_projbuild.in 9 10 11ifeq ($(OS),Windows_NT) 12# kconfiglib requires Windows-style paths for kconfig files 13COMPONENT_KCONFIGS := $(shell cygpath -m $(COMPONENT_KCONFIGS)) 14COMPONENT_KCONFIGS_PROJBUILD := $(shell cygpath -m $(COMPONENT_KCONFIGS_PROJBUILD)) 15COMPONENT_SDKCONFIG_RENAMES := $(shell cygpath -m $(COMPONENT_SDKCONFIG_RENAMES)) 16COMPONENT_KCONFIGS_SOURCE_FILE := $(shell cygpath -m $(COMPONENT_KCONFIGS_SOURCE_FILE)) 17COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE := $(shell cygpath -m $(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)) 18endif 19 20#For doing make menuconfig etc 21KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig 22 23# set SDKCONFIG to the project's sdkconfig, 24# unless it's overriden (happens for bootloader) 25SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig 26 27SDKCONFIG_RENAME ?= $(IDF_PATH)/sdkconfig.rename 28 29# SDKCONFIG_DEFAULTS is an optional file containing default 30# overrides (usually used for esp-idf examples) 31SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults 32 33# Workaround to run make parallel (-j). mconf-idf and conf-idf cannot be made simultaneously 34$(KCONFIG_TOOL_DIR)/mconf-idf: $(KCONFIG_TOOL_DIR)/conf-idf 35 36# reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules 37$(KCONFIG_TOOL_DIR)/mconf-idf $(KCONFIG_TOOL_DIR)/conf-idf: $(wildcard $(KCONFIG_TOOL_DIR)/*.c) $(wildcard $(KCONFIG_TOOL_DIR)/*.y) 38ifeq ($(OS),Windows_NT) 39 # mconf-idf is used only in MSYS 40 MAKEFLAGS="" CC=$(HOSTCC) LD=$(HOSTLD) \ 41 $(MAKE) -C $(KCONFIG_TOOL_DIR) 42else 43 @echo "mconf-idf is not required on this platform" 44endif 45 46ifeq ("$(wildcard $(SDKCONFIG))","") 47# if no configuration file is present we need a rule for it 48ifeq ("$(filter $(NON_INTERACTIVE_TARGET), $(MAKECMDGOALS))","") 49# if special non-interactive item is not a named target (eg. 'defconfig', 'clean') 50# run defconfig then menuconfig to get the initial config 51$(SDKCONFIG): menuconfig 52menuconfig: defconfig 53else 54# otherwise, just run defconfig 55$(SDKCONFIG): defconfig 56endif 57endif 58 59ifeq ("$(PYTHON)","") 60# fallback value when menuconfig is called without a build directory and sdkconfig file 61PYTHON=python 62endif 63 64SDKCONFIG_DEFAULTS_FILES := $(foreach f,$(SDKCONFIG_DEFAULTS),$(wildcard $(f))) 65# for each sdkconfig.defaults file, also add sdkconfig.defaults.IDF_TARGET, if it exists 66SDKCONFIG_DEFAULTS_FILES += $(foreach f,$(SDKCONFIG_DEFAULTS_FILES),$(wildcard $(f).$(IDF_TARGET))) 67 68ifeq ($(OS),Windows_NT) 69# -i is for ignore missing arguments in case SDKCONFIG_DEFAULTS_FILES is empty 70SDKCONFIG_DEFAULTS_FILES := $(shell cygpath -i -m $(SDKCONFIG_DEFAULTS_FILES)) 71endif 72DEFAULTS_ARG := $(foreach f,$(SDKCONFIG_DEFAULTS_FILES),--defaults $(f)) 73 74prepare_kconfig_files: 75 mkdir -p $(BUILD_DIR_BASE) 76 $(PYTHON) $(IDF_PATH)/tools/kconfig_new/prepare_kconfig_files.py \ 77 --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \ 78 --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \ 79 --env "COMPONENT_KCONFIGS_SOURCE_FILE=$(COMPONENT_KCONFIGS_SOURCE_FILE)" \ 80 --env "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" 81 82# macro for running confgen.py 83define RunConfGen 84 mkdir -p $(BUILD_DIR_BASE)/include/config 85 $(PYTHON) $(IDF_PATH)/tools/kconfig_new/confgen.py \ 86 --kconfig $(IDF_PATH)/Kconfig \ 87 --config $(SDKCONFIG) \ 88 --sdkconfig-rename $(SDKCONFIG_RENAME) \ 89 --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \ 90 --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \ 91 --env "COMPONENT_KCONFIGS_SOURCE_FILE=$(COMPONENT_KCONFIGS_SOURCE_FILE)" \ 92 --env "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \ 93 --env "COMPONENT_SDKCONFIG_RENAMES=$(strip $(COMPONENT_SDKCONFIG_RENAMES))" \ 94 --env "IDF_CMAKE=n" \ 95 --env "IDF_ENV_FPGA=n" \ 96 $(DEFAULTS_ARG) \ 97 --output config ${SDKCONFIG} \ 98 --output makefile $(SDKCONFIG_MAKEFILE) \ 99 --output header $(BUILD_DIR_BASE)/include/sdkconfig.h \ 100 $1 101endef 102 103export MENUCONFIG_STYLE ?= aquatic 104 105ifeq ($(OS),Windows_NT) 106MENUCONFIG_CMD := $(KCONFIG_TOOL_DIR)/mconf-idf 107else 108MENUCONFIG_CMD := $(PYTHON) -m menuconfig 109endif 110 111.PHONY: term_check 112term_check: 113ifneq ($(OS),Windows_NT) 114 ${PYTHON} ${IDF_PATH}/tools/check_term.py 115endif 116 117# macro for running menuconfig 118define RunMenuConf 119 mkdir -p $(BUILD_DIR_BASE)/include/config 120 cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \ 121 KCONFIG_CONFIG=$(SDKCONFIG) \ 122 COMPONENT_KCONFIGS_SOURCE_FILE="$(COMPONENT_KCONFIGS_SOURCE_FILE)" \ 123 COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE="$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \ 124 IDF_CMAKE=n \ 125 IDF_ENV_FPGA=n \ 126 $(MENUCONFIG_CMD) $(IDF_PATH)/Kconfig 127endef 128 129ifndef MAKE_RESTARTS 130# menuconfig, defconfig and "GENCONFIG" configuration generation only 131# ever run on the first make pass, subsequent passes don't run these 132# (make often wants to re-run them as the conf tool can regenerate the 133# sdkconfig input file as an output file, but this is not what the 134# user wants - a single config pass is enough to produce all output 135# files.) 136# 137# To prevent problems missing genconfig, ensure none of these targets 138# depend on any prerequisite that may cause a make restart as part of 139# the prerequisite's own recipe. 140 141menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies term_check prepare_kconfig_files 142 $(summary) MENUCONFIG 143ifdef BATCH_BUILD 144 @echo "Can't run interactive configuration inside non-interactive build process." 145 @echo "" 146 @echo "Open a command line terminal and run 'make menuconfig' from there." 147 @echo "See esp-idf documentation for more details." 148 @exit 1 149else 150 $(call RunConfGen,--dont-write-deprecated) 151 # RunConfGen before menuconfig ensures that deprecated options won't be ignored (they've got renamed) 152 $(call RunMenuConf) 153 # RunConfGen after menuconfig ensures that deprecated options are appended to $(SDKCONFIG) for backward compatibility 154 $(call RunConfGen,) 155endif 156 157# defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present 158defconfig: | check_python_dependencies prepare_kconfig_files 159 $(summary) DEFCONFIG 160 $(call RunConfGen,) 161 162# if neither defconfig or menuconfig are requested, use the GENCONFIG rule to 163# ensure generated config files are up to date 164$(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD) | check_python_dependencies prepare_kconfig_files $(call prereq_if_explicit,defconfig) $(call prereq_if_explicit,menuconfig) 165 $(summary) GENCONFIG 166 $(call RunConfGen,) 167 touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig 168 169else # "$(MAKE_RESTARTS)" != "" 170# on subsequent make passes, skip config generation entirely 171defconfig: 172menuconfig: 173endif 174 175.PHONY: config-clean defconfig menuconfig 176config-clean: 177 $(summary) RM CONFIG 178ifeq ($(OS),Windows_NT) 179 MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean 180endif 181 rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h \ 182 $(COMPONENT_KCONFIGS_SOURCE_FILE) $(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE) 183