-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-exec.sh
executable file
·126 lines (98 loc) · 3.27 KB
/
build-exec.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
#!/bin/bash
# MIT License
# Copyright (c) 2022 MightyElemental
# https://github.com/MightyElemental/libgdx-game-exporter
# Build game into executables for various platforms
windowsjdk="OpenJDK11U-jre_x64_windows_hotspot_11.0.14.1_1.zip"
linuxjdk="OpenJDK11U-jre_x64_linux_hotspot_11.0.14.1_1.tar.gz"
buildlocation="desktop/build/libs"
# Change to your game's main class
mainclass="io.github.annabeths.desktop.DesktopLauncher"
# Change to what you want your game file to be called (excluding version)
gamename="pirategame-mario_shard"
# Set tag if missing
# The tag can be the game version
if [ -z "$TAG" ]; then
# set TAG to the latest tag in git
TAG=`git tag -l --sort=refname \*.\*.\* | tail -1`
fi
# Apply the version tag at the end of the name
gamename="$gamename-$TAG"
function build_game() {
echo "Building game file with default method..."
rm -rf build # ensure build dir is not present
./gradlew clean desktop:dist
}
# Ensure game was built
if ! compgen -G "$buildlocation/*.jar" > /dev/null; then
echo "Game file was not built!"
build_game
fi
# Ensure only one jar file is present
if [ $(ls $(compgen -G "$buildlocation/*.jar") -1 | wc -l) -gt 1 ]; then
echo "Multiple jar files exist in the $buildlocation directory!"
echo "Rebuilding game..."
build_game
fi
# Rename game file
mv $(compgen -G "$buildlocation/*.jar") "$buildlocation/$gamename.jar"
# Create and enter build directory
mkdir -p builds && cd builds
# Download JRE for Windows
# https://github.com/adoptium/temurin11-binaries
wget -q -N --show-progress https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.14.1%2B1/OpenJDK11U-jre_x64_windows_hotspot_11.0.14.1_1.zip{,.sha256.txt}
# Download JRE for Linux
wget -q -N --show-progress https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.14.1%2B1/OpenJDK11U-jre_x64_linux_hotspot_11.0.14.1_1.tar.gz{,.sha256.txt}
# Compare Windows Hash
echo "comparing sha256 hash..."
sha256sum -c $windowsjdk.sha256.txt
if [ $? -eq 1 ]; then
echo "Hash did not match!"
exit 1
fi
# Compare Linux Hash
echo "comparing sha256 hash..."
sha256sum -c $linuxjdk.sha256.txt
if [ $? -eq 1 ]; then
echo "Hash did not match!"
exit 1
fi
# Download packr
# https://github.com/libgdx/packr
wget -N -q --show-progress https://github.com/libgdx/packr/releases/download/4.0.0/packr-all-4.0.0.jar -O packr4.jar
# Create exports folder
rm -rf "export"
mkdir -p "export"
# -= BUILD WINDOWS FILE =-
# remove windows directory if present
rm -rf windows
# Pack program into windows executable
java -jar packr4.jar \
--platform windows64 \
--jdk $windowsjdk \
--executable $gamename \
--classpath "../$buildlocation/$gamename.jar" \
--mainclass $mainclass \
--output windows
# Zip packaged windows executable
cd windows
zip -FSr "../export/$gamename-windows.zip" .
cd ..
echo "Completed Windows build"
echo "Starting Linux build"
# -= BUILD LINUX FILE =-
# remove linux directory if present
rm -rf linux
# Pack program into linux executable
java -jar packr4.jar \
--platform linux64 \
--jdk $linuxjdk \
--executable $gamename \
--classpath "../$buildlocation/$gamename.jar" \
--mainclass $mainclass \
--output linux
# Archive packaged linux executable
cd linux
tar -czvf "../export/$gamename-linux.tar.gz" *
cd ..
echo "Completed Linux build"