Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 1 | # |
Chris Kay | c7ea347 | 2024-01-15 18:45:07 +0000 | [diff] [blame] | 2 | # Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 3 | # |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | # SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 5 | # |
| 6 | |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 7 | toolchains := rk3399-m0 |
| 8 | |
| 9 | include ../../../../../make_helpers/toolchain.mk |
| 10 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 11 | # Cross Compile |
| 12 | M0_CROSS_COMPILE ?= arm-none-eabi- |
| 13 | |
| 14 | # Build architecture |
| 15 | ARCH := cortex-m0 |
| 16 | |
| 17 | # Build platform |
| 18 | PLAT_M0 ?= rk3399m0 |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 19 | PLAT_M0_PMU ?= rk3399m0pmu |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 20 | |
| 21 | ifeq (${V},0) |
| 22 | Q=@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 23 | else |
| 24 | Q= |
| 25 | endif |
| 26 | export Q |
| 27 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 28 | .SUFFIXES: |
| 29 | |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 30 | INCLUDES += -Iinclude/ \ |
| 31 | -I../../include/shared/ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 32 | |
| 33 | # NOTE: Add C source files here |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 34 | C_SOURCES_COMMON := src/startup.c |
| 35 | C_SOURCES := src/dram.c \ |
Lin Huang | e7c2422 | 2016-11-30 16:57:08 +0800 | [diff] [blame] | 36 | src/stopwatch.c |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 37 | C_SOURCES_PMU := src/suspend.c |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 38 | |
| 39 | # Flags definition |
Julius Werner | f585246 | 2017-01-30 16:13:21 -0800 | [diff] [blame] | 40 | COMMON_FLAGS := -g -mcpu=$(ARCH) -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft |
| 41 | CFLAGS := -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common |
| 42 | ASFLAGS := -Wa,--gdwarf-2 |
| 43 | LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 44 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 45 | # NOTE: The line continuation '\' is required in the next define otherwise we |
| 46 | # end up with a line-feed characer at the end of the last c filename. |
| 47 | # Also bare this issue in mind if extending the list of supported filetypes. |
| 48 | define SOURCES_TO_OBJS |
| 49 | $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ |
| 50 | $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) |
| 51 | endef |
| 52 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 53 | SOURCES_COMMON := $(C_SOURCES_COMMON) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 54 | SOURCES := $(C_SOURCES) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 55 | SOURCES_PMU := $(C_SOURCES_PMU) |
| 56 | OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON))) |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 57 | OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES))) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 58 | OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU))) |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 59 | LINKERFILE := $(BUILD)/$(PLAT_M0).ld |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 60 | MAPFILE := $(BUILD)/$(PLAT_M0).map |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 61 | MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 62 | ELF := $(BUILD)/$(PLAT_M0).elf |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 63 | ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 64 | BIN := $(BUILD)/$(PLAT_M0).bin |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 65 | BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 66 | LINKERFILE_SRC := src/$(PLAT_M0).ld.S |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 67 | |
| 68 | # Function definition related compilation |
| 69 | define MAKE_C |
| 70 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
Julius Werner | 844782d | 2016-11-03 12:25:48 -0700 | [diff] [blame] | 71 | -include $(patsubst %.o,%.d,$(OBJ)) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 72 | |
| 73 | $(OBJ) : $(2) |
| 74 | @echo " CC $$<" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 75 | $$(Q)$(rk3399-m0-cc) $$(COMMON_FLAGS) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 76 | endef |
| 77 | |
| 78 | define MAKE_S |
| 79 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
| 80 | |
| 81 | $(OBJ) : $(2) |
| 82 | @echo " AS $$<" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 83 | $$(Q)$(rk3399-m0-cc) -x assembler-with-cpp $$(COMMON_FLAGS) $$(ASFLAGS) -c $$< -o $$@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 84 | endef |
| 85 | |
| 86 | define MAKE_OBJS |
| 87 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 88 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 89 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) |
| 90 | |
| 91 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 92 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 93 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) |
| 94 | |
| 95 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 96 | endef |
| 97 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 98 | .PHONY: all |
| 99 | all: $(BIN) $(BIN_PMU) |
| 100 | |
| 101 | .DEFAULT_GOAL := all |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 102 | |
| 103 | $(LINKERFILE): $(LINKERFILE_SRC) |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 104 | $(rk3399-m0-cc) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $< |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 105 | -include $(LINKERFILE).d |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 106 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 107 | $(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 108 | @echo " LD $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 109 | $(Q)$(rk3399-m0-cc) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 110 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 111 | %.bin : %.elf |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 112 | @echo " BIN $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 113 | $(Q)$(rk3399-m0-oc) -O binary $< $@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 114 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 115 | $(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE) |
| 116 | @echo " LD $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 117 | $(Q)$(rk3399-m0-cc) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 118 | |
| 119 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1))) |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 120 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1))) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 121 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1))) |