forked from Leodau/sfml-vscode-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
185 lines (156 loc) · 3.22 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
#!/bin/bash
CMD=$1
BUILD=$2
VSCODE=$3
cwd=${PWD##*/}
if [[ $CMD == '' ]]; then
CMD=buildprod
fi
if [[ $BUILD == '' ]]; then
BUILD=Release
fi
if [[ $OSTYPE == 'linux-gnu'* || $OSTYPE == 'cygwin'* ]]; then
if [[ $OSTYPE == 'linux-gnueabihf' ]]; then
export PLATFORM=rpi
else
export PLATFORM=linux
fi
if [[ $NAME == '' ]]; then
export NAME=$cwd
fi
elif [[ $OSTYPE == 'darwin'* ]]; then
export PLATFORM=osx
if [[ $NAME == '' ]]; then
export NAME=$cwd
fi
elif [[ $OSTYPE == 'msys' || $OSTYPE == 'win32' ]]; then
export PLATFORM=windows
if [[ $NAME == '' ]]; then
export NAME=$cwd.exe
fi
fi
if [[ $VSCODE != 'vscode' ]]; then
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
if [[ $PLATFORM == 'windows' ]]; then
export PATH="/c/SFML-2.5.1/bin:/c/mingw32/bin:$PATH"
else
if [[ $PLATFORM == 'rpi' ]]; then
export PATH="/usr/local/gcc-8.1.0/bin:$PATH"
fi
fi
echo
echo build.sh PATH=$PATH
echo
fi
export MAKE_EXEC=make
if [[ $PLATFORM == 'windows' ]]; then
if [ $(type -P "mingw32-make.exe") ]; then
export MAKE_EXEC=mingw32-make.exe
elif [ $(type -P "make.exe") ]; then
export MAKE_EXEC=make.exe
fi
fi
if [[ $BUILD != "Release" && $BUILD != 'Debug' ]]; then
BUILD=Release
fi
PROF_EXEC=gprof
PROF_ANALYSIS_FILE=profiler_analysis.stats
dec=\=\=\=\=\=\=
display_styled() {
tput setaf $1
tput bold
echo $dec $2 $dec
tput sgr0
}
build_success() {
display_styled 2 "Build Succeeded"
}
build_success_launch() {
display_styled 2 "Build Succeeded: Launching bin/$BUILD/$NAME"
}
build_fail() {
display_styled 1 "Build Failed: Review the compile errors above"
tput sgr0
exit 1
}
build_prod_error() {
display_styled 1 "Error: buildprod must be run on Release build."
tput sgr0
exit 1
}
launch() {
display_styled 2 "Launching bin/$BUILD/$NAME"
}
launch_prod() {
display_styled 2 "Launching Production Build: $NAME"
}
profiler_done() {
display_styled 2 "Profiler Completed: View $PROF_ANALYSIS_FILE for details"
}
profiler_error() {
display_styled 1 "Error: Profiler must be run on Debug build."
tput sgr0
exit 1
}
profiler_osx() {
display_styled 1 "Error: Profiling (with gprof) is not supported on Mac OSX."
tput sgr0
exit 1
}
tput setaf 4
if [[ $CMD == 'buildrun' ]]; then
if $MAKE_EXEC BUILD=$BUILD; then
build_success_launch
bin/$BUILD/$NAME
else
build_fail
fi
elif [[ $CMD == 'build' ]]; then
if $MAKE_EXEC BUILD=$BUILD; then
build_success
else
build_fail
fi
elif [[ $CMD == 'rebuild' ]]; then
if $MAKE_EXEC BUILD=$BUILD rebuild; then
build_success
else
build_fail
fi
elif [[ $CMD == 'run' ]]; then
launch
bin/$BUILD/$NAME
elif [[ $CMD == 'buildprod' ]]; then
if [[ $BUILD == 'Release' ]]; then
if $MAKE_EXEC BUILD=$BUILD buildprod; then
build_success
else
build_fail
fi
else
build_prod_error
fi
elif [[ $CMD == 'profile' ]]; then
if [[ $PLATFORM == 'osx' ]]; then
profiler_osx
elif [[ $BUILD == 'Debug' ]]; then
if $MAKE_EXEC BUILD=$BUILD; then
build_success_launch
tput sgr0
bin/$BUILD/$NAME
tput setaf 4
gprof bin/Debug/$NAME gmon.out > $PROF_ANALYSIS_FILE
profiler_done
else
build_fail
fi
else
profiler_error
fi
else
tput setaf 1
tput bold
echo $dec Error: Command \"$CMD\" not recognized. $dec
tput sgr0
fi
tput sgr0