forked from garglk/garglk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgargoyle_osx.sh
executable file
·128 lines (103 loc) · 4.39 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
#!/bin/sh
# 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
# XCode 10+ min target SDK is 10.9 (Mavericks) due to removal of libstdc++
SDK_VERSION=$(xcrun --show-sdk-version)
echo "SDK_VERSION $SDK_VERSION"
case $SDK_VERSION in
*10.1[4-9]* )
MACOS_MIN_VER=10.9
;;
* )
MACOS_MIN_VER=10.7
;;
esac
echo "MACOS_MIN_VER $MACOS_MIN_VER"
# Use as many CPU cores as possible
NUMJOBS=$(sysctl -n hw.ncpu)
GARGDIST=build/dist
DYLIBS=support/dylibs
BUNDLE=Gargoyle.app/Contents
GARVERSION=$(cat garglk/garversion.h | /usr/bin/grep -E '^\s*#\s*define[[:space:]]*VERSION\s*' | /usr/bin/sed -E -e 's/^[^"]*"([^"]+)"/\1/')
rm -rf Gargoyle.app
mkdir -p "$BUNDLE/MacOS"
mkdir -p "$BUNDLE/Frameworks"
mkdir -p "$BUNDLE/Resources/Fonts"
mkdir -p "$BUNDLE/PlugIns"
rm -rf $GARGDIST
jam "-sUSETTS=yes" "-sBUNDLEFONTS=no" "-sMAC_USEHOMEBREW=${MAC_USEHOMEBREW}" "-j${NUMJOBS}" "-sMACOS_MIN_VER=${MACOS_MIN_VER}" install
# 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.
for dylib in $(find "${GARGDIST}" -type f -name '*.dylib'); do
cp "${dylib}" "$BUNDLE/Frameworks"
done
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)"
for file in $(find "${BUNDLE}" -type f); do
otool -L "${file}" | fgrep "${HOMEBREW_OR_MACPORTS_LOCATION}" | sed -E -e 's/^[[:space:]]+(.*)[[:space:]]+\([^)]*\)$/\1/' >> "${ALL_DYLIB_PATHS}"
done
UNIQUE_DYLIB_PATHS="$(mktemp -t gargoylebuild)"
cat "${ALL_DYLIB_PATHS}" | sort | 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.
for dylib in $(cat ${UNIQUE_DYLIB_PATHS}); do
cp "${dylib}" "$BUNDLE/Frameworks"
chmod 644 "$BUNDLE/Frameworks/$(basename ${dylib})"
done
return 1
}
until copy_new_dylibs ; do true; done
echo "Changing dylib IDs and references..."
# Change the dylib IDs in Frameworks.
for dylib_path in $(find "${BUNDLE}/Frameworks" -type f); do
install_name_tool -id "@executable_path/../Frameworks/$(basename "${dylib_path}")" "${dylib_path}"
done
# Use the dylibs in Frameworks.
for file_path in $(find "${BUNDLE}" -type f); do
# Replace dylib paths.
for original_dylib_path in $(otool -L "${file_path}" | fgrep "${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.
for file_path in $(find "${BUNDLE}" -type f); do
for dylib_built_path in $(find "${GARGDIST}" -type f -name '*.dylib'); do
install_name_tool -change "@executable_path/$(basename "${dylib_built_path}")" "@executable_path/../Frameworks/$(basename "${dylib_built_path}")" "${file_path}"
done
done
echo "Copying additional support files..."
cat garglk/launcher.plist | /usr/bin/sed -E -e "s/INSERT_VERSION_HERE/$GARVERSION/" > $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/Go-Mono*.ttf $BUNDLE/Resources/Fonts
cp fonts/LiberationMono*.ttf $BUNDLE/Resources/Fonts
cp fonts/LinLibertine*.otf $BUNDLE/Resources/Fonts
cp fonts/NotoSerif*.ttf $BUNDLE/Resources/Fonts
echo "Creating DMG..."
hdiutil create -fs "HFS+J" -ov -srcfolder Gargoyle.app/ "gargoyle-$GARVERSION-mac.dmg"
echo "Done."