project_config.mk 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Makefile support for the menuconfig system
  2. #Find all Kconfig files for all components
  3. COMPONENT_KCONFIGS := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig))
  4. COMPONENT_KCONFIGS_PROJBUILD := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/Kconfig.projbuild))
  5. #For doing make menuconfig etc
  6. KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig
  7. # set SDKCONFIG to the project's sdkconfig,
  8. # unless it's overriden (happens for bootloader)
  9. SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
  10. # SDKCONFIG_DEFAULTS is an optional file containing default
  11. # overrides (usually used for esp-idf examples)
  12. SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
  13. # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
  14. $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf:
  15. MAKEFLAGS=$(ORIGINAL_MAKEFLAGS) CC=$(HOSTCC) LD=$(HOSTLD) \
  16. $(MAKE) -C $(KCONFIG_TOOL_DIR)
  17. # use a wrapper environment for where we run Kconfig tools
  18. KCONFIG_TOOL_ENV=KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
  19. COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
  20. COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)"
  21. menuconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(call prereq_if_explicit,defconfig)
  22. $(summary) MENUCONFIG
  23. $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig
  24. ifeq ("$(wildcard $(SDKCONFIG))","")
  25. ifeq ("$(call prereq_if_explicit,defconfig)","")
  26. # if not configuration is present and defconfig is not a target, run defconfig then menuconfig
  27. $(SDKCONFIG): defconfig menuconfig
  28. else
  29. # otherwise, just defconfig
  30. $(SDKCONFIG): defconfig
  31. endif
  32. endif
  33. # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
  34. defconfig: $(KCONFIG_TOOL_DIR)/mconf $(IDF_PATH)/Kconfig $(BUILD_DIR_BASE)
  35. $(summary) DEFCONFIG
  36. ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
  37. cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG) # append defaults to sdkconfig, will override existing values
  38. endif
  39. mkdir -p $(BUILD_DIR_BASE)/include/config
  40. $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --olddefconfig $(IDF_PATH)/Kconfig
  41. # Work out of whether we have to build the Kconfig makefile
  42. # (auto.conf), or if we're in a situation where we don't need it
  43. NON_CONFIG_TARGETS := clean %-clean help menuconfig defconfig
  44. AUTO_CONF_REGEN_TARGET := $(SDKCONFIG_MAKEFILE)
  45. # disable AUTO_CONF_REGEN_TARGET if all targets are non-config targets
  46. # (and not building default target)
  47. ifneq ("$(MAKECMDGOALS)","")
  48. ifeq ($(filter $(NON_CONFIG_TARGETS), $(MAKECMDGOALS)),$(MAKECMDGOALS))
  49. AUTO_CONF_REGEN_TARGET :=
  50. # dummy target
  51. $(SDKCONFIG_MAKEFILE):
  52. endif
  53. endif
  54. $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(KCONFIG_TOOL_DIR)/conf $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD)
  55. $(summary) GENCONFIG
  56. mkdir -p $(BUILD_DIR_BASE)/include/config
  57. cd $(BUILD_DIR_BASE); $(KCONFIG_TOOL_ENV) $(KCONFIG_TOOL_DIR)/conf --silentoldconfig $(IDF_PATH)/Kconfig
  58. touch $(AUTO_CONF_REGEN_TARGET) $(BUILD_DIR_BASE)/include/sdkconfig.h
  59. # touch to ensure both output files are newer - as 'conf' can also update sdkconfig (a dependency). Without this,
  60. # sometimes you can get an infinite make loop on Windows where sdkconfig always gets regenerated newer
  61. # than the target(!)
  62. .PHONY: config-clean
  63. config-clean:
  64. $(summary RM CONFIG)
  65. $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
  66. rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h