-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmake.sh
More file actions
executable file
·348 lines (291 loc) · 11.6 KB
/
make.sh
File metadata and controls
executable file
·348 lines (291 loc) · 11.6 KB
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
#!/usr/bin/env bash
# (c) 2005-2025 by Panayotis Katsaloulis
# SPDX-License-Identifier: AGPL-3.0-only
# This file is part of Jubler.
# Be strict with script
set -euo pipefail
# ANSI escape codes for colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Get the directory where the script is located
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
dist_dir=$script_dir/dist
valid_targets=("windows" "linux" "generic" "macos" "all")
# KPacker configuration
kpacker_bin="$HOME/Works/System/bin/arch/linux-x86_64/kpacker"
jubler_source_generic="$script_dir/build/jubler-generic"
jubler_source_linux64="$script_dir/build/jubler-linux64"
jubler_source_macos="$script_dir/build/jubler-macos"
jubler_source_win64="$script_dir/build/jubler-win64"
jubler_icon="$script_dir/resources/logo/logo.svg"
installer_icon="$script_dir/resources/logo/installer.svg"
subfile_icon="$script_dir/resources/logo/subfile.svg"
document_extensions="srt,vtt,ass,ssa,ttml,dfxp,itt,txt,sub,stl,xml,sbv"
document_name="Jubler subtitle file"
display_help() {
echo -e "This is a helper script for building Jubler:"
echo -e " ${GREEN}version X.Y.Z${NC} Update Jubler version."
echo -e " ${GREEN}build TARGET1[,TARGET2]${NC} Build Jubler for the list of provided targets."
echo -e " ${GREEN}winget X.Y.Z [--submit]${NC} Update WinGet manifest (dry-run by default)."
echo -e " ${GREEN}clean${NC} Clean build files."
echo -e " ${GREEN}headers${NC} Check header files for copyright notice."
echo -e " ${GREEN}--help${NC} Display information about this script."
echo
echo -e "Available build targets:"
(IFS=,; echo -e " ${GREEN}${valid_targets[*]}${NC}")
echo
echo -e "Note: Signing and notarization are always performed when configured."
}
version_action() {
local version=$2
if [ $# -lt 2 ]; then
echo -e "${RED}Error:${NC} Missing argument for 'version'. Provide a value in X.Y.Z form."
exit 1
fi
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9_]+)?$ ]]; then
echo -e "${RED}Error:${NC} Invalid version format."
exit 1
fi
local version=$2
cd $script_dir
# Update version in build.gradle.kts
sed -i "s/^version = \".*\"/version = \"$version\"/" build.gradle.kts
echo -e "${GREEN}Version updated to $version in build.gradle.kts${NC}"
}
winget_action() {
if [ $# -lt 2 ]; then
echo -e "${RED}Error:${NC} Missing version argument for 'winget'. Usage: ./make.sh winget X.Y.Z [--submit]"
exit 1
fi
local version=$2
local submit_flag=""
if [ "${3:-}" = "--submit" ]; then
submit_flag="--submit"
fi
# Check if komac is installed
if ! command -v komac &> /dev/null; then
echo -e "${RED}Error:${NC} komac is not installed. Install it with: cargo install komac"
exit 1
fi
local installer_url="https://github.com/teras/Jubler/releases/download/v${version}/Jubler-${version}-x64.exe"
echo -e "${GREEN}Updating WinGet manifest for Jubler.App version ${version}...${NC}"
echo -e "Installer URL: ${installer_url}"
if [ -n "$submit_flag" ]; then
echo -e "${GREEN}Will submit PR to microsoft/winget-pkgs${NC}"
komac update Jubler.App --version "$version" --urls "$installer_url" --submit
else
echo -e "Dry run mode (use --submit to create PR)"
komac update Jubler.App --version "$version" --urls "$installer_url" --dry-run
fi
}
build_windows() {
echo -e "${GREEN}Building for Windows...${NC}"
cd "$script_dir"
# Build Jubler distribution first if needed
if [ ! -d "$jubler_source_win64" ]; then
gradle clean assembleDistribution
fi
# Get version from environment variable or build.gradle.kts
version=${JUBLER_VERSION:-$(gradle properties -q | grep "^version:" | awk '{print $2}')}
# Use separate temp directory for multi-target build mode
local output_dir="$dist_dir"
if [ "$build_multi_mode" = "true" ]; then
output_dir="$dist_dir/temp_windows"
fi
# Use KPacker to create Windows installer
"$kpacker_bin" --source="$jubler_source_win64/lib" --out="$output_dir" --name=Jubler --version="$version" --mainjar=jubler.jar --target=WindowsX64 --icon="$jubler_icon" --install-icon="$installer_icon" --document-extensions="$document_extensions" --document-name="$document_name" --document-icon="$subfile_icon"
# Move result to final location if in multi-target build mode
if [ "$build_multi_mode" = "true" ]; then
mv "$output_dir"/Jubler-*-x64.exe "$dist_dir/"
rm -rf "$output_dir"
fi
if [ -e "$dist_dir"/Jubler-*-x64.exe ]; then
echo -e "${GREEN}Windows installer created successfully.${NC}"
else
echo -e "${RED}Error:${NC} Could not create Windows installer."
exit 1
fi
}
build_linux() {
echo -e "${GREEN}Building for Linux...${NC}"
cd "$script_dir"
# Build Jubler distribution first if needed
if [ ! -d "$jubler_source_linux64" ]; then
gradle clean assembleDistribution
fi
# Get version from environment variable or build.gradle.kts
version=${JUBLER_VERSION:-$(gradle properties -q | grep "^version:" | awk '{print $2}')}
# Use separate temp directory for multi-target build mode
local output_dir="$dist_dir"
if [ "$build_multi_mode" = "true" ]; then
output_dir="$dist_dir/temp_linux"
fi
# Use KPacker to create Linux x64 AppImage
"$kpacker_bin" --source="$jubler_source_linux64/lib" --out="$output_dir" --name=Jubler --version="$version" --mainjar=jubler.jar --target=LinuxX64 --icon="$jubler_icon" --install-icon="$installer_icon" --document-extensions="$document_extensions" --document-name="$document_name" --document-icon="$subfile_icon"
# Move result to final location if in multi-target build mode
if [ "$build_multi_mode" = "true" ]; then
mv "$output_dir"/Jubler-*-x86_64.AppImage "$dist_dir/"
rm -rf "$output_dir"
fi
if [ -e "$dist_dir"/Jubler-*-x86_64.AppImage ]; then
echo -e "${GREEN}Linux AppImage created successfully.${NC}"
else
echo -e "${RED}Error:${NC} Could not create Linux AppImage."
exit 1
fi
}
build_generic() {
echo -e "${GREEN}Building for Generic...${NC}"
cd "$script_dir"
# Build Jubler distribution first if needed
if [ ! -d "$jubler_source_generic" ]; then
gradle clean assembleDistribution
fi
# Get version from environment variable or build.gradle.kts
version=${JUBLER_VERSION:-$(gradle properties -q | grep "^version:" | awk '{print $2}')}
# Use separate temp directory for multi-target build mode
local output_dir="$dist_dir"
if [ "$build_multi_mode" = "true" ]; then
output_dir="$dist_dir/temp_generic"
fi
# Use KPacker to create Generic package
"$kpacker_bin" --source="$jubler_source_generic/lib" --out="$output_dir" --name=Jubler --version="$version" --mainjar=jubler.jar --target=Generic --icon="$jubler_icon" --install-icon="$installer_icon" --document-extensions="$document_extensions" --document-name="$document_name" --document-icon="$subfile_icon"
# Move result to final location if in multi-target build mode
if [ "$build_multi_mode" = "true" ]; then
mv "$output_dir"/Jubler-*.tar.gz "$dist_dir/"
rm -rf "$output_dir"
fi
if [ -e "$dist_dir"/Jubler-*.tar.gz ]; then
echo -e "${GREEN}Generic package created successfully.${NC}"
else
echo -e "${RED}Error:${NC} Could not create Generic package."
exit 1
fi
}
build_macos() {
echo -e "${GREEN}Building for MacOS...${NC}"
cd "$script_dir"
# Build Jubler distribution first if needed
if [ ! -d "$jubler_source_macos" ]; then
gradle clean assembleDistribution
fi
# Get version from environment variable or build.gradle.kts
version=${JUBLER_VERSION:-$(gradle properties -q | grep "^version:" | awk '{print $2}')}
# Use separate temp directory for multi-target build mode
local output_dir="$dist_dir"
if [ "$build_multi_mode" = "true" ]; then
output_dir="$dist_dir/temp_macos"
fi
# Use KPacker to create macOS DMG with template (uncompressed for CI/CD signing)
# KPacker auto-detects CI/CD environment and uses sudo when needed
dmg_template="$script_dir/resources/installer/dmg_mac.zip"
"$kpacker_bin" --source="$jubler_source_macos/lib" --out="$output_dir" --name=Jubler --version="$version" --mainjar=jubler.jar --target=MacX64 --icon="$jubler_icon" --install-icon="$installer_icon" --dmg-template="$dmg_template" --no-dmg-compress --document-extensions="$document_extensions" --document-name="$document_name" --document-icon="$subfile_icon"
# Move result to final location if in multi-target build mode
if [ "$build_multi_mode" = "true" ]; then
mv "$output_dir"/Jubler-*.dmg "$dist_dir/"
rm -rf "$output_dir"
else
# Clean up intermediate .app directory when building single target
rm -rf "$dist_dir"/Jubler.app
fi
if [ -e "$dist_dir"/Jubler-*.dmg ]; then
echo -e "${GREEN}macOS DMG (uncompressed) created successfully.${NC}"
else
echo -e "${RED}Error:${NC} Could not create macOS DMG."
exit 1
fi
}
clean_action() {
gradle clean
rm -rf "$dist_dir/"
rm -rf "$script_dir/build/"
}
check_headers() {
cd $script_dir/modules
for java_file in $(find . -name "*.java" | grep -v com/panayotis/jubler/subs/color/Quantize.java ) ; do
if ! grep -q 'SPDX-License-Identifier' "$java_file"; then
echo "${java_file}"
fi
done
}
build_action() {
# Check if targets are provided
if [ $# -lt 2 ]; then
echo -e "${RED}Error:${NC} Missing targets for 'build'. Provide one or more targets."
(IFS=,; echo -e "Valid build targets: ${valid_targets[*]}")
exit 1
fi
mkdir -p dist
targets=$2
IFS=',' read -ra target_array <<< "$targets"
# Set build_multi_mode if multiple targets are specified (including "all")
build_multi_mode="false"
if [ "${#target_array[@]}" -gt 1 ]; then
build_multi_mode="true"
fi
for target in "${target_array[@]}"; do
if [ "$target" = "all" ]; then
build_multi_mode="true"
break
fi
done
for target in "${target_array[@]}"; do
case "$target" in
"windows")
build_windows
;;
"linux")
build_linux
;;
"generic")
build_generic
;;
"macos")
build_macos
;;
"all")
build_windows
build_macos
build_generic
build_linux
;;
*)
echo -e "${RED}Error:${NC} Unknown build target: $target"
(IFS=,; echo -e "Valid build targets: ${valid_targets[*]}")
exit 1
;;
esac
done
}
# Check if the script is called with an argument
if [ $# -eq 0 ]; then
echo -e "${RED}Error:${NC} Missing parameter. Use --help for information."
exit 1
fi
# Check the value of the first parameter
case "$1" in
"--help")
display_help
;;
"version")
version_action "$@"
;;
"build")
build_action "$@"
;;
"headers")
check_headers
;;
"clean")
clean_action
;;
"winget")
winget_action "$@"
;;
*)
echo -e "${RED}Error:${NC} Unknown parameter. Use --help for information."
exit 1
;;
esac
exit 0