project_config.mk 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 and conf cannot be made simultaneously
  14. $(KCONFIG_TOOL_DIR)/mconf: $(KCONFIG_TOOL_DIR)/conf
  15. # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
  16. $(KCONFIG_TOOL_DIR)/mconf $(KCONFIG_TOOL_DIR)/conf: $(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 or mconf.
  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. $(KCONFIG_TOOL_DIR)/$1 $(IDF_PATH)/Kconfig
  39. endef
  40. ifndef MAKE_RESTARTS
  41. # menuconfig, defconfig and "GENCONFIG" configuration generation only
  42. # ever run on the first make pass, subsequent passes don't run these
  43. # (make often wants to re-run them as the conf tool can regenerate the
  44. # sdkconfig input file as an output file, but this is not what the
  45. # user wants - a single config pass is enough to produce all output
  46. # files.)
  47. #
  48. # To prevent problems missing genconfig, ensure none of these targets
  49. # depend on any prerequisite that may cause a make restart as part of
  50. # the prerequisite's own recipe.
  51. menuconfig: $(KCONFIG_TOOL_DIR)/mconf
  52. $(summary) MENUCONFIG
  53. ifdef BATCH_BUILD
  54. @echo "Can't run interactive configuration inside non-interactive build process."
  55. @echo ""
  56. @echo "Open a command line terminal and run 'make menuconfig' from there."
  57. @echo "See esp-idf documentation for more details."
  58. @exit 1
  59. else
  60. $(call RunConf,mconf)
  61. endif
  62. # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
  63. defconfig: $(KCONFIG_TOOL_DIR)/conf
  64. $(summary) DEFCONFIG
  65. ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
  66. cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG) # append defaults to sdkconfig, will override existing values
  67. endif
  68. $(call RunConf,conf --olddefconfig)
  69. # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
  70. # ensure generated config files are up to date
  71. $(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)
  72. $(summary) GENCONFIG
  73. ifdef BATCH_BUILD # can't prompt for new config values like on terminal
  74. $(call RunConf,conf --olddefconfig)
  75. endif
  76. $(call RunConf,conf --silentoldconfig)
  77. touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
  78. else # "$(MAKE_RESTARTS)" != ""
  79. # on subsequent make passes, skip config generation entirely
  80. defconfig:
  81. menuconfig:
  82. endif
  83. .PHONY: config-clean defconfig menuconfig
  84. config-clean:
  85. $(summary) RM CONFIG
  86. MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
  87. rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h