project_config.mk 3.8 KB

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