-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·325 lines (268 loc) · 5.85 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
oldCC=$CC
oldCXX=$CXX
# Set the compiler to clang
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
usage()
{
cat << EOF
This script can build, clean, and grab new versions,
usage: $0 options
OPTIONS:
-h Show this message
-v Verbose
-p Pull, pulls the latest code and all its gitmodules
-t Test Build, once built run the unit tests
-o Option, can be 'build', 'full' or 'os' [default: build]
-g Generate build files, can be 'osx', 'windows' or 'linux' [default: linux]
-n No Clean
EOF
}
# Make the build
makeIt()
{
beLoud=$1
if [[ $beLoud == 1 ]]; then
echo "Make Verbose"
make
else
echo "Make Quiet"
make >> /dev/null
fi
}
# Pull the latest stuff
pullCode()
{
beLoud=$1
if [[ $beLoud == 1 ]]; then
echo "Pull Verbose"
git submodule init
git submodule update --recursive
git submodule foreach git pull origin master --recurse-submodules
else
echo "Pull Quiet"
git submodule init >> /dev/null
git submodule update --recursive >> /dev/null
git submodule foreach git pull origin master --recurse-submodules >> /dev/null
fi
}
# Full Engine
fullEngine()
{
beLoud=$1
testIt=$2
doGenerate=$3
endEcho="Full Engine"
endResult="cmake -C CMakeConfigs/"
# Test Build
if [[ $testIt == 1 ]]; then
endEcho+=", Test"
endResult+="TestFull.txt"
else
endEcho+=", Non-Test"
endResult+="Full.txt"
fi
# Generate IDE builds or Make
if [[ $doGenerate == "osx" ]]; then
endEcho+=", XCode Build"
endResult+=" -G Xcode ."
elif [[ $doGenerate == "windows" ]]; then
endEcho+=", Ninja Build"
endResult+=" -G Ninja ."
else
endEcho+=", MakeFiles Build"
endResult+=" ."
fi
# Verbose
if [[ $beLoud == 1 ]]; then
endEcho+=", Verbose"
else
endEcho+=", Quiet"
endResult+=" >> /dev/null"
fi
echo $endEcho
eval $endResult
}
# OS Only
osOnly()
{
beLoud=$1
testIt=$2
doGenerate=$3
endEcho="OS Only"
endResult="cmake -C CMakeConfigs/"
# Test Build
if [[ $testIt == 1 ]]; then
endEcho+=", Test"
endResult+="TestOS.txt"
else
endEcho+=", Non-Test"
endResult+="OSOnly.txt"
fi
# Generate IDE builds or Make
if [[ $doGenerate == "osx" ]]; then
endEcho+=", XCode Build"
endResult+=" -G Xcode ."
elif [[ $doGenerate == "windows" ]]; then
endEcho+=", Ninja Build"
endResult+=" -G Ninja ."
else
endEcho+=", MakeFiles Build"
endResult+=" ."
fi
# Verbose
if [[ $beLoud == 1 ]]; then
endEcho+=", Verbose"
else
endEcho+=", Quiet"
endResult+=" >> /dev/null"
fi
echo $endEcho
eval $endResult
}
# Build
builder()
{
beLoud=$1
testIt=$2
endEcho="ReBuild"
endResult=""
# Testing
if [[ $testIt == 1 ]]; then
endEcho+=", Test"
endResult+="cmake -C CMakeConfigs/Test.txt ."
else
endEcho+=", Non-Test"
endResult+="cmake ."
fi
# Verbose
if [[ $beLoud == 1 ]]; then
endEcho+=", Verbose"
else
endEcho+=", Quiet"
endResult+=" >> /dev/null"
fi
echo $endEcho
eval $endResult
makeIt $beLoud
}
# Build Number
buildNumber()
{
buildName=$1
beLoud=$2
# Text file
#if [[ $beLoud == 1 ]]; then
# echo "awk -F, '{$1=$1+1}1' OFS= buildNumber.txt > buildNumberNew.txt && mv buildNumberNew.txt buildNumber.txt"
#fi
awk -F, '{$1=$1+1}1' OFS= buildNumber.txt > buildNumberNew.txt && mv buildNumberNew.txt buildNumber.txt
# Get the result
buildNumber=$(cat buildNumber.txt)
# Build the header
l1="#ifndef NORDICARTS_"
l1+=$buildName
l1+="_BUILDNUMBER"
l2="#define NORDICARTS_"
l2+=$buildName
l2+="_BUILDNUMBER "
l2+=$buildNumber
l3="#endif"
echo -e $l1 > $buildName/buildNumber.hpp
echo -e $l2 >> $buildName/buildNumber.hpp
echo -e $l3 >> $buildName/buildNumber.hpp
#if [[ $beLoud == 1 ]]; then
# echo $l2
#fi
}
# Variables
OPT='build'
GENERATE='linux'
VERBOSE=false
TEST=false
PULL=false
MAKER=false
CLEAN=1
# Go through the options
while getopts ":o:g:?phnvt" OPTION; do
case $OPTION in
o)
OPT=$OPTARG
;;
g)
GENERATE=$OPTARG
;;
t)
TEST=1
;;
p)
PULL=1
;;
n)
CLEAN=false
;;
h)
usage
exit 1
;;
v)
VERBOSE=1
;;
?)
usage
exit
;;
esac
done
# Clear screen
clear
# Pull
if [[ $PULL == 1 ]]; then
pullCode $VERBOSE
fi
# Build Standard
if [[ $OPT == "build" ]]; then
if [[ $CLEAN == 1 ]]; then
./cleaner.sh -t build
fi
buildNumber "NORDICENGINE" $VERBOSE
builder $VERBOSE $TEST
if [[ $CLEAN == true ]]; then
./cleaner.sh -t cmake
fi
fi
# Build OS
if [[ $OPT == "os" ]]; then
if [[ $CLEAN == 1 ]]; then
./cleaner.sh -t all
fi
buildNumber "NORDICENGINE" $VERBOSE
osOnly $VERBOSE $TEST $GENERATE
if [[ $GENERATE == "linux" ]]; then
makeIt $VERBOSE
fi
if [[ $CLEAN == 1 ]]; then
./cleaner.sh -t cmake
fi
fi
# Build Full
if [[ $OPT == "full" ]]; then
if [[ $CLEAN == 1 ]]; then
./cleaner.sh -t all
fi
buildNumber "NORDICENGINE" $VERBOSE
fullEngine $VERBOSE $TEST $GENERATE
if [[ $GENERATE == "linux" ]]; then
makeIt $VERBOSE
fi
if [[ $CLEAN == 1 ]]; then
./cleaner.sh -t cmake
fi
fi
# Run the tests if its supposed to
if [[ $TEST == 1 ]]; then
./UnitTests.app
fi
# Set Compiler Back
export CC=$CC
export CXX=$CXX