1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
|
# $Id: Makefile.PL,v 1.48 2012/10/26 19:11:54 mpeppler Exp $
use ExtUtils::MakeMaker;
require 5.004;
use strict;
# If either of these aren't available on your system then you need to
# get them!
use DBI;
use DBI::DBD;
use Config;
use Getopt::Long;
use vars qw($SYBASE $inc_string $lib_string $LINKTYPE $written_pwd_file
$newlibnames $libdir);
$LINKTYPE = 'dynamic';
$written_pwd_file = 'PWD';
# regexp to find libct/libsybct, and avoid picking up libct_cu which isn't anything we want at all...
# https://github.com/mpeppler/DBD-Sybase/issues/64
my $libct_re = qr/\blib(syb)?ct(64)?\./i;
# freetds can be installed in system lib directories. We can pick those out
# from Config{libsdir}
my @libsdir = split(' ', $Config{libsdirs});
my $file;
my $chained;
my $threaded_libs;
my $accept_test_defaults;
GetOptions(
'--file' => \$file,
'--chained:s' => \$chained,
'--threaded_libs:s' => \$threaded_libs,
'--accept_test_defaults' => \$accept_test_defaults
);
select(STDOUT);
$| = 1;
configure();
configPwd();
my $lddlflags = $Config{lddlflags};
# According to https://github.com/mpeppler/DBD-Sybase/issues/62 we don't need to set
# lddlflags or ldflags on Windows.
$lddlflags = "-L$SYBASE/$libdir $lddlflags" unless $^O eq 'VMS' || $^O eq 'MSWin32';
my $ldflags = $Config{ldflags};
$ldflags = "-L$SYBASE/$libdir $ldflags" unless $^O eq 'VMS' || $^O eq 'MSWin32';
WriteMakefile(
'NAME' => 'DBD::Sybase',
PREREQ_PM => {
'DBI' => '0'
},
LIBS => [$lib_string],
INC => $inc_string,
clean => { FILES => "Sybase.xsi $written_pwd_file" },
OBJECT => '$(O_FILES)',
'VERSION_FROM' => 'Sybase.pm',
'LDDLFLAGS' => $lddlflags,
# 'LDFLAGS' => $ldflags,
LINKTYPE => $LINKTYPE,
(
$^O eq 'VMS'
? ( MAN3PODS => { 'Sybase.pm' => 'blib/man3/DBD_Sybase.3' } )
: ( MAN3PODS => { 'Sybase.pm' => 'blib/man3/DBD::Sybase.3pm' } )
),
ABSTRACT => 'DBI driver for Sybase datasources',
AUTHOR => 'Michael Peppler (mpeppler@peppler.org)',
(
$] >= 5.005
&& $^O eq 'MSWin32'
&& $Config{archname} =~ /-object\b/i ? ( CAPI => 'TRUE' ) : ()
),
'dist' => { 'TARFLAGS' => 'cvf', 'COMPRESS' => 'gzip' },
( $^O eq 'VMS' ? ( PM => 'Sybase.pm' ) : () ),
META_MERGE => {
'meta-spec' => { version => 2 },
resources => {
bugtracker => {
web => 'https://github.com/mpeppler/DBD-Sybase/issues',
},
repository => {
url => 'https://github.com/mpeppler/DBD-Sybase.git',
web => 'https://github.com/mpeppler/DBD-Sybase',
type => 'git',
}
},
}
);
sub MY::postamble {
return dbd_postamble();
}
sub configure {
my %attr;
my ( $key, $val );
my $sybase_dir = $ENV{SYBASE};
if ( !$sybase_dir ) {
# PR 517 - getpwnam() isn't portable.
eval q{
$sybase_dir = (getpwnam('sybase'))[7];
};
}
open( IN, "CONFIG" ) || die "Can't open CONFIG: $!";
while (<IN>) {
chomp;
next if /^\s*\#/;
next if /^\s*$/;
( $key, $val ) = split( /\s*=\s*/, $_ );
$key =~ s/\s//g;
$val =~ s/\s*$//;
$attr{$key} = $val;
}
if ( -d $sybase_dir ) {
$SYBASE = $sybase_dir;
} else {
if ( $attr{SYBASE} && -d $attr{SYBASE} ) {
$SYBASE = $attr{SYBASE};
}
}
if ( !$SYBASE || $SYBASE =~ /^\s*$/ ) {
die "Please set SYBASE in CONFIG, or set the \$SYBASE environment variable";
}
$SYBASE = VMS::Filespec::unixify($SYBASE) if $^O eq 'VMS';
if ( $^O eq 'darwin' ) {
my $osxdir = 'Applications/Sybase/System';
$SYBASE = $osxdir if -d $SYBASE && -d $osxdir;
}
# System 12.0 has a different directory structure...
if ( defined( $ENV{SYBASE_OCS} ) ) {
# if $SYBASE_OCS is an absolute path, then use that
if ( $ENV{SYBASE_OCS} =~ m!^/! ) {
$SYBASE = $ENV{SYBASE_OCS};
} else {
$SYBASE .= "/$ENV{SYBASE_OCS}";
}
}
my @libdir = ( "$SYBASE/lib", "$SYBASE/lib64", @libsdir);
if ( $^O eq 'MSWin32' ) {
@libdir = ("$SYBASE/dll");
}
foreach my $l (@libdir) {
if ( -d $l ) {
if ( checkLib($l) ) {
$libdir = $l;
last;
}
}
}
die "Can't find any Sybase libraries in "
. join( ' or ', @libdir )
unless defined $libdir;
my $inc_found = 0;
if ( -d "$SYBASE/include" && -f "$SYBASE/include/cspublic.h" ) {
++$inc_found;
$inc_string = "-I$SYBASE/include";
}
# In some freetds installations the include files have been moved
# into /usr/include/freetds.
if ( -d "$SYBASE/include/freetds" && "$SYBASE/include/freetds/cspublic.h" ) {
++$inc_found;
$inc_string = "-I$SYBASE/include/freetds";
}
die "Can't find the Client Library include files under $SYBASE"
unless ($inc_found);
my $version = getLibVersion($libdir);
# if(!$version || $version lt '12') {
#print "FreeTDS or older Client Library. Enabling CS-Lib Callbacks\n";
#$inc_string .= " -DUSE_CSLIB_CB=1";
# }
checkChainedAutoCommit();
# print "OS = $^O\n";
my %libname = loadSybLibs( $libdir,
$^O eq 'MSWin32' ? qr/lib/
: $^O eq 'VMS' ? qr/olb/
: qr/(?:so|a|sl)/ );
my $libtype = '';
if ( $^O eq 'MSWin32' ) {
if ( $version ge '15' ) {
# $libsub is "dll" on Windows...
$lib_string =
"-L$libdir -llibsybct.lib -llibsybcs.lib -llibsybtcl.lib -llibsybcomn.lib -llibsybintl.lib -llibsybblk.lib $attr{EXTRA_LIBS} -lm";
} else {
$lib_string =
"-L$libdir -llibct.lib -llibcs.lib -llibtcl.lib -llibcomn.lib -llibintl.lib -llibblk.lib $attr{EXTRA_LIBS} -lm";
}
} elsif ( $^O eq 'VMS' ) {
$lib_string =
"-L$SYBASE/lib -llibct.olb -llibcs.olb -llibtcl.olb -llibcomn.olb -llibintl.olb -llibblk.olb $attr{EXTRA_LIBS}";
} elsif ( $^O =~ /cygwin/ ) {
# $lib_string = "-L$SYBASE/lib -lct -lcs -lblk";
# $inc_string .= " -D_MSC_VER=800";
$inc_string .= " -D_MSC_VER=800";
my $bits64 = "";
if ($Config{ptrsize} == 8) {
$bits64 = 64;
$inc_string .= " -DSYB_LP64";
}
if ($version ge '15') {
$lib_string = "-L$SYBASE/lib -lsybct$bits64 -lsybcs$bits64 -lsybblk$bits64";
} else {
$lib_string = "-L$SYBASE/lib -lct$bits64 -lcs$bits64 -lblk$bits64";
}
} else {
# Supplied by Erick Calder. I'm not sure why libsybsrv is needed...
$attr{EXTRA_LIBS} .= " -lsybsrv" if $^O eq 'darwin';
my $extra = getExtraLibs( $attr{EXTRA_LIBS}, $version );
if ($file) {
$lib_string =
"-L$libdir -lct -lcs -ltcl -lcomn -lintl -lblk $attr{EXTRA_LIBS} -ldl -lm";
} else {
$lib_string =
"-L$libdir -lct -lcs -ltcl -lcomn -lintl -lblk $extra -ldl -lm";
}
if ($newlibnames) {
foreach (qw(ct cs tcl comn intl blk)) {
$lib_string =~ s/-l$_/-lsyb$_/;
}
} elsif ( $^O =~ /linux|freebsd/i ) {
$lib_string =~ s/-ltcl/-lsybtcl/;
}
# Logic to replace normal libs with _r (re-entrant) libs if
# usethreads is defined provided by W. Phillip Moore (wpm@ms.com)
# I have no idea if this works on Win32 systems (probably not!)
if ( $Config{usethreads} ) {
print "Running in threaded mode - looking for _r libraries...\n";
if ( checkForThreadedLibs() ) {
my $found = 0;
foreach ( split( /\s+/, $lib_string ) ) {
next unless /^-l(\S+)/;
my $oldname = $1;
my $newname = $1 . "_r";
next unless exists $libname{$newname};
print "Found -l$newname for -l$oldname\n";
++$found;
$lib_string =~ s/-l$oldname\b/-l$newname/;
}
if ( !$found ) {
print "No thread-safe Sybase libraries found\n";
$inc_string .= ' -DNO_THREADS ';
} else {
$libtype .= '_r';
}
} else {
print "OK - I'll use the normal libs\n\n";
}
}
# If we are building for a 64 bit platform that also supports 32 bit
# (i.e. Solaris 8, HP-UX11, etc) then we need to make some adjustments
if ( $Config{use64bitall} ) {
# Tru64/DEC OSF does NOT use the SYB_LP64 define
# as it is ALWAYS in 64 bit mode.
$inc_string .= ' -DSYB_LP64' unless $^O eq 'dec_osf';
print "Running in 64bit mode - looking for '64' libraries...\n";
my $found = 0;
foreach ( split( /\s+/, $lib_string ) ) {
next unless /^-l(\S+)/;
my $oldname = $1;
my $newname = $1 . '64';
next unless exists $libname{$newname};
print "Found -l$newname for -l$oldname\n";
$lib_string =~ s/-l$oldname\b/-l$newname/;
++$found;
}
if ($found) {
$libtype .= '64';
}
}
}
# Is the blk library available?
#my @k = keys(%libname);
#print "@k\n";
#print "libtype = $libtype\n";
if ( my @l = grep( /(syb)?blk$libtype/, keys(%libname) ) ) {
print "BLK api available - found: @l\n";
} else {
print "BLK api NOT available.\n";
$inc_string .= ' -DNO_BLK=1';
}
my $config_sitearch = $Config{sitearchexp};
my $attr_dbi_include = $attr{DBI_INCLUDE};
if ( $^O eq 'VMS' ) {
$config_sitearch = VMS::Filespec::unixify($config_sitearch);
$attr_dbi_include = VMS::Filespec::unixify($attr_dbi_include);
}
my @try = ( @INC, $Config{sitearchexp} );
unshift @try, $attr{DBI_INCLUDE} if $attr{DBI_INCLUDE};
my $dbidir;
for my $trydir (@try) {
if ( -e "$trydir/auto/DBI/DBIXS.h" ) {
$dbidir = "$trydir/auto/DBI";
last;
}
}
die "Can't find the DBI include files. Please set DBI_INCLUDE in CONFIG"
if !$dbidir;
$inc_string .= " -I$dbidir";
if ( $attr{LINKTYPE} ) {
$LINKTYPE = $attr{LINKTYPE};
}
}
sub loadSybLibs {
my ( $dir, $extensionRegexp ) = @_;
my %libname = ();
opendir( SYBLIB, $dir )
or die "Unable to opendir $dir: $!\n";
foreach ( readdir(SYBLIB) ) {
next unless -f "$dir/$_";
next unless /^lib(\S+)\.$extensionRegexp/;
$libname{$1} = 1;
}
closedir(SYBLIB);
return %libname;
}
sub getLibVersion {
my $lib = shift;
opendir( DIR, $lib );
# reverse to pick up libsybct before libct...
my @files = reverse( grep( /$libct_re/, readdir(DIR) ) );
closedir(DIR);
my $file;
foreach (@files) {
$file = "$lib/$_";
last if -e $file;
}
open( IN, $file ) || die "Can't open $file: $!";
binmode(IN);
my $version;
while (<IN>) {
if (/S(?:AP|ybase) Client-Library\/([^\/]+)\//) {
$version = $1;
last;
}
}
close(IN);
if ( !$version ) {
print "Unknown Client Library version - assuming FreeTDS.\n";
} else {
print "Sybase OpenClient $version found.\n";
}
return $version;
}
sub getExtraLibs {
my $cfg = shift;
my $version = shift;
opendir( DIR, "$libdir" ) || die "Can't access $libdir: $!";
my %files =
map { $_ =~ s/lib([^\.]+)\..*/$1/; $_ => 1 }
grep( /lib/ && -f "$libdir/$_", readdir(DIR) );
closedir(DIR);
my %x = map { $_ => 1 } split( ' ', $cfg );
my $dlext = $Config{dlext} || 'so';
foreach my $f ( keys(%x) ) {
my $file = $f;
$file =~ s/-l//;
next if ( $file =~ /^-/ );
delete( $x{$f} ) unless exists( $files{$file} );
}
foreach my $f (qw(insck tli sdna dnet_stub tds skrb gss)) {
$x{"-l$f"} = 1 if exists $files{$f} && -f "$libdir/lib$f.$dlext";
}
if ( $version gt '11' ) {
delete( $x{-linsck} );
delete( $x{-ltli} );
}
# if($version ge '12.5.1') {
# delete($x{-lskrb});
# }
join( ' ', keys(%x) );
}
sub checkLib {
my $dir = shift;
opendir( DIR, "$dir" ) || die "Can't access $dir: $!";
my @files = grep( /$libct_re/i, readdir(DIR) );
closedir(DIR);
if ( grep( /libsybct/, @files ) ) {
$newlibnames = 1;
} else {
$newlibnames = 0;
}
scalar(@files);
}
sub configPwd {
open( IN, "PWD.factory" ) || die "Can't open PWD.factory: $!";
my %pwd;
while (<IN>) {
chomp;
next if (/^\s*\#/);
next if (/^\s*$/);
my ( $key, $val ) = split( /=/, $_ );
$pwd{$key} = $val || "undef";
}
close(IN);
if ($accept_test_defaults) {
$pwd{SRV} = $pwd{SRV};
$pwd{UID} = $pwd{UID};
$pwd{PWD} = $pwd{PWD};
$pwd{DB} = $pwd{DB};
} else {
print
"The DBD::Sybase module need access to a Sybase server to run the tests.\n";
print "To clear an entry please enter 'undef'\n";
print "Sybase server to use (default: $pwd{SRV}): ";
$pwd{SRV} = getAns(0) || $pwd{SRV};
print "User ID to log in to Sybase (default: $pwd{UID}): ";
$pwd{UID} = getAns(0) || $pwd{UID};
print "Password (default: $pwd{PWD}): ";
$pwd{PWD} = getAns(1) || $pwd{PWD};
print "Sybase database to use on $pwd{SRV} (default: $pwd{DB}): ";
$pwd{DB} = getAns(0) || $pwd{DB};
}
warn
"\n* Writing login information, including password, to file $written_pwd_file.\n\n";
# Create the file non-readable by anyone else.
my $old_umask;
unless ( $^O =~ /MSWin32/ ) {
$old_umask = umask(077);
warn "cannot umask(): $!" unless defined($old_umask);
}
open( OUT, ">$written_pwd_file" ) || die "Can't open $written_pwd_file: $!";
unless ( $^O =~ /MSWin32/ ) {
umask($old_umask) != 077 && warn "strange return from umask()";
}
print OUT <<EOF;
# This file contains optional login id, passwd and server info for the test
# programs:
# You probably don't want to have it lying around after you've made
# sure that everything works OK.
EOF
foreach ( keys %pwd ) {
$pwd{$_} = '' if $pwd{$_} eq 'undef';
print OUT "$_=$pwd{$_}\n";
}
close(OUT);
}
sub checkChainedAutoCommit {
print <<EOF;
By default DBD::Sybase 1.05 and later use the 'CHAINED' mode (where available)
when 'AutoCommit' is turned off. Versions 1.04 and older instead managed
the transactions explicitly with a 'BEGIN TRAN' before the first DML
statement. Using the 'CHAINED' mode is preferable as it is the way that
Sybase implements AutoCommit handling for both its ODBC and JDBC drivers.
EOF
print "Use 'CHAINED' mode by default (Y/N) [Y]: ";
my $ans;
if ( defined($chained) ) {
$ans = $chained;
} else {
$ans = getAns(0);
}
if ( $ans and $ans !~ /^y/i ) {
$inc_string .= " -DNO_CHAINED_TRAN=1";
}
print "\n";
}
sub checkForThreadedLibs {
my $ret = 1;
if ( $] >= 5.008 ) {
$ret = 0;
print <<EOF;
***NOTE***
There is an incompatibility between perl (5.8.x or later) built in threaded
mode and Sybase's threaded libraries, which means that signals delivered to
the perl process result in a segment violation.
I suggest building DBD::Sybase with the normal libraries in this case to get
reasonable behavior for signal handling.
EOF
print "Use the threaded (lib..._r) libraries [N]: ";
my $ans;
if ( defined($threaded_libs) ) {
$ans = $threaded_libs;
} else {
$ans = getAns(0);
}
if ( $ans and $ans =~ /^y/i ) {
$ret = 1;
}
print "\n";
}
return $ret;
}
sub getAns {
my $flag = shift;
if ( $flag && -t ) {
eval {
require Term::ReadKey;
Term::ReadKey::ReadMode('noecho');
};
}
my $ans = <STDIN>;
if ( $flag && -t ) {
eval { Term::ReadKey::ReadMode('normal'); };
print "\n"; # because newline from user wasn't echo'd
}
$ans =~ s/^\s+//;
$ans =~ s/\s+$//;
return $ans;
}
|