• このエントリーをはてなブックマークに追加


メモ

Mac で ImageMagick をビルドする際,それが依存するライブラリについては,homebrew で入れたものを利用してました.

あまり考えなしに brew up; brew upgrade してきたら,こんな感じ:

% ~/local/bin/convert --version
dyld: Library not loaded: /usr/local/lib/libgs.9.06.dylib
  Referenced from: /Users/issm/local/bin/convert
  Reason: image not found
[1]    68938 trace trap  ~/local/bin/convert --version

に「依存ライブラリが見つからん」とかなったり.

バージョン上げずに,というのも手だけど brew outdated で表示されるものが増えていくのはなんとも.

そんなわけで,ImageMagick(今回は 6.8.9-5) をビルドする際に,上記のような被害が起こりやすい(と個人的に思っている)ライブラリ libjpeglibpngghotstscript あとついでに libtiff あたりもビルドして,同だけが参照するような風にもっていってみます.

目的

$HOME/local/imagemagick/6.8.9-5/bin/convert のような感じで使えるようにする.

tarballs

% pwd
/Users/issm/local/imagemagick/6.8.9-5/dist
% ls -1
ImageMagick-6.8.9-5.tar.gz
ghostscript-9.14.tar.gz
jpeg-8d.tar.gz
libpng-1.6.12.tar.gz
tiff-4.0.3.tar.gz

jpeg

% CFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
LDFLAGS="-L$HOME/local/imagemagick/6.8.9-5/lib" \
CPPFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
./configure \
    --prefix=$HOME/local/imagemagick/6.8.9-5
% make
% make install

tiff

% CFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
LDFLAGS="-L$HOME/local/imagemagick/6.8.9-5/lib" \
CPPFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
./configure \
    --prefix=$HOME/local/imagemagick/6.8.9-5
% nmake
% make install

png

% CFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
LDFLAGS="-L$HOME/local/imagemagick/6.8.9-5/lib" \
CPPFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
./configure \
    --prefix=$HOME/local/imagemagick/6.8.9-5
% make
% make test
% make install

ghostscript

% CFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
LDFLAGS="-L$HOME/local/imagemagick/6.8.9-5/lib" \
CPPFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
./configure \
    --prefix=$HOME/local/imagemagick/6.8.9-5 \
    --without-x \
    --disable-cups \
    --disable-compile-inits \
    --disable-gtk
% make
% make install

ImageMagick

% PATH="$HOME/local/imagemagick/6.8.9-5/bin:$PATH" \
LDFLAGS="-L$HOME/local/imagemagick/6.8.9-5/lib" \
CPPFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
CFLAGS="-I$HOME/local/imagemagick/6.8.9-5/include" \
./configure \
    --prefix=$HOME/local/imagemagick/6.8.9-5 \
    --with-jpeg \
    --with-png \
    --without-gslib \
    --without-jbig \
    --without-wmf \
    --with-freetype \
    --enable-shared \
    --disable-static \
    --without-x \
    --disable-dependency-tracking \
    --with-lcms2 \
    --with-perl
% make
% make install

ライブラリの依存状況は次のような感じ:

% otool -L  ~/local/imagemagick/6.8.9-5/bin/convert
/Users/issm/local/imagemagick/6.8.9-5/bin/convert:
	/Users/issm/local/imagemagick/6.8.9-5/lib/libMagickCore-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
	/Users/issm/local/imagemagick/6.8.9-5/lib/libMagickWand-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
	/usr/local/lib/liblcms2.2.dylib (compatibility version 3.0.0, current version 3.6.0)
	/Users/issm/local/imagemagick/6.8.9-5/lib/libtiff.5.dylib (compatibility version 8.0.0, current version 8.0.0)
	/Users/issm/local/imagemagick/6.8.9-5/lib/libjpeg.8.dylib (compatibility version 13.0.0, current version 13.0.0)
	/Users/issm/local/imagemagick/6.8.9-5/lib/libpng16.16.dylib (compatibility version 29.0.0, current version 29.0.0)
	/usr/local/lib/libfontconfig.1.dylib (compatibility version 10.0.0, current version 10.0.0)
	/usr/local/lib/libfreetype.6.dylib (compatibility version 18.0.0, current version 18.2.0)
	/usr/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.3.0)
	/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
	/usr/local/lib/libpango-1.0.0.dylib (compatibility version 3601.0.0, current version 3601.5.0)
	/usr/local/lib/libgobject-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
	/usr/local/lib/libglib-2.0.0.dylib (compatibility version 4001.0.0, current version 4001.0.0)
	/usr/local/opt/gettext/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.2.0)
	/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

狙ったとおりの参照になっている感じかな.

ちなみに

./configure の際にPATH をセットしているのは,$HOME/local/imagemagick/6.8.9-5/bin/gs を通すため.

./configure の result:

                  Option                        Value
-------------------------------------------------------------------------------
Shared libraries  --enable-shared=yes		yes
Static libraries  --enable-static=no		no
Module support    --with-modules=no		no
GNU ld            --with-gnu-ld=no		no
Quantum depth     --with-quantum-depth=16	16
High Dynamic Range Imagery
                  --enable-hdri=no		no
 
Install documentation:		yes
 
