-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·226 lines (185 loc) · 3.72 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
#!/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
-n No Clean
-g Game Name
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
}
# Build Number
buildNumber()
{
buildName=$1
beLoud=$2
# Text file
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
}
# Game Library
gameLibrary()
{
beLoud=$1
testIt=$2
endEcho="GameLib"
endResult="cmake -C CMakeConfigs/"
# Test Builds
if [[ $testIt == 1 ]]; then
endEcho+=", Test"
endResult+="TestFull.txt"
else
endEcho+=", Non-Test"
endResult+="Full.txt"
fi
endResult+=" ."
# Verbose
if [[ $beLoud == 1 ]]; then
endEcho+=", Verbose"
else
endEcho+=", Quiet"
endResult+=" >> /dev/null"
fi
echo $endEcho
eval $endResult
}
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
}
# Variables
OPT='build'
GENERATE='linux'
VERBOSE=false
TEST=false
PULL=false
MAKER=false
CLEAN=1
GAMENAME="Game"
# Go through the options
while getopts ":o:g:?phvnt" OPTION; do
case $OPTION in
o)
OPT=$OPTARG
;;
t)
TEST=1
;;
n)
CLEAN=false
;;
p)
PULL=1
;;
h)
usage
exit 1
;;
v)
VERBOSE=1
;;
g)
GAMENAME=$OPTARG
;;
?)
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 $GAMENAME $VERBOSE
gameLibrary $VERBOSE $TEST
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