-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfullBuild.bash
executable file
·287 lines (245 loc) · 6.24 KB
/
fullBuild.bash
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
#!/bin/bash
LIB=$(dirname "${BASH_SOURCE[0]}")
cd $LIB
. scripts/os.bash
. scripts/cpu.bash
#check cmake if installed
. scripts/check_program.bash
check_all
export CPU=$(nbcpu)
export CPU=$((CPU>4 ? 4 : CPU))
function hr(){
echo "---------------------------------------------------------------------------------"
}
#if the last command failed display the log and stop the program
function stopOnError(){
error=$1
log=$2
if [ $error -ne 0 ] ; then
cat $log
exit 1
fi
}
#launch cmake and make in a multicore maner
#if the build fails, it displays the logs
function cmakeBuild(){
directory=$1
target=$2
cmakelist='../../'
if [ $# -eq 3 ] ; then
cmakelist=$3
else
mkdir build/$1
cd build/$1
fi
tmplog=`$MKTEMP`
if [[ "${CMAKE_ARGS[@]}" == '' ]] ; then
cmake $cmakelist -DCMAKE_BUILD_TYPE=$2 >& $tmplog
else
eval "cmake $cmakelist -DCMAKE_BUILD_TYPE=$2 ${CMAKE_ARGS[@]} >& $tmplog"
fi
stopOnError $? $tmplog
cp $tmplog cmake.log
echo '' > $tmplog
if [ $XCODE -eq 0 ] ; then
make -j $CPU >& $tmplog
stopOnError $? $tmplog
else
xcodebuild >& $tmplog
stopOnError $? $tmplog
fi
mv $tmplog build.log
cd ../..
}
#recall cmake & make in a multicore maner
function cmakeBuildRecall(){
directory=$1
cmakelist='../../'
if [ $# -eq 2 ] ; then
cmakelist=$2
else
cd build/$directory
fi
tmplog=`$MKTEMP`
cmake $cmakelist >& $tmplog
stopOnError $? $tmplog
cp $tmplog cmake.log
echo '' > $tmplog
if [ $XCODE -eq 0 ] ; then
make -j $CPU >& $tmplog
stopOnError $? $tmplog
else
xcodebuild >& $tmplog
stopOnError $? $tmplog
fi
mv $tmplog build.log
cd ../..
}
#found all the CMakeLists.txt and create 3 targets to build (release, debug, release with debug info)
function buildDir(){
dir=$1
if [ ! -e $dir ] ; then
echo "Please cd into the root directory of DRL"
exit 1
fi
here=`pwd`
for subdir in $($FIND $dir/ -maxdepth 2 -name 'CMakeLists.txt' -printf '%h\n' | sort -rn | grep -v old) ; do
cd $here/$subdir
if [[ $PYTHON_ONLY -eq 1 && $subdir == "agent/cmaes" ]] ; then
continue
fi
if [ $CLEAR -eq 1 ] ; then
rm -rf build
rm -rf lib
echo "INFO : $subdir cleared."
continue
fi
if [ -e build ]; then
if [ $FORCE_REMOVE -eq 0 ]; then
echo "INFO : $subdir already contains a build directory. Just recall..."
if [ $BUILD_DEBUG -eq 1 ] ; then
if [ -e build/debug ] ; then
cmakeBuildRecall debug
else
cmakeBuild debug Debug
fi
else
if [ -e build/release ] ; then
cmakeBuildRecall release
else
cmakeBuild release Release
fi
if [ -e build/debug ] ; then
cmakeBuildRecall debug
else
cmakeBuild debug Debug
fi
if [ $BUILD_RELWITHDEB -eq 1 ] ; then
if [ -e build/relwithdeb ] ; then
cmakeBuildRecall relwithdeb
else
cmakeBuild relwithdeb RelWithDebInfo
fi
fi
fi
continue
else
echo "INFO : $subdir already contains a build directory. Removing it..."
rm -rf build/
fi
fi
if [[ -e lib && $FORCE_REMOVE -eq 1 ]]; then
rm -rf lib/
fi
#building
mkdir build
if [ $BUILD_DEBUG -eq 1 ] ; then
cmakeBuild debug Debug
else
cmakeBuild release Release
cmakeBuild debug Debug
if [ $BUILD_RELWITHDEB -eq 1 ] ; then
cmakeBuild relwithdeb RelWithDebInfo
fi
fi
echo "INFO : $subdir well builed. Congratz."
hr
done
cd $here
}
function merge_report(){
$FIND . -name 'build.log' -type f | xargs cat > build_report.log
}
function echo_usage(){
echo "usage : $0 [options...] "
echo "Following options are possible : "
echo "codeblocks | CB : generates Codeblocks projects"
echo "eclipse | EC : generates Eclipse projects"
echo "xcode | XC : generates Xcode projects"
echo "--force : always remove old build without asking"
echo "--clear : remove old build (without starting a new build)"
echo "--debug : build only debug"
echo "--with-cpp : build every c++ binaries"
echo "--report : merge all report into one (build_report.log) usefull for continuous integration"
echo "-j n : limit the build with n cpu (use all by default)"
echo "-with-relwithdeb : build also relwithdeb"
echo "--help | -h : displays this message"
}
export CMAKE_ARGS=''
export FORCE_REMOVE=''
export CLEAR=0
export XCODE=0
export BUILD_DEBUG=0
export BUILD_RELWITHDEB=0
export PYTHON_ONLY=1
REPORT=0
for ARG in $*
do
case $ARG in
"--help" | "-h")
echo_usage
exit 0
;;
"codeblocks" | "CB")
echo "Will generate Codeblocks projects"
export CMAKE_ARGS='-G "CodeBlocks - Unix Makefiles"'
;;
"eclipse" | "EC")
echo "Will generate Eclipse projects"
export CMAKE_ARGS='-G "Eclipse CDT4 - Unix Makefiles"'
;;
"xcode" | "XC")
echo "Will generate Xcode projects"
export CMAKE_ARGS='-G "Xcode"'
XCODE=1
;;
"--with-cpp")
echo "build every c++ binaries"
export PYTHON_ONLY=0
export CMAKE_ARGS='-DPYTHON_ONLY=OFF"'
XCODE=1
;;
"--force")
export FORCE_REMOVE='1'
;;
"--report")
REPORT=1
;;
"--clear")
CLEAR=1
;;
"--debug")
export BUILD_DEBUG=1
;;
"-j")
shift
export CPU=$1
;;
"-with-relwithdeb")
export BUILD_RELWITHDEB=1
;;
esac
done
echo "INFO : $CPU CPU used"
echo "INFO : cmake well found. Look what following to know if you need other software."
if [[ "$FORCE_REMOVE" == '' && $CLEAR -eq 0 ]] ; then
echo "QUESTION : if a subdirectory already contains a build, should I remove it ? (y/n) [y]:"
force_remove="a"
while [[ $force_remove != "" && $force_remove != "y" && $force_remove != "n" ]] ; do
read force_remove
done
hr
if [[ $force_remove == "n" ]] ; then
export FORCE_REMOVE=0
else
export FORCE_REMOVE=1
fi
fi
buildDir common
if [ $PYTHON_ONLY -eq 0 ] ; then
buildDir environment
fi
buildDir agent
if [ $REPORT -eq 1 ] ; then
merge_report
fi