Skip Menu |

This queue is for tickets about the DBD-mysql CPAN distribution.

Report information
The Basics
Id: 46926
Status: resolved
Priority: 0/
Queue: DBD-mysql

People
Owner: Nobody in particular
Requestors: csjewell [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 4.011
Fixed in: (no value)



Subject: Building DBD-mysql on (Win32) Strawberry Perl is much harder than it needs to be...
The best directions I found were at http://www.perlmonks.org/?node_id=738604. The first time I tried those, I dead-ended with link errors. 3 weeks later, I was able to figure out why. It's still complicated, so I tried to make it simple. This patch includes everything from those directions, including creating the mysql_config.bat script (while trying not to affect non-Win32 building) plus the fact that Strawberry Perl uses .a files rather than .lib files (but they happen to be identical, so a renamed/copied file can be used,) and the information I found out trying to do it myself (DBD::mysql needs libmysql, rather than libmysqlclient, for example.) So the best directions will now be: 1. Apply patch (or use patched version of Makefile.PL) 2. perl Makefile.PL 3. dmake && dmake test && dmake install I have not tested this patch with --embedded - is that used on Win32? Hopefully you apply this for 4.012...
Subject: DBD-mysql-Makefile.PL.patch
--- DBD-mysql-4.011.orig/Makefile.PL 2009-04-13 06:10:40.000000000 -0600 +++ DBD-mysql-4.011/Makefile.PL 2009-06-13 17:28:36.000000000 -0600 @@ -1,9 +1,9 @@ # -*- cperl -*- +use Config; BEGIN { - use Config; - if ($] == 5.008 && $ENV{"LANG"} ne "C") { + if ($] == 5.008 && $ENV{"LANG"} ne "C" && $^O ne 'MSWin32') { $ENV{LANG} = "C"; print STDERR "\n\n\n\$ENV{LANG} is not 'C' execing 'perl Makefile.PL'". " with ENV{LANG} == 'C'\n You can skip this check by: 'export ". @@ -20,6 +20,7 @@ use Data::Dumper (); use File::Path; use File::Copy; +use File::Basename; require DBI::DBD; my $TESTDB = "test"; @@ -45,17 +46,18 @@ "nofoundrows!", "embedded=s", "mysql_config=s", - "force-embedded" + "force-embedded", + "with-mysql=s" ) || die Usage(); my $source = {}; -if ($^O !~ /mswin32/i) -{ #Check for mysql_config first $source->{'mysql_config'}="guessed"; if ($opt->{'mysql_config'}) - { + { + $opt->{'mysql_config'} = Win32::GetShortPathName($opt->{'mysql_config'}) + if $^O eq 'MSWin32'; if (-f $opt->{'mysql_config'}) { $source->{'mysql_config'} = "Users choice"; @@ -73,6 +75,9 @@ } else { + if ($^O eq 'MSWin32') { + win32_mysql_config($opt->{'with-mysql'}); + } if (! `mysql_config`) { print <<MSG; @@ -83,7 +88,6 @@ } $opt->{'mysql_config'} = "mysql_config"; } -} for my $key (qw/testdb testhost testuser testpassword testsocket cflags embedded libs nocatchstderr ssl nofoundrows @@ -391,7 +395,7 @@ by default the port number is choosen from the mysqlclient library --mysql_config=<path> Specify <path> for mysql_config script - (Not supported on Win32) + --with-mysql=<path> Specify <path> for the root of the MySQL installation. --nocatchstderr Supress using the "myld" script that redirects STDERR while running the linker. --nofoundrows Change the behavior of \$sth->rows() so that it @@ -445,8 +449,6 @@ return; } - if ($^O !~ /mswin32/i) - { # First try to get options values from mysql_config my $command = $opt->{'mysql_config'} . " --$param"; eval @@ -480,29 +482,30 @@ { print "Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located\n"; } - } # Ok, mysql_config doesn't work. We need to do our best if ($param eq 'testuser') { unless ($opt->{$param}) { + my $user = $ENV{USER} || ''; print " PLEASE NOTE: For 'make test' to run properly, you must ensure that the -database user '$ENV{USER}' can connect to your MySQL server +database user '$user' 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 '$ENV{USER}'\@'localhost' identified by 's3kr1t'; +mysql> grant all privileges on test.* to '$user'\@'localhost' identified by 's3kr1t'; You can also optionally set the user to run 'make test' with: perl Makefile.pl --testuser=username "; - $opt->{$param}= $ENV{USER}; + $opt->{$param} = $user; + $source->{$param} = 'guessed'; } } elsif ($param eq "nocatchstderr" || $param eq "nofoundrows") @@ -735,6 +738,166 @@ close(LOG); } +sub win32_mysql_config { + my ($mysql_dir) = @_; + my $mysqladmin; + + if ($mysql_dir) { + unless (-d $mysql_dir) { + die qq{"$mysql_dir" does not exist}; + } + $mysqladmin = File::Spec->catfile($mysql_dir, 'bin', 'mysqladmin.exe'); + unless (-f $mysqladmin) { + die qq{"bin/mysqladmin.exe" not found under "$mysql_dir"}; + } + } + + my (@path_ext) = path_ext(); + unless ($mysqladmin) { + $mysqladmin = which('mysqladmin', @path_ext); + unless ($mysqladmin) { + die << 'DEATH'; +mysqladmin.exe was not found in your PATH. +Please either add the directory containing mysqladmin.exe +to your PATH environment variable, or rerun this script +with the --with-mysql=C:\Path\to\Mysql option, giving the +root directory of your MySQL installation. +DEATH + } + ($mysql_dir = dirname($mysqladmin)) =~ s{[/\\]bin[/\\]?$}{}; + } + + my $basedir = Win32::GetShortPathName($mysql_dir); + my $ldata = File::Spec->catdir($basedir, 'data'); + my $execdir = File::Spec->catdir($basedir, 'bin'); + my $bindir = File::Spec->catdir($basedir, 'bin'); + my $pkglibdir= File::Spec->catdir($basedir, 'lib', 'opt'); + my $pkgincludedir = File::Spec->catdir($basedir, 'include'); + my $ldflags = ''; + my $client_libs = $Config{'cc'} eq 'gcc' ? '-lmysql -lzlib' : '-lmysqlclient -lzlib'; + + if (($Config{'_a'} eq '.a') and (! -e File::Spec->catfile($pkglibdir, 'libmysql.a'))) { + # This is done because ExtUtils::Liblist expects .a files, not .lib files. + copy(File::Spec->catfile($pkglibdir, 'libmysql.lib'), File::Spec->catfile($pkglibdir, 'libmysql.a')); + copy(File::Spec->catfile($pkglibdir, 'zlib.lib'), File::Spec->catfile($pkglibdir, 'libzlib.a')); + } + + $mysqladmin = Win32::GetShortPathName($mysqladmin); + my $v = qx($mysqladmin version); + unless ($v) { + print STDERR "Problem running $mysqladmin - aborting ...\n"; + exit(1); + } + + my ($version, $port); + if ($v =~ /Server version\s+(.*?)\n/m) { + $version = $1; + } + if ($v =~ /TCP port\s+(.*?)\n/m) { + $port = $1; + } + + my $libs = qq{$ldflags -L"$pkglibdir" $client_libs}; + my $cflags = qq{-I"$pkgincludedir"}; + my $embedded_libs = qq{$ldflags -L"$pkglibdir"}; + + my $license = <<'EOL'; +# Copyright (C) 2005 MySQL AB & MySQL Finland AB & TCX DataKonsult AB +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# This script reports various configuration settings that may be needed +# when using the MySQL client library. +EOL + + my $mysql_config = File::Spec->catfile($basedir, 'bin', 'mysql_config.pl'); + open(my $fh, '>', $mysql_config) + or die "Cannot open $mysql_config for writing: $!"; + + print $fh <<"EOL"; +#!$^X +use strict; +use warnings; +use Getopt::Long; + +$license + +my \$basedir = q{$basedir}; +my \$ldata = q{$ldata}; +my \$execdir = q{$execdir}; +my \$bindir = q{$bindir}; +my \$pkglibdir = q{$pkglibdir}; +my \$pkgincludedir = q{$pkgincludedir}; +my \$ldflags = q{$ldflags}; +my \$client_libs = q{$client_libs}; +my \$version = q{$version}; +my \$port = q{$port}; +my \$libs = q{$libs}; +my \$cflags = q{$cflags}; +my \$embedded_libs = q{$embedded_libs}; +EOL + + while (<DATA>) { + print $fh $_; + } + close $fh; + my @args = ('pl2bat', $mysql_config); + system(@args) == 0 or die "System @args failed: $?"; + + print << "END"; + +mysql_config.pl, and an associated bat file, has been +successfully created under + $basedir\\bin + +END + + return; +} + +sub path_ext { + my @path_ext; + + if ($ENV{PATHEXT}) { + push @path_ext, split ';', $ENV{PATHEXT}; + for my $ext (@path_ext) { + $ext =~ s/^\.*(.+)$/$1/; + } + } + else { + #Win9X: doesn't have PATHEXT + push @path_ext, qw(com exe bat); + } + + return @path_ext; +} + +sub which { + my $program = shift; + my @path_ext = @_; + return unless $program; + my @a = map {File::Spec->catfile($_, $program) } File::Spec->path(); + for my $base (@a) { + return $base if -x $base; + for my $ext (@path_ext) { + return "$base.$ext" if -x "$base.$ext"; + } + } + return; +} + package MY; sub libscan { @@ -760,3 +923,67 @@ } return $result; } + +package main; + +__DATA__ + +my %opts = (); +GetOptions(\%opts, + 'cflags', + 'libs', + 'port', + 'version', + 'libmysqld-libs', + 'embedded', + 'embedded-libs', + 'help', + ) or usage(); + +usage() if ($opts{help} or not %opts); + +SWITCH : { + local $\ = "\n"; + $opts{cflags} and do { + print $cflags; + last SWITCH; + }; + $opts{libs} and do { + print $libs; + last SWITCH; + }; + $opts{port} and do { + print $port; + last SWITCH; + }; + $opts{version} and do { + print $version; + last SWITCH; + }; + ($opts{'libmysqld-libs'} or $opts{embedded} or $opts{'libmysqld-libs'} ) + and do { + print $embedded_libs; + last SWITCH; + }; + usage(); +} + +exit(0); + +sub usage { + print << "EOU"; +Usage: $0 [OPTIONS] + +Options: + --cflags [$cflags] + --libs [$libs] + --port [$port] + --version [$version] + --libmysqld-libs [$embedded_libs] +EOU + exit(1); +} + + + +
Thank you so much for this! Windows is something I need to give love to more. When I wrote my book, I tried to get DBD::mysql/Strawberry Perl working, I had difficulties (mod_perl wasn't working either), and I'm not a Windows kind of guy, so thank you for this. Yes, I need to do a release this week. I may have questions for you on how I can test this. On Sat Jun 13 19:54:02 2009, CSJEWELL wrote: Show quoted text
> The best directions I found were at > http://www.perlmonks.org/?node_id=738604. The first time I tried those, > I dead-ended with link errors. 3 weeks later, I was able to figure out
why. Show quoted text
> > It's still complicated, so I tried to make it simple. > > This patch includes everything from those directions, including creating > the mysql_config.bat script (while trying not to affect non-Win32 > building) plus the fact that Strawberry Perl uses .a files rather than > .lib files (but they happen to be identical, so a renamed/copied file > can be used,) and the information I found out trying to do it myself > (DBD::mysql needs libmysql, rather than libmysqlclient, for example.) > > So the best directions will now be: > > 1. Apply patch (or use patched version of Makefile.PL) > 2. perl Makefile.PL > 3. dmake && dmake test && dmake install > > I have not tested this patch with --embedded - is that used on Win32? > > Hopefully you apply this for 4.012...
Thank you! This patch will be included in 4.012 released tomorrow.