mtk_build_helpers.mk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #
  2. # Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. # Get local directory path
  7. define GET_LOCAL_DIR
  8. $(patsubst %/,%,$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))
  9. endef
  10. # Clear module source variable
  11. define CLEAR_LOCAL_SRCS
  12. $(eval $(1) :=)
  13. endef
  14. define EXPAND_SUB_MAKEFILE
  15. include $(S)
  16. endef
  17. # Expand sub rules.mk
  18. define INCLUDE_MAKEFILE
  19. $(eval MODULES_SUB_MAKEFILE := $(patsubst %,%/rules.mk,$(1)))
  20. $(foreach S,$(MODULES_SUB_MAKEFILE),$(eval $(EXPAND_SUB_MAKEFILE)))
  21. endef
  22. # Determine option variable is defined or not then define it
  23. define add_defined_option
  24. ifdef $(1)
  25. ifeq ($(strip $(value $(1))),y)
  26. DEFINES += -D$(1)$(if $(value $(1)),=1,)
  27. else ifneq ($(strip $(value $(1))),n)
  28. DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),)
  29. endif
  30. endif
  31. endef
  32. define EXPAND_RULES_MAKEFILE
  33. LOCAL_SRCS-y :=
  34. MODULE :=
  35. SUB_RULES-y :=
  36. include $(S)
  37. endef
  38. # INCLUDE_MODULES macro expand included modules rules.mk
  39. # Arguments:
  40. # $(1) = MODULES variables
  41. define INCLUDE_MODULES
  42. $(eval MODULES_TEMP := $(1))
  43. $(eval MODULES_MAKEFILE := $(patsubst %,%/rules.mk,$(MODULES_TEMP)))
  44. $(foreach S,$(MODULES_MAKEFILE),$(eval $(EXPAND_RULES_MAKEFILE)))
  45. endef
  46. # MAKE_LOCALS expand module source file variable to BL${BL}_SOURCES
  47. # Arguments:
  48. # $(1) = source file
  49. # $(2) = BL stage (1, 2, 2u, 31, 32)
  50. define MAKE_LOCALS
  51. $(eval $(call uppercase,$(2))_SOURCES += $(1))
  52. endef
  53. # MAKE_MODULE reference MAKE_OBJS.
  54. # Create module folder under out/bl$(BL)/$(module)
  55. # Arguments:
  56. # $(1) = module name
  57. # $(2) = source file
  58. # $(3) = BL stage
  59. define MAKE_MODULE
  60. $(eval MODULE := $(strip $(1)))
  61. $(eval BUILD_DIR := ${BUILD_PLAT}/${3})
  62. $(eval SOURCES := $(2))
  63. $(eval OBJS_TEMP := $(addprefix $(BUILD_DIR)/$(MODULE)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
  64. $(eval MODULE_OBJS += $(OBJS_TEMP))
  65. $(eval $(call MAKE_OBJS,$(BUILD_DIR)/$(MODULE),$(SOURCES),${3}))
  66. libraries: $(OBJS_TEMP)
  67. endef
  68. # Include MTK configuration files
  69. # MTK makefile variables
  70. ifeq (${COREBOOT},1)
  71. MTK_COMMON_CFG := $(MTK_PLAT)/common/coreboot_config.mk
  72. else
  73. MTK_COMMON_CFG := $(MTK_PLAT)/common/common_config.mk
  74. endif
  75. MTK_PLAT := plat/mediatek
  76. MTK_PLAT_SOC := ${MTK_PLAT}/${MTK_SOC}
  77. MTK_PLAT_CFG := $(MTK_PLAT_SOC)/plat_config.mk
  78. MTK_PROJECT_CFG := $(MTK_PLAT)/project/$(PLAT)/project_config.mk
  79. MTK_OPTIONS := $(MTK_PLAT)/build_helpers/options.mk
  80. MTK_COND_EVAL := $(MTK_PLAT)/build_helpers/conditional_eval_options.mk
  81. MTK_BL := bl31
  82. # Include common, platform, board level config
  83. include $(MTK_COMMON_CFG)
  84. include $(MTK_PLAT_CFG)
  85. -include $(MTK_PROJECT_CFG)
  86. include $(MTK_COND_EVAL)
  87. include $(MTK_OPTIONS)