-
Notifications
You must be signed in to change notification settings - Fork 41
/
Makefile
214 lines (177 loc) · 7.22 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
# http://clarkgrubb.com/makefile-style-guide
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
CONFIG ?= examples/alpha250/fft/config.yml
SDK_PATH ?= .
MODE ?= development
SDK_FULL_PATH = $(realpath $(SDK_PATH))
HOST ?= 192.168.1.100
TMP ?= tmp
KOHERON_VERSION_FILE := $(SDK_PATH)/version
KOHERON_VERSION := $(shell cat $(KOHERON_VERSION_FILE))
VIVADO_VERSION := 2017.2
VIVADO_PATH := /opt/Xilinx/Vivado
PYTHON := python3
# Use GCC version >=7
GCC_VERSION := 9
# Use this command to set GCC_VERSION to 9 on Ubuntu 22.04
.PHONY: set_gcc_version
set_gcc_version:
unlink /usr/bin/arm-linux-gnueabihf-gcc
ln -s /usr/bin/arm-linux-gnueabihf-gcc-$(GCC_VERSION) /usr/bin/arm-linux-gnueabihf-gcc
arm-linux-gnueabihf-gcc --version
#BUILD_METHOD := native
BUILD_METHOD = docker
.PHONY: help
help:
@echo ' - all : (Default goal) build the instrument: fpga, server and web'
@echo ' - run : Run the instrument'
@echo ' - fpga : Build the FPGA bitstream'
@echo ' - server : Build the server'
@echo ' - web : Build the web interface'
@echo ' - os : Build the operating system'
@echo ' - image : Build the root file system (run as root)'
@echo ' - block_design : Build the Vivado block design interactively'
@echo ' - open_project : Open the Vivado .xpr project'
# Directory for storing the build artifacts
PROJECT_PATH := $(dir $(CONFIG))
TMP_PROJECT_PATH := $(TMP)/$(PROJECT_PATH)
# Python script that manages the instrument configuration
MAKE_PY := SDK_PATH=$(SDK_PATH) $(PYTHON) $(SDK_PATH)/make.py
MEMORY_YML := $(TMP_PROJECT_PATH)/memory.yml
# Number of CPU cores available for parallel execution
N_CPUS ?= $(shell nproc 2> /dev/null || echo 1)
NAME := $(shell $(MAKE_PY) --name $(CONFIG) $(TMP_PROJECT_PATH)/name && cat $(TMP_PROJECT_PATH)/name)
###############################################################################
# DOCKER
###############################################################################
DOCKER_PATH := $(SDK_PATH)/docker
DOCKER_MK ?= $(DOCKER_PATH)/docker.mk
include $(DOCKER_MK)
###############################################################################
# INSTRUMENT
###############################################################################
# The instrument is packaged in a zip file that contains:
# - FPGA bitstream
# - TCP / Websocket server
# - Bash configuration script
# - Web files (HTML, CSS, Javascript)
BITSTREAM := $(TMP_PROJECT_PATH)/$(NAME).bit # FPGA bitstream
SERVER := $(TMP_PROJECT_PATH)/serverd # TCP / Websocket server executable that communicates with the FPGA
VERSION_FILE := $(TMP_PROJECT_PATH)/version
$(VERSION_FILE): $(CONFIG)
$(MAKE_PY) --version $(CONFIG) $@
# Zip file that contains all the files needed to run the instrument:
INSTRUMENT_ZIP := $(TMP_PROJECT_PATH)/$(NAME).zip
$(INSTRUMENT_ZIP): server $(BITSTREAM) web $(VERSION_FILE)
zip --junk-paths $(INSTRUMENT_ZIP) $(BITSTREAM) $(SERVER) $(WEB_ASSETS) $(VERSION_FILE)
@echo [$@] OK
# Make builds the instrument zip file by default
.PHONY: all
all: $(INSTRUMENT_ZIP)
# The "run" target launches the instrument on the Zynq board
# this is done via the HTTP API (see os/api)
.PHONY: run
run: $(INSTRUMENT_ZIP)
curl -v -F $(NAME).zip=@$(INSTRUMENT_ZIP) http://$(HOST)/api/instruments/upload
curl http://$(HOST)/api/instruments/run/$(NAME)
@echo
###############################################################################
# FPGA BITSTREAM
###############################################################################
OS_PATH := $(SDK_PATH)/os
OS_MK ?= $(OS_PATH)/os.mk
FPGA_PATH := $(SDK_PATH)/fpga
FPGA_MK ?= $(FPGA_PATH)/fpga.mk
include $(FPGA_MK)
###############################################################################
# TCP / WEBSOCKET SERVER
###############################################################################
SERVER_PATH := $(SDK_PATH)/server
SERVER_MK ?= $(SERVER_PATH)/server.mk
include $(SERVER_MK)
###############################################################################
# C++ CLIENT
###############################################################################
CLIENT_PATH := $(PROJECT_PATH)/client
ifneq ("$(wildcard $(CLIENT_PATH)/client.mk)","")
-include $(CLIENT_PATH)/client.mk
else
PHONY: client
client:
@echo 'No client available for this instrument'
endif
###############################################################################
# WEB FILES
###############################################################################
WEB_PATH := $(SDK_PATH)/web
WEB_MK ?= $(WEB_PATH)/web.mk
include $(WEB_MK)
###############################################################################
# LINUX OS
###############################################################################
include $(OS_MK)
###############################################################################
# TESTS
###############################################################################
TESTS_PATH := $(SDK_PATH)/tests
TESTS_MK ?= $(TESTS_PATH)/tests.mk
include $(TESTS_MK)
###############################################################################
# PYTHON
###############################################################################
PYTHON_PATH := $(SDK_PATH)/python
PYTHON_MK ?= $(PYTHON_PATH)/python.mk
include $(PYTHON_MK)
###############################################################################
# SETUP TARGETS
###############################################################################
.PHONY: setup
setup: setup_docker setup_fpga setup_server setup_web setup_os
.PHONY: setup_base
setup_base:
sudo apt-get install -y g++-$(GCC_VERSION)-arm-linux-gnueabihf
sudo rm -f /usr/bin/arm-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-g++
sudo ln -s /usr/bin/arm-linux-gnueabihf-gcc-$(GCC_VERSION) /usr/bin/arm-linux-gnueabihf-gcc
sudo ln -s /usr/bin/arm-linux-gnueabihf-g++-$(GCC_VERSION) /usr/bin/arm-linux-gnueabihf-g++
sudo apt-get install -y $(PYTHON)-pip
sudo apt-get install -y curl
$(PIP) install -r $(SDK_PATH)/requirements.txt
$(PIP) install $(SDK_PATH)/python
.PHONY: setup_docker
setup_docker: setup_base
sudo bash docker/install_docker.sh
sudo usermod -aG docker $(shell whoami)
sudo docker build -t gnu-gcc-9.5 ./docker/.
.PHONY: setup_fpga
setup_fpga: setup_base
sudo apt-get install device-tree-compiler
sudo rm -f /usr/bin/gmake && sudo ln -s make /usr/bin/gmake
.PHONY: setup_server
setup_server: setup_base
.PHONY: setup_web
setup_web: setup_base
sudo apt-get install -y nodejs
# sudo apt-get install -y node-typescript
# sudo apt-get install -y npm # npm installed with nodejs
# sudo rm -f /usr/bin/node && sudo ln -s /usr/bin/nodejs /usr/bin/node
npm install typescript
npm install @types/[email protected] @types/[email protected] websocket @types/node
.PHONY: setup_os
setup_os: setup_base
sudo apt-get install -y libssl-dev bc qemu-user-static zerofree
sudo apt-get install -y lib32stdc++6 lib32z1 u-boot-tools
###############################################################################
# CLEAN TARGETS
###############################################################################
# The "clean" target only removes the files related to the instrument specified by $(NAME)
# Use "clean_all" to remove everything
.PHONY: clean
clean:
rm -rf $(patsubst %/.,%,$(TMP_PROJECT_PATH))
.PHONY: clean_all
clean_all:
rm -rf $(TMP)