project_config.mk 4.1 KB

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