project_config.mk 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. COMPONENT_SDKCONFIG_RENAMES := $(foreach component,$(COMPONENT_PATHS),$(wildcard $(component)/sdkconfig.rename))
  6. COMPONENT_KCONFIGS_SOURCE_FILE:=$(BUILD_DIR_BASE)/kconfigs.in
  7. COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE:=$(BUILD_DIR_BASE)/kconfigs_projbuild.in
  8. ifeq ($(OS),Windows_NT)
  9. # kconfiglib requires Windows-style paths for kconfig files
  10. COMPONENT_KCONFIGS := $(shell cygpath -m $(COMPONENT_KCONFIGS))
  11. COMPONENT_KCONFIGS_PROJBUILD := $(shell cygpath -m $(COMPONENT_KCONFIGS_PROJBUILD))
  12. COMPONENT_SDKCONFIG_RENAMES := $(shell cygpath -m $(COMPONENT_SDKCONFIG_RENAMES))
  13. COMPONENT_KCONFIGS_SOURCE_FILE := $(shell cygpath -m $(COMPONENT_KCONFIGS_SOURCE_FILE))
  14. COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE := $(shell cygpath -m $(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE))
  15. endif
  16. #For doing make menuconfig etc
  17. KCONFIG_TOOL_DIR=$(IDF_PATH)/tools/kconfig
  18. # set SDKCONFIG to the project's sdkconfig,
  19. # unless it's overriden (happens for bootloader)
  20. SDKCONFIG ?= $(PROJECT_PATH)/sdkconfig
  21. SDKCONFIG_RENAME ?= $(IDF_PATH)/sdkconfig.rename
  22. # SDKCONFIG_DEFAULTS is an optional file containing default
  23. # overrides (usually used for esp-idf examples)
  24. SDKCONFIG_DEFAULTS ?= $(PROJECT_PATH)/sdkconfig.defaults
  25. # Workaround to run make parallel (-j). mconf-idf and conf-idf cannot be made simultaneously
  26. $(KCONFIG_TOOL_DIR)/mconf-idf: $(KCONFIG_TOOL_DIR)/conf-idf
  27. # reset MAKEFLAGS as the menuconfig makefile uses implicit compile rules
  28. $(KCONFIG_TOOL_DIR)/mconf-idf $(KCONFIG_TOOL_DIR)/conf-idf: $(wildcard $(KCONFIG_TOOL_DIR)/*.c) $(wildcard $(KCONFIG_TOOL_DIR)/*.y)
  29. ifeq ($(OS),Windows_NT)
  30. # mconf-idf is used only in MSYS
  31. MAKEFLAGS="" CC=$(HOSTCC) LD=$(HOSTLD) \
  32. $(MAKE) -C $(KCONFIG_TOOL_DIR)
  33. else
  34. @echo "mconf-idf is not required on this platform"
  35. endif
  36. ifeq ("$(wildcard $(SDKCONFIG))","")
  37. # if no configuration file is present we need a rule for it
  38. ifeq ("$(filter $(NON_INTERACTIVE_TARGET), $(MAKECMDGOALS))","")
  39. # if special non-interactive item is not a named target (eg. 'defconfig', 'clean')
  40. # run defconfig then menuconfig to get the initial config
  41. $(SDKCONFIG): menuconfig
  42. menuconfig: defconfig
  43. else
  44. # otherwise, just run defconfig
  45. $(SDKCONFIG): defconfig
  46. endif
  47. endif
  48. ifeq ("$(PYTHON)","")
  49. # fallback value when menuconfig is called without a build directory and sdkconfig file
  50. PYTHON=python
  51. endif
  52. SDKCONFIG_DEFAULTS_FILES := $(foreach f,$(SDKCONFIG_DEFAULTS),$(wildcard $(f)))
  53. # for each sdkconfig.defaults file, also add sdkconfig.defaults.IDF_TARGET, if it exists
  54. SDKCONFIG_DEFAULTS_FILES += $(foreach f,$(SDKCONFIG_DEFAULTS_FILES),$(wildcard $(f).$(IDF_TARGET)))
  55. ifeq ($(OS),Windows_NT)
  56. # -i is for ignore missing arguments in case SDKCONFIG_DEFAULTS_FILES is empty
  57. SDKCONFIG_DEFAULTS_FILES := $(shell cygpath -i -m $(SDKCONFIG_DEFAULTS_FILES))
  58. endif
  59. DEFAULTS_ARG := $(foreach f,$(SDKCONFIG_DEFAULTS_FILES),--defaults $(f))
  60. prepare_kconfig_files:
  61. mkdir -p $(BUILD_DIR_BASE)
  62. $(PYTHON) $(IDF_PATH)/tools/kconfig_new/prepare_kconfig_files.py \
  63. --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \
  64. --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \
  65. --env "COMPONENT_KCONFIGS_SOURCE_FILE=$(COMPONENT_KCONFIGS_SOURCE_FILE)" \
  66. --env "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)"
  67. # macro for running confgen.py
  68. define RunConfGen
  69. mkdir -p $(BUILD_DIR_BASE)/include/config
  70. $(PYTHON) $(IDF_PATH)/tools/kconfig_new/confgen.py \
  71. --kconfig $(IDF_PATH)/Kconfig \
  72. --config $(SDKCONFIG) \
  73. --sdkconfig-rename $(SDKCONFIG_RENAME) \
  74. --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \
  75. --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \
  76. --env "COMPONENT_KCONFIGS_SOURCE_FILE=$(COMPONENT_KCONFIGS_SOURCE_FILE)" \
  77. --env "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \
  78. --env "COMPONENT_SDKCONFIG_RENAMES=$(strip $(COMPONENT_SDKCONFIG_RENAMES))" \
  79. --env "IDF_CMAKE=n" \
  80. --env "IDF_ENV_FPGA=n" \
  81. $(DEFAULTS_ARG) \
  82. --output config ${SDKCONFIG} \
  83. --output makefile $(SDKCONFIG_MAKEFILE) \
  84. --output header $(BUILD_DIR_BASE)/include/sdkconfig.h \
  85. $1
  86. endef
  87. export MENUCONFIG_STYLE ?= aquatic
  88. ifeq ($(OS),Windows_NT)
  89. MENUCONFIG_CMD := $(KCONFIG_TOOL_DIR)/mconf-idf
  90. else
  91. MENUCONFIG_CMD := $(PYTHON) -m menuconfig
  92. endif
  93. .PHONY: term_check
  94. term_check:
  95. ifneq ($(OS),Windows_NT)
  96. ${PYTHON} ${IDF_PATH}/tools/check_term.py
  97. endif
  98. # macro for running menuconfig
  99. define RunMenuConf
  100. mkdir -p $(BUILD_DIR_BASE)/include/config
  101. cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
  102. KCONFIG_CONFIG=$(SDKCONFIG) \
  103. COMPONENT_KCONFIGS_SOURCE_FILE="$(COMPONENT_KCONFIGS_SOURCE_FILE)" \
  104. COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE="$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \
  105. IDF_CMAKE=n \
  106. IDF_ENV_FPGA=n \
  107. $(MENUCONFIG_CMD) $(IDF_PATH)/Kconfig
  108. endef
  109. ifndef MAKE_RESTARTS
  110. # menuconfig, defconfig and "GENCONFIG" configuration generation only
  111. # ever run on the first make pass, subsequent passes don't run these
  112. # (make often wants to re-run them as the conf tool can regenerate the
  113. # sdkconfig input file as an output file, but this is not what the
  114. # user wants - a single config pass is enough to produce all output
  115. # files.)
  116. #
  117. # To prevent problems missing genconfig, ensure none of these targets
  118. # depend on any prerequisite that may cause a make restart as part of
  119. # the prerequisite's own recipe.
  120. menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies term_check prepare_kconfig_files
  121. $(summary) MENUCONFIG
  122. ifdef BATCH_BUILD
  123. @echo "Can't run interactive configuration inside non-interactive build process."
  124. @echo ""
  125. @echo "Open a command line terminal and run 'make menuconfig' from there."
  126. @echo "See esp-idf documentation for more details."
  127. @exit 1
  128. else
  129. $(call RunConfGen,--dont-write-deprecated)
  130. # RunConfGen before menuconfig ensures that deprecated options won't be ignored (they've got renamed)
  131. $(call RunMenuConf)
  132. # RunConfGen after menuconfig ensures that deprecated options are appended to $(SDKCONFIG) for backward compatibility
  133. $(call RunConfGen,)
  134. endif
  135. # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
  136. defconfig: | check_python_dependencies prepare_kconfig_files
  137. $(summary) DEFCONFIG
  138. $(call RunConfGen,)
  139. # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
  140. # ensure generated config files are up to date
  141. $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h: $(SDKCONFIG) $(COMPONENT_KCONFIGS) $(COMPONENT_KCONFIGS_PROJBUILD) | check_python_dependencies prepare_kconfig_files $(call prereq_if_explicit,defconfig) $(call prereq_if_explicit,menuconfig)
  142. $(summary) GENCONFIG
  143. $(call RunConfGen,)
  144. touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
  145. else # "$(MAKE_RESTARTS)" != ""
  146. # on subsequent make passes, skip config generation entirely
  147. defconfig:
  148. menuconfig:
  149. endif
  150. .PHONY: config-clean defconfig menuconfig
  151. config-clean:
  152. $(summary) RM CONFIG
  153. ifeq ($(OS),Windows_NT)
  154. MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
  155. endif
  156. rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h \
  157. $(COMPONENT_KCONFIGS_SOURCE_FILE) $(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)