-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfigure.sh
executable file
·350 lines (296 loc) · 8.62 KB
/
configure.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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/sh
#
# colorful - simple 2D sideview shooter
# Copyright (C) 2022-2024 suve (a.k.a. Artur Frenszek-Iwicki)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 3,
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -eu
show_help() {
cat <<EOF
configure.sh for colorful
Accepted options:
--android BOOLEAN
Controls whether Android-specific build settings are enabled.
The default value is "false".
--assets <bundle, standalone, systemwide>
Specifies where the game should expect asset files to be located.
* bundle: Assets are expected to be found two directory levels
above the executable, like in the following structure:
- bin/linux64
- bin/win64
- gfx/
* standalone: Assets are expected to be found in the same directory,
right next to the executable.
* systemwide: Assets are expected to be found in
\${PREFIX}/share/suve/colorful.
The default value is "standalone".
This setting is ignored in Android builds.
--compat <auto, v1, v2>
Controls whether the game should be built with compatibility for old config
files and savegames. This means that users upgrading from an old version
of the game will have their settings and savegames preserved.
* v1: Include compat code for v1 files.
* v2: Support only v2 files.
The default value for this option is "auto", which resolves to "v2"
for Android builds and "v1" otherwise.
--debug BOOLEAN
Controls whether debugging features are enabled.
The default value is "false".
--donate BOOLEAN
Controls whether the "Donate" option appears in the main menu.
The default value is "true".
--fpc FULL_PATH
Use the Free Pascal Compiler located at FULL_PATH.
The default is to use "fpc".
--flags FLAGS
Pass FLAGS to fpc. Can be specified multiple times.
--ogg-quality QUALITY
Encode sound effects to .ogg with this quality setting.
The default value is "10".
--platform <auto, desktop, mobile>
Controls whether the game should be built in desktop mode (keyboard focus,
no touch controls) or mobile mode (touch, extra menus for accessibility).
The default value is "auto", which resolves to "mobile" for Android builds
and "desktop" otherwise.
--prefix PREFIX
Controls the prefix used when installing the app and - if built with
"assets" set to "systemwide" - when loading assets.
The default value is "/usr/local".
--strip BOOLEAN
Controls whether the built executable should be stripped of debug symbols.
The default value is "false".
Option syntax is "--option=value". "--option" "value" will not work.
For BOOLEAN options, the value can be omitted; it will be treated as \"true\".
EOF
}
# Helper functions
parse_bool() {
flag="${1}"
value="${2}"
if [ -z "${value}" ] || [ "${value}" = "true" ] || [ "${value}" = "yes" ] || [ "${value}" = "1" ]; then
echo "true"
elif [ "${value}" = "false" ] || [ "${value}" = "no" ] || [ "${value}" = "0" ]; then
echo "false"
else
echo "Error: The argument to ${flag} must be one of \"true\", \"yes\", \"1\", \"false\", \"no\", or \"0\"" >&2
exit 1
fi
}
# Set defaults
ANDROID="false"
ASSETS="standalone"
COMPAT="auto"
DEBUG="false"
DONATE="true"
FPC="fpc"
USER_FLAGS=""
OGG_QUALITY="10"
PLATFORM="auto"
PREFIX="/usr/local"
STRIP="false"
while [ "${#}" -gt 0 ]; do
if [ "${1}" = "--help" ]; then
show_help
exit
fi
opt="${1%%=*}"
val="${1#*=}"
if [ "${val}" = "${1}" ]; then
val=""
fi
shift
if [ "${opt}" = "--android" ]; then
ANDROID="$(parse_bool "--android" "${val}")"
elif [ "${opt}" = "--assets" ]; then
if [ "${val}" != "bundle" ] && [ "${val}" != "standalone" ] && [ "${val}" != "systemwide" ]; then
echo "Error: The argument to --assets must be one of \"bundle\", \"standalone\", or \"systemwide\"" >&2
exit 1
fi
ASSETS="${val}"
elif [ "${opt}" = "--compat" ]; then
if [ "${val}" != "auto" ] && [ "${val}" != "v1" ] && [ "${val}" != "v2" ]; then
echo "Error: The argument to --compat must be one of \"auto\", \"v1\" or \"v2\"" >&2
exit 1
fi
COMPAT="${val}"
elif [ "${opt}" = "--debug" ]; then
DEBUG="$(parse_bool "--debug" "${val}")"
elif [ "${opt}" = "--donate" ]; then
DONATE="$(parse_bool "--donate" "${val}")"
elif [ "${opt}" = "--fpc" ]; then
FPC="${val}"
elif [ "${opt}" = "--flags" ]; then
USER_FLAGS="${USER_FLAGS} ${val}"
elif [ "${opt}" = "--ogg-quality" ]; then
OGG_QUALITY="${val}"
elif [ "${opt}" = "--platform" ]; then
if [ "${val}" != "auto" ] && [ "${val}" != "desktop" ] && [ "${val}" != "mobile" ]; then
echo "Error: The argument to --platform must be one of \"auto\", \"desktop\", or \"mobile\"" >&2
exit 1
fi
PLATFORM="${val}"
elif [ "${opt}" = "--prefix" ]; then
PREFIX="${val}"
elif [ "${opt}" = "--strip" ]; then
STRIP="$(parse_bool "--strip" "${val}")"
else
echo "Unknown option \"${opt}\"" >&2
exit 1
fi
done
# Resolve "auto" values
if [ "${COMPAT}" = "auto" ]; then
if [ "${ANDROID}" = "true" ]; then
COMPAT="v2"
else
COMPAT="v1"
fi
fi
if [ "${PLATFORM}" = "auto" ]; then
if [ "${ANDROID}" = "true" ]; then
PLATFORM="mobile"
else
PLATFORM="desktop"
fi
fi
# Print out used values
cat <<EOF
Config values:
ANDROID = ${ANDROID}
ASSETS = ${ASSETS}
COMPAT = ${COMPAT}
DEBUG = ${DEBUG}
DONATE = ${DONATE}
FPC = ${FPC}
FLAGS =${USER_FLAGS}
OGG_QUALITY = ${OGG_QUALITY}
PLATFORM = ${PLATFORM}
PREFIX = ${PREFIX}
STRIP = ${STRIP}
EOF
# Calculate src/buildconfig.pas variables
pascal_string() {
input_str="${1}"
output_str="''"
open_apos=0
while [ "${#input_str}" -gt 0 ]; do
letter="$(echo "${input_str}" | cut -b1)"
input_str="$(echo "${input_str}" | cut -b2-)"
letter_ord="$(printf "%d" "'${letter}")"
if [ "${letter_ord}" -ge 32 ] && [ "${letter_ord}" -le 126 ]; then
if [ "${letter}" != "'" ]; then
if [ "${open_apos}" = "0" ]; then
output_str="${output_str} + '"
open_apos=1
fi
output_str="${output_str}${letter}"
else
if [ "${open_apos}" = "0" ]; then
output_str="${output_str} + #39"
else
output_str="${output_str}''"
fi
fi
else
if [ "${open_apos}" = "1" ]; then
output_str="${output_str}'"
open_apos=0
fi
output_str="${output_str} + #${letter_ord}"
fi
done
if [ "${open_apos}" = "0" ]; then
echo "${output_str}"
else
echo "${output_str}'"
fi
}
PAS_PREFIX="$(pascal_string "${PREFIX}")"
# Calculate Makefile variables from arguments
BUILD_FLAGS="-vewnh -dLD25_ASSETS_${ASSETS}"
GFX_FILTER=""
if [ "${ANDROID}" = "true" ]; then
EXE_PREFIX="lib"
EXE_SUFFIX=".so"
BUILD_FLAGS="-Tandroid ${BUILD_FLAGS}"
GFX_FILTER="gfx/toasts.png ${GFX_FILTER}"
else
EXE_PREFIX=""
EXE_SUFFIX=""
fi
if [ "${COMPAT}" = "v1" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -dLD25_COMPAT_V1"
fi
if [ "${DEBUG}" = "true" ]; then
# Note: No -O1/-O2/-O3/-O4 flag - no optimisations!
BUILD_FLAGS="${BUILD_FLAGS} -dLD25_DEBUG"
else
BUILD_FLAGS="${BUILD_FLAGS} -O3"
fi
if [ "${DONATE}" = "true" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -dLD25_DONATE"
fi
if [ "${PLATFORM}" = "mobile" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -dLD25_MOBILE"
PLATFORM_GOOD="mobile"
PLATFORM_BAD="desktop"
else
GFX_FILTER="gfx/touch-controls.png ${GFX_FILTER}"
PLATFORM_GOOD="desktop"
PLATFORM_BAD="mobile"
fi
if [ "${STRIP}" = "true" ]; then
BUILD_FLAGS="${BUILD_FLAGS} -CX -XX -Xs"
else
BUILD_FLAGS="${BUILD_FLAGS} -gl -gw"
fi
FPC_FLAGS="${BUILD_FLAGS}${USER_FLAGS}"
# cd to this script's directory and create src/buildconfig.pas and the Makefile
cd "$(dirname "${0}")"
GENERATED_DATE="$(date '+%Y-%m-%dT%H:%M:%S%z')"
echo 'Generating src/buildconfig.pas...'
{ cat <<EOF
// !
// ! This file has been generated by "configure.sh".
// ! Do not edit manually.
// !
// ! Generated on: ${GENERATED_DATE}
// !
Unit BuildConfig;
Interface
Const
Prefix = ${PAS_PREFIX};
Implementation
End.
EOF
} > src/buildconfig.pas
echo 'Generating Makefile...'
{ cat <<EOF
# !
# ! This file has been generated by "configure.sh".
# ! Do not edit manually.
# !
# ! Generated on: ${GENERATED_DATE}
# !
EXE_PREFIX := ${EXE_PREFIX}
EXE_SUFFIX := ${EXE_SUFFIX}
FPC := ${FPC}
FPC_FLAGS := ${FPC_FLAGS}
GFX_FILTER := ${GFX_FILTER}
PLATFORM_GOOD := ${PLATFORM_GOOD}
PLATFORM_BAD := ${PLATFORM_BAD}
PREFIX := ${PREFIX}
OGG_QUALITY := ${OGG_QUALITY}
EOF
} | cat - Makefile.in > Makefile
echo 'Done.'