forked from lnis-uofu/OpenFPGA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
122 lines (102 loc) · 3.9 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
#
# Top Makefile
# ------------
#
# Top-level makefile to compile the codebase
#
# Following options are available
#
# .. option:: BUILD_TYPE=<string>
#
# Pick the type of compilation. Can be either ``release`` or ``debug``. By default, release mode is selected (full optimization on runtime).
#
# .. option:: CMAKE_FLAGS=<string>
#
# Force compilation flags for CMake to generate Makefiles
BUILD_TYPE ?= release
# Convert to lower case for consistency
BUILD_TYPE := $(shell echo ${BUILD_TYPE} | tr '[:upper:]' '[lower]')
# Trim any _pgo or _strict in the build type name (since it would not match any of CMake's standard build types
CMAKE_BUILD_TYPE := $(shell echo ${BUILD_TYPE} | sed 's/_\?pgo//' | sed 's/_\?strict//')
# Allow users to pass parameters to cmake, without defining build types
# e.g. make CMAKE_FLAGS="-DCMAKE_CXX_COMPILER=g++-9'
override CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -G 'Unix Makefiles' ${CMAKE_FLAGS}
# -s : Suppress makefile output (e.g. entering/leaving directories)
# --output-sync target : For parallel compilation ensure output for each target is synchronized (make version >= 4.0)
MAKEFLAGS := -s
# Directory to build the codes
SOURCE_DIR :=${PWD}
BUILD_DIR ?= build
CMAKE_GOALS = all
# Find CMake command from system variable, otherwise use a default one
ifeq ($(origin CMAKE_COMMAND),undefined)
CMAKE_COMMAND := cmake
else
CMAKE_COMMAND := ${CMAKE_COMMAND}
endif
# Define executables
PYTHON_EXEC ?= python3
CLANG_FORMAT_EXEC ?= clang-format-10
XML_FORMAT_EXEC ?= xmllint
PYTHON_FORMAT_EXEC ?= black
# Put it first so that "make" without argument is like "make help".
export COMMENT_EXTRACT
# Put it first so that "make" without argument is like "make help".
help:
@${PYTHON_EXEC} -c "$$COMMENT_EXTRACT"
.PHONY: help
checkout:
# Update all the submodules
git submodule init
git submodule update --init --recursive
prebuild:
# Run cmake to generate Makefile under the build directory, before compilation
@mkdir -p ${BUILD_DIR} && \
echo "cd ${BUILD_DIR} && ${CMAKE_COMMAND} ${CMAKE_FLAGS} ${SOURCE_DIR}" && \
cd ${BUILD_DIR} && ${CMAKE_COMMAND} ${CMAKE_FLAGS} ${SOURCE_DIR}
compile: | prebuild
# Compile the code base. By default, all the targets will be compiled
# Following options are available
# .. option:: CMAKE_GOALS
#
# Define the target for cmake to compile. for example, ``cmake_goals=openfpga`` indicates that only openfpga binary will be compiled
echo "Building target(s): ${CMAKE_GOALS}"
@+${MAKE} -C ${BUILD_DIR} ${CMAKE_GOALS}
list_cmake_targets: | prebuild
# Show the targets available to be built, which can be specified through ``CMAKE_GOALS`` when compile
cd ${BUILD_DIR} && make help && cd -
all: checkout
# A shortcut command to run checkout and compile in serial
@+${MAKE} compile
format-cpp:
# Format all the C/C++ files under this project, excluding submodules
for f in `find libs openfpga -iname *.cpp -o -iname *.hpp -o -iname *.c -o -iname *.h`; \
do \
${CLANG_FORMAT_EXEC} --style=file -i $${f} || exit 1; \
done
format-xml:
# Format all the XML files under this project, excluding submodules
for f in `find openfpga_flow/vpr_arch openfpga_flow/openfpga_arch -iname *.xml`; \
do \
XMLLINT_INDENT=" " && ${XML_FORMAT_EXEC} --format $${f} --output $${f} || exit 1; \
done
format-py:
# Format all the python scripts under this project, excluding submodules
for f in `find openfpga_flow/scripts -iname *.py`; \
do \
${PYTHON_FORMAT_EXEC} $${f} --line-length 100 || exit 1; \
done
format-all: format-cpp format-xml format-py
# Format all the C/C++, XML and Python codes
clean:
# Remove current build results
rm -rf ${BUILD_DIR} yosys/install
# Functions to extract comments from Makefiles
define COMMENT_EXTRACT
import re
with open ('Makefile', 'r' ) as f:
matches = re.finditer('^([a-zA-Z-_]*):.*\n#(.*)', f.read(), flags=re.M)
for _, match in enumerate(matches, start=1):
header, content = match[1], match[2]
print(f" {header:10} {content}")
endef