-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.PL
550 lines (471 loc) · 16.1 KB
/
Makefile.PL
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
# $Id: Makefile.PL 394 2008-01-08 05:29:19Z edpratomo $
#
# Copyright (c) 1999-2005 Edwin Pratomo
# Portions Copyright (c) 2001-2005 Daniel Ritz
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file,
# with the exception that it cannot be placed on a CD-ROM or similar media
# for commercial distribution without the prior approval of the author.
BEGIN { $^W = 0 } # turn warnings off
BEGIN { require 5.004 } # 5.003 fixes very important bugs
use ExtUtils::MakeMaker 5.16, qw(prompt &WriteMakefile $Verbose);
use Config;
use Carp;
use strict;
use File::Basename;
use File::Spec;
use vars qw($Registry);
# This DBI must be installed before we can build a DBD.
# For those not using Dynamic loading this means building a
# new static perl in the DBI directory by saying 'make perl'
# and then using _that_ perl to make this one.
use DBI 1.41 ();
use Test::More 0.4;
use DBI::DBD; # DBD creation tools
my $ib_dir_prefix;
# init stuff
my $IB_Bin_path = '';
my $isql_name;
my $isql_path;
my @ib_bin_dirs;
my @ib_inc_dirs;
my $ib_lib_dir = '';
################################################################################
# OS specific configuration
################################################################################
if ($Config::Config{osname} eq 'MSWin32')
{
$isql_name = 'isql.exe';
# try to find InterBase installation via the registry
my $ib_bin_dir = '';
eval
{
require Win32::TieRegistry;
Win32::TieRegistry->import('$Registry');
$Registry->Delimiter("/");
my $sw = $Registry->{"LMachine/Software/"} or die "Can't read LMachine/Software key: $^E\n";
# We have to check more than one keys, because different
# releases of InterBase have used different key hierarchies.
my $key = $sw->{"InterBase Corp/InterBase/CurrentVersion/"} ||
$sw->{"Borland/InterBase/CurrentVersion/"} ||
$sw->{"Firebird Project/Firebird Server/Instances/"} ||
$sw->{"FirebirdSQL/Firebird/CurrentVersion/"};
if (defined($key))
{
$ib_bin_dir = $key->{"/ServerDirectory"};
$ib_bin_dir ||= $key->{"/DefaultInstance"} . "bin";
$ib_lib_dir = $key->{"/RootDirectory"};
$ib_lib_dir ||= $key->{"/DefaultInstance"};
}
};
die "Error: $@\n" if $@;
$ib_lib_dir .= '\\' unless ($ib_lib_dir =~ m|^.*\\$|gi);
@ib_bin_dirs = ($ib_bin_dir);
@ib_inc_dirs = ($ib_lib_dir . "SDK\\include", $ib_lib_dir . "include");
}
else
{
$isql_name = 'isql';
@ib_bin_dirs = (qw(/opt/firebird/bin /usr/bin /usr/local/bin));
@ib_inc_dirs = (qw(/opt/firebird/include /usr/include));
}
sub locate_dbi_arch_dir {
my $dbidir = dbd_dbi_dir();
my @try = map { "$_/auto/DBI" } @INC;
my @xst = grep { -f "$_/Driver.xst" } @try;
Carp::croak("Unable to locate Driver.xst in @try") unless @xst;
Carp::carp( "Multiple copies of Driver.xst found in: @xst") if @xst > 1;
return $xst[0];
}
sub get_isql_path
{
# try to find isql
return $isql_path if $isql_path;
for ($IB_Bin_path, split /:/ => $ENV{PATH}) {
s!/ +$ !!xg;
next unless $_;
if (-x "$_/$isql_name") {
$isql_path = "$_/$isql_name";
return $isql_path;
}
}
EXEC:
{
for (1..3)
{
$isql_path = prompt("Enter full path to isql: ", $isql_path);
last EXEC if (-x $isql_path);
}
die "Unable to execute isql. Aborting..";
}
return File::Spec->canonpath($isql_path);
}
################################################################################
# sub test_files - checks if at least one of the files in the list exists
# Paramters:
# 0: directory
# 1: reference to file list
# Return value: true value if at least on file exists, 0 otherwise
################################################################################
sub test_files
{
my($dir, $files) = @_;
local $_;
-f "$dir/$_" && return $_ for @$files;
0;
}
################################################################################
# sub dir_choice - prompts for a directory
# Parameters:
# 0: prompt string
# 1: reference to directory list
# 2: reference to file list
# Return value: directory name
################################################################################
sub dir_choice
{
my($prompt, $dirs, $files) = @_;
my %dirs;
my $i;
my $ret;
test_files($_, $files) && ($dirs{++$i} = $_) for @$dirs;
for (1..3)
{
foreach my $d (sort keys %dirs) {
my $choice = prompt("$prompt :", $dirs{$d});
return $choice if test_files($choice, $files);
}
}
print "Cannot proceed. Aborting..\n";
}
################################################################################
# sub make_test_conf - configure for test (save to ./t/test.conf)
# Parameters: <none>
# Return value: <none>
################################################################################
sub make_test_conf
{
my $test_conf = './t/test.conf';
my ($dsn, $user, $pass, $path, $db, $host);
# read cached config if available
if (-r $test_conf)
{
print "\nReading cached test configuration...";
open F, $test_conf or die "Can't open $test_conf: $!";
local @ARGV = ($test_conf);
($dsn, $user, $pass) = map {chomp;$_} <>;
($db) = $dsn =~ /(?:db|database)=([^;]+);/;
($host) = $dsn =~ /(?:host|hostname)=([^;]+);/;
$path = ($host ? "$host:" : '') . $db;
close F;
}
# ask for database path
DBPATH: {
for ( 1 .. 3 ) {
last
if $path =
prompt( "\nFull path to test database to create or use: ",
$path );
}
die "Must specify a test database" unless $path;
$path = File::Spec->canonpath($path); # correct path on all platforms
print "paths is $path\n";
($db, $host) = reverse split /:/, $path;
$user = prompt("Username :", $user);
$pass = prompt("Password :", $pass);
my $isql = get_isql_path();
# print "isql is $isql\n";
my $dialect;
my $database_ok = 1;
# Using isql CLI to connect to the database and retrieve the
# dialect. If I/O error then just create a new database
my $ocmd = qq($isql -u $user -p $pass -x $path 2>&1);
eval {
#print "cmd is $ocmd\n";
open my $fh, '-|', $ocmd;
OPEN:
while (<$fh>) {
my $line = $_;
# print " $line\n";
# check for I/O error
if ($line =~ /error/i) {
$database_ok = 0;
last OPEN;
}
# check for I/O error
if ($line =~ /Firebird login/i) {
print "!!! Check your Firebird login parameters !!!\n";
$path = undef, goto DBPATH; # should change this!
}
# get dialect if got here
if ($line =~ /DIALECT (\d)/i) {
$dialect = $1;
last OPEN;
}
}
close $fh;
};
if ($@) {
die "isql open error!\n";
}
unless ($database_ok) {
print "Creating new database: $path\n";
create_test_db($path, $user, $pass);
last DBPATH;
}
unless (defined $dialect) {
print <<"EOM";
Dialect of $path is UNKNOWN.
This test requires a database of dialect 3. You may specify a non-existent database to create a new one.
EOM
my $is_proceed = prompt("Proceed anyway or create a NEW test database (P/N)?", "P");
last DBPATH if $is_proceed =~ /P/i;
$path = undef, goto DBPATH;
}
unless ($dialect == 3) {
print <<"EOM";
The dialect of $path is: $dialect !!.
This test requires a database of dialect 3. Please specify a non-existent database to create a new one.
EOM
$path = undef, goto DBPATH;
}
}
# save test config to file
open my $t_fh, '>', $test_conf or die "Can't write $test_conf: $!";
print { $t_fh } 'dbi:InterBase:' . ($host ? "host=$host;" : '') . "db=$db;ib_dialect=3;ib_charset=ISO8859_1\n$user\n$pass\n";
close $t_fh;
}
################################################################################
# sub create_test_db - Creates the test database
# Parameters:
# 0: path to testdatabase to be created
# 1: username used to connect to the DB
# 2: password
# Return value: <none>
################################################################################
sub create_test_db
{
my ($path, $user, $pass) = @_;
# create the SQL file with CREATE statement
open my $t_fh, '>', './t/create.sql' or die "Can't write to t/create.sql";
while(<DATA>)
{
s/__TESTDB__/$path/;
s/__USER__/$user/;
s/__PASS__/$pass/;
print {$t_fh} $_;
}
close $t_fh;
# try to execute isql and create the test database
my $isql = get_isql_path();
# system($isql, '-sql_dialect', 3, '-i', './t/create.sql') == 0
# or die "Fail calling $isql -i t/create/sql: $?";
my $ocmd = qq($isql -sql_dialect 3 -i ./t/create.sql 2>&1);
eval {
# print "cmd is $ocmd\n";
open my $isql_fh, '-|', $ocmd;
while (<$isql_fh>) {
# For debug:
#print "> $_\n";
}
close $isql_fh;
};
if ($@) {
die "ISQL open error!\n";
}
}
################################################################################
# MAIN
################################################################################
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
# prompt for InterBase bin directory
$IB_Bin_path = dir_choice("InterBase/Firebird bin directory", [@ib_bin_dirs], [qw(gfix gfix.exe)]);
unless(-x $IB_Bin_path)
{
carp "I cannot find your InterBase/Firebird installation.\nDBD::InterBase cannot build or run without InterBase.\n";
exit 1;
}
# get InterBase version
my $IBVERSION;
my $GFIX_PATH = $IB_Bin_path . "/" . test_files($IB_Bin_path, [qw(gfix gfix.exe)]);
chop($IBVERSION = `$GFIX_PATH -z 2>&1`);
$IBVERSION =~ s/^gfix version //o;
my $is_final = $IBVERSION =~ /\.6\d+$/ ? 1 : 0;
# prompt for IB include dir
my $ib_inc = dir_choice("InterBase/Firebird include directory", [@ib_inc_dirs], [qw(gds.h ibase.h)]);
# we use a hash for the MakeMaker parameters
my %MakeParams = (
'NAME' => 'DBD::InterBase',
'VERSION_FROM' => 'InterBase.pm', # finds $VERSION
'C' => ['dbdimp.c'],
'H' => ['dbdimp.h', 'InterBase.h'],
'CCFLAGS' => '-Wall -fno-strict-aliasing',
'INC' => qq(-I"$ib_inc" -I"${\locate_dbi_arch_dir()}"),
'OBJECT' => "InterBase.o dbdimp.o",
'LIBS' => [''],
'OPTIMIZE' => $Config::Config{'optimize'},
'XSPROTOARG' => '-noprototypes',
'dist' => {COMPRESS=>'gzip -9f', SUFFIX=>'gz'},
'clean' => {FILES => "*.xsi *.old t/*.old *~ t/*~ trace.txt t/trace.txt lib/DBD/InterBase/*~ lib/DBD/InterBase/*.old lib/Bundle/DBD/*~ lib/Bundle/DBD/*.old"},
'realclean' => {FILES => "t/test.conf"},
);
# the OS specific build environment setup
my $os = $Config::Config{'osname'};
if ($os eq 'MSWin32')
{
# set up PPM package parameters
$MakeParams{'AUTHOR'} = 'Edwin Pratomo ([email protected])';
$MakeParams{'ABSTRACT'} = 'DBD::InterBase is a DBI driver for Firebird , written using Firebird C API.';
my $vc_dir = '';
if ($Config::Config{'cc'} eq "cl")
{
# try to find Microsoft Visual C++ compiler
eval
{
require Win32::TieRegistry;
Win32::TieRegistry->import('$Registry');
$Registry->Delimiter("/");
my $sw = $Registry->{"LMachine/Software/"};
# We have to check more than one keys, because different
# releases of Visual C++ have used different key hierarchies.
my $key =
$sw->{"Microsoft/VisualStudio/6.0/Setup/Microsoft Visual C++"} ||
$sw->{"Microsoft/VisualStudio/7.0/Setup/VC"};
if (defined($key))
{
$vc_dir = $key->{"/ProductDir"};
}
};
my @vc_dirs = ($vc_dir . "/bin");
my $VC_PATH = dir_choice("Visual C++ directory", [@vc_dirs], [qw(cl.exe)]);
unless (-x $VC_PATH){
carp "I can't find your MS VC++ installation.\nDBD::InterBase cannot build.\n";
exit 1;
}
my $vc_inc = $VC_PATH . "/include";
my $vc_lib = $VC_PATH . "/lib";
$INC .= " -I\"$vc_inc\"";
my $ib_lib = dir_choice("InterBase lib directory",
[$ib_lib_dir . "SDK\\lib_ms", $ib_lib_dir . "lib"],
[qw(gds32_ms.lib fbclient_ms.lib)]);
my $cur_libs = $Config::Config{'libs'} ;
my $cur_lddlflags = $Config::Config{'lddlflags'} ;
my $lib;
if (-f "$ib_lib/fbclient_ms.lib")
{ $lib = "$ib_lib/fbclient_ms.lib"; }
else
{ $lib = "$ib_lib/gds32_ms.lib"; }
eval "
sub MY::const_loadlibs {
'
LDLOADLIBS = \"$lib\" $cur_libs
LDDLFLAGS = -L\"$vc_lib\" $cur_lddlflags
'
} ";
}
# Support for MinGW with hard wired Strawberry default paths
elsif ($Config::Config{'cc'} eq "gcc") {
print "Using MinGW gcc (hard wired Strawberry default paths)\n";
my $MGW_PATH = 'C:\\strawberry\\c';
# Copy from above
my $mingw_inc = $MGW_PATH . "\\include";
my $mingw_lib = $MGW_PATH . "\\lib";
$INC .= " -I\"$mingw_inc\"";
my $ib_lib = dir_choice("InterBase lib directory",
[$ib_lib_dir . "SDK\\lib_ms", $ib_lib_dir . "lib"],
[qw(gds32_ms.lib fbclient_ms.lib)]);
my $cur_libs = $Config::Config{'libs'} ;
my $cur_lddlflags = $Config::Config{'lddlflags'} ;
my $lib;
if (-f "$ib_lib/fbclient_ms.lib")
{ $lib = "$ib_lib/fbclient_ms.lib"; }
else
{ $lib = "$ib_lib/gds32_ms.lib"; }
eval "
sub MY::const_loadlibs {
'
LDLOADLIBS = \"$lib\" $cur_libs
LDDLFLAGS = -L\"$mingw_lib\" $cur_lddlflags
'
} ";
}
else
{
}
}
elsif ($os eq 'solaris')
{
$MakeParams{'LIBS'} = '-lgdsmt -lm -lc';
}
elsif (($os eq 'linux') || ($os eq 'freebsd'))
{
my $ib_lib = dir_choice("InterBase/Firebird lib directory",
[qw(/usr/firebird/lib /opt/firebird/lib /usr/lib /usr/local/lib)],
[qw(libgds.a libgds.so libfbclient.so libfbembed.so)]);
my $lib;
if (-f "$ib_lib/libfbclient.so")
{
my $emb = 0;
if (-f "$ib_lib/libfbembed.so")
{
while ($emb ne 'n' && $emb ne 'y')
{ $emb = prompt("Build with libfbembed? (y/n)", 'n'); }
}
if ($emb eq 'y')
{ $lib = 'fbembed'; }
else
{ $lib = 'fbclient'; }
}
else
{ $lib = 'gds'; }
my $ldl = ($os eq 'linux') ? '-ldl' : '';
$MakeParams{'LIBS'} = "-L$ib_lib -l$lib $ldl ";
}
elsif ($os eq 'hpux')
{
$MakeParams{'LIBS'} = '-lgds -ldld';
}
elsif ($os eq 'sunos')
{
$MakeParams{'LIBS'} = '-lgdslib -ldl';
}
elsif ($os eq 'irix')
{
$MakeParams{'LIBS'} = '-lgds -lsun';
}
elsif ($os eq 'aix')
{
$MakeParams{'LIBS'} = '-lgdsshr';
}
elsif ($os eq 'dgux')
{
$MakeParams{'LIBS'} = '-lgds -lgdsf -ldl -ldgc';
}
elsif ($os eq 'osf1')
{
$MakeParams{'LIBS'} = '-lgds';
}
elsif ($os eq 'sysv')
{
$MakeParams{'LIBS'} = '-lgds -lnsl -lsocket -ldl';
}
else
{
carp "DBD::InterBase is not supported on platform $os.\n";
exit 1;
}
# create the test config file
make_test_conf();
# and last but not least write the makefile
WriteMakefile(%MakeParams);
sub MY::postamble
{
return dbd_postamble(@_);
}
package main;
# the data used to create the database creation script
__DATA__
CREATE DATABASE "__TESTDB__" user "__USER__" password "__PASS__";
quit;