Makefile.PL を直接書き換えなくとも,
perl Makefile.PL の際のオプションとして指定できるとのご指摘をいただき,該当個所を修正しました.(Thanks to @nekokak)
はじめに
perlbrew + cpanminus(以下,cpanm) な環境を試みている今日この頃,DBIがらみで一部つまずいたので,その解決までのメモです.
環境について
現状
- Perl-5.8.9
- MySQL-5.0.85
- …
これらを MacPorts 経由でインストールしています.
これから
Perl-5.8.9 に加え,さすがにそろそろ Perl-5.12 なんかも使いたいよね,ということで,perlbrew + cpanm な環境を準備しています.
エラー
cpanm DBI や cpanm DBIx::Skinny などが「Successfully installed」された後に,以前の環境で動作していたアプリを動かしてみたところ,次のようなが出ました.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@ DBIx::Skinny 's Exception @@@@@ Reason : install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC contains: /Works/Hoya/master/lib /Works/Hoya/master/extlib lib /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9/darwin-2level /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9 /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9/darwin-2level /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9 .) at (eval 178) line 3. Perhaps the DBD::mysql perl module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge. at lib/DBIx/Skinny.pm line 229
手動でインストール
コマンドラインで確認
先のエラーでは,DBD::mysql がない,と言われています.
% perl -MDBD::mysql -le 1 Can't locate DBD/mysql.pm in @INC (@INC contains: /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9/darwin-2level /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9 /Users/iwata/perl5/perlbrew/perls/p erl-5.8.9/lib/site_perl/5.8.9/darwin-2level /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9 .). BEGIN failed--compilation aborted. %
確かに.
とりあえず cpanm
まずは脊髄反射的に cpanm DBD::mysql してみます.
% cpanm -v DBD::mysql ... DBD-mysql-4.017/t/mysql.dbtest DBD-mysql-4.017/t/mysql.mtest DBD-mysql-4.017/TODO Entering DBD-mysql-4.017 Checking if you have ExtUtils::MakeMaker 0 ... Yes (6.48) Configuring DBD-mysql-4.017 ... Running Makefile.PL Can't exec "mysql_config": No such file or directory at Makefile.PL line 82. Cannot find the file 'mysql_config'! Your execution PATH doesn't seem not contain the path to mysql_config. Resorting to guessed values! Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user 'iwata' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to 'iwata'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Can't exec "mysql_config": No such file or directory at Makefile.PL line 464. Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located Failed to determine directory of mysql.h. Use perl Makefile.PL --cflags=-I<dir> to set this directory. For details see the INSTALL.html file, section "C Compiler flags" or type perl Makefile.PL --help N/A ! Configure failed for DBD-mysql-4.017. See /Users/iwata/.cpanm/build.log for details. %
失敗しました orz
Makefile.PL を直接編集する
メッセージを見るに,mysql_config がない,ということが,なんとなくわかります.
MacPorts 経由で MySQL(5系) を入れると,同様のコマンドが mysql_config5 となっている(正確には/opt/local/lib/mysql5/bin/mysql_config へのシンボリックリンク)ようなので,これが原因のようです.
そこで,~/.cpanm/work/latest-build/DBD-mysql-4.017/Makefile.PL のそれっぽい個所を直接編集してみます.その差分を次に.
% perl Makefile.PL --mysql_config=/opt/local/bin/mysql_config5 [14:48:53] denske.local PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user 'iwata' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to 'iwata'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username I will use the following settings for compiling and testing: cflags (mysql_config) = -I/opt/local/include/mysql5/mysql -arch i386 -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT embedded (mysql_config) = libs (mysql_config) = -L/opt/local/lib -L/opt/local/lib/mysql5/mysql -lmysqlclient -L/opt/local/lib -lz -lm -L/opt/local/lib -lssl -lcrypto mysql_config (Users choice) = /opt/local/bin/mysql_config5 nocatchstderr (default ) = 0 nofoundrows (default ) = 0 ssl (guessed ) = 1 testdb (default ) = test testhost (default ) = testpassword (default ) = testsocket (default ) = testuser (guessed ) = iwata To change these settings, see 'perl Makefile.PL --help' and 'perldoc INSTALL'. Using DBI 1.613 (for perl 5.008009 on darwin-2level) installed in /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9/darwin-2level/auto/DBI/ Writing Makefile for DBD::mysql %
オプションをつけて Makefile.PL を実行する
メッセージを見るに,「mysql_config がないよ」とか「perl Makefile.PL --help してみてね」というようなことが,なんとなくわかります.(見落としていました ><)
そこで,~/.cpanm/work/latest-build/DBD-mysql-4.017 に入って,perl Makefile.PL --help してみます.
% perl Makefile.PL --help [14:56:50] denske.local Usage: perl Makefile.PL [options] Possible options are: ... --mysql_config=<path> Specify <path> for mysql_config script ... All options may be configured on the command line. If they are not present on the command line, then mysql_config is called (if it can be found): mysql_config --cflags mysql_config --libs mysql_config --embedded mysql_config --testdb and so on. See the INSTALL.html file for details. %
--mysql_config オプション,ありましたね.これに正しいパスを指定してあげればよさげです.
MacPorts 経由で MySQL(5系) を入れると,同様のコマンドが mysql_config5 となっている(正確には/opt/local/lib/mysql5/bin/mysql_config へのシンボリックリンク)ようなので,このフルパスを与えてみます.
% perl Makefile.PL --mysql_config=/opt/local/bin/mysql_config5 [15:01:00] denske.local PLEASE NOTE: For 'make test' to run properly, you must ensure that the database user 'iwata' can connect to your MySQL server and has the proper privileges that these tests require such as 'drop table', 'create table', 'drop procedure', 'create procedure' as well as others. mysql> grant all privileges on test.* to 'iwata'@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.PL --testuser=username I will use the following settings for compiling and testing: cflags (mysql_config) = -I/opt/local/include/mysql5/mysql -arch i386 -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT embedded (mysql_config) = libs (mysql_config) = -L/opt/local/lib -L/opt/local/lib/mysql5/mysql -lmysqlclient -L/opt/local/lib -lz -lm -L/opt/local/lib -lssl -lcrypto mysql_config (Users choice) = /opt/local/bin/mysql_config5 nocatchstderr (default ) = 0 nofoundrows (default ) = 0 ssl (guessed ) = 1 testdb (default ) = test testhost (default ) = testpassword (default ) = testsocket (default ) = testuser (guessed ) = iwata To change these settings, see 'perl Makefile.PL --help' and 'perldoc INSTALL'. Using DBI 1.613 (for perl 5.008009 on darwin-2level) installed in /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9/darwin-2level/auto/DBI/ Writing Makefile for DBD::mysql %
お,Makefile を書き出せたようです.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 | PREFIX = $(SITEPREFIX) PERLPREFIX = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9 SITEPREFIX = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9 VENDORPREFIX = INSTALLPRIVLIB = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9 DESTINSTALLPRIVLIB = $(DESTDIR)$(INSTALLPRIVLIB) INSTALLSITELIB = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9 DESTINSTALLSITELIB = $(DESTDIR)$(INSTALLSITELIB) INSTALLVENDORLIB = DESTINSTALLVENDORLIB = $(DESTDIR)$(INSTALLVENDORLIB) INSTALLARCHLIB = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/5.8.9/darwin-2level DESTINSTALLARCHLIB = $(DESTDIR)$(INSTALLARCHLIB) INSTALLSITEARCH = /Users/iwata/perl5/perlbrew/perls/perl-5.8.9/lib/site_perl/5.8.9/darwin-2level ... |
インストール先も問題なさげです.
インストール
ということで,あとはいつものインストール操作.
% make && make test % make install
とりあえずコマンドラインで確認
% perl -MDBD::mysql -le 1 %
入っているっぽいですね.
まとめ
MacPorts 経由で MySQL5 をインストールしている場合,DBD::mysql モジュールを入れる際には,
mysql_config コマンドを mysql_config5 に置き換える感じで Makefile.PL を編集してから手動で make すべし,という感じでしょうか.--mysql_config オプションに,mysql_config5 へのフルパスを与えて perl Makefile.PL を実行してみましょう.これは試していませんが,
% sudo ln -s /opt/local/bin/mysql_config5 /usr/local/bin/mysql_config
みたいなことを予めしておけば,cpanm コマンドのみでいけるかも.
おわりに
以上,DBD::mysql モジュールのインストールにつまずき,ごにょごにょした後に手動でインストールするまでの過程でした.

Makefile.PLの中身を触るんじゃなくてMakefile.PLを実行するときの引数で指定可能ですよ
@nekokak
ご指摘ありがとうございます!
普段 perl Makefile.PL することがまずなかったので,
オプションを指定するという頭がありませんでした.
(エラーメッセージを読むとしっかり書いてありますね><)
perl Makefile.PL –mysql_config=
とすることで,解決できましたので,エントリもそのように修正しておきました.