developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2022, MediaTek Inc. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
| 7 | # Get local directory path |
| 8 | define GET_LOCAL_DIR |
| 9 | $(patsubst %/,%,$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))) |
| 10 | endef |
| 11 | |
| 12 | # Clear module source variable |
| 13 | define CLEAR_LOCAL_SRCS |
| 14 | $(eval $(1) :=) |
| 15 | endef |
| 16 | |
| 17 | define EXPAND_SUB_MAKEFILE |
| 18 | include $(S) |
| 19 | endef |
| 20 | |
| 21 | # Expand sub rules.mk |
| 22 | define INCLUDE_MAKEFILE |
| 23 | $(eval MODULES_SUB_MAKEFILE := $(patsubst %,%/rules.mk,$(1))) |
| 24 | $(foreach S,$(MODULES_SUB_MAKEFILE),$(eval $(EXPAND_SUB_MAKEFILE))) |
| 25 | endef |
| 26 | |
| 27 | # Determine option variable is defined or not then define it |
| 28 | define add_defined_option |
| 29 | ifdef $(1) |
| 30 | ifeq ($(findstring $(value $(1)), $(uppercase_table)),) |
| 31 | DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) |
| 32 | else |
| 33 | ifeq ($(strip $(value $(1))),y) |
| 34 | DEFINES += -D$(1)$(if $(value $(1)),=1,) |
| 35 | endif |
| 36 | endif |
| 37 | endif |
| 38 | endef |
| 39 | |
| 40 | define EXPAND_RULES_MAKEFILE |
| 41 | LOCAL_SRCS-y := |
| 42 | MODULE := |
| 43 | SUB_RULES-y := |
| 44 | include $(S) |
| 45 | endef |
| 46 | |
| 47 | # INCLUDE_MODULES macro expand included modules rules.mk |
| 48 | # Arguments: |
| 49 | # $(1) = MODULES variables |
| 50 | define 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))) |
| 54 | endef |
| 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) |
| 60 | define MAKE_LOCALS |
| 61 | $(eval $(call uppercase,$(2))_SOURCES += $(1)) |
| 62 | endef |
| 63 | |
developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 64 | # 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 |
| 70 | define 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 | |
| 88 | libraries: $(OBJS_TEMP) |
| 89 | endef |
| 90 | |
| 91 | # Include MTK configuration files |
| 92 | |
| 93 | # MTK makefile variables |
developer | d7e5948 | 2022-08-09 19:37:25 +0800 | [diff] [blame] | 94 | ifeq (${COREBOOT},1) |
| 95 | MTK_COMMON_CFG := $(MTK_PLAT)/common/coreboot_config.mk |
| 96 | else |
| 97 | MTK_COMMON_CFG := $(MTK_PLAT)/common/common_config.mk |
| 98 | endif |
developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 99 | MTK_PLAT := plat/mediatek |
| 100 | MTK_PLAT_SOC := ${MTK_PLAT}/${MTK_SOC} |
developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 101 | MTK_PLAT_CFG := $(MTK_PLAT_SOC)/plat_config.mk |
| 102 | MTK_PROJECT_CFG := $(MTK_PLAT)/project/$(PLAT)/project_config.mk |
| 103 | MTK_OPTIONS := $(MTK_PLAT)/build_helpers/options.mk |
| 104 | MTK_COND_EVAL := $(MTK_PLAT)/build_helpers/conditional_eval_options.mk |
| 105 | |
| 106 | # Indicate which BL should be built in command line |
developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 107 | ifeq (${NEED_BL32},yes) |
| 108 | MTK_BL := bl32 |
developer | 6d8e8f8 | 2022-06-20 10:25:35 +0800 | [diff] [blame] | 109 | else |
| 110 | MTK_BL := bl31 |
developer | e5732cc | 2022-03-24 10:55:08 +0800 | [diff] [blame] | 111 | endif |
| 112 | # Include common, platform, board level config |
| 113 | include $(MTK_COMMON_CFG) |
| 114 | include $(MTK_PLAT_CFG) |
| 115 | -include $(MTK_PROJECT_CFG) |
| 116 | include $(MTK_COND_EVAL) |
| 117 | include $(MTK_OPTIONS) |