forked from phoenix-rtos/phoenix-rtos-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
134 lines (108 loc) · 2.93 KB
/
Makefile.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# Common makefile for Phoenix-RTOS 3
#
# Copyright 2020 Phoenix Systems
#
# %LICENSE%
#
#
# Check TARGET and set building options
#
TARGET_FAMILY ?= $(firstword $(subst -, ,$(TARGET)-))
TARGET_SUBFAMILY ?= $(word 2,$(subst -, ,$(TARGET)-))
# ARM Cortex Mx
TARGETS_ARMCORTEXM = \
armv7m3-stm32l152xd \
armv7m3-stm32l152xe \
armv7m4-stm32l4x6 \
armv7m7-imxrt105x \
armv7m7-imxrt106x \
armv7m7-imxrt117x
TARGETS = $(TARGETS_ARMCORTEXM)
ifneq (,$(filter $(TARGETS_ARMCORTEXM),$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)))
TARGET_SUFF ?= armv7m
endif
# ARM Cortex Ax
TARGETS_ARMCORTEXA = \
armv7a7-imx6ull
TARGETS += $(TARGETS_ARMCORTEXA)
ifneq (,$(filter $(TARGETS_ARMCORTEXA),$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)))
TARGET_SUFF ?= arm
endif
# IA32
TARGETS_IA32 += ia32-generic
TARGETS += $(TARGETS_IA32)
ifneq (,$(filter $(TARGETS_IA32),$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)))
TARGET_SUFF ?= ia32
endif
#RISCV64
TARGETS_RISCV64 += \
riscv64-spike \
riscv64-virt
TARGETS += $(TARGETS_RISCV64)
ifneq (,$(filter $(TARGETS_RISCV64),$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)))
TARGET_SUFF ?= riscv64
endif
TARGETS += host-pc
ifeq ($(TARGET_FAMILY), host)
TARGET_SUFF ?= host
endif
# Check target
ifeq (,$(filter $(TARGETS),$(TARGET_FAMILY)-$(TARGET_SUBFAMILY)))
$(error Incorrect TARGET $(TARGET_FAMILY)-$(TARGET_SUBFAMILY). Available targets: $(TARGETS))
endif
#
# Establish sed tool
#
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SED += gsed
else
SED = sed
endif
#
# Common rules
#
# reset compilation flags
CFLAGS :=
TOPDIR := $(CURDIR)
PREFIX_BUILD ?= ../_build/$(TARGET)
PREFIX_BUILD := $(abspath $(PREFIX_BUILD))
BUILD_DIR ?= $(PREFIX_BUILD)/$(notdir $(TOPDIR))
BUILD_DIR := $(abspath $(BUILD_DIR))
# build artifacts dir
CURR_SUFFIX := $(patsubst $(TOPDIR)/%,%,$(abspath $(CURDIR))/)
PREFIX_O := $(BUILD_DIR)/$(CURR_SUFFIX)
# target install paths, can be provided exterally
PREFIX_A ?= $(PREFIX_BUILD)/lib/
PREFIX_H ?= $(PREFIX_BUILD)/include/
PREFIX_PROG ?= $(PREFIX_BUILD)/prog/
PREFIX_PROG_STRIPPED ?= $(PREFIX_BUILD)/prog.stripped/
# add include path for auto-generated files
#CFLAGS += -I"$(BUILD_DIR)/$(CURR_SUFFIX)"
ifneq ($(KERNEL), 1)
CFLAGS += -I$(PREFIX_H)
endif
ARCH = $(SIL)@mkdir -p $(@D); \
(printf "AR %-24s\n" "$(@F)"); \
$(AR) $(ARFLAGS) $@ $^ 2>/dev/null
LINK = $(SIL)mkdir -p $(@D); \
(printf "LD %-24s\n" "$(@F)"); \
$(LD) $(LDFLAGS) -o "$@" $^ $(LDLIBS)
HEADER = $(SIL)mkdir -p $(@D); \
(printf "HEADER %-24s\n" "$<"); \
cp -pR "$<" "$@"
$(PREFIX_O)%.o: %.c
@mkdir -p $(@D)
$(SIL)(printf "CC %-24s\n" "$<")
$(SIL)$(CC) -c $(CFLAGS) "$<" -o "$@"
$(SIL)$(CC) -M -MD -MP -MF $(PREFIX_O)$*.c.d -MT "$@" $(CFLAGS) $<
$(PREFIX_O)%.o: %.S
@mkdir -p $(@D)
$(SIL)(printf "ASM %-24s\n" "$<")
$(SIL)$(CC) -c $(CFLAGS) "$<" -o "$@"
$(SIL)$(CC) -M -MD -MP -MF $(PREFIX_O)$*.S.d -MT "$@" $(CFLAGS) $<
$(PREFIX_PROG_STRIPPED)%: $(PREFIX_PROG)%
@mkdir -p $(@D)
@(printf "STR %-24s\n" "$(@F)")
$(SIL)$(STRIP) --strip-unneeded -o $@ $<