-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
265 lines (209 loc) · 6.24 KB
/
Makefile
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#
# Before using make, you need to create the file dependencies:
#
# > script/gen.sh
#
# There are four builds possible, with output directories:
#
# obj/emu - using emulator
# obj/emu-debug - output debug info, using emulator
# obj/qpu - using hardware
# obj/qpu-debug - output debug info, using hardware
#
#==============================================================================
# NOTES
# =====
#
# * valgrind goes into a fit when used on `runTests`:
#
# --8346-- WARNING: Serious error when reading debug info
# --8346-- When reading debug info from /lib/arm-linux-gnueabihf/ld-2.28.so:
# --8346-- Ignoring non-Dwarf2/3/4 block in .debug_info
# --8346-- WARNING: Serious error when reading debug info
# --8346-- When reading debug info from /lib/arm-linux-gnueabihf/ld-2.28.so:
# --8346-- Last block truncated in .debug_info; ignoring
# ==8346== Conditional jump or move depends on uninitialised value(s)
# ==8346== at 0x401A5D0: index (in /lib/arm-linux-gnueabihf/ld-2.28.so)
# ...
#
# This has to do with valgrind not being able to read compressed debug info.
# Note that this happens in system libraries.
#
# Tried countering this with compiler options:
#
# * -Wa,--nocompress-debug-sections -Wl,--compress-debug-sections=none
# * -gz=none
#
# ...with no effect. This is somewhat logical, the system libraries are
# pre-compiled.
#
###############################################################################
#
# Stuff for external libraries
#
INCLUDE_EXTERN= \
-I ../CmdParameter/Lib \
-I mesa/include \
-I mesa/src
LIB_EXTERN= \
-Lobj/mesa/bin -lmesa
LIB_DEPEND=
ifeq ($(DEBUG), 1)
LIB_EXTERN += -L ../CmdParameter/obj-debug -lCmdParameter
LIB_DEPEND += ../CmdParameter/obj-debug/libCmdParameter.a
else
LIB_EXTERN += -L ../CmdParameter/obj -lCmdParameter
LIB_DEPEND += ../CmdParameter/obj/libCmdParameter.a
endif
ROOT= Lib
# Compiler and default flags
CXX= g++
LINK= $(CXX) $(CXX_FLAGS)
LIBS := $(LIB_EXTERN)
#
# -I is for access to bcm functionality
#
# -Wno-psabi avoids following note (happens in unit tests):
#
# note: parameter passing for argument of type ‘std::move_iterator<Catch::SectionEndInfo*>’ changed in GCC 7.1
#
# It is benign: https://stackoverflow.com/a/48149400
#
CXX_FLAGS = \
-Wall \
-Wconversion \
-Wno-psabi \
-I $(ROOT) $(INCLUDE_EXTERN) -MMD -MP -MF"$(@:%.o=%.d)"
# Object directory
OBJ_DIR := obj
# QPU or emulation mode
ifeq ($(QPU), 1)
$(info Building for QPU)
# Check platform before building.
# Can't be indented, otherwise make complains.
RET := $(shell Tools/detectPlatform.sh 1>/dev/null && echo "yes" || echo "no")
#$(info info: '$(RET)')
ifneq ($(RET), yes)
$(error QPU-mode specified on a non-Pi platform; aborting)
else
$(info Building on a Pi platform)
endif
CXX_FLAGS += -DQPU_MODE -I /opt/vc/include
OBJ_DIR := $(OBJ_DIR)/qpu
LIBS += -L /opt/vc/lib -l bcm_host
else
OBJ_DIR := $(OBJ_DIR)/emu
endif
# Debug mode
ifeq ($(DEBUG), 1)
CXX_FLAGS += -DDEBUG -g
OBJ_DIR := $(OBJ_DIR)-debug
else
# -DNDEBUG disables assertions
# -g0 still adds debug info, using -s instead
CXX_FLAGS += -DNDEBUG -s
endif
-include sources.mk
LIB = $(patsubst %,$(OBJ_DIR)/Lib/%,$(OBJ))
EXAMPLE_TARGETS = $(patsubst %,$(OBJ_DIR)/bin/%,$(EXAMPLES))
TESTS_OBJ = $(patsubst %,$(OBJ_DIR)/%,$(TESTS_FILES))
EXAMPLES_OBJ = $(patsubst %,$(OBJ_DIR)/%,$(EXAMPLES_EXTRA))
#$(info $(EXAMPLES_OBJ))
#
# Dependencies from list of object files
#
-include $(LIB:.o=.d)
-include $(EXAMPLES_OBJ:.o=.d)
-include $(TESTS_OBJ:.o=.d)
V3DLIB=$(OBJ_DIR)/libv3dlib.a
MESA_LIB = obj/mesa/bin/libmesa.a
# Top-level targets
.PHONY: help clean all lib test $(EXAMPLES) init
# Following prevents deletion of object files after linking
# Otherwise, deletion happens for targets of the form '%.o'
.PRECIOUS: $(OBJ_DIR)/%.o
help:
@echo 'Usage:'
@echo
@echo ' make [QPU=1] [DEBUG=1] [target]*'
@echo
@echo 'Where target:'
@echo
@echo ' help - Show this text'
@echo ' all - Build all test programs'
@echo ' clean - Delete all interim and target files'
@echo ' test - Run the unit tests'
@echo
@echo ' one of the test programs - $(EXAMPLES)'
@echo
@echo 'Flags:'
@echo
@echo ' QPU=1 - Output code for hardware. If not specified, the code is compiled for the emulator'
@echo ' DEBUG=1 - If specified, the source code and target code is shown on stdout when running a test'
@echo
all: $(V3DLIB) $(EXAMPLES)
clean:
rm -rf obj/emu obj/emu-debug obj/qpu obj/qpu-debug obj/test
init:
@./script/install.sh
@./script/detect_tabs.sh
@mkdir -p ./obj/test
#
# Targets for static library
#
$(V3DLIB): $(LIB) $(MESA_LIB)
@echo Creating $@
@ar rcs $@ $^
$(MESA_LIB):
cd mesa && make compile
# Rule for creating object files
$(OBJ_DIR)/%.o: %.cpp | init
@echo Compiling $<
@mkdir -p $(@D)
@$(CXX) -std=c++17 -c -o $@ $< $(CXX_FLAGS)
# Same thing for C-files
$(OBJ_DIR)/%.o: %.c | init
@echo Compiling $<
@mkdir -p $(@D)
@$(CXX) -x c -c -o $@ $< $(CXX_FLAGS)
$(OBJ_DIR)/bin/%: $(OBJ_DIR)/Examples/%.o $(EXAMPLES_OBJ) $(V3DLIB) $(LIB_DEPEND)
@echo Linking $@...
@mkdir -p $(@D)
@$(LINK) $^ $(LIBS) -o $@
$(OBJ_DIR)/bin/%: $(OBJ_DIR)/Tools/%.o $(V3DLIB) $(LIB_DEPEND)
@echo Linking $@...
@mkdir -p $(@D)
@$(LINK) $^ $(LIBS) -o $@
$(EXAMPLES) :% : $(OBJ_DIR)/bin/%
#
# Targets for Unit Tests
#
UNIT_TESTS := $(OBJ_DIR)/bin/runTests
## sudo required for QPU-mode on Pi
ifeq ($(QPU), 1)
SUDO := sudo
else
SUDO :=
endif
$(UNIT_TESTS): $(TESTS_OBJ) $(EXAMPLES_OBJ) $(V3DLIB) $(LIB_DEPEND)
@echo Linking unit tests
@mkdir -p $(@D)
@$(CXX) $(CXX_FLAGS) $(TESTS_OBJ) $(EXAMPLES_OBJ) -L$(OBJ_DIR) -lv3dlib $(LIBS) -o $@
runTests: $(UNIT_TESTS)
make_test: runTests ID Hello Rot3D ReqRecv GCD Tri detectPlatform OET
#
# Running unit test [fft][test2] in combination with the rest *sometimes* results in IO timeouts (Pi4 64bit).
# Running it separately appears to work fine.
# The infuriating bit is 'sometimes'.
#
test : make_test
@echo Running unit tests with \'$(SUDO) $(UNIT_TESTS)\'
@$(SUDO) $(UNIT_TESTS) -tce=*[fft][test2]*
@$(SUDO) $(UNIT_TESTS) -tc=*[fft][test2]*
###############################
# Gen stuff
################################
gen : $(OBJ_DIR)/sources.mk
$(OBJ_DIR)/sources.mk :
@mkdir -p $(@D)
@script/gen.sh