project_config.mk 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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)
  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. SDKCONFIG_DEFAULTS_FILES := $(shell cygpath -m $(SDKCONFIG_DEFAULTS_FILES))
  57. endif
  58. DEFAULTS_ARG := $(foreach f,$(SDKCONFIG_DEFAULTS_FILES),--defaults $(f))
  59. # macro for running confgen.py
  60. define RunConfGen
  61. mkdir -p $(BUILD_DIR_BASE)/include/config
  62. $(PYTHON) $(IDF_PATH)/tools/kconfig_new/confgen.py \
  63. --kconfig $(IDF_PATH)/Kconfig \
  64. --config $(SDKCONFIG) \
  65. --sdkconfig-rename $(SDKCONFIG_RENAME) \
  66. --env "COMPONENT_KCONFIGS=$(strip $(COMPONENT_KCONFIGS))" \
  67. --env "COMPONENT_KCONFIGS_PROJBUILD=$(strip $(COMPONENT_KCONFIGS_PROJBUILD))" \
  68. --env "COMPONENT_KCONFIGS_SOURCE_FILE=$(COMPONENT_KCONFIGS_SOURCE_FILE)" \
  69. --env "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE=$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \
  70. --env "COMPONENT_SDKCONFIG_RENAMES=$(strip $(COMPONENT_SDKCONFIG_RENAMES))" \
  71. --env "IDF_CMAKE=n" \
  72. $(DEFAULTS_ARG) \
  73. --output config ${SDKCONFIG} \
  74. --output makefile $(SDKCONFIG_MAKEFILE) \
  75. --output header $(BUILD_DIR_BASE)/include/sdkconfig.h
  76. endef
  77. ifeq ($(OS),Windows_NT)
  78. MENUCONFIG_CMD := $(KCONFIG_TOOL_DIR)/mconf-idf
  79. else
  80. MENUCONFIG_CMD := MENUCONFIG_STYLE=aquatic $(PYTHON) $(IDF_PATH)/tools/kconfig_new/menuconfig.py
  81. endif
  82. # macro for running menuconfig
  83. define RunMenuConf
  84. mkdir -p $(BUILD_DIR_BASE)/include/config
  85. cd $(BUILD_DIR_BASE); KCONFIG_AUTOHEADER=$(abspath $(BUILD_DIR_BASE)/include/sdkconfig.h) \
  86. KCONFIG_CONFIG=$(SDKCONFIG) \
  87. COMPONENT_KCONFIGS_SOURCE_FILE="$(COMPONENT_KCONFIGS_SOURCE_FILE)" \
  88. COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE="$(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)" \
  89. IDF_CMAKE=n \
  90. $(MENUCONFIG_CMD) $(IDF_PATH)/Kconfig
  91. endef
  92. ifndef MAKE_RESTARTS
  93. # menuconfig, defconfig and "GENCONFIG" configuration generation only
  94. # ever run on the first make pass, subsequent passes don't run these
  95. # (make often wants to re-run them as the conf tool can regenerate the
  96. # sdkconfig input file as an output file, but this is not what the
  97. # user wants - a single config pass is enough to produce all output
  98. # files.)
  99. #
  100. # To prevent problems missing genconfig, ensure none of these targets
  101. # depend on any prerequisite that may cause a make restart as part of
  102. # the prerequisite's own recipe.
  103. menuconfig: $(KCONFIG_TOOL_DIR)/mconf-idf | check_python_dependencies
  104. $(summary) MENUCONFIG
  105. ifdef BATCH_BUILD
  106. @echo "Can't run interactive configuration inside non-interactive build process."
  107. @echo ""
  108. @echo "Open a command line terminal and run 'make menuconfig' from there."
  109. @echo "See esp-idf documentation for more details."
  110. @exit 1
  111. else
  112. $(call RunConfGen)
  113. # RunConfGen before menuconfig ensures that deprecated options won't be ignored (they've got renamed)
  114. $(call RunMenuConf)
  115. # RunConfGen after menuconfig ensures that deprecated options are appended to $(SDKCONFIG) for backward compatibility
  116. $(call RunConfGen)
  117. endif
  118. # defconfig creates a default config, based on SDKCONFIG_DEFAULTS if present
  119. defconfig: | check_python_dependencies
  120. $(summary) DEFCONFIG
  121. $(call RunConfGen)
  122. # if neither defconfig or menuconfig are requested, use the GENCONFIG rule to
  123. # ensure generated config files are up to date
  124. $(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)
  125. $(summary) GENCONFIG
  126. $(call RunConfGen)
  127. touch $(SDKCONFIG_MAKEFILE) $(BUILD_DIR_BASE)/include/sdkconfig.h # ensure newer than sdkconfig
  128. else # "$(MAKE_RESTARTS)" != ""
  129. # on subsequent make passes, skip config generation entirely
  130. defconfig:
  131. menuconfig:
  132. endif
  133. .PHONY: config-clean defconfig menuconfig
  134. config-clean:
  135. $(summary) RM CONFIG
  136. MAKEFLAGS="" $(MAKE) -C $(KCONFIG_TOOL_DIR) clean
  137. rm -rf $(BUILD_DIR_BASE)/include/config $(BUILD_DIR_BASE)/include/sdkconfig.h \
  138. $(COMPONENT_KCONFIGS_SOURCE_FILE) $(COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE)