cpanm で Image::Magick のインストールをする方法

その前に

cpanm で Image::Magick をインストールする環境は次のようになっている。

  • perlbrew で Perl 5.12.1 をインストールしている
  • cpanm は perlbrew のインストール時にインストールされたもの
    手動で入れても、適宜設定を自分の環境に読み替えれば、成功すると思う
  • MacportsPerl 5.8.9 がインストールされているが、perlbrew の switch オプションで 5.12.1を 使う設定にしている
  • ImageMagickMacports でインストールをしている

cpanm で Image::Magick をインストールする際に出るエラー表示

% cd ~
% cpanm Image::Magick
--> Working on Image::Magick
Fetching http://search.cpan.org/CPAN/authors/id/J/JC/JCRISTY/PerlMagick-6.66.tar.gz ... OK
Configuring . ... N/A
! The distribution doesn't have a proper Makefile.PL/Build.PL See /Users/littlebuddha/.cpanm/build.log for details.

上記のエラー内容は、build.log を見ても同じ内容しか記録されていないので、役に立たない。また、「! The distribution doesn't have a proper Makefile.PL/Build.PL」のエラーを Google で探しても対応方法が見つからなかった。

救世主現る

今回、Image::Magick のインストールに成功したのは、下記のページを参考にしたため。

タイミングとしては、昨夜 Image::Magick のインストールに悩み、今夜も調べていたら、昨日公開された記事が運良く見つかったという幸運。

Image::Magick インストール前の準備

cpanm の --prompt オプションを使って、Image::Magcik のソースが展開されているディレクトリに移動する。

% cpanm --prompt Image::Magick
--> Working on Image::Magick
Fetching http://search.cpan.org/CPAN/authors/id/J/JC/JCRISTY/PerlMagick-6.66.tar.gz ... OK
Configuring . ... Configuring PerlMagick failed.
You can s)kip, r)etry or l)ook ? [s] l <-- ここで小文字の「l」を入力する
Entering /Users/littlebuddha/.cpanm/work/1290183254.757 with /bin/zsh
% pwd
/Users/littlebuddha/.cpanm/work/1290183254.757
% ls
PerlMagick-6.66        PerlMagick-6.66.tar.gz

MacPortsImageMagick をインストールしているが、Perl で使う Image::Magick のビルドに必要なデータは下記のディレクトリになる。他の環境でも、ImageMagick をインストールされたディレクトリを何とか探しておく(正確な場所が分からない場合は、それらしいディレクトリを入力して Try & Error を繰り返す)。

  1. Image::Magick をインストールするディレクト
    ~/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/
  2. man をそれぞれインストールするディレクト
    ~/perl5/perlbrew/perls/perl-5.12.1/man/man1/
    ~/perl5/perlbrew/perls/perl-5.12.1/man/man3/
  3. Image::Magick ビルドに必要な MacPorts でインストールされた ImageMagcik のディレクト
    /opt/local/include/ImageMagick
    /opt/local/lib/

make の前の準備

% pwd
/Users/littlebuddha/.cpanm/work/1290183254.757
% perl Makefile.PL LIB=~/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/ INSTALLMAN1DIR=~/perl5/perlbrew/perls/perl-5.12.1/man/man1/ INSTALLMAN3DIR=~/perl5/perlbrew/perls/perl-5.12.1/man/man3/
Checking if your kit is complete...
Looks good
Note (probably harmless): No library found for -lperl
Writing Makefile for Image::Magick

Makefile.PL の編集

編集箇所は下記の4行のうち、最初の2行目と4行目を編集する。編集する行は160行目ぐらいにある。
編集前の内容。

167 # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
168 my $INC_magick = trim(`MagickCore-config --cppflags`) . ' -I../ -I.. -I"' . $Config{'usrinc'} . '/ImageMagick" ';
169 my $LIBS_magick = '-L../magick/.libs -lMagickCore -lperl -lm';
170 my $CCFLAGS_magick = trim(`MagickCore-config --cflags`) . ' -fopenmp -g -O2 -Wall -pthread' . $Config{'ccflags'};

編集後。

167 # defaults for LIBS & INC & CCFLAGS params that we later pass to Writemakefile
168 my $INC_magick = '-I/opt/local/include/ImageMagick ' . trim(`MagickCore-config --cppflags`) . ' -I../ -I.. -I"' . $Config{'usrinc'} . '/ImageMagic    k" ';
169 my $LIBS_magick = '-L/opt/local/lib -L../magick/.libs -lMagickCore -lperl -lm';
170 my $CCFLAGS_magick = trim(`MagickCore-config --cflags`) . ' -fopenmp -g -O2 -Wall -pthread' . $Config{'ccflags'};

Image::Magick をインストールをする

ここまでできたら、あとはインストールするのみ。

% make && make install
chmod 755 blib/arch/auto/Image/Magick/Magick.bundle
cp Magick.bs blib/arch/auto/Image/Magick/Magick.bs
chmod 644 blib/arch/auto/Image/Magick/Magick.bs
Manifying blib/man3/Image::Magick.3
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/Image/Magick/Magick.bs
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/Image/Magick/Magick.bundle
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/auto/Image/Magick/autosplit.ix
Installing /Users/littlebuddha/local/lib/perl5/darwin-2level/Image/Magick.pm
Installing /Users/littlebuddha/local/man/man3/Image::Magick.3
Appending installation info to /Users/littlebuddha/local/lib/perl5/darwin-2level/perllocal.pod
%

今回、Image::Magick をインストールできたのは、本当にラッキーだったに尽きる。