forked from Hydr8gon/NooDS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mac-bundle.sh
executable file
·64 lines (49 loc) · 1.74 KB
/
mac-bundle.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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
app=NooDS.app
contents=$app/Contents
if [[ ! -f noods ]]; then
echo 'Error: NooDS binary was not found.'
echo 'Please run `make` to compile NooDS before bundling.'
exit 1
fi
if [[ -d "$app" ]]; then
rm -rf "$app"
fi
install -dm755 "${contents}"/{MacOS,Resources,Frameworks}
install -sm755 noods "${contents}/MacOS/NooDS"
install -m644 Info.plist "$contents/Info.plist"
# macOS does not have the -f flag for readlink
abspath() {
perl -MCwd -le 'print Cwd::abs_path shift' "$1"
}
# Recursively copy dependent libraries to the Frameworks directory
# and fix their load paths
fixup_libs() {
local libs=($(otool -L "$1" | grep -vE "/System|/usr/lib|:$" | sed -E 's/'$'\t''(.*) \(.*$/\1/'))
for lib in "${libs[@]}"; do
# Dereference symlinks to get the actual .dylib as binaries' load
# commands can contain paths to symlinked libraries.
local abslib="$(abspath "$lib")"
local base="$(basename "$abslib")"
local install_path="$contents/Frameworks/$base"
install_name_tool -change "$lib" "@rpath/$base" "$1"
if [[ ! -f "$install_path" ]]; then
install -m644 "$abslib" "$install_path"
strip -Sx "$install_path"
fixup_libs "$install_path"
fi
done
}
install_name_tool -add_rpath "@executable_path/../Frameworks" $contents/MacOS/NooDS
fixup_libs $contents/MacOS/NooDS
cp "icon/icon-mac.icns" "$contents/Resources/NooDS.icns"
codesign --deep -s - NooDS.app
if [[ $1 == '--dmg' ]]; then
mkdir build/dmg
cp -a NooDS.app build/dmg/
ln -s /Applications build/dmg/Applications
hdiutil create -volname NooDS -srcfolder build/dmg -ov -format UDBZ NooDS.dmg
rm -r build/dmg
fi