forked from RyanJeffresonUNSW/hart-software-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
targets.mk
205 lines (169 loc) · 6.72 KB
/
targets.mk
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#
# 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 build targets
#
all: config.h $(TARGET)
##############################################################################
#
# KConfig support
#
menuconfig:
$(CMD_PREFIX)menuconfig
@$(ECHO) " MENUCONFIG"
config:
$(CMD_PREFIX)menuconfig
@$(ECHO) " MENUCONFIG"
.config:
$(CMD_PREFIX)menuconfig
@$(ECHO) " MENUCONFIG"
config.h: .config
$(CMD_PREFIX)genconfig
@$(ECHO) " GENCONFIG"
genconfig: config.h
##############################################################################
#
# Files that use CSRs needs GCC extensions..
#
hss_clock.o: hss_clock.c config.h
@$(ECHO) " CC $@";
$(CMD_PREFIX)$(CC) $(CFLAGS_GCCEXT) $(OPT-y) $(INCLUDES) -c -o $@ $<
##############################################################################
#
# Build Targets
#
#coverage: CORE_CFLAGS +=-fsanitize=address
coverage: CORE_CFLAGS +=-fprofile-arcs -ftest-coverage
coverage: OPT-y:=-O0 # lcov seg-faults without at least -O1 for some reason..
coverage: clean $(TARGET)
profile: CFLAGS +=-pg -DLOOP_COUNT=10000
profile: clean $(TARGET)
./$(TARGET) >/dev/null 2>/dev/null
$(GPROF) $(TARGET) |less
.PHONY: clean cppcheck splint cscope cscope.files
clean:
$(CMD_PREFIX)$(RM) $(TARGET) $(TEST_TARGET) cppcheck.log splint.log valgrind.log \
$(OBJS:.o=.gcda) $(OBJS) $(OBJS:.o=.gcno) $(OBJS:.o=.c.gcov) $(OBJS:.o=.su) \
$(EXTRA_OBJS) $(EXTRA_OBJS:.o=.c.gcov) $(EXTRA_OBJS:.o=.su) \
$(TEST_OBJS) $(TEST_OBJS.o=.gcno) $(TEST_OBJS.o=.c.gcov) $(TEST_OBJS:.o=.su) \
$(DEPENDENCIES) \
gmon.out cscope.out \
error.log flawfinder.log sparse.log output.map config.h \
$(TARGET:.elf=.hex) $(TARGET:.elf=.lss) $(TARGET:.elf=.sym) $(TARGET:.elf=.bin)
$(CMD_PREFIX)$(RM) -r docs/DoxygenOutput
$(CMD_PREFIX)$(RM) -r lcovOutput coverage.info
$(CMD_PREFIX)$(RM) *.gcov
$(CMD_PREFIX)$(RM) *.lss *.hex *.sym
ifdef CONFIG_OPENSBI
+$(CMD-PREFIX)$(MAKE) -C thirdparty/opensbi CROSS_COMPILE=$(CROSS_COMPILE) CC=$(CC) clean V=$(V)
endif
$(CMD_PREFIX)$(RM) $(BINDIR)/hss* $(BINDIR)/output.map
distclean:
$(CMD_PREFIX)$(RM) $(OBJS) $(TARGET) cppcheck.log splint.log valgrind.log \
cscope.out cscope.files
$(CMD_PREFIX)$(RM) -r docs/DoxygenOutput
cppcheck: $(SRCS-y)
cppcheck --suppress=missingIncludeSystem -v --enable=all --inconclusive --std=posix \
-ibaremetal/polarfire-soc-bare-metal-library/examples -ithirdparty \
$(INCLUDES) -UDECLARE_CAUSE -UDECLARE_CSR -UDECLARE_INSN --force . \
>cppcheck.log 2>&1
sparse: REAL_CC:=$(CC)
sparse: MCMODEL:=
sparse: CC=cgcc
sparse: clean $(TARGET)
smatch: $(SRCS-y) $(EXTRA_SRCS-y) $(TEST_SRCS)
smatch $(INCLUDES) $(SRCS-y) $(EXTRA_SRCS-y) $(TEST_SRCS)
splint: $(SRCS-y)
find . -name \*.c -exec splint +posixlib -DPRIu64=\"llu\" -Dtarget_ulong="unsigned long" \
-Dasm="(void)" -weak $(INCLUDES) \
-D__riscv_xlen=64 -D__SIZEOF_POINTER__=8 -D__SIZEOF_INT__=4 -D__SIZEOF_SHORT__=2 \
\{\} \; >splint.log 2>&1
cscope: cscope.files cscope.out
cscope.files:
find . -name \*.[chS] > cscope.files
cscope.out: cscope.files
cscope -b
lcov: coverage
./$(TARGET) | tee foo
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/include/*' 'test/*' --output-file coverage2.info
mv coverage2.info coverage.info
genhtml coverage.info --output-directory lcovOutput
showloc:
@$(ECHO) -n "There are " && \
$(ECHO) -n `find . -name \*.[chs] -exec wc -l \{\} \; | awk '{count += $$1;} END { print count;}'` && \
$(ECHO) " lines of source code"
valgrind: CC=cc
valgrind: MCMODEL:=
valgrind: $(TARGET)
valgrind -v --tool=memcheck --show-reachable=yes --leak-check=yes --track-origins=yes \
./$(TARGET) 2> valgrind.log
doxygen:
doxygen docs/doxygen.cfg
$(MAKE) -C docs/DoxygenOutput/latex all
flawfinder:
flawfinder `find . -type d | grep -v thirdparty | grep -v .git | grep -v baremetal | tail -n +2` baremetal/drivers baremetal/polarfire-soc-bare-metal-library/src >flawfinder.log
showsize:
@echo
@$(SIZE) $(TARGET) 2>/dev/null
showfullsize: hss.elf
@echo
@$(NM) --print-size --size-sort --radix=x hss.elf
@$(READELF) -e hss.elf
ifdef CONFIG_CC_DUMP_STACKSIZE
showstack: hss.elf
@echo
@cat `find . -name \*.su` | awk '{print $$2 " " $$0}' | sort -rn | cut -d " " -f 2- | head -20
showmaxstack: hss.elf
@echo
@cat `find . -name \*.su` | awk '$$2>a {a=$$2; b=$$0} END {print b}'
endif
.PHONY: config clean docs distclean doxygen showsize \
cppcheck splint sparse smatch cscope lcov valgrind flawfinder
help:
@$(ECHO) "Valid targets include:"
@$(ECHO) " $ make" $(TARGET) " # Build binary"
@$(ECHO) " $ make clean # Delete all built files"
@$(ECHO) " $ make distclean # Fully clean all built files and test outputs"
@$(ECHO) ""
@$(ECHO) " $ make doxygen # Generate doxygen documentation"
@$(ECHO) " $ make cppcheck # Run cppcheck on source code"
@$(ECHO) " $ make splint # Run splint on source code"
@$(ECHO) " $ make sparse # Run sparse on source code"
@$(ECHO) " $ make smatch # Run smatch on source code"
@$(ECHO) " $ make cscope # Build cscope database"
@$(ECHO) " $ make lcov # Rebuild instrumented binaries and run lcov"
@$(ECHO) " $ make valgrind # Run valgrind on binary"
@$(ECHO) " $ make flawfinder # Run flawfinder on this directory"
@$(ECHO) ""
@$(ECHO) " $ make showloc # Print number of lines of code"
@$(ECHO) " $ make showsize # Print information about binary size"
@$(ECHO) " $ make showfullsize # Dump detailed information about object sizes"
ifdef CONFIG_CC_DUMP_STACKSIZE
@$(ECHO) " $ make showstack # Print top 10 functions by stack usage"
@$(ECHO) " $ make showmaxstack # Print top function by stack usage"
endif
@$(ECHO) " $ make dep # Remake dependencies"