-
Notifications
You must be signed in to change notification settings - Fork 1
/
mybuild
executable file
·231 lines (207 loc) · 5.65 KB
/
mybuild
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
#!/bin/bash
#------------------------------------------------------------------------------
# Author : Albert Akhriev, [email protected]
# Copyright : IBM Research Ireland, 2017-2018
#------------------------------------------------------------------------------
CONF=Debug # Release
FULL=false
TEST=false
TEST_DIR=app
BUILD_DIR=build
OUTPUT_DIR=output
RAMDISK=
NO_RAMDISK=false
RAMDISK_SIZE=512
LINUX=false
MACOS=false
useNCPUs=1
if [[ "$(uname)" == 'Linux' ]]; then
echo "Linux OS"
LINUX=true
# This custom script (if presents) activates a fresh
# g++ compiler on RedHat 7 system.
if [ -f ${HOME}/bin/enable-gcc6.sh ]; then
source ${HOME}/bin/enable-gcc6.sh
fi
elif [[ "$(uname)" == 'Darwin' ]]; then
echo "Mac OS"
MACOS=true
else
echo "Unknown OS"
fi
# N O T E: any subsequent(*) commands which fail will cause
# the shell script to exit immediately:
set -e
# Function prints a warning regarding this script.
function About()
{
echo
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Please, do NOT use this script to build a production code."
echo "It was designed solely for the development, testing and debugging."
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
echo
}
# Function retrieves the number of available CPUs on this computer.
GetNumberCPUs()
{
# Get the number of CPUs to run building and testing.
if ${LINUX}; then
NCPUs=$(grep -c ^processor /proc/cpuinfo)
elif ${MACOS}; then
NCPUs=$(sysctl -n hw.ncpu)
fi
echo "Number of available CPUs: ${NCPUs}"
ONE=1
useNCPUs=$((NCPUs-ONE))
echo "Number of CPUs used for building and testing: ${useNCPUs}"
echo
}
# Function creates symbolic link from $1 to $RAMDISK/$1.
MakeSymbolicLink()
{
# Remove file or folder which is not a symbolic link.
if [ ! -L $1 ] ; then
/bin/rm -fr $1
fi
# Create a destination folder.
if [ ! -e ${RAMDISK}/$1 ] ; then
mkdir -p ${RAMDISK}/$1
sync
fi
# Create a symbolic to the destination folder and clear it
# (otherwise on Mac OS we get a recursive symbolic link).
if ${LINUX}; then
if [ ! -d $1 ]; then
ln -svd ${RAMDISK}/$1 $1
/bin/rm -fr ${RAMDISK}/$1/*
fi
elif ${MACOS}; then
if [ ! -d $1 ]; then
ln -sv ${RAMDISK}/$1 $1
/bin/rm -fr ${RAMDISK}/$1/*
fi
fi
}
# Function creates a regular folder.
MakeNormalFolder()
{
# Remove symbolic link of the same name.
if [ -L $1 ] ; then
/bin/rm -f $1
fi
# Make a regular folder.
mkdir -p $1
sync
}
# Function creates the build and the output directories.
# Folders will be created inside a ramdisk for performance.
MakeAllFoldersNeeded()
{
if ${NO_RAMDISK}; then
if [ -e /dev/shm/allscale ] ; then
/bin/rm -fr /dev/shm/allscale
fi
MakeNormalFolder ${BUILD_DIR}
MakeNormalFolder ${OUTPUT_DIR}
elif ${LINUX}; then
RAMDISK=/dev/shm/allscale
MakeSymbolicLink ${BUILD_DIR}
MakeSymbolicLink ${OUTPUT_DIR}
elif ${MACOS}; then
RAMDISK=/Volumes/ramdisk
if [ -d ${RAMDISK} ]; then
echo "Ramdisk already exists: ${RAMDISK}"
else
echo "Creating a ramdisk ..."
bash ./scripts/helper/ramdisk_mac.sh create ${RAMDISK_SIZE}
echo "Ramdisk: ${RAMDISK}"
fi
sync
MakeSymbolicLink ${BUILD_DIR}
MakeSymbolicLink ${OUTPUT_DIR}
else
echo "Unknown OS"
exit 1
fi
echo "Build directory: ${BUILD_DIR}"
echo "Output directory: ${OUTPUT_DIR}"
echo
echo
}
# Function invokes cmake to configure the project files.
Configure()
{
CURR_DIR=$(pwd)
if ${FULL}; then
/bin/rm -fr ${BUILD_DIR}/*
#/bin/rm -fr ${OUTPUT_DIR}/*
fi
cd ${BUILD_DIR}
cmake -DCMAKE_BUILD_TYPE=${CONF} ${CURR_DIR}/code
cd ${CURR_DIR}
}
# Function generate ctags for Vim editor (ctags must exist).
GenerateCTags()
{
if [ -f /usr/bin/ctags ] ; then
ctags -R .
elif [ -f /usr/local/bin/ctags ] ; then
ctags -R .
fi
}
# Function builds the application and, possibly, runs the unit tests.
BuildAndTest()
{
cd ${BUILD_DIR}
if ${TEST} ; then
KALMAN_PY=${CURR_DIR}/code/app/test/kalman_test_plot.py
KALMAN_OUT=${TEST_DIR}/kalman_test.out
(make -j ${useNCPUs}) && \
(/bin/rm -fr ${TEST_DIR}/*.log) && \
(/bin/rm -fr ${TEST_DIR}/*.out) && \
(ctest -j ${useNCPUs}) && \
(cat ${TEST_DIR}/*.log) # && (python3 ${KALMAN_PY} ${KALMAN_OUT})
else
make -j ${useNCPUs}
fi
cd ${CURR_DIR}
}
# Print blank lines and a visual separator for better visibility.
for i in {1..100}; do echo; done
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
echo
# Parse the command line arguments.
# http://wiki.bash-hackers.org/howto/getopts_tutorial
while getopts ":fdrt" opt; do
case $opt in
f) # -f configuring and building
FULL=true
;;
d) # -d Debug mode
CONF=Debug
;;
r) # -r Release mode
CONF=Release
;;
t) # -t building and running the tests
TEST=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2; exit 1
;;
esac
done
About
echo "Building in >>>>> ${CONF} <<<<< mode"
GetNumberCPUs
MakeAllFoldersNeeded
Configure
GenerateCTags
BuildAndTest
About
echo
echo