Skip to content

Instantly share code, notes, and snippets.

@sprout42
Last active June 28, 2020 13:21
Show Gist options
  • Save sprout42/b86ec97edd362ed64fef4cf5385f15d4 to your computer and use it in GitHub Desktop.
Save sprout42/b86ec97edd362ed64fef4cf5385f15d4 to your computer and use it in GitHub Desktop.
WIP: Building a standalone Instagiffer install for MacOS
brew install tcl-tk
brew install pyenv
<setup .bash_profile for pyenv>
# Make sure not to use a virtualenv! py2app doesn't work
# we have to use a pyenv-alias instead to make a clean pythong env
git clone https://github.com/s1341/pyenv-alias.git $(pyenv root)/plugins/pyenv-alias
VERSION_ALIAS="2.7.16_instagiffer" \
LDFLAGS="-L$(brew --prefix zlib)/lib -L$(brew --prefix sqlite)/lib -L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6" \
CPPFLAGS="-I$(brew --prefix zlib)/include -I$(brew --prefix sqlite)/include -I$(brew --prefix tcl-tk)/include" \
PYTHON_CONFIGURE_OPTS='--enable-framework' \
pyenv install 2.7.16
git clone https://github.com/ex-hale/instagiffer
cd instagiffer
pyenv local 2.7.16_instagiffer
pip install pillow py2app pyobjc-framework-Cocoa
# because the Mac sed version sucks
brew install gnu-sed
# Patch py2app to disable compression, if we don't do this the resulting applications can't unpack
# themselves because py2app is doing something wrong
#gsed -ie "s/self\.compressed = True/self.compressed = False/" $(dirname $(python -c "import py2app; print py2app.__file__"))/build_app.py
# adaptation of the "ImageMagick build instructions"
# https://github.com/ex-hale/instagiffer/blob/704a8abcab6b0e4fa5ea69feddcc6ae5e9caedbe/README.md#building-imagemagick-mac
# run from the instagiffer git root
brew install imagemagick
IM_PATH=$(realpath $(brew --prefix imagemagick))
mkdir -p ./macdeps/im/bin ./macdeps/im/etc ./macdeps/im/usr ./macdeps/im/lib
cp -af $IM_PATH ./macdeps/im
cp -af $(brew --prefix)/etc/fonts ./macdeps/im/etc
find . \( -name "*.xml" -o -name "*.conf" \) | xargs gsed -ie "s:$IM_PATH:./macdeps/im:"
# Utility function to recursively find dependencies
BREW_PREFIX=$(brew --prefix)
getdeps() {
deps=( $(otool -L $1 | tail -n +2 | awk '{print substr($1, 1, length($1))}') )
for x in ${deps[@]}; do
if [[ $(basename $x) != $(basename $1) && $x =~ ^$BREW_PREFIX ]]; then
echo $x
getdeps $x
fi
done
}
# Copy non-standard dependencies into the "im" lib folder
for x in $(getdeps ./macdeps/im/bin/magick | sort | uniq); do
cp -af $x ./macdeps/im/lib/
done
# Now modify the link paths for all dylibs and Mach-O binaries copied
dylibs=( $(find ./macdeps/im -name "*.dylib" -type f) )
dylibs+=('./macdeps/im/bin/magick')
for dylib in ${dylibs[@]}; do
chmod +w $dylib
deps=( $(otool -L $dylib | tail -n +2 | awk '{print substr($1, 1, length($1))}') )
for x in ${deps[@]}; do
if [[ $(basename $x) != $(basename $dylib) && $x =~ ^$BREW_PREFIX ]]; then
install_name_tool -change $x @executable_path/../lib/$(basename $x) $dylib
fi
done
chmod -w $dylib
done
gsed -i "s/'packages': \['PIL'\]/#\0/" setup-mac-py2app.py
gsed -i "s/^\tmake_dmg$/#\0/" make_app.sh
gsed -i "s/^\tmake_pkg$/#\0/" make_app.sh
./make_app.sh
dylibs=( $(find ./dist -name "*.so" -type f) )
for dylib in ${dylibs[@]}; do
deps=( $(otool -L $dylib | tail -n +2 | awk '{print substr($1, 1, length($1))}') )
for x in ${deps[@]}; do
if [[ $(basename $x) != $(basename $dylib) ]]; then
if [[ $x =~ ^@loader_path/.dylibs/ ]]; then
install_name_tool -change $x @executable_path/../Frameworks/$(basename $x) $dylib
#elif [[ $x == /System/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl ]]; then
# install_name_tool -delete_rpath $x $dylib
#elif [[ $x == /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk ]]; then
# install_name_tool -delete_rpath $x $dylib
fi
fi
done
done
# Well... it's different anyway
$ dist/Instagiffer.app/Contents/MacOS/Instagiffer
Traceback (most recent call last):
File "<snip>/instagiffer/dist/Instagiffer.app/Contents/Resources/__boot__.py", line 132, in <module>
_recipes_pil_prescript(['Hdf5StubImagePlugin', 'FitsStubImagePlugin', 'SunImagePlugin', 'IptcImagePlugin', 'GbrImagePlugin', 'PngImagePlugin', 'Jpeg2KImagePlugin', 'MicImagePlugin', 'FpxImagePlugin', 'PcxImagePlugin', 'ImImagePlugin', 'SpiderImagePlugin', 'PsdImagePlugin', 'BufrStubImagePlugin', 'SgiImagePlugin', 'BlpImagePlugin', 'XpmImagePlugin', 'DdsImagePlugin', 'MpoImagePlugin', 'BmpImagePlugin', 'TgaImagePlugin', 'PalmImagePlugin', 'XVThumbImagePlugin', 'GribStubImagePlugin', 'PdfImagePlugin', 'ImtImagePlugin', 'FtexImagePlugin', 'GifImagePlugin', 'CurImagePlugin', 'McIdasImagePlugin', 'MpegImagePlugin', 'IcoImagePlugin', 'TiffImagePlugin', 'PpmImagePlugin', 'MspImagePlugin', 'EpsImagePlugin', 'JpegImagePlugin', 'PixarImagePlugin', 'PcdImagePlugin', 'WmfImagePlugin', 'FliImagePlugin', 'DcxImagePlugin', 'IcnsImagePlugin', 'WebPImagePlugin', 'XbmImagePlugin'])
File "<snip>/instagiffer/dist/Instagiffer.app/Contents/Resources/__boot__.py", line 90, in _recipes_pil_prescript
from PIL import Image
File "PIL/Image.pyo", line 93, in <module>
File "PIL/_imaging.pyo", line 14, in <module>
File "PIL/_imaging.pyo", line 10, in __load
ImportError: dlopen(<snip>/instagiffer/dist/Instagiffer.app/Contents/Resources/lib/python2.7/lib-dynload/PIL/_imaging.so, 2): bad rebase opcode 183 in /<snip>/instagiffer/dist/Instagiffer.app/Contents/MacOS/../Frameworks/libz.1.2.11.dylib
2019-06-04 22:34:55.770 Instagiffer[42347:28821440] Instagiffer Error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment