blob: 83a4dd2a191829b68512ba40d492f45426dc7307 [file] [log] [blame]
developere5732cc2022-03-24 10:55:08 +08001#
2# Copyright (c) 2022, MediaTek Inc. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# Get local directory path
8define GET_LOCAL_DIR
9$(patsubst %/,%,$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))))
10endef
11
12# Clear module source variable
13define CLEAR_LOCAL_SRCS
14$(eval $(1) :=)
15endef
16
17define EXPAND_SUB_MAKEFILE
18include $(S)
19endef
20
21# Expand sub rules.mk
22define INCLUDE_MAKEFILE
23$(eval MODULES_SUB_MAKEFILE := $(patsubst %,%/rules.mk,$(1)))
24$(foreach S,$(MODULES_SUB_MAKEFILE),$(eval $(EXPAND_SUB_MAKEFILE)))
25endef
26
27# Determine option variable is defined or not then define it
28define add_defined_option
29ifdef $(1)
30ifeq ($(findstring $(value $(1)), $(uppercase_table)),)
31DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),)
32else
33ifeq ($(strip $(value $(1))),y)
34DEFINES += -D$(1)$(if $(value $(1)),=1,)
35endif
36endif
37endif
38endef
39
40define EXPAND_RULES_MAKEFILE
41LOCAL_SRCS-y :=
42MODULE :=
43SUB_RULES-y :=
44include $(S)
45endef
46
47# INCLUDE_MODULES macro expand included modules rules.mk
48# Arguments:
49# $(1) = MODULES variables
50define INCLUDE_MODULES
51$(eval MODULES_TEMP := $(1))
52$(eval MODULES_MAKEFILE := $(patsubst %,%/rules.mk,$(MODULES_TEMP)))
53$(foreach S,$(MODULES_MAKEFILE),$(eval $(EXPAND_RULES_MAKEFILE)))
54endef
55
56# MAKE_LOCALS expand module source file variable to BL${BL}_SOURCES
57# Arguments:
58# $(1) = source file
59# $(2) = BL stage (1, 2, 2u, 31, 32)
60define MAKE_LOCALS
61$(eval $(call uppercase,$(2))_SOURCES += $(1))
62endef
63
developere5732cc2022-03-24 10:55:08 +080064# MAKE_MODULE reference MAKE_OBJS.
65# Create module folder under out/bl$(BL)/$(module)
66# Arguments:
67# $(1) = module name
68# $(2) = source file
69# $(3) = BL stage
70define MAKE_MODULE
71 $(eval MODULE := $(strip $(1)))
72 $(eval BUILD_DIR := ${BUILD_PLAT}/${3})
73 $(eval SOURCES := $(2))
74 $(eval OBJS_TEMP := $(addprefix $(BUILD_DIR)/$(MODULE)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
75 $(eval MODULE_OBJS += $(OBJS_TEMP))
76 # We use sort only to get a list of unique object directory names.
77 # ordering is not relevant but sort removes duplicates.
78 $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS_TEMP} ${LINKERFILE})))
79 # The $(dir ) function leaves a trailing / on the directory names
80 # Rip off the / to match directory names with make rule targets.
81 $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS)))
82
83$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR})))
84${3}_dirs: | ${OBJ_DIRS}
85
86$(eval $(call MAKE_OBJS,$(BUILD_DIR)/$(MODULE),$(SOURCES),${3}))
87
88libraries: $(OBJS_TEMP)
89endef
90
91# Include MTK configuration files
92
93# MTK makefile variables
developerd7e59482022-08-09 19:37:25 +080094ifeq (${COREBOOT},1)
95MTK_COMMON_CFG := $(MTK_PLAT)/common/coreboot_config.mk
96else
97MTK_COMMON_CFG := $(MTK_PLAT)/common/common_config.mk
98endif
developere5732cc2022-03-24 10:55:08 +080099MTK_PLAT := plat/mediatek
100MTK_PLAT_SOC := ${MTK_PLAT}/${MTK_SOC}
developere5732cc2022-03-24 10:55:08 +0800101MTK_PLAT_CFG := $(MTK_PLAT_SOC)/plat_config.mk
102MTK_PROJECT_CFG := $(MTK_PLAT)/project/$(PLAT)/project_config.mk
103MTK_OPTIONS := $(MTK_PLAT)/build_helpers/options.mk
104MTK_COND_EVAL := $(MTK_PLAT)/build_helpers/conditional_eval_options.mk
105
106# Indicate which BL should be built in command line
developere5732cc2022-03-24 10:55:08 +0800107ifeq (${NEED_BL32},yes)
108MTK_BL := bl32
developer6d8e8f82022-06-20 10:25:35 +0800109else
110MTK_BL := bl31
developere5732cc2022-03-24 10:55:08 +0800111endif
112# Include common, platform, board level config
113include $(MTK_COMMON_CFG)
114include $(MTK_PLAT_CFG)
115-include $(MTK_PROJECT_CFG)
116include $(MTK_COND_EVAL)
117include $(MTK_OPTIONS)