forked from pulp-platform/mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (146 loc) · 5.58 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
# Copyright 2021 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
# Author: Matheus Cavalcante, ETH Zurich
# Samuel Riedel, ETH Zurich
SHELL = /usr/bin/env bash
ROOT_DIR := $(patsubst %/,%, $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
MEMPOOL_DIR := $(shell git rev-parse --show-toplevel 2>/dev/null || echo $$MEMPOOL_DIR)
# Include configuration
config_mk = $(abspath $(ROOT_DIR)/config/config.mk)
include $(config_mk)
INSTALL_PREFIX ?= install
SOFTWARE_DIR ?= software
INSTALL_DIR ?= ${ROOT_DIR}/${INSTALL_PREFIX}
GCC_INSTALL_DIR ?= ${INSTALL_DIR}/riscv-gcc
ISA_SIM_INSTALL_DIR ?= ${INSTALL_DIR}/riscv-isa-sim
LLVM_INSTALL_DIR ?= ${INSTALL_DIR}/llvm
HALIDE_INSTALL_DIR ?= ${INSTALL_DIR}/halide
BENDER_INSTALL_DIR ?= ${INSTALL_DIR}/bender
VERILATOR_INSTALL_DIR ?= ${INSTALL_DIR}/verilator
RISCV_TESTS_DIR ?= ${ROOT_DIR}/${SOFTWARE_DIR}/riscv-tests
CMAKE ?= cmake
# CC and CXX are Makefile default variables that are always defined in a Makefile. Hence, overwrite
# the variable if it is only defined by the Makefile (its origin in the Makefile's default).
ifeq ($(origin CC),default)
CC = gcc
endif
ifeq ($(origin CXX),default)
CXX = g++
endif
BENDER_VERSION = 0.23.2
# We need a recent LLVM installation (>11) to compile Verilator.
# We also need to link the binaries with LLVM's libc++.
# Define CLANG_PATH to be the path of your Clang installation.
# At IIS, check .gitlab/.gitlab-ci.yml for an example CLANG_PATH.
ifneq (${CLANG_PATH},)
CLANG_CC := $(CLANG_PATH)/bin/clang
CLANG_CXX := $(CLANG_PATH)/bin/clang++
CLANG_CXXFLAGS := "-nostdinc++ -isystem $(CLANG_PATH)/include/c++/v1"
CLANG_LDFLAGS := "-L $(CLANG_PATH)/lib -Wl,-rpath,$(CLANG_PATH)/lib -lc++ -nostdlib++"
else
CLANG_CC ?= clang
CLANG_CXX ?= clang++
CLANG_CXXFLAGS := ""
CLANG_LDFLAGS := ""
endif
# Default target
all: toolchain riscv-isa-sim halide
# Halide
halide:
mkdir -p $(HALIDE_INSTALL_DIR)
cd toolchain/halide && mkdir -p build && cd build; \
$(CMAKE) \
-DLLVM_DIR=$(LLVM_INSTALL_DIR)/lib/cmake/llvm \
-DCMAKE_INSTALL_PREFIX=$(HALIDE_INSTALL_DIR) \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_CXX_COMPILER=$(CXX) \
-DCMAKE_C_COMPILER=$(CC) \
-DWITH_PYTHON_BINDINGS=OFF \
-DCMAKE_BUILD_TYPE=Release \
.. && \
make -j4 all && \
make install
# Toolchain
toolchain: tc-riscv-gcc tc-llvm
tc-riscv-gcc:
mkdir -p $(GCC_INSTALL_DIR)
cd $(CURDIR)/toolchain/riscv-gnu-toolchain && rm -rf build && mkdir -p build && cd build && \
../configure --prefix=$(GCC_INSTALL_DIR) --with-arch=rv32im --with-cmodel=medlow --enable-multilib && \
$(MAKE) MAKEINFO=true -j4
tc-llvm:
mkdir -p $(LLVM_INSTALL_DIR)
cd $(CURDIR)/toolchain/llvm-project && mkdir -p build && cd build; \
$(CMAKE) \
-DCMAKE_INSTALL_PREFIX=$(LLVM_INSTALL_DIR) \
-DCMAKE_CXX_COMPILER=$(CXX) \
-DCMAKE_C_COMPILER=$(CC) \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_TARGETS_TO_BUILD="RISCV;host" \
-DLLVM_BUILD_DOCS="0" \
-DLLVM_ENABLE_BINDINGS="0" \
-DLLVM_ENABLE_TERMINFO="0" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=Release \
../llvm && \
make -j4 all && \
make install
riscv-isa-sim: update_opcodes
cd toolchain/riscv-isa-sim && mkdir -p build && cd build; \
../configure --prefix=$(ISA_SIM_INSTALL_DIR) && make && make install
# Unit tests for verification
.PHONY: test build_test clean_test
test: build_test
export PATH=$(ISA_SIM_INSTALL_DIR)/bin:$$PATH; \
make -C $(RISCV_TESTS_DIR)/isa run && \
config=minpool COMPILER=gcc make -C $(SOFTWARE_DIR) test && \
config=minpool make -C hardware verilate_test
build_test: update_opcodes
cd $(RISCV_TESTS_DIR); \
autoconf && ./configure --with-xlen=32 --prefix=$$(pwd)/target && \
make isa -j4 && make install && \
cd isa && make -j4 all
clean_test:
$(MAKE) -C hardware clean
$(MAKE) -C $(SOFTWARE_DIR) clean
$(MAKE) -C $(RISCV_TESTS_DIR) clean
# Bender
bender: check-bender
check-bender:
@if [ -x $(BENDER_INSTALL_DIR)/bender ]; then \
req="bender $(BENDER_VERSION)"; \
current="$$($(BENDER_INSTALL_DIR)/bender --version)"; \
if [ "$$(printf '%s\n' "$${req}" "$${current}" | sort -V | head -n1)" != "$${req}" ]; then \
rm -rf $(BENDER_INSTALL_DIR); \
fi \
fi
@$(MAKE) -C $(ROOT_DIR) $(BENDER_INSTALL_DIR)/bender
$(BENDER_INSTALL_DIR)/bender:
mkdir -p $(BENDER_INSTALL_DIR) && cd $(BENDER_INSTALL_DIR) && \
curl --proto '=https' --tlsv1.2 https://pulp-platform.github.io/bender/init -sSf | sh -s -- $(BENDER_VERSION)
# Verilator
verilator: $(VERILATOR_INSTALL_DIR)/bin/verilator
$(VERILATOR_INSTALL_DIR)/bin/verilator: toolchain/verilator Makefile
cd $<; unset VERILATOR_ROOT; \
autoconf && CC=$(CLANG_CC) CXX=$(CLANG_CXX) CXXFLAGS=$(CLANG_CXXFLAGS) LDFLAGS=$(CLANG_LDFLAGS) ./configure --prefix=$(VERILATOR_INSTALL_DIR) $(VERILATOR_CI) && \
make -j4 && make install
# Update and patch hardware dependencies for MemPool
# Previous changes will be stashed. Clear all the stashes with `git stash clear`
.PHONY: update-deps
update-deps:
for dep in $(shell git config --file .gitmodules --get-regexp path \
| awk '/hardware/{ print $$2 }'); do \
git -C $${dep} diff --quiet || { echo $${dep}; git -C $${dep} stash -u; }; \
git submodule update --init --recursive -- $${dep}; \
done
git apply hardware/deps/patches/*
# Helper targets
.PHONY: clean format apps
apps:
make -C $(SOFTWARE_DIR) apps
update_opcodes:
make -C toolchain/riscv-opcodes all
format:
$(ROOT_DIR)/scripts/run_clang_format.py --clang-format-executable=$(LLVM_INSTALL_DIR)/bin/clang-format -i -r $(ROOT_DIR)
clean: clean_test
rm -rf $(INSTALL_DIR)