-
Notifications
You must be signed in to change notification settings - Fork 1
/
_build.sh
executable file
·145 lines (112 loc) · 4.02 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
#!/bin/bash
source ./buildconfig.sh
MUSTACHE="${MUSTACHE?-mustache}"
TMP_YML="$(mktemp)"
TMP_INI="$(mktemp)"
packagefull="$package"-"$build"
packagedir="."
cleanup() {
( cd "$utdir" && rm -r "$packagefull" )
}
( # Subshell to preserve original working dir
cat "$makeini">"$TMP_INI"
echo EditPackages="$packagefull">>"$TMP_INI"
cd "$utdir"
( # Subshell to exit early on error, to go right into cleanup
set -e
mkdir "$packagefull"
# Build temporary YAML file
echo "build: '$build'" > "$TMP_YML"
echo "name: '$name'" > "$TMP_YML"
echo "version: '$version'" >> "$TMP_YML"
echo "package: '$packagefull'" >> "$TMP_YML"
echo "debug: '$debug'" >> "$TMP_YML"
if [[ "$debug" == 1 ]]; then
echo "namesuffix: ' ($build)'" >> "$TMP_YML"
else
echo "namesuffix: ''" >> "$TMP_YML"
fi
echo >> "$TMP_YML"
cat "$package/template-options.yml" >> "$TMP_YML"
# Copy assets
for asset in Models/ Textures/ Sounds/; do
if [[ -d "$package"/"$asset" ]]; then
cp -rv "$package"/"$asset" "$packagefull"
fi
done
# Format classes with Mustache
mkdir "$packagefull"/Classes
for class in "$package"/Classes/**; do
class="$(basename "$class")"
echo "Formatting: $packagefull/Classes/$class"
"$MUSTACHE" "$package/Classes/$class" < "$TMP_YML" > "$packagefull/Classes/$class"
done
# Include extra assets (map, sound and texture packages)
# Do this before building because extra packages here may be referenced by the code.
x_array=()
for x_asset in "Maps" "Sounds" "Textures" "Music"; do
if [[ -d "Extra/$x_asset" ]]; then
for fname in Extra/"$x_asset"/*; do
if [[ "$fname" == ".gitignore" ]]; then
continue
fi
cp -vf "$fname" "$x_asset"
x_array+=("$x_asset/$fname")
done
fi
done
# Build .u
(
cd System
#WINEPREFIX="$wineprefix" wine "$umake" "$package-$build"
if [[ -f "$packagefull.u" ]]; then rm "$packagefull.u"; fi
echo "* Invoking ucc make in $(pwd)"
"$ucc" make -NoBind ini="$TMP_INI" | tee "$packagedir/make.log"
# Ensure .u is built
if [[ ! -f "$packagefull.u" ]]; then
if [[ -f "$HOME/.utpg/System/$packagefull.u" ]]; then
mv "$HOME/.utpg/System/$packagefull.u" .
else
exit 1
fi
fi
)
code=$?; [[ $code == 0 ]] || exit $code
pkg_members=("System/$packagefull.u" "${x_array[@]}")
# Format .int with Mustache
if [[ "$makeint" == "1" ]]; then
echo "Formatting: System/$package.int"
"$MUSTACHE" "$package/template.int" < "$TMP_YML" > "System/$packagefull.int"
pkg_members+=("System/$packagefull.int")
fi
# Include readme inside Help/
if [[ "$incl_readme" == "1" ]]; then
cp -f "$package/README.adoc" "Help/$package.adoc"
pkg_members+=("Help/$package.adoc")
fi
# Package up
tar cf "$packagefull.tar" "${pkg_members[@]}"
zip -9r "$packagefull.zip" "${pkg_members[@]}" >/dev/null
gzip --best -k "$packagefull.tar"
bzip2 --best -k "$packagefull.tar"
rm "$packagefull.tar"
# Move to dist
echo Packaging up...
mkdir -p "$dist/$package/$build"
mv "$packagefull."{tar.*,zip} "$dist/$package/$build"
# Update dist/latest
echo Organizing dist directory...
mkdir -p "$dist/$package/latest"
rm -f "$dist/$package/latest/"*
cp "$dist/$package/$build/"* "$dist/$package/latest"
)
exit $?
)
code=$?
# Finish up
rm "$TMP_YML"
rm "$TMP_INI"
echo
echo Cleaning up...
cleanup
exit $code