Delegate Configuration:
BZLIB             --with-bzlib=yes		yes
Autotrace         --with-autotrace=no		no
Dejavu fonts      --with-dejavu-font-dir=default	none
DJVU              --with-djvu=yes		no
DPS               --with-dps=yes		no
FFTW              --with-fftw=yes		no
FlashPIX          --with-fpx=yes		no
FontConfig        --with-fontconfig=yes		yes
FreeType          --with-freetype=yes		yes
GhostPCL          None				pcl6 (unknown)
GhostXPS          None				gxps (unknown)
Ghostscript       None				gs (9.14)
Ghostscript fonts --with-gs-font-dir=default	/usr/local/share/ghostscript/fontsx/
Ghostscript lib   --with-gslib=no		no
Graphviz          --with-gvc=no
JBIG              --with-jbig=no		no
JPEG v1           --with-jpeg=yes		yes
JPEG-2000         --with-jp2=
LCMS v1           --with-lcms=no		no
LCMS v2           --with-lcms2=yes		yes
LQR               --with-lqr=yes		no
LTDL              --with-ltdl=yes		no
LZMA              --with-lzma=yes		yes
Magick++          --with-magick-plus-plus=yes	yes
OpenEXR           --with-openexr=yes		no
OpenJP2           --with-openjp2=yes		no
PANGO             --with-pango=yes		yes
PERL              --with-perl=yes		/Users/issm/.plenv/shims/perl
PNG               --with-png=yes		yes
RSVG              --with-rsvg=no		no
TIFF              --with-tiff=yes		yes
WEBP              --with-webp=yes		no
Windows fonts     --with-windows-font-dir=	none
WMF               --with-wmf=no		no
X11               --with-x=no			no
XML               --with-xml=yes		yes
ZLIB              --with-zlib=yes		yes
 
X11 Configuration:
      X_CFLAGS        =
      X_PRE_LIBS      =
      X_LIBS          =
      X_EXTRA_LIBS    =
 
Options used to compile and link:
  PREFIX          = /Users/issm/local/imagemagick/6.8.9-5
  EXEC-PREFIX     = /Users/issm/local/imagemagick/6.8.9-5
  VERSION         = 6.8.9
  CC              = gcc
  CFLAGS          = -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/Users/issm/local/imagemagick/6.8.9-5/include -Wall -march=corei7-avx -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
  CPPFLAGS        = -D_REENTRANT -I/usr/local/Cellar/pango/1.36.5/include/pango-1.0 -I/usr/local/Cellar/glib/2.40.0_1/include/glib-2.0 -I/usr/local/Cellar/glib/2.40.0_1/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/xz/5.0.5/include -I/usr/local/Cellar/fontconfig/2.11.1/include -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/Users/issm/local/imagemagick/6.8.9-5/include -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
  PCFLAGS         =
  DEFS            = -DHAVE_CONFIG_H
  LDFLAGS         = -L/Users/issm/local/imagemagick/6.8.9-5/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
  LIBS            =
  CXX             = g++
  CXXFLAGS        = -g -O2 -D_THREAD_SAFE -pthread
  FEATURES        = DPC
  DELEGATES       = bzlib mpeg fontconfig freetype jng jpeg lcms lzma pango png ps tiff xml zlib

のうち, “Ghostscript” の部分に影響してくる感じ:

Ghostscript       None				gs (9.14)

Image::Magick

plenv にて,PLENV_VERSION=5.18@default として入れた perl に対してモジュールをインストール.

% cd ~/local/imagemagick/6.8.9-5/dist/ImageMagick-6.8.9-5
% cp -r PerlMagick PerlMagick.5.18@default
% cd PerlMagick.5.18@default

Makefile.PL を編集.

$LIBS_magick-L/Users/issm/.plenv/versions/5.18@default/lib/perl5/5.18.2/darwin-2level/CORE を追加します:

diff --git a/Makefile.PL b/Makefile.PL
index a01c11d..d17b463 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -162,7 +162,7 @@ foreach my $delegate (@tested_delegates) {
 
 # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
 my $INC_magick = '-I../ -I.. -D_REENTRANT -I/usr/local/Cellar/pango/1.36.5/include/pango-1.0 -I/usr/local/Cellar/glib/2.40.0_1/include/glib-2.0 -I/usr/local/Cellar/glib/2.40.0_1/lib/glib-2.0/include -I/usr/local/opt/gettext/include -I/usr/local/Cellar/xz/5.0.5/include -I/usr/local/Cellar/fontconfig/2.11.1/include -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/Users/issm/local/imagemagick/6.8.9-5/include -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 -I"' . $Config{'usrinc'} . '/ImageMagick"';
-my $LIBS_magick = '-L../magick/.libs -lMagickCore-6.Q16 -lperl -lm';
+my $LIBS_magick = '-L/Users/issm/.plenv/versions/5.18@default/lib/perl5/5.18.2/darwin-2level/CORE -L../magick/.libs -lMagickCore-6.Q16 -lperl -lm';
 my $CCFLAGS_magick = "$Config{'ccflags'} -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/Users/issm/local/imagemagick/6.8.9-5/include -Wall -march=corei7-avx -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16";
 my $LDFLAGS_magick   = "-L../magick/.libs -lMagickCore-6.Q16 $Config{'ldflags'} -L/Users/issm/local/imagemagick/6.8.9-5/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib";
 my $LDDLFLAGS_magick = "-L../magick/.libs -lMagickCore-6.Q16 $Config{'lddlflags'} -L/Users/issm/local/imagemagick/6.8.9-5/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib";

そして:

% PLENV_VERSION=5.18@default perl Makefile.PL
% make
% make test

そして:

% make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/issm/.plenv/versions/5.18@default/lib/perl5/site_perl/5.18.2/darwin-2level/auto/Image/Magick/Magick.bundle
Appending installation info to /Users/issm/.plenv/versions/5.18@default/lib/perl5/5.18.2/darwin-2level/perllocal.pod

これで,

% PLENV_VERSION=5.18@default perl -MImage::Magick -le 1

としても,Can't locate とか言われない.