forked from garglk/garglk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgargoyle_osx.sh
executable file
·145 lines (116 loc) · 5.19 KB
/
gargoyle_osx.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
set -e
# XXX Temporary hack for a broken sdl2_mixer or readline package in Homebrew.
# sdl2_mixer's pkg-config file requires readline, but the readline pkg-config
# file isn't installed to /usr/local/lib/pkgconfig, meaning it can't be found.
# I don't know the logic behind what gets symlinked into /usr/local/lib/pkgconfig
# so I don't know who's at fault here, but the hacky way around it is to set
# $PKG_CONFIG_PATH to point to readline's pkg-config directory. This only
# happens if $PKG_CONFIG_PATH isn't already set.
if ! pkg-config readline --exists; then
if [[ -z "${PKG_CONFIG_PATH}" ]]; then
export PKG_CONFIG_PATH="$(dirname $(find /usr/local/Cellar/readline -name readline.pc|tail -1))"
fi
fi
# Use Homebrew if available. Alternately, you could just set the variable to
# either yes or no.
if [ "${MAC_USEHOMEBREW}" == "" ]; then
MAC_USEHOMEBREW=no
brew --prefix > /dev/null 2>&1 && MAC_USEHOMEBREW=yes
fi
if [ "${MAC_USEHOMEBREW}" == "yes" ]; then
HOMEBREW_OR_MACPORTS_LOCATION="$(brew --prefix)"
else
HOMEBREW_OR_MACPORTS_LOCATION="$(pushd "$(dirname "$(which port)")/.." > /dev/null ; pwd -P ; popd > /dev/null)"
fi
if [[ "$(sw_vers -productVersion)" =~ ^10\.([0-9]+) && ${BASH_REMATCH[1]} -lt 15 ]]; then
MACOS_MIN_VER="10.13"
else
MACOS_MIN_VER="10.15"
fi
echo "MACOS_MIN_VER $MACOS_MIN_VER"
# Use as many CPU cores as possible
NUMJOBS=$(sysctl -n hw.ncpu)
GARGDIST=build/dist
BUNDLE=Gargoyle.app/Contents
GARVERSION=$(cat VERSION)
rm -rf Gargoyle.app
mkdir -p "$BUNDLE/MacOS"
mkdir -p "$BUNDLE/Frameworks"
mkdir -p "$BUNDLE/Resources/Fonts"
mkdir -p "$BUNDLE/Resources/themes"
mkdir -p "$BUNDLE/PlugIns"
rm -rf $GARGDIST
mkdir -p build-osx
cd build-osx
cmake .. -DBUILD_SHARED_LIBS=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_MIN_VER} -DDIST_INSTALL=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DWITH_FRANKENDRIFT=ON
make "-j${NUMJOBS}"
make install
cd -
# Copy the main executable to the MacOS directory;
cp "$GARGDIST/gargoyle" "$BUNDLE/MacOS/Gargoyle"
# Copy terps to the PlugIns directory.
find "${GARGDIST}" -type f -not -name '*.dylib' -not -name 'gargoyle' -print0 | xargs -0 -J @ cp @ "$BUNDLE/PlugIns"
# Copy the dylibs built to the Frameworks directory.
find "${GARGDIST}" -type f -name '*.dylib' -exec cp {} "$BUNDLE/Frameworks" \;
echo "Copying all required dylibs..."
PREVIOUS_UNIQUE_DYLIB_PATHS="$(mktemp -t gargoylebuild)"
copy_new_dylibs() {
# Get the dylibs needed.
ALL_DYLIB_PATHS="$(mktemp -t gargoylebuild)"
find "${BUNDLE}" -type f -print0 | while IFS= read -r -d "" file
do
otool -L "${file}" | grep -F "${HOMEBREW_OR_MACPORTS_LOCATION}" | sed -E -e 's/^[[:space:]]+(.*)[[:space:]]+\([^)]*\)$/\1/' >> "${ALL_DYLIB_PATHS}"
done
UNIQUE_DYLIB_PATHS="$(mktemp -t gargoylebuild)"
sort "${ALL_DYLIB_PATHS}" | uniq > "${UNIQUE_DYLIB_PATHS}"
rm "${ALL_DYLIB_PATHS}"
# Compare the list to the previous one.
if diff -q "${PREVIOUS_UNIQUE_DYLIB_PATHS}" "${UNIQUE_DYLIB_PATHS}" > /dev/null ; then
rm "${PREVIOUS_UNIQUE_DYLIB_PATHS}"
rm "${UNIQUE_DYLIB_PATHS}"
return 0
fi
cp "${UNIQUE_DYLIB_PATHS}" "${PREVIOUS_UNIQUE_DYLIB_PATHS}"
diff "${PREVIOUS_UNIQUE_DYLIB_PATHS}" "${UNIQUE_DYLIB_PATHS}"
# Copy dylibs to the Frameworks directory.
while IFS= read -r dylib
do
cp "${dylib}" "$BUNDLE/Frameworks"
chmod 644 "$BUNDLE/Frameworks/$(basename "${dylib}")"
done < "${UNIQUE_DYLIB_PATHS}"
return 1
}
until copy_new_dylibs ; do true; done
echo "Changing dylib IDs and references..."
# Change the dylib IDs in Frameworks.
find "${BUNDLE}/Frameworks" -type f -exec install_name_tool -id "@executable_path/../Frameworks/$(basename "{}")" {} \;
# Use the dylibs in Frameworks.
find "${BUNDLE}" -type f -print0 | while IFS= read -r -d "" file_path
do
# Replace dylib paths.
for original_dylib_path in $(otool -L "${file_path}" | grep -F "${HOMEBREW_OR_MACPORTS_LOCATION}" | sed -E -e 's/^[[:space:]]+(.*)[[:space:]]+\([^)]*\)$/\1/'); do
install_name_tool -change "${original_dylib_path}" "@executable_path/../Frameworks/$(basename "${original_dylib_path}")" "${file_path}"
done
done
# Use the built dylibs.
find "${BUNDLE}" -type f -print0 | while IFS= read -r -d "" file_path
do
find "${GARGDIST}" -type f -name '*.dylib' -exec install_name_tool -change "@executable_path/$(basename "{}")" "@executable_path/../Frameworks/$(basename "{}")" "${file_path}" \;
done
# Ensure interpreters can find libgarglk
find Gargoyle.app/Contents/PlugIns/ -type f -exec install_name_tool -add_rpath '@executable_path/../Frameworks' {} \;
install_name_tool -add_rpath '@executable_path/../Frameworks' "$BUNDLE/MacOS/Gargoyle"
echo "Copying additional support files..."
/usr/bin/sed -E -e "s/INSERT_VERSION_HERE/$GARVERSION/" garglk/launcher.plist > $BUNDLE/Info.plist
cp garglk/launchmac.nib "$BUNDLE/Resources/MainMenu.nib"
cp garglk/garglk.ini "$BUNDLE/Resources"
cp garglk/*.icns "$BUNDLE/Resources"
cp licenses/* "$BUNDLE/Resources"
cp fonts/Gargoyle*.ttf $BUNDLE/Resources/Fonts
cp fonts/unifont*.otf $BUNDLE/Resources
cp themes/*.json $BUNDLE/Resources/themes
codesign -s - -f --deep Gargoyle.app
echo "Creating DMG..."
hdiutil create -fs "HFS+J" -ov -srcfolder Gargoyle.app/ "gargoyle-$GARVERSION-mac.dmg"
echo "Done."