This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-targets.sh
executable file
·240 lines (185 loc) · 4.85 KB
/
build-targets.sh
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
#!/bin/bash
# Check we have verilator
if ! test $(which verilator)
then
echo "ERROR: verilator required for building the GDB Server"
exit 1
fi
TOOLCHAIN_DIR=$(cd "`dirname \"$0\"`"; pwd)
TOP=$(cd ${TOOLCHAIN_DIR}/..; pwd)
# ====================================================================
CLEAN_BUILD=no
DEBUG_BUILD=no
BUILD_DIR=${TOP}/build
VERILATOR_DIR=`pkg-config --variable=prefix verilator`
PICORV32_SRC_DIR=${TOP}/picorv32
RI5CY_SRC_DIR=${TOP}/ri5cy
JOBS=
LOAD=
# ====================================================================
function usage () {
MSG=$1
echo "${MSG}"
echo
echo "Usage: ./build-targets.sh [--build-dir <build_dir>]"
echo " [--jobs <count>] [--load <load>]"
echo " [--picorv32-source <source_dir>]"
echo " [--ri5cy-source <source_dir>]"
echo " [--single-thread]"
echo " [--clean]"
echo " [--debug]"
exit 1
}
# Parse options
until
opt=$1
case ${opt} in
--build-dir)
shift
BUILD_DIR=$(realpath -m $1)
;;
--jobs)
shift
JOBS=$1
;;
--load)
shift
LOAD=$1
;;
--picorv32-source)
shift
PICORV32_SRC_DIR=$1
;;
--ri5cy-source)
shift
RI5CY_SRC_DIR=$1
;;
--single-thread)
JOBS=1
LOAD=1000
;;
--clean)
CLEAN_BUILD=yes
;;
--debug)
DEBUG_BUILD=yes
;;
?*)
usage "Unknown argument $1"
;;
*)
;;
esac
[ "x${opt}" = "x" ]
do
shift
done
set -u
# ====================================================================
PICORV32_BUILD_DIR=${BUILD_DIR}/picorv32
RI5CY_BUILD_DIR=${BUILD_DIR}/ri5cy
echo " Top: ${TOP}"
echo " Toolchain: ${TOOLCHAIN_DIR}"
echo " Build Dir: ${BUILD_DIR}"
echo " PICORV32 Build Dir: ${PICORV32_BUILD_DIR}"
echo "PICORV32 Source Dir: ${PICORV32_SRC_DIR}"
echo " RI5CY Build Dir: ${RI5CY_BUILD_DIR}"
echo " RI5CY Source Dir: ${RI5CY_SRC_DIR}"
if [ "x${CLEAN_BUILD}" = "xyes" ]
then
for T in `seq 5 -1 1`
do
echo -ne "\rClean Build: yes (in ${T} seconds)"
sleep 1
done
echo -e "\rClean Build: yes "
rm -fr ${RI5CY_BUILD_DIR} ${PICORV32_BUILD_DIR}
else
echo "Clean Build: no"
fi
if [ "x${DEBUG_BUILD}" = "xyes" ]
then
export CFLAGS="-g3 -O0"
export CXXFLAGS="-g3 -O0"
fi
if [ ! -e ${PICORV32_SRC_DIR} ]
then
echo "PICORV32 source directory does not exist"
exit 1
fi
if [ ! -e ${RI5CY_SRC_DIR} ]
then
echo "RI5CY source directory does not exist"
exit 1
fi
# Default parallellism
processor_count="`(echo processor; cat /proc/cpuinfo 2>/dev/null echo processor) \
| grep -c processor`"
if [ "x${JOBS}" == "x" ]; then JOBS=${processor_count}; fi
if [ "x${LOAD}" == "x" ]; then LOAD=${processor_count}; fi
PARALLEL="-j ${JOBS} -l ${LOAD}"
JOB_START_TIME=
JOB_TITLE=
SCRIPT_START_TIME=`date +%s`
LOGDIR=${TOP}/logs
LOGFILE=${LOGDIR}/build-$(date +%F-%H%M).log
echo " Log file: ${LOGFILE}"
echo " Start at: "`date`
echo " Parallel: ${PARALLEL}"
echo ""
rm -f ${LOGFILE}
if ! mkdir -p ${LOGDIR}
then
echo "Failed to create log directory: ${LOGDIR}"
exit 1
fi
if ! touch ${LOGFILE}
then
echo "Failed to initialise logfile: ${LOGFILE}"
exit 1
fi
# ====================================================================
# Defines: msg, error, times_to_time_string, job_start, job_done,
# mkdir_and_enter, enter_dir, run_command
#
# Requires LOGFILE and SCRIPT_START_TIME environment variables to be
# set.
source common.sh
# ====================================================================
# Verilate PICORV32
# ====================================================================
job_start "Verilating PICORV32"
rm -rf ${PICORV32_BUILD_DIR}
mkdir_and_enter ${PICORV32_BUILD_DIR}
if ! run_command cp -r ${PICORV32_SRC_DIR}/scripts/gdbserver/* \
${PICORV32_BUILD_DIR}
then
error "Failed to copy files for PICORV32 build"
fi
if ! run_command make
then
error "Failed to verilate PICORV32"
fi
job_done
# ====================================================================
# Verilate RI5CY
# ====================================================================
job_start "Verilating RI5CY"
rm -rf ${RI5CY_BUILD_DIR}
mkdir_and_enter ${RI5CY_BUILD_DIR}
if ! run_command cp -r ${RI5CY_SRC_DIR}/* ${RI5CY_BUILD_DIR}
then
error "Failed to copy files for RI5CY build"
fi
enter_dir ${RI5CY_BUILD_DIR}/verilator-model
if ! run_command make
then
error "Failed to verilate R15CY"
fi
job_done
# ====================================================================
# Finished
# ====================================================================
SCRIPT_END_TIME=`date +%s`
TIME_STR=`times_to_time_string ${SCRIPT_START_TIME} ${SCRIPT_END_TIME}`
echo "All finished ${TIME_STR}." | tee -a ${LOGFILE}