project_config.mk 5.6 KB

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