forked from polarfire-soc/hart-software-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules.mk
More file actions
173 lines (143 loc) · 5.28 KB
/
rules.mk
File metadata and controls
173 lines (143 loc) · 5.28 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#
# MPFS HSS Embedded Software
#
# Copyright 2019 Microchip Corporation.
#
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
#
# Defines Rules such as compiler and tool choice/settings, build flags, and
# basic build rules (.c to .o, etc)
#
CROSS_COMPILE?=riscv64-unknown-elf-
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
SIZE=$(CROSS_COMPILE)size
GPROF=$(CROSS_COMPILE)gprof
OBJCOPY=$(CROSS_COMPILE)objcopy
OBJDUMP=$(CROSS_COMPILE)objdump
READELF=$(CROSS_COMPILE)readelf
NM=$(CROSS_COMPILE)nm
ECHO=echo
MAKE=make
CP=cp
MAKEDEP=makedepend
PLATFORM_RISCV_ABI=lp64
PLATFORM_RISCV_ISA=rv64imac
CORE_CFLAGS+=$(MCMODEL) -mstrict-align
ifdef CONFIG_WITH_ARCH
CORE_CFLAGS+=-mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
endif
# Debug options
CORE_CFLAGS+=-g3 -DDEBUG -pipe -grecord-gcc-switches
# Warning / Code Quality
CORE_CFLAGS+=-Wall -Werror -Wshadow -fno-builtin-printf \
-fomit-frame-pointer -Wredundant-decls -Wall -Wundef -Wwrite-strings -fno-strict-aliasing \
-fno-common -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wformat=2 -Wformat-security \
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition \
-Wtype-limits -Wstrict-prototypes -Wimplicit-fallthrough=5
CORE_CFLAGS+=-mno-fdiv
# CORE_CFLAGS+=-fanalyzer
# Compiler hooks to enable link-time garbage collection
CORE_CFLAGS+=-ffunction-sections -fdata-sections
# Stack Usage
ifdef CONFIG_CC_DUMP_STACKSIZE
CORE_CFLAGS+=-fstack-usage
endif
#-ffreestanding
# TODO - introduce the following prototype warnings...
#CORE_CFLAGS+=-Wmissing-prototypes
# TODO - introduce the following conversion warnings... Currently fails on drivers and OpenSBI
#CORE_CFLAGS+=-Wconversion
# TODO - introduce trapv for integer overflows etc... Currently missing primitives
#CORE_CFLAGS+=-ftrapv
CFLAGS=-std=c11 $(CORE_CFLAGS) $(PLATFORM_CFLAGS) -Wmissing-prototypes
# separate flags for C files that need GCC Extensions...
CFLAGS_GCCEXT=$(CORE_CFLAGS) $(PLATFORM_CFLAGS)
#OPT-y=-O2
#OPT-y+=-Os -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las
OPT-y+=-Os -fno-strict-aliasing
ifndef CONFIG_LD_RELAX
OPT-y+=-Wl,--no-relax
endif
#
# for some reason, -flto isn't playing nicely currently with -fstack-protector-strong...
# Stack protection is really useful, but if it is enabled, for now disabling LTO optimisation
#
ifdef CONFIG_CC_STACKPROTECTOR_STRONG
$(info Not enabling -flto as stack protector enabled)
CORE_CFLAGS+=-fstack-protector-strong
# CORE_CFLAGS+=-fstack-clash-protection # currently does nothing on RISC-V
else
$(info NOTICE: enabling -flto (which means stack protection is disabled))
OPT-y+=-flto=auto -ffat-lto-objects -fcompare-debug -fno-stack-protector
endif
##############################################################################
#
# Build Rules
#
# Check if verbosity is ON for build process
CMD_PREFIX_DEFAULT := @
ifeq ($(V), 1)
CMD_PREFIX :=
else
CMD_PREFIX := $(CMD_PREFIX_DEFAULT)
endif
OBJS = $(SRCS-y:.c=.o)
%.S: %.c config.h
@$(ECHO) " CC -S $@";
$(CMD_PREFIX)$(CC) $(CFLAGS_GCCEXT) $(OPT-y) $(INCLUDES) -c -Wa,-adhln -g $< > $@
%.e: %.c config.h
@$(ECHO) " CC -E $@";
$(CMD_PREFIX)$(CC) $(CFLAGS_GCCEXT) $(OPT-y) $(INCLUDES) -c -E -o $@ $<
#%.dot: %.c config.h
# @$(ECHO) " DOT $@";
# $(CMD_PREFIX)$(CC) $(CFLAGS_GCCEXT) $(OPT-y) $(INCLUDES) -fdump-tree-all-graph -o $@ $<
ifdef CONFIG_CC_USE_MAKEDEP
%.o: %.c config.h %.d
else
%.o: %.c config.h
endif
@$(ECHO) " CC $@";
$(CMD_PREFIX)$(CC) $(CFLAGS) $(OPT-y) $(INCLUDES) -c -o $@ $<
%.o: %.S config.h
@$(ECHO) " CC $@";
$(CMD_PREFIX)$(CC) $(CFLAGS) $(defs) -D__ASSEMBLY__=1 -c $(INCLUDES) $< -o $@
%.hex: %.elf
@$(ECHO) " HEX $@";
$(CMD_PREFIX)$(OBJCOPY) -O ihex $< $@
$(CMD_PREFIX)$(OBJCOPY) -O ihex $< Default/$@
%.lss: %.elf
@$(ECHO) " LSS $@";
$(CMD_PREFIX)$(OBJDUMP) -h -S -z $< > $@
%.sym: %.elf
@$(ECHO) " NM $@";
$(CMD_PREFIX)$(NM) -n $< > $@
%.bin: %.elf
@$(ECHO) " BIN $@";
$(CMD_PREFIX)$(OBJCOPY) -O binary $< $@
#
%.d: %.c
@$(ECHO) " MAKEDEP $@";
$(CMD_PREFIX)$(MAKEDEP) -f - $(INCLUDES) $< 2>/dev/null | sed 's,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\n\1 : \2,g' > $*.d
%.d: %.S
@$(ECHO) " MAKEDEP $@";
$(CMD_PREFIX)$(MAKEDEP) -f - $(INCLUDES) $< 2>/dev/null | sed 's,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\n\1 : \2,g' > $*.d