-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
248 lines (200 loc) · 6.76 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
# ----------------------------------------------------------------------------#
# --------------- MAKEFILE FOR DELTAFLOW-ON-ARTIQ ----------------------------#
# ----------------------------------------------------------------------------#
# --------------- DECLARATIONS -----------------------------------------------#
.DEFAULT_GOAL := help
.PHONY: help
help: ## List of main goals
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / \
{printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
ifeq ($(OS),Windows_NT)
# Windows is not supported!
else
# Some commands are different in Linux and Mac
UNAME_S := $(shell uname -s)
# User's credential will be passed to the image and container
USERNAME=$(shell whoami)
USER_UID=$(shell id -u)
USER_GID=$(shell id -g)
endif
PWD=$(shell pwd)
IMAGENAME=deltaflow-on-artiq
CONTAINERNAME=deltaflow-on-artiq
ENV_HASH=$(shell cat enviroment/Dockerfile-env enviroment/apt-list | shasum -a 1 | tr " " "\n" | head -n 1)
DEXEC = docker exec $(shell cat container)
BUILD_THREADS := $(shell cat /proc/cpuinfo | grep processor | wc -l)
ifeq ($(shell uname -s),Darwin)
HOST=OSX
else
ifneq (,$(findstring NT,$(shell uname -s)))
HOST=windows
else
HOST=linuxX11
endif
endif
.PHONY: external-deps
external-deps:
git submodule init
git submodule update
# Passing arguments to documentation builder in docs/Makefile
# i.e. `make docs command` in ./ --> `make command` in ./docs/
#
# For HTML documentation run `make docs html`, then
# open docs/_build/html/index.html in your favourite browser.
#
# Ref https://stackoverflow.com/a/14061796
# Ref https://stackoverflow.com/a/9802777/3454146
FORDOCS=$(firstword $(MAKECMDGOALS))
ifeq ($(FORDOCS), $(filter $(FORDOCS), docs dev-docs))
DOCS_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
$(eval $(DOCS_ARGS):;@:)
endif
# --------------- DOCKER STUFF -----------------------------------------------#
.PHONY: image
image: environment/Dockerfile
docker build . \
--tag ${IMAGENAME} \
--build-arg USERNAME=${USERNAME} \
--build-arg USER_UID=${USER_UID} \
--build-arg USER_GID=${USER_GID} \
--file environment/Dockerfile
# build a docker image called image-* from a dockerfile environment/Dockerfile-*
image-%: environment/Dockerfile-%
docker build ./environment \
-t $@ \
--network=host \
--build-arg USERNAME=${USERNAME} \
--build-arg USER_UID=${USER_UID} \
--build-arg USER_GID=${USER_GID} \
-f $<
LPWD = $(shell pwd)
WPWD = $(shell cygpath -w ${PWD})
container:
make image
docker run \
--rm -dt \
-v `pwd`:/workdir \
-w /workdir \
--name=${CONTAINERNAME} \
--privileged \
--cidfile=container \
${IMAGENAME} /bin/bash
mkdir -p build
.PHONY: shell
shell: container
docker exec -it $(shell cat container) /bin/bash
shell-tools: image-tools
docker run --rm -it -v `pwd`:/workdir -w /workdir image-tools /bin/bash
ADRUN=docker run --rm -v `pwd`:/workdir -w /workdir image-artiq-nix
.PHONY: ashell
ashell: image-artiq-nix
${ADRUN}
.PHONY: anotebook
anotebook: image-artiq-nix
docker run \
-it --rm \
-v `pwd`:/workdir \
-w /workdir \
${IMAGENAME}-artiq \
bash -c ". ~/.profile && jupyter notebook"
CPPFLAGS=-std=c++17 \
-DSC_CPLUSPLUS=201703L \
-D_FORTIFY_SOURCE=2 \
-faligned-new \
-fstack-protector \
-Wno-maybe-uninitialized \
-Wall \
-g \
-grecord-gcc-switches \
-O2 \
-pipe \
-fPIE \
-Wno-error=sign-compare
SYSC_INC = -I$(shell ${DEXEC} printenv SYSTEMC_INCLUDE)
TBB_INC = -I$(shell ${DEXEC} printenv TBB_INCLUDE)
PYINCLUDES = $(shell ${DEXEC} python3.8-config --cflags)
VERILATOR_BASE =/usr/local/share/verilator
VERILATOR_INC = -I${VERILATOR_BASE}/include/ -I${VERILATOR_BASE}/include/vltstd/
INCLUDE = ${SYSC_INC} ${TBB_INC} ${PYINCLUDES} ${VERILATOR_INC} -I./
SYSC_LNK = -L$(shell ${DEXEC} printenv SYSTEMC_HOME)/lib-linux64/
VERILATOR_LNK=-L${VERILATOR_BASE}/include/
TBB_LNK = -L$(shell ${DEXEC} printenv TBB_LIBRARY_RELEASE)
PYLINK=/usr/local/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.a \
$(shell ${DEXEC} python3.8-config --ldflags)
VERILATOR_TRACE_FILES=${VERILATOR_BASE}/include/verilated.cpp \
${VERILATOR_BASE}/include/verilated_vcd_c.cpp \
${VERILATOR_BASE}/include/verilated_vcd_sc.cpp
# add sub-makefiles to keep the build logic or examples and tests somewhat confined
include emulator/or-tlm/Makefile
include emulator/Makefile
include demos/deltalanguage/Makefile
include demos/deltasimulator/Makefile
include demos/deltaflow_on_artiq/Makefile
###########################
# Start of the real targets - the basic idea for the build process is to
# map everything into SystemC and build testbenches there, and go via verilog
# so we can get to real hardware if needed.
###########################
# same trick for explicitly present verilog.
# this only works for verilog present before a make invocation, this is deliberate.
VERILOG_SOURCES := $(shell find . -name '*.v')
vpath %.v $(dir ${VERILOG_SOURCES})
build/verilated/V%.cpp: %.v container
-${DEXEC} verilator \
-CFLAGS "${CPPFLAGS}" \
--sc $< \
--Mdir build/verilated/ \
--top-module $(basename $(notdir $<)) \
-I$(dir $<) \
-Wno-lint
# some prereqs may be generated as part of the build process - pick those
# up seperatly.
build/verilated/V%.cpp: build/%.v container
-${DEXEC} verilator \
-CFLAGS "${CPPFLAGS}" \
--sc $< \
--Mdir build/verilated/ \
--top-module $(basename $(notdir $<)) \
-I$(dir $<) \
-Wno-lint
build/verilated/V%.h: build/verilated/V%.cpp
-echo
build/verilated/V%__ALL.a: build/verilated/V%.cpp
${DEXEC} make -C build/verilated/ -j \
-f $(addsuffix .mk, $(basename $(notdir $^))) $(notdir $@)
# can use ANY V*.mk file to build this object.
# pipe ignores up-to-dateness of prereq, as long as it exists.
build/verilated.o: build/verilated/VAXILiteTarget.cpp
${DEXEC} make -C build/verilated/ -j -f VAXILiteTarget.mk verilated.o
cp build/verilated/verilated.o build/ | true
CPP_SOURCES := $(shell find . -name '*.cpp')
vpath %.cpp $(dir ${CPP_SOURCES})
## default cpp rule for nodeps objects
build/%.o: %.cpp container
${DEXEC} g++ ${CPPFLAGS} ${INCLUDE} -o $@ -c $<
# --------------- DOCUMENTATION ----------------------------------------------#
.PHONY: docs
docs: container ## Generate docs
${DEXEC} make -C docs $(DOCS_ARGS)
# --------------- CLEANING ---------------------------------------------------#
.PHONY: clean
clean: clean-build clean-data clean-docs clean-logs clean-container
.PHONY: clean-build
clean-build:
-rm -f vivado*.jou vivado*.log
-rm -rf build/
-find . -type f -name "*.o" -exec rm -f {} \;
.PHONY: clean-container
clean-container: ## Stop and remove the container
docker ps -q --filter "name=${CONTAINERNAME}" | grep -q . && \
docker stop ${CONTAINERNAME}
rm -f container
.PHONY: clean-data
clean-data:
rm -f *.vcd *.png
.PHONY: clean-docs
clean-docs:
make -C docs clean
.PHONY: clean-logs
clean-logs: ## Clean logs
rm -f docs/sphinx-build-*.log