-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Optimize macOS build & add build script for universal binary
- Loading branch information
1 parent
d7b01b3
commit 7491ea2
Showing
6 changed files
with
294 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,73 @@ | ||
#!/bin/sh | ||
#!/bin/bash | ||
set -xeu | ||
|
||
LANGUAGES="bs ca cs da de el eo es fi fr gl he hu id it ja ko lv nb nl pl pt_BR ru sk sr@latin sv th tr uk vi zh_CN zh_TW" | ||
LOCALEDIR="/usr/local/share/locale/" | ||
[ ! -d "$LOCALEDIR" ] && [ -d "$HOMEBREW_PREFIX/share/locale/" ] && LOCALEDIR="$HOMEBREW_PREFIX/share/locale/" | ||
PROJDIR=$(realpath "$(dirname $0)/../..") | ||
|
||
cd $(dirname $0)/../.. | ||
[ -z "${ARCH-}" ] && ARCH=$(uname -m) | ||
if [ "$ARCH" = "x86_64" ]; then | ||
echo "Target architecture: $ARCH" | ||
MACOSX_DEPLOYMENT_TARGET=10.10 | ||
elif [ "$ARCH" = "arm64" ]; then | ||
echo "Target architecture: $ARCH" | ||
MACOSX_DEPLOYMENT_TARGET=12.0 | ||
else | ||
echo "Unsupported architecture: $ARCH" >&2 | ||
exit 1 | ||
fi | ||
|
||
rm -f src/spek | ||
DEPSDIR="$(realpath "$(dirname $0)")/deps.$ARCH" | ||
if [ ! -e "$DEPSDIR" ]; then | ||
echo "Dependency not found. Running ./install_deps.sh ..." | ||
env ARCH="$ARCH" ./install_deps.sh | ||
fi | ||
|
||
export MACOSX_DEPLOYMENT_TARGET | ||
export PATH="$DEPSDIR/bin:$PATH" | ||
export ACLOCAL="aclocal -I $DEPSDIR/share/aclocal" | ||
export PKG_CONFIG_PATH="$DEPSDIR/lib/pkgconfig" | ||
export CXX="/usr/bin/clang++ -arch $ARCH" | ||
|
||
cd "$PROJDIR" | ||
|
||
cp "$HOMEBREW_PREFIX"/share/wx/*/aclocal/wxwin.m4 . | ||
echo "m4_include([wxwin.m4])" > acinclude.m4 | ||
rm -f src/spek | ||
|
||
./autogen.sh && make -j2 || exit 1 | ||
mkdir -p builddir | ||
cd builddir | ||
BUILDDIR=$(pwd) | ||
../autogen.sh --host="$ARCH-apple-darwin" && make clean && make -j$(nproc) || exit 1 | ||
|
||
cd dist/osx | ||
rm -fr Spek.app | ||
cd "$PROJDIR/dist/osx" | ||
rm -fr Spek.app "Spek-$ARCH.app" | ||
mkdir -p Spek.app/Contents/MacOS | ||
mkdir -p Spek.app/Contents/Frameworks | ||
mkdir -p Spek.app/Contents/Resources | ||
mv ../../src/spek Spek.app/Contents/MacOS/Spek | ||
cp Info.plist Spek.app/Contents/ | ||
cp Spek.icns Spek.app/Contents/Resources/ | ||
cp *.png Spek.app/Contents/Resources/ | ||
cp ../../LICENCE.md Spek.app/Contents/Resources/ | ||
cp ../../README.md Spek.app/Contents/Resources/ | ||
mv "$BUILDDIR"/src/spek Spek.app/Contents/MacOS/Spek | ||
cp "$BUILDDIR"/dist/osx/Info.plist Spek.app/Contents/ | ||
cp "$PROJDIR"/dist/osx/Spek.icns Spek.app/Contents/Resources/ | ||
cp "$PROJDIR"/dist/osx/*.png Spek.app/Contents/Resources/ | ||
cp "$PROJDIR"/LICENCE.md Spek.app/Contents/Resources/ | ||
cp "$PROJDIR"/README.md Spek.app/Contents/Resources/ | ||
mkdir Spek.app/Contents/Resources/lic | ||
cp ../../lic/* Spek.app/Contents/Resources/lic/ | ||
cp "$PROJDIR"/lic/* Spek.app/Contents/Resources/lic/ | ||
|
||
for lang in $LANGUAGES; do | ||
mkdir -p Spek.app/Contents/Resources/"$lang".lproj | ||
cp -v ../../po/"$lang".gmo Spek.app/Contents/Resources/"$lang".lproj/spek.mo | ||
cp -v "$LOCALEDIR""$lang"/LC_MESSAGES/wxstd*.mo Spek.app/Contents/Resources/"$lang".lproj/wxstd.mo | ||
cp "$BUILDDIR"/po/"$lang".gmo Spek.app/Contents/Resources/"$lang".lproj/spek.mo | ||
mo=("$DEPSDIR"/share/locale/"$lang"/LC_MESSAGES/wxstd*.mo) | ||
test -f "$mo" && cp "$mo" Spek.app/Contents/Resources/"$lang".lproj/wxstd.mo | ||
done | ||
unset lang mo | ||
mkdir -p Spek.app/Contents/Resources/en.lproj | ||
|
||
BINS="Spek.app/Contents/MacOS/Spek" | ||
while [ ! -z "$BINS" ]; do | ||
NEWBINS="" | ||
for bin in $BINS; do | ||
echo "Updating dependendies for $bin." | ||
LIBS=$(otool -L $bin | grep -e /usr/local/ -e /opt/ | tr -d '\t' | awk '{print $1}') | ||
for lib in $LIBS; do | ||
reallib=$(realpath $lib) | ||
libname=$(basename $reallib) | ||
install_name_tool -change $lib @executable_path/../Frameworks/$libname $bin | ||
if [ ! -f Spek.app/Contents/Frameworks/$libname ]; then | ||
echo "\tBundling $reallib." | ||
cp $reallib Spek.app/Contents/Frameworks/ | ||
chmod +w Spek.app/Contents/Frameworks/$libname | ||
install_name_tool -id @executable_path/../Frameworks/$libname Spek.app/Contents/Frameworks/$libname | ||
NEWBINS="$NEWBINS Spek.app/Contents/Frameworks/$libname" | ||
fi | ||
done | ||
done | ||
BINS="$NEWBINS" | ||
done | ||
bin="Spek.app/Contents/MacOS/Spek" | ||
echo "Updating dependendies for $bin." | ||
cp -a "$DEPSDIR"/lib/*.dylib Spek.app/Contents/Frameworks/ | ||
install_name_tool -add_rpath "@executable_path/../Frameworks" "$bin" | ||
|
||
# Sign the app | ||
codesign -fs - ./Spek.app --deep | ||
|
||
# Create a gzip tar archive | ||
rm -f Spek.tgz | ||
tar cvzf Spek.tgz ./Spek.app | ||
|
||
# Clean up | ||
cd ../.. | ||
rm wxwin.m4 acinclude.m4 | ||
rm -f "Spek.$ARCH.tgz" | ||
tar cvzf "Spek.$ARCH.tgz" Spek.app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
set -xeu | ||
|
||
cd "$(dirname $0)" | ||
|
||
if [ "${1-}" != "merge_only" ]; then | ||
ARCH=x86_64 ./bundle.sh | ||
ARCH=arm64 ./bundle.sh | ||
fi | ||
|
||
SPEK_X86_64="$(realpath .)/Spek.x86_64.app" | ||
SPEK_ARM64="$(realpath .)/Spek.arm64.app" | ||
SPEK_UNIVERSAL="$(realpath .)/Spek.app" | ||
|
||
rm -rf "Spek.app" | ||
tar xf Spek.x86_64.tgz | ||
mv "Spek.app" "$SPEK_X86_64" | ||
tar xf Spek.arm64.tgz | ||
mv "Spek.app" "$SPEK_ARM64" | ||
|
||
cp -a "$SPEK_X86_64" "$SPEK_UNIVERSAL" | ||
|
||
# Merge x86_64, arm64 excutables | ||
cd "$SPEK_UNIVERSAL/Contents/MacOS" | ||
for bin in *; do | ||
test -L "$bin" && continue | ||
rm $bin | ||
lipo -create \ | ||
"$SPEK_X86_64/Contents/MacOS/$bin" \ | ||
"$SPEK_ARM64/Contents/MacOS/$bin" \ | ||
-o "$SPEK_UNIVERSAL/Contents/MacOS/$bin" | ||
done | ||
|
||
# Merge x86_64, arm64 libraries | ||
cd "$SPEK_UNIVERSAL/Contents/Frameworks" | ||
for bin in *; do | ||
test -L "$bin" && continue | ||
rm $bin | ||
lipo -create \ | ||
"$SPEK_X86_64/Contents/Frameworks/$bin" \ | ||
"$SPEK_ARM64/Contents/Frameworks/$bin" \ | ||
-o "$SPEK_UNIVERSAL/Contents/Frameworks/$bin" | ||
done | ||
|
||
# Sign the app | ||
codesign -fs - "$SPEK_UNIVERSAL" --deep | ||
|
||
# Create a gzip tar archive | ||
cd "$SPEK_UNIVERSAL/.." | ||
rm -f Spek.tgz | ||
tar cvzf Spek.tgz Spek.app |
Oops, something went wrong.