project_config.mk 4.3 KB

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