Makefile 2.58 KB
Newer Older
1
#
John Tsichritzis's avatar
John Tsichritzis committed
2
# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
#
# SPDX-License-Identifier: BSD-3-Clause
#

AS          = $(CROSS_COMPILE)as
8
AR          = $(CROSS_COMPILE)ar
9
10
11
LD          = $(CROSS_COMPILE)ld
OC          = $(CROSS_COMPILE)objcopy
CPP         = $(CROSS_COMPILE)cpp
12
ROMLIB_GEN  = ./romlib_generator.py
13
14
15
BUILD_DIR   = $(BUILD_PLAT)/romlib
LIB_DIR     = $(BUILD_PLAT)/lib
WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
16
17
LIBS        = -lmbedtls -lfdt -lc
INC         = $(INCLUDES:-I%=-I../../%)
18
PPFLAGS     = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
19
OBJS        = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
20
MAPFILE     = $(BUILD_PLAT)/romlib/romlib.map
21

22
23
24
25
26
ifneq ($(PLAT_DIR),)
  WRAPPER_SOURCES   = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)
  WRAPPER_OBJS      = $(WRAPPER_SOURCES:.s=.o)
endif

27
28
29
30
31
32
33
V ?= 0
ifeq ($(V),0)
  Q := @
else
  Q :=
endif

34
LDFLAGS := --gc-sections -O1
35
ifeq ($(DEBUG),1)
36
   LDFLAGS += -Map=$(MAPFILE)
37
38
endif

39
40
41
42
43
ifeq (${ARM_ARCH_MINOR},0)
	ASFLAGS = -march=armv8-a
else
	ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
endif
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

.PHONY: all clean distclean

all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a

%.o: %.s
	@echo "  AS      $@"
	$(Q)$(AS) $(ASFLAGS) -o $@ $<

$(BUILD_DIR)/%.o: %.s
	@echo "  AS      $@"
	$(Q)$(AS) $(ASFLAGS) -o $@ $<

$(BUILD_DIR)/romlib.ld: romlib.ld.S
	@echo "  PP      $@"
	$(Q)$(CPP) $(PPFLAGS) -o $@ romlib.ld.S

$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
	@echo "  LD      $@"
	$(Q)$(LD) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
	@echo "  BIN     $@"
	$(Q)$(OC) -O binary $(BUILD_DIR)/romlib.elf $@

$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
	@echo "  VAR     $@"
71
	$(Q)$(ROMLIB_GEN) genvar --output $@ $<
72

73
$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
74
	@echo "  AR      $@"
75
76
77
78
79
80
81
82
83
84
85
86
	$(Q)$(AR) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)

$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
	@echo "  PRE     $@"
	$(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<

$(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i
	@echo "  WRP     $<"
	$(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
	@touch $@

$(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp
87

88
$(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp
John Tsichritzis's avatar
John Tsichritzis committed
89

90
$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
91
	@echo "  TBL     $@"
92
	$(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
93
94
95
96
97

clean:
	@rm -f $(BUILD_DIR)/*

-include $(BUILD_DIR)/romlib.d
98
-include $(BUILD_DIR)/jmptbl.d