forked from thoth-tech/arcade-games
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile-game.sh
executable file
·146 lines (128 loc) · 3.12 KB
/
compile-game.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
#!/bin/bash
GAME_DIR=$1
BINARY_NAME=$2
cd $GAME_DIR
file=config.txt
# Removing CRLF characters
sed -i "s/\r//g" "${file}"
# Read the file
while read line || [ -n "$line" ]; do
# Ignoring lines starting with # or empty lines
if [[ ${line:0:1} == *"#"* ]] || [[ -z $line ]]; then
continue
fi
# Split string with delimiter "="
IFS='=' read -ra item <<< $line
# If key is language
if [[ ${item[0]} == "language" ]]; then
# Store the value in language
language="${item[1]}"
continue
fi
# If key is compile-command
if [[ ${item[0]} == "compile-command" ]]; then
# Store the value in command
command="${item[1]}"
continue
fi
done < $file
# Get the game name
game_name=$(basename $GAME_DIR)
echo Compiling game $game_name...
#Check for C# Language
if [[ $language == "C#" ]]; then
echo "C# language detected, using skm dotnet publish"
# If command is empty
if [[ -z "$command" ]]; then
echo "No compile command found, using default"
if [[ $BINARY_NAME == "linux-arm" ]]; then
skm dotnet publish --runtime linux-arm --no-self-contained -o ./compiled/
else
skm dotnet publish -o ./compiled/
fi
else
echo Appending output flag and name/loc
command+=" -o ./compiled/"
fi
else
#Assume C++ Language or Makefile
# create compiled folder
mkdir compiled
# If command is empty
if [[ -z "$command" ]]; then
echo "No compile command found, using default"
skm g++ program.cpp -o ./compiled/$game_name
else
# If command starts with skm
if [[ $command == "skm"* ]]; then
echo Appending output flag and name/loc
command+=" -o ./compiled/$game_name"
else
echo Assuming usage of makefile, appending output name/loc
command+=" ./compiled/$game_name"
fi
echo "Running compile command: $command"
eval $command
fi
fi
#Create tar Archvie of the compiled folder
mkdir published
tar -czvf published/$game_name-$BINARY_NAME.tar.gz -C compiled/ .
#Assets tar
AssetsTar=published/$game_name-assets.tar
# Create an empty Assets tar archive
tar -cvf "$AssetsTar" --files-from /dev/null
# Function to add a directory to the archive if it exists
add_directory_to_archive() {
local directory="$1"
if [ -d "$directory" ]; then
tar -rf "$AssetsTar" -C "$(dirname "$directory")" "$(basename "$directory")"
fi
}
if [ $BINARY_NAME = "win-x86" ]; then
#List of Directories that may have assets (non case senstive)
AssetsDirectories=(
"resources"
"animations"
"bundles"
"databases"
"fonts"
"images"
"json"
"sounds"
)
else
#List of Directories that may have assets (case senstive)
AssetsDirectories=(
"Resources"
"resources"
"Animations"
"animations"
"Bundles"
"bundles"
"Databases"
"databases"
"Fonts"
"fonts"
"Images"
"images"
"Json"
"json"
"Sounds"
"sounds"
)
fi
for dir in "${AssetsDirectories[@]}"; do
add_directory_to_archive "$dir"
done
# List contents of the archive
archive_contents=$(tar -tf "$AssetsTar")
# Check if the archive is empty
if [ -z "$archive_contents" ]; then
echo "No Assets Found"
rm "$AssetsTar"
else
#compress the assets tar
gzip "$AssetsTar"
echo "Archive '$AssetsTar' created with specified directories."
fi