Skip to content

Instantly share code, notes, and snippets.

@fny
Last active July 27, 2020 01:20
Show Gist options
  • Save fny/4583529 to your computer and use it in GitHub Desktop.
Save fny/4583529 to your computer and use it in GitHub Desktop.
OS X shell script to fix RMagick compilation issues when using Homebrew's ImageMagick installation. This script will create the symlinks needed for RMagick to compile. Quantum depths of 8 and 16-bits supported.
#! /bin/sh
#
# An OS X shell script to fix RMagick compilation issues when using Homebrew's
# ImageMagick installation. This script creates the symlinks needed for
# RMagick to compile. Quantum depths of 8 and 16-bits are supported.
#
# You can run this script with "sh whatever_script_name.sh" in your terminal
# or with a click if you change the file extension to "command".
#
# You can manually make the links by visiting the ImagicMagick library
# directory via "cd `Magick-config --prefix`/lib" and running the code block
# code block below under the heading "# L is for Linkage".
#
# Copyright (C) 2013 Faraz Yashar
#
# Distributed under the MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
set -e
echo "
This OS X shell script will create the symlinks needed for RMagick to compile for
quantum depths of 8 and 16-bits as appropriate for your ImageMagick installation.
You can manually make the modifications by visiting the ImagicMagick library
directory via 'cd \`Magick-config --prefix\`/lib' and running the appropriate
code block in this scripts source found after the heading '\# L is for Linkage'.
Many thanks to Pavel Pasoud (rwz@github) for providing this solution:
- https://coderwall.com/p/wnomjg
- https://github.com/mxcl/homebrew/issues/16625#issuecomment-11519383
As of this gist's publication, RMagick was last updated forever ago: 2010-04-05.
Consider using another library. Seriously.
"
[ "`uname`" = "Darwin" ] || { "This script is for OS X, yo. RTFM!"; exit 1; }
[ `command -v Magick-config` ] || {
echo "Hmm... I can't find ImageMagick."
[ `command -v brew` ] || {
echo "And I can't find Homebrew!"
echo "How can you expect me to install ImageMagick without it?"
echo "Go to the Homebrew homepage for installation instructions: http://mxcl.github.com/homebrew/"
exit 1;
}
echo "Want me to install it via Homebrew? (y/n)"
read response
case $response in
y|Y|yes|Yes|YES)
echo "Attempting to install ImageMagick with Homebrew."
echo "Note if anything goes wrong during installation this script will exit."
echo "In that case, you can run this script again after you've installed imagemagick."
brew install imagemagick;;
*) echo "Bye bye!"; exit;;
esac
}
magick_lib=`Magick-config --prefix`/lib
[ "`Magick-config --version | grep Q8`" ] && quantum_depth=8
[ "`Magick-config --version | grep Q16`" ] && quantum_depth=16
if [ -z "$quantum_depth" ]; then
echo "I couldn't determine your ImageMagick installation's quantum depth from \`Magick-config --version\`."
echo "Perhaps a look in $magick_lib will provide a hint?"
echo "Which do you have installed 8 or 16?"
while true; do
read response
case $response in
0) exit;;
8) quantum_depth=8; break;;
16) quantum_depth=16; break;;
*) echo "8 or 16, please (or 0 if you give up)";;
esac
done
else
echo "Quantum depth of $quantum_depth bits detected!"
fi
echo "Linking $quantum_depth-bit libraries in $magick_lib..."
cd $magick_lib
# L is for Linkage
if [ $quantum_depth -eq 16 ]; then
ln -sf libMagick++-Q16.7.dylib libMagick++.dylib
ln -sf libMagickCore-Q16.7.dylib libMagickCore.dylib
ln -sf libMagickWand-Q16.7.dylib libMagickWand.dylib
fi
if [ $quantum_depth -eq 8 ]; then
ln -sf libMagick++-Q8.7.dylib libMagick++.dylib
ln -sf libMagickCore-Q8.7.dylib libMagickCore.dylib
ln -sf libMagickWand-Q8.7.dylib libMagickWand.dylib
fi
echo "Done! Here are the contents of $magick_lib after linking:"
ls -G $magic_lib
echo "\nHappy hacking. ;D"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment