project_config.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 -w $(COMPONENT_KCONFIGS))
  8. COMPONENT_KCONFIGS_PROJBUILD := $(shell cygpath -w $(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 running confgen.py
  37. define RunConfGen
  38. mkdir -p $(BUILD_DIR_BASE)/include/config
  39. $(PYTHON) $(IDF_PATH)/tools/kconfig_new/confgen.py \
  40. --kconfig $(IDF_PATH)/Kconfig \
  41. --config $(SDKCONFIG) \
  42. --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \
  43. --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \
  44. --env "IDF_CMAKE=n" \
  45. --output config ${SDKCONFIG} \
  46. --output makefile $(SDKCONFIG_MAKEFILE) \
  47. --output header $(BUILD_DIR_BASE)/include/sdkconfig.h
  48. endef
  49. # macro for the commands to run kconfig tools conf-idf or mconf-idf.
  50. # $1 is the name (& args) of the conf tool to run
  51. # Note: Currently only mconf-idf is used for compatibility with the CMake build system. The header file used is also
  52. # the same.
  53. define RunConf
  54. mkdir -p $(BUILD_DIR_BASE)/include/config
  55. cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
  56. COMPONENT_KCONFIGS="$(COMPONENT_KCONFIGS)" KCONFIG_CONFIG=$(SDKCONFIG) \
  57. COMPONENT_KCONFIGS_PROJBUILD="$(COMPONENT_KCONFIGS_PROJBUILD)" \
  58. IDF_CMAKE=n \
  59. $(KCONFIG_TOOL_DIR)/$1 $(IDF_PATH)/Kconfig
  60. endef
  61. ifndef MAKE_RESTARTS
  62. # menuconfig, defconfig and "GENCONFIG" configuration generation only
  63. # ever run on the first make pass, subsequent passes don't run these
  64. # (make often wants to re-run them as the conf tool can regenerate the
  65. # sdkconfig input file as an output file, but this is not what the
  66. # user wants - a single config pass is enough to produce all output
  67. # files.)
  68. #
  69. # To prevent problems missing genconfig, ensure none of these targets
  70. # depend on any prerequisite that may cause a make restart as part of
  71. # the prerequisite's own recipe.
  72. menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies
  73. $(summary) MENUCONFIG
  74. ifdef BATCH_BUILD
  75. @echo "Can't run interactive configuration inside non-interactive build process."
  76. @echo ""
  77. @echo "Open a command line terminal and run 'make menuconfig' from there."
  78. @echo "See esp-idf documentation for more details."
  79. @exit 1
  80. else
  81. $(call RunConfGen)
  82. # RunConfGen before mconf-idf ensures that deprecated options won't be ignored (they've got renamed)
  83. $(call RunConf,mconf-idf)
  84. # RunConfGen after mconf-idf ensures that deprecated options are appended to $(SDKCONFIG) for backward compatibility
  85. $(call RunConfGen)
  86. endif
  87. # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
  88. defconfig: | check_python_dependencies
  89. $(summary) DEFCONFIG
  90. ifneq ("$(wildcard $(SDKCONFIG_DEFAULTS))","")
  91. cat $(SDKCONFIG_DEFAULTS) >> $(SDKCONFIG) # append defaults to sdkconfig, will override existing values
  92. endif
  93. $(call RunConfGen)
  94. # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
  95. # ensure generated config files are up to date
  96. $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD) | check_python_dependencies $(call prereq_if_explicit,defconfig) $(call prereq_if_explicit,menuconfig)
  97. $(summary) GENCONFIG
  98. $(call RunConfGen)
  99. touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
  100. else # "$(MAKE_RESTARTS)" != ""
  101. # on subsequent make passes, skip config generation entirely
  102. defconfig:
  103. menuconfig:
  104. endif
  105. .PHONY: config-clean defconfig menuconfig
  106. config-clean:
  107. $(summary) RM CONFIG
  108. MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
  109. rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h