-
Notifications
You must be signed in to change notification settings - Fork 33
/
build.sh
executable file
·303 lines (267 loc) · 7.67 KB
/
build.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/env bash
# ***************************************************************************************
# Copyright (c) 2023-2025 Peng Cheng Laboratory
# Copyright (c) 2023-2025 Institute of Computing Technology, Chinese Academy of Sciences
# Copyright (c) 2023-2025 Beijing Institute of Open Source Chip
#
# iEDA is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
#
# See the Mulan PSL v2 for more details.
# ***************************************************************************************
set -e
# variables
IEDA_WORKSPACE=$(cd "$(dirname "$0")";pwd)
BINARY_TARGET="iEDA"
BINARY_DIR="${IEDA_WORKSPACE}/bin"
BUILD_DIR="${IEDA_WORKSPACE}/build"
CPP_COMPILER_PATH="g++-10"
RUN_IEDA="OFF"
NO_BUILD="OFF"
DEL_BUILD="OFF"
INSTALL_DEP="OFF"
BUILD_THREADS=""
# cmake defines
D_CMD_BUILD="-DCMD_BUILD=ON"
D_SANITIZER="-DSANITIZER=OFF"
D_CPP_COMPILER="-DCMAKE_CXX_COMPILER:FILEPATH=${CPP_COMPILER_PATH}"
D_BINARY_DIR="-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:FILEPATH=${BINARY_DIR}"
G_BUILD_GENERATOR=""
# pretty print
clear="\e[0m"
bold="\e[1m"
underline="\e[4m"
red="\e[31m"
yellow="\e[33m"
# functions
help_msg_exit()
{
echo -e "build.sh: Build iEDA executable binary"
echo -e "Usage:"
echo -e " ${bold}bash build.sh${clear} [-h] [-n] [-r] [-b] [-c] [-d] [-i] "
echo -e " [-b ${underline}binary path${clear}] [-c ${underline}compiler path${clear}]"
echo -e " [-j ${underline}num${clear}] [-i apt|docker]"
echo -e "Options:"
echo -e " ${bold}-h${clear} display this help and exit"
echo -e " ${bold}-n${clear} do not build iEDA (default OFF)"
echo -e " ${bold}-d${clear} delete build directory, (default OFF)"
echo -e " ${bold}-r${clear} run iEDA after build (default OFF)"
echo -e " ${bold}-j${clear} job threads for building iEDA (default -j128)"
echo -e " ${bold}-b${clear} iEDA binary path (default at ${BINARY_DIR})"
echo -e " ${bold}-c${clear} compiler(g++ version >= 10) path (default at \"$(which ${CPP_COMPILER_PATH})\")"
echo -e " ${bold}-i${clear} apt-get install (root permission) dependencies before build (default OFF)"
exit $1;
}
build_ieda()
{
if [[ ${DEL_BUILD} == "ON" ]]; then
rm -rf $BUILD_DIR
fi
check_build
# --graphviz=foo.dot
cmake -S$IEDA_WORKSPACE -B$BUILD_DIR $D_SANITIZER $D_CMD_BUILD $D_CPP_COMPILER $D_BINARY_DIR $G_BUILD_GENERATOR
cmake --build $BUILD_DIR $BUILD_THREADS --target $BINARY_TARGET
}
check_build()
{
check_gcc_version ${CPP_COMPILER_PATH}
check_cmake
set_build_generator_ninja
}
check_gcc_version()
{
if ! command_exists $1; then
echo -e "${red}ERROR: Compiler \"$1\" not found!
Please install or set g++(>=10) path
by ${bold}bash build.sh -c ${underline}compiler path${clear}"
help_msg_exit 1
fi
CPP_COMPILER_VERSION=$($1 --version | grep g++ | awk '{print $4+0}')
# echo "g++ version: ${CPP_COMPILER_VERSION}"
if [[ ${CPP_COMPILER_VERSION} < 10.0 ]]; then
echo -e "${red}ERROR: minimum g++ version: 10${clear}"
exit 1
fi
}
check_cmake()
{
if ! command_exists cmake ; then
echo -e "${red}ERROR: command \"cmake\" not found!
Please install or set cmake(>=3.11) path to env \$PATH${clear}"
help_msg_exit 1
fi
}
set_build_generator_ninja()
{
if command_exists ninja; then
G_BUILD_GENERATOR="-G Ninja"
fi
}
# for init developer environment, need sudo
install_dependencies_apt()
{
if command_exists apt-get; then
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y \
g++-10 cmake ninja-build \
tcl-dev libgflags-dev libgoogle-glog-dev libboost-all-dev libgtest-dev flex\
libeigen3-dev libyaml-cpp-dev libunwind-dev libmetis-dev libgmp-dev bison rustc cargo\
libhwloc-dev libcairo2-dev
exit 0
else
echo -e "${red}apt-get not found, pleas make sure you were running on Debian-Based Linux distribution${clear}"
exit 1
fi
}
install_dependencies()
{
if [[ $INSTALL_DEP == "apt" ]]; then
sys_requirement_warning
install_dependencies_apt
elif [[ $INSTALL_DEP == "mirror" ]]; then
sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
install_dependencies_apt
elif [[ $INSTALL_DEP == "docker" ]]; then
install_docker_experimental
else
echo "unknown arg $INSTALL_DEP"
help_msg_exit 1
fi
}
# sudo
opt_install_dependencies()
{
INSTALL_DEP=$1
}
command_exists() {
command -v "$@" > /dev/null 2>&1
}
read_continue_or_exit()
{
while true; do
read -p "Continue? (y/n) " answer
case $answer in
[Yy]* ) break ;;
[Nn]* ) exit 1 ;;
* ) echo "invalid answer";;
esac
done
}
# experimental function, (may) need sudo
install_docker_experimental()
{
if command_exists docker; then
echo -e "${yellow}Warning:"
echo -e " Docker exists, try \`docker pull iedaopensource/base:latest\` instead${clear}"
exit 1;
fi
echo -e "${yellow}Warning:\n Experimental option, caution with sudo!\n\
See https://docs.docker.com/engine/install for manual installation${clear}"
read_continue_or_exit
export DOWNLOAD_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
if command_exists curl; then
curl -fsSL https://get.docker.com/ | sh
elif command_exists wget; then
wget -O- https://get.docker.com/ | sh
else
echo -e "${red}ERROR: please install curl or wget first${clear}"
exit 1;
fi
}
# TODO
run_ieda()
{
${BINARY_DIR}/iEDA -script ${IEDA_WORKSPACE}/scripts/hello.tcl
}
sys_requirement_warning()
{
echo -e "${yellow}Warning:"
echo -e " iEDA had only been tested on Debian-Based Linux distribution (Debian 11, Ubuntu 20.04)"
echo -e " We recommend using Docker image (based on Debian 11): iedaopensource/base:latest"
echo -e " Continue the script may cause problems.${clear}"
read_continue_or_exit
}
perf_report_svg()
{
rm -rf perf_report
mkdir perf_report
for PROF_REPORT in *.prof; do
pprof --svg iEDA ${PROF_REPORT} > perf_report/${PROF_REPORT%.prof}.svg
done
}
opt_no_build()
{
NO_BUILD="ON"
}
opt_binary_dir()
{
echo "change CMAKE_RUNTIME_OUTPUT_DIRECTORY from ${BINARY_DIR} to $1"
BINARY_DIR=$1
D_BINARY_DIR="-DCMAKE_RUNTIME_OUTPUT_DIRECTORY:FILEPATH=${BINARY_DIR}"
}
opt_compiler_path()
{
check_gcc_version $1
echo "change CMAKE_CXX_COMPILER from ${CPP_COMPILER_PATH} to $1"
CPP_COMPILER_PATH=$1
D_CPP_COMPILER="-DCMAKE_CXX_COMPILER:FILEPATH=${CPP_COMPILER_PATH}"
}
opt_run_ieda()
{
RUN_IEDA="ON"
}
opt_jenkins()
{
echo "jenkins do not support task: ${OPTARG}"
help_msg_exit 1
}
# opt_dockerbuild()
# {
# # docker tag local-image:tagname new-repo:tagname
# # docker push new-repo:tagname
# }
opt_thread_num()
{
BUILD_THREADS="-j ${OPTARG}"
}
opt_del_build()
{
DEL_BUILD="ON"
}
opt_build_target()
{
BINARY_TARGET=${OPTARG}
}
# invalid args
if [[ $1 != "" ]] && [[ $1 != -* ]]; then
help_msg_exit 1
fi
while getopts j:t:b:c:dnhi:r opt; do
case "${opt}" in
j) opt_thread_num $OPTARG ;;
b) opt_binary_dir $OPTARG ;;
t) opt_build_target $OPTARG ;;
c) opt_compiler_path $OPTARG ;;
i) opt_install_dependencies $OPTARG ;;
r) opt_run_ieda ;;
n) opt_no_build ;;
d) opt_del_build ;;
h) help_msg_exit 0 ;;
*) help_msg_exit 1 ;;
esac
done
if [[ ${INSTALL_DEP} != "OFF" ]]; then
install_dependencies $INSTALL_DEP
fi
if [[ ${NO_BUILD} == "OFF" ]]; then
build_ieda
fi
if [[ ${RUN_IEDA} == "ON" ]]; then
run_ieda
fi