forked from danirod/cartero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacos-build.sh
executable file
·257 lines (235 loc) · 11.8 KB
/
macos-build.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
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
#!/bin/bash
set -e
cd "$(dirname "$0")/.."
export GETTEXT_DIR=$(brew --prefix)/opt/gettext
case "$1" in
devel)
BUNDLE_ID="es.danirod.Cartero.Devel"
APP_NAME="Cartero (Devel)"
APP_VERSION="0.2.0"
MESON_FLAGS="-Dprofile=development"
ICON_PATH="$PWD/data/icons/scalable/apps/es.danirod.Cartero.Devel.svg"
DOC_ICON_PATH="$PWD/data/icons/scalable/mimetypes/es.danirod.Cartero.Devel-request.svg"
;;
stable)
BUNDLE_ID="es.danirod.Cartero"
APP_NAME="Cartero"
APP_VERSION="0.2.0"
MESON_FLAGS="-Dprofile=default"
ICON_PATH="$PWD/data/icons/scalable/apps/es.danirod.Cartero.svg"
DOC_ICON_PATH="$PWD/data/icons/scalable/mimetypes/es.danirod.Cartero-request.svg"
;;
*)
echo "Usage: $0 [devel / stable]"
exit 1
;;
esac
meson setup build --prefix="/" -Ddecorations=no-csd $MESON_FLAGS
ninja -C build
APP_ROOT="$PWD/build/cartero-darwin/$APP_NAME.app"
RESOURCES_ROOT="$APP_ROOT/Contents/Resources"
rm -rf "$APP_ROOT"
# Prepare share directory
mkdir -p "$RESOURCES_ROOT/share/glib-2.0/schemas"
cp -R $(brew --prefix)/opt/glib/share/glib-2.0/schemas/* "$RESOURCES_ROOT/share/glib-2.0/schemas"
cp -R $(brew --prefix)/opt/gtk4/share/glib-2.0/schemas/* "$RESOURCES_ROOT/share/glib-2.0/schemas"
cp -R $(brew --prefix)/opt/gtksourceview5/share/gtksourceview-5 "$RESOURCES_ROOT/share"
mkdir -p "$RESOURCES_ROOT/share/icons"
cp -R $(brew --prefix)/opt/adwaita-icon-theme/share/icons/Adwaita "$RESOURCES_ROOT/share/icons"
cp -R $(brew --prefix)/opt/hicolor-icon-theme/share/icons/hicolor "$RESOURCES_ROOT/share/icons"
# Compile share directory
DESTDIR="$RESOURCES_ROOT" ninja -C build install
glib-compile-schemas "$RESOURCES_ROOT/share/glib-2.0/schemas"
gtk4-update-icon-cache -q -t -f "$RESOURCES_ROOT/share/icons/hicolor"
gtk4-update-icon-cache -q -t -f "$RESOURCES_ROOT/share/icons/Adwaita"
# Add extra locales
for lang in $(cat "po/LINGUAS" | grep -v '^#'); do
for pkg in gdk-pixbuf gettext-runtime glib20 gtk40 gtksourceview-5 libadwaita shared-mime-info; do
if [ -f $(brew --prefix)/share/locale/$lang/LC_MESSAGES/$pkg.mo ]; then
cp -f $(brew --prefix)/share/locale/$lang/LC_MESSAGES/$pkg.mo "$RESOURCES_ROOT/share/locale/$lang/LC_MESSAGES"
fi
done
done
# Mangle bin directory
mv "$RESOURCES_ROOT/bin" "$APP_ROOT/Contents/MacOS"
# This part is a mess. To anyone trying to understand what does this do, here is an overview.
#
# It has to find every shared library used by the executable that comes from Homebrew, and vendor
# it into the Resources/lib directory, so that it is packed with the application. Otherwise,
# Cartero won't run because the shared library has to be somewhere.
function get_absolute_nonrelocated() {
otool -L "$1" | grep $(brew --prefix) | awk '{ print $1 }'
}
function get_relative_nonrelocated() {
otool -L "$1" | grep "@loader_path/../../../.." | awk '{ print $1 }'
}
mkdir -p "$RESOURCES_ROOT/lib"
# Relocate Cartero executable
for dep in $(get_absolute_nonrelocated "$APP_ROOT/Contents/MacOS/cartero"); do
dep_name=$(basename "$dep")
cp -v $dep "$RESOURCES_ROOT/lib"
install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$APP_ROOT/Contents/MacOS/cartero"
done
# Copy and relocate gdk-pixbuf-2.0 loaders for gdk-pixbuf-2.0 and librsvg
mkdir -p "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders"
cp $(brew --prefix)/opt/gdk-pixbuf/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders"
cp $(brew --prefix)/opt/librsvg/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders"
find "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders" -name '*.so' | while read f; do
file_name=$(basename "$f")
echo "FILE: $file_name"
install_name_tool -id "@executable_path/../Resources/lib/gdk-pixbuf-2.0/2.10.0/loaders/$file_name" "$f"
for dep in $(get_absolute_nonrelocated "$f"); do
dep_name=$(basename "$dep")
if ! [ -f "$RESOURCES_ROOT/lib/$dep_name" ]; then
cp -v "$dep" "$RESOURCES_ROOT/lib"
fi
install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
done
for dep in $(get_relative_nonrelocated "$f"); do
real_name=$(get_relative_nonrelocated "$f" | sed "s|@loader_path/../../../..|$(brew --prefix)|")
dep_name=$(basename "$dep")
if ! [ -f "$RESOURCES_ROOT/lib/$dep_name" ]; then
cp -v "$real_name" "$RESOURCES_ROOT/lib"
fi
install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
done
done
# Copy then relocate additional dylibs
function concat_absolute_dylibs() {
find "$RESOURCES_ROOT/lib" -name '*.dylib' | while read f; do
otool -L "$f"
done | grep $(brew --prefix) | awk '{ print $1 }' | sort | uniq
}
function concat_relative_dylibs() {
find "$RESOURCES_ROOT/lib" -name '*.dylib' | while read f; do
otool -L "$f"
done | grep "@loader_path/../../../.." | awk '{ print $1 }' | sort | uniq
}
function any_pending_dylibs() {
[[ -n "$(concat_absolute_dylibs)" ]] && return 0
[[ -n "$(concat_relative_dylibs)" ]] && return 0
return 1
}
while any_pending_dylibs; do
[[ -n "$(concat_absolute_dylibs)" ]] && cp -vf $(concat_absolute_dylibs) "$RESOURCES_ROOT/lib"
[[ -n "$(concat_relative_dylibs)" ]] && cp -vf $(concat_relative_dylibs | sed "s|@loader_path/../../../..|$(brew --prefix)|") "$RESOURCES_ROOT/lib"
find "$RESOURCES_ROOT/lib" -name '*.dylib' | while read f; do
file_name=$(basename "$f")
install_name_tool -id "@executable_path/../Resources/lib/$file_name" "$f"
for dep in $(get_absolute_nonrelocated "$f"); do
dep_name=$(basename "$dep")
if ! [ -f "$RESOURCES_ROOT/lib/$dep_name" ]; then
cp "$dep" "$RESOURCES_ROOT/lib"
fi
# install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
done
for dep in $(get_relative_nonrelocated "$f"); do
real_name=$(get_relative_nonrelocated "$f" | sed "s|@loader_path/../../../..|$(brew --prefix)|")
dep_name=$(basename "$dep")
if ! [ -f "$RESOURCES_ROOT/lib/$dep_name" ]; then
cp "$real_name" "$RESOURCES_ROOT/lib"
fi
# install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
install_name_tool -change "$dep" "@executable_path/../Resources/lib/$dep_name" "$f"
done
done
done
# Create cache
GDK_PIXBUF_MODULEDIR="$(brew --prefix)/opt/gdk-pixbuf/lib/gdk-pixbuf-2.0/2.10.0/loaders" gdk-pixbuf-query-loaders | sed "s|\".*/lib/gdk-pixbuf-2.0|\"@executable_path/../Resources/lib/gdk-pixbuf-2.0|" > "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"
GDK_PIXBUF_MODULEDIR="$(brew --prefix)/opt/librsvg/lib/gdk-pixbuf-2.0/2.10.0/loaders" gdk-pixbuf-query-loaders | sed "s|\".*/lib/gdk-pixbuf-2.0|\"@executable_path/../Resources/lib/gdk-pixbuf-2.0|" >> "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"
codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime "$APP_ROOT/Contents/MacOS/cartero"
find "$RESOURCES_ROOT/lib" -name '*.dylib' | while read f; do
codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime "$f"
done
find "$RESOURCES_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders" -name '*.so' | while read f; do
codesign --sign - --force --preserve-metadata=entitlements,requirements,flags,runtime "$f"
done
# These directories must exist for macOS to pick the locales (they can be empty)
mkdir -p "$RESOURCES_ROOT/en.lproj"
for lang in $(cat "po/LINGUAS" | grep -v '^#'); do
mkdir -p "$RESOURCES_ROOT/$lang.lproj"
done
# Create Info.plist
cat > "$APP_ROOT/Contents/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>cartero</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>cartero</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>CarteroRequest.icns</string>
<key>CFBundleTypeMIMETypes</key>
<array>
<string>application/cartero</string>
</array>
<key>CFBundleTypeName</key>
<string>Cartero request</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>CFBundleIconFile</key>
<string>Cartero.icns</string>
<key>CFBundleIdentifier</key>
<string>${BUNDLE_ID}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>${APP_NAME}</string>
<key>CFBundleShortVersionString</key>
<string>${APP_VERSION}</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2024 The Cartero Authors</string>
<key>CFBundleSignature</key>
<string>Cartero</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
</dict>
</plist>
EOF
# Create icon
mkdir -p "$RESOURCES_ROOT/Cartero.iconset"
rsvg-convert "$ICON_PATH" -w 16 -h 16 -o "$RESOURCES_ROOT/Cartero.iconset/icon_16x16.png"
rsvg-convert "$ICON_PATH" -w 32 -h 32 -o "$RESOURCES_ROOT/Cartero.iconset/icon_32x32.png"
rsvg-convert "$ICON_PATH" -w 64 -h 64 -o "$RESOURCES_ROOT/Cartero.iconset/icon_64x64.png"
rsvg-convert "$ICON_PATH" -w 128 -h 128 -o "$RESOURCES_ROOT/Cartero.iconset/icon_128x128.png"
rsvg-convert "$ICON_PATH" -w 256 -h 256 -o "$RESOURCES_ROOT/Cartero.iconset/icon_256x256.png"
rsvg-convert "$ICON_PATH" -w 512 -h 512 -o "$RESOURCES_ROOT/Cartero.iconset/icon_512x512.png"
rsvg-convert "$ICON_PATH" -w 1024 -h 1024 -o "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
cp "$RESOURCES_ROOT/Cartero.iconset/icon_32x32.png" "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
cp "$RESOURCES_ROOT/Cartero.iconset/icon_64x64.png" "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
cp "$RESOURCES_ROOT/Cartero.iconset/icon_128x128.png" "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
cp "$RESOURCES_ROOT/Cartero.iconset/icon_256x256.png" "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
cp "$RESOURCES_ROOT/Cartero.iconset/icon_512x512.png" "$RESOURCES_ROOT/Cartero.iconset/[email protected]"
iconutil -c icns "$RESOURCES_ROOT/Cartero.iconset"
rm -rf "$RESOURCES_ROOT/Cartero.iconset"
mkdir -p "$RESOURCES_ROOT/CarteroRequest.iconset"
rsvg-convert "$DOC_ICON_PATH" -w 16 -h 16 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_16x16.png"
rsvg-convert "$DOC_ICON_PATH" -w 32 -h 32 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_32x32.png"
rsvg-convert "$DOC_ICON_PATH" -w 64 -h 64 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_64x64.png"
rsvg-convert "$DOC_ICON_PATH" -w 128 -h 128 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_128x128.png"
rsvg-convert "$DOC_ICON_PATH" -w 256 -h 256 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_256x256.png"
rsvg-convert "$DOC_ICON_PATH" -w 512 -h 512 -o "$RESOURCES_ROOT/CarteroRequest.iconset/icon_512x512.png"
rsvg-convert "$DOC_ICON_PATH" -w 1024 -h 1024 -o "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
cp "$RESOURCES_ROOT/CarteroRequest.iconset/icon_32x32.png" "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
cp "$RESOURCES_ROOT/CarteroRequest.iconset/icon_64x64.png" "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
cp "$RESOURCES_ROOT/CarteroRequest.iconset/icon_128x128.png" "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
cp "$RESOURCES_ROOT/CarteroRequest.iconset/icon_256x256.png" "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
cp "$RESOURCES_ROOT/CarteroRequest.iconset/icon_512x512.png" "$RESOURCES_ROOT/CarteroRequest.iconset/[email protected]"
iconutil -c icns "$RESOURCES_ROOT/CarteroRequest.iconset"
rm -rf "$RESOURCES_ROOT/CarteroRequest.iconset"