File: Makefile.PL

package info (click to toggle)
msql-mysql-modules 1.2005-1
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 744 kB
  • ctags: 412
  • sloc: perl: 4,402; ansic: 1,753; makefile: 73
file content (967 lines) | stat: -rw-r--r-- 30,691 bytes parent folder | download
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
#   Hej, Emacs, don't you see this is -*- perl -*- mode? :-)
#
#   Copyright (c) 1997  Andreas K´┐Żnig, Jochen Wiedmann
#
#  You may distribute this 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.
#
#  $Id: Makefile.PL 1.1 Tue, 30 Sep 1997 01:28:08 +0200 joe $
#
BEGIN {require 5.004;}
use strict;
require Config;
use ExtUtils::MakeMaker qw(prompt WriteMakefile);
require File::Path;
require Config;
require Cwd;
use lib ".";

use vars qw($MyConfig $VERSION $DBD_VERSION);

$VERSION = "1.2005";
$DBD_VERSION = "2.0205";


############################################################################
#
#   Name:    Search
#
#   Purpose: Find installed files (headers or libraries)
#
#   Inputs:  $gooddirs - List of directories where to search; these
#                directories are accepted immediately if a file is
#                found there
#            $dirs - List of additional directories where to search;
#                these are accepted only if the users confirms them
#            $files - List of files to search for; any of these will
#                be sufficient
#            $prompt - Prompt for asking the user to confirm a
#                directory
#
#   Returns: List of two directories: The first directory is the basename
#       of "$dir/$file" where $dir is one of $gooddirs or $dirs and $file
#       is one of $files. (Note that the file name may contain preceding
#       directory names!) The second directory is the corresponding dir
#       od $gooddirs or $dirs.
#
############################################################################

sub Search ($$$$) {
    my ($gooddirs, $dirs, $files, $prompt) = @_;
    my ($dir, $file, $realfile);
    foreach $dir (@$gooddirs) {
	foreach $file (@$files) {
	    if (-f ($realfile = "$dir/$file")) {
		return (File::Basename::dirname($realfile), $dir);
	    }
	}
    }
    my ($gooddir);
    foreach $dir (@$dirs) {
	foreach $file (@$files) {
	    if (-f "$dir/$file") {
		$gooddir = $dir;
		last;
	    }
	}
	if ($gooddir) {
	    last;
	}
    }
    $gooddir ||= $$gooddirs[0] || $$dirs[0];

    $gooddir = prompt($prompt, $gooddir)  ||  $gooddir;  # for 5.002;

    foreach $file (@$files) {
	if (-f ($realfile = "$gooddir/$file")) {
	    return (File::Basename::dirname($realfile), $gooddir);
	}
    }

    if (@$files == 1) {
	die "Cannot find " . $$files[0] . " in $gooddir.\n";
    }
    die "Cannot find one of " . join(", ", @$files) . " in $gooddir";
}


############################################################################
#
#   Name:    QueryDb
#
#   Purpose: Query settings for running the test suite
#
#   Inputs:  $cfg - Config hash ref
#            $db - Database name
#            $driver - Driver name
#
#   Returns: Nothing; creates
#            $cfg->{$driver}->{test_(db|host|dsn|user|pass)}
#
############################################################################

sub QueryDb ($$$) {
    my($cfg, $db, $driver) = @_;
    my $db_lc = lc $driver;

    my $dbname = prompt("Which database should I use for testing the $db"
			. " drivers?", "test");
    my $host = prompt("On which host is database $dbname running (hostname, "
		      . " ip address or host:port)\n", "localhost");
    my($user, $pass);
    if ($driver eq 'mysql') {
	$user = prompt("User name for connecting to database $dbname?",
		       "undef");
	$pass = prompt("Password for connecting to database $dbname?",
		       "undef");
    }

    $cfg->{$driver}->{"test_db"} = $dbname;
    $cfg->{$driver}->{"test_host"} = $host;
    if ($host eq 'undef'  ||  $host eq 'localhost') {
	$host = '';
    }
    $cfg->{$driver}->{"test_dsn"} = "DBI:$driver:database=$dbname";
    if ($host) {
	$cfg->{$driver}->{"test_dsn"} .= ";host=$host";
    }
    $cfg->{$driver}->{"test_user"} =
	($user && $user ne 'undef') ? $user : "";
    $cfg->{$driver}->{"test_pass"} =
	($pass && $pass ne 'undef') ? $pass : "";
}


############################################################################
#
#   Name:    Xtract
#
#   Purpose: Create files from the distribution directories dbd and nodbd
#            using the "xtract" utility.
#
#   Inputs:  $ref - Array ref representing one file; the elements are
#
#                      $ref->[0]  Source file
#                      $ref->[1]  Destination file
#                      $ref->[2]  TRUE for executable (Mode 0755),
#                                 FALSE otherwise
#            $driver - Either "Msql" or "Mysql"
#            $dbdDriver - Either "mSQL" or "mysql"
#            $path - Path of the utility, defaults to "./xtract"
#
#   Returns: Nothing, aborts in case of trouble.
#
############################################################################

sub Xtract($$$;$) {
    my ($ref, $driver, $dbdDriver, $path) = @_;
    if (!$path) {
	$path = "xtract";
    }
    $ENV{'XTRACT_NOT_RUNNING'} = 1;
    require "xtract";
    Extract($ref->[0], $ref->[1], $driver, $dbdDriver,
	    $MyConfig->{'VERSION'}, $MyConfig->{'DBD_VERSION'});
    delete $ENV{'XTRACT_NOT_RUNNING'};
    chmod $ref->[2] ? 0755 : 0644, $ref->[1];
}


############################################################################
#
#   Name:    XtractF
#
#   Purpose: Create Makefile rules for updating files from the distribution
#            directories dbd and nodbd using the "xtract" utility.
#
#   Inputs:  $ref - Array ref representing one file; the elements are
#
#                      $ref->[0]  Source file
#                      $ref->[1]  Destination file
#                      $ref->[2]  TRUE for executable (Mode 0755),
#                                 FALSE otherwise
#            $driver - Either "Msql" or "Mysql"
#            $dbdDriver - Either "mSQL" or "mysql"
#            $path - Path of the utility, defaults to "./xtract"
#
#   Returns: String being inserted in the postamble.
#
############################################################################

sub XtractF($$$;$) {
    my ($ref, $driver, $dbdDriver, $path) = @_;
    if (!$path) {
	$path = "xtract";
    }
    sprintf("pm_to_blib: ../%s\n\n"
	    . "../%s: ../%s\n"
	    . "\t%s %s ../%s ../%s %s %s %s %s\n\tchmod %s ../%s\n\n",
	    $ref->[1],
	    $ref->[1], $ref->[0], $^X, $path,
	    $ref->[0], $ref->[1], $driver, $dbdDriver,
	    $MyConfig->{'VERSION'}, $MyConfig->{'DBD_VERSION'},
	    $ref->[2] ? "0755" : "0644", $ref->[1]);
}


############################################################################
#
#   Name:    InitializeMysql
#
#   Purpose: Setup mysql dependent variables
#
#   Inputs:  None
#
#   Returns: Hash ref of MakeMaker variables
#
############################################################################

sub CheckForLibGcc() {
    # For reasons I don't understand the 'specs' files of some
    # gcc versions disable linking against libgcc.a in conjunction
    # with '-shared'. Unfortunately we need libgcc.a because of
    # some arithmetic functions.
    #
    # We try to fix this by always linking against libgcc.a. Unfortunately
    # it's somewhat hard to find out the path of this file ...
    #
    if ($Config::Config{gccversion} eq '') {
	return '';
    }

    my($libgccfile) = `$Config::Config{cc} -print-libgcc-file-name 2>&1`;
    my($libgccdir);
    if ($libgccfile =~ /^\S+$/) {
	if ($libgccfile =~ /(.*)\/lib(\S+)\.a/) {
	    $libgccdir = $1;
	    $libgccfile = $2;
	}
    } else {
	my($specs) = `$Config::Config{cc} -v 2>&1`;
	if ($specs =~ /Reading specs from (\S+)/) {
	    $specs = $1;
	} else {
	    printf(<<"MSG", $Config::Config{cc});
Your Perl configuration says you are using gcc, but your compiler (%s) doesn't
look like gcc. There might be missing symbols in libmysqlclient.a, typically
'umoddi3' or something similar, if you have precompiled mysql binaries. If so,
try to compile your own binaries, perhaps the '--without-server' option
might help in the configure stage.
MSG
	    return '';
	}

	$specs = $1;
	if ($specs =~ /(.*)\//) {
	    $libgccdir = $1;
	    $libgccfile = "gcc";
	} else {
	    printf(<<"MSG", $Config::Config{cc});
Your Perl configuration says you are using gcc (%s), but I cannot determine the
path of your libgcc.a file. There might be missing symbols in
libmysqlclient.a, typically 'umoddi3' or something similar, if you have
precompiled mysql binaries. If so, try to compile your own binaries, perhaps
the '--without-server' option might help in the configure stage.
MSG
	    return '';
	}
    }

    if ($libgccdir) {
        " -L$libgccdir -l$libgccfile";
    } else {
        " $libgccfile";
    }
}


sub InitializeMysql () {
    my %X;
    my @mysqldirs = ($^O =~ /mswin32/i) ?  qw(C:/my/myodbc)  :
	qw{/usr/local /usr/local/mysql /usr /usr/mysql /opt/mysql};
    my @gooddirs = ();
    if (exists($ENV{MYSQL_HOME})) {
	unshift @gooddirs, $ENV{MYSQL_HOME};
    }
    if (exists($ENV{MYSQL_BUILD})) {
	unshift @gooddirs, $ENV{MYSQL_BUILD};
    }

    my($headerdir, $gooddir);
    if (exists($ENV{'MYSQL_HEADERDIR'})) {
	$headerdir = $ENV{'MYSQL_HEADERDIR'};
    } else {
	($headerdir, $gooddir) = Search(\@gooddirs, \@mysqldirs,
					["include/mysql/mysql.h",
					 "include/mysql.h"],
					"Where is your mysql installed? Please"
					. " tell me the directory that"
					. " contains\n"
					. "the subdir include/.");
	unshift(@gooddirs, $gooddir);
    }

    my $libdir;
    if (exists($ENV{'MYSQL_LIBDIR'})) {
	$libdir = $ENV{'MYSQL_LIBDIR'};
    } else {
	my @searchpath;
	if ($^O =~ /mswin32/i) {
	    @searchpath =
		("lib/mysqlclient.lib", "lib_release/mysqlclient.lib",
		 "lib_debug/mysqlclient.lib", "lib/lib.lib",
		 "lib_release/lib.lib", "lib_debug/lib.lib");
	} else {
	    @searchpath = ("lib/mysql/libmysqlclient.a",
			   "lib/mysql/libmysqlclient.so",
			   "lib/libmysqlclient.a",
			   "lib/libmysqlclient.so",
			   "client/libmysqlclient.a",
			   "client/libmysqlclient.so");
	}
	($libdir) = Search(\@gooddirs, \@mysqldirs, \@searchpath,
			   "Where is your mysql installed? Please tell me the"
			   . " directory that contains\n"
			   . "the subdir lib/.");
    }
    
    # List the libraries we're linking with (ADESC)
    my $sysliblist = "-L$libdir -lmysqlclient -lm";
    my $linkwith = "";
    my $defines = "-DDBD_MYSQL -DMyConnect=mysql_dr_connect"
	. " -DMyLogin=mysql_dr_login";
    if ($Config::Config{osname} eq 'sco_sv') {
	# Some extra libraries need added for SCO
	$sysliblist .= " -lc";
    } elsif ($Config::Config{osname} eq 'solaris') {
	# We need to link with -R if we're on Solaris.......Brain-damaged....
	$linkwith = "-R$libdir";
    } elsif ($Config::Config{osname} eq 'hpux') {
	# We need to add +z to the list of CFLAGS if we're on HP-SUX, or -fPIC 
	# if we're on HP-SUX and using 'gcc'
	if ($Config::Config{cccdlflags} eq '+z') {
	    print("\nYou're building on HP-UX with the HP compiler.\n");
	} elsif ($Config::Config{cccdlflags} eq '-fPIC') {
	    print("\nYou're building on HP-UX with the GNU C Compiler.\n");
	} else {
	    print("\nYou're building on HP-UX with an unknown compiler.\n");
	}
	print("You might get a warning at the link stage of:\n\n",
	      "ld: DP-Relative Code in file .../libmysqlclient.a",
	      "(libmysql.o)\n",
	      ">  - Shared Library must be Position-Independent\n\n",
	      "You'll have to recompile libmysqlclient.a from the mysql",
	      " distribution specifying\n",
	      "the '", $Config::Config{cccdlflags}, "' flag",
	      " of your C compiler.\n");
    } elsif ($Config::Config{osname} eq 'MSWin32') {
	$defines .= " -D__WIN32__";

	if (! -f "$libdir/mysqlclient.lib"  &&
	    -f "$libdir/lib.lib") {
	    # Looks like we're using MyODBC ...
	    $sysliblist =~ s/-lmysqlclient/-llib/;
	    $sysliblist .= " -lmysys -lstrings -lzlib";
	}

	# For some reasons libs.lib is not linked against msvcrt.lib
	# with VC++ ...
	if ($Config::Config{libs} =~ /\bmsvcrt\.lib\b/ &&
	    $Config::Config{libs} !~ /\blibc.lib\b/) {
	    $sysliblist .= " -lmsvcrt -lc";
	}
    }

    $sysliblist .= CheckForLibGcc();

    my(@headerfiles) = ("$headerdir/mysql.h");
    $X{dynamic_lib} = { OTHERLDFLAGS => "-L$libdir $linkwith" };
    $X{DEFINE}   = $defines;
    $X{LIBS}     = $sysliblist;
    $X{INC}      = "-I$headerdir -I../dbd  -I\$(INSTALLSITEARCH)/auto/DBI"
	. " -I\$(INSTALLARCHLIB)";
    $X{H}        = \@headerfiles;
    if ($ENV{HOSTNAME} eq 'laptop.ispsoft.de'  &&  $ENV{'LOGNAME'} eq 'joe') {
	$X{'DEFINE'} .= ' -Wall -Wstrict-prototypes';
    }

    my $dir;
    foreach $dir (@INC) {
	if (-f "$dir/auto/DBI/DBIXS.h") {
	    $X{INC} = "-I$dir/auto/DBI " . $X{INC};
	    last;
	}
    }

    \%X;
}


############################################################################
#
#   Name:    InitializeMsql
#
#   Purpose: Setup msql dependent variables
#
#   Inputs:  None
#
#   Returns: Hash ref of MakeMaker variables
#
############################################################################

sub InitializeMsql ($) {
    my($ver) = @_;
    my($homeVar, $dbVar, $dbiDriver);
    my($queryVar) = $ver ? "mSQL $ver" : "mSQL";
    if ($ver && $ver == 1) {
	$homeVar = "MSQL1_HOME";
	$dbVar = "-DDBD_MSQL -DDBD_MSQL1";
	$dbiDriver = "mSQL1";
    } else {
	$homeVar = "MSQL_HOME";
	$dbVar = "-DDBD_MSQL";
	$dbiDriver = "mSQL";
	$ver = 2;
    }

    my %X;
    my @msqldirs = qw{/usr/local/Hughes /usr/local/Minerva /usr/local
			  /usr/mSQL /opt/mSQL /usr};
    my @gooddirs;
    if (exists($ENV{$homeVar})) { push(@gooddirs, $ENV{$homeVar}); }

    my($headerdir, $gooddir) = Search(\@gooddirs, \@msqldirs,
				      ["include/msql.h"],
				      "Where is your $queryVar installed? Please"
				      . " tell me the directory that"
				      . " contains\n"
				      . " the subdir include/.");
    unshift(@gooddirs, $gooddir);
    my($libdir) = Search(\@gooddirs, \@msqldirs, ["lib/libmsql.a"],
			 "Where is your $queryVar installed? Please tell me the"
			 . " directory that contains\n"
			 . " the subdir lib/.");

    # the necessity to determine how many arguments are needed for
    # msqlget*conf is due to random changes in the API
    my($getconf) = '';
    open MSQL, "$headerdir/msql.h" 
	or die "Couldn't open $headerdir/msql.h: $!";
    local $/ = "\n";
    while (<MSQL>) {
	if (m{
	        ^
		(int|char)
		\s+
		\*?
		msqlGet
		(Int|Char)
		Conf
		\s+
		__ANSI_PROTO
		\(\(
		char
		\s*
		\*\)\)
	    }x) {
	    $getconf = " -DMSQLGETXCONF1";
	}
    }

    my $extralibs = "";
    my $linkwith = "";
    if ( $Config::Config{osname} eq 'sco_sv' ) {
	# Some extra libraries need added for SCO
	$extralibs = "-lc";
    } elsif ( $Config::Config{osname} eq 'solaris' ) {
	# We need to link with -R if we're on Solaris.......Brain-damaged....
	$linkwith = "-R$libdir";
    } elsif ( $Config::Config{osname} eq 'hpux' ) {
	# We need to add +z to the list of CFLAGS if we're on HP-SUX, or -fPIC 
	# if we're on HP-SUX and using 'gcc'
	if ( $Config::Config{cccdlflags} eq '+z' ) {
	    print q{You\'re building on HP-UX with the HP compiler.
You might get a warning at the link stage of:

ld: DP-Relative Code in file .../libmsql.a(libmsql.o)
>  - Shared Library must be Position-Independent

You\'ll have to recompile libmsql.a from the mSQL distribution with the
'+z' flag of your C compiler.
};
	} elsif( $Config::Config{cccdlflags} eq '-fPIC' ) {
	    print q{You\'re building on HP-UX with the GNU C Compiler.
You might get a warning at the link stage like:

ld: DP-Relative Code in file .../libmsql.a(libmsql.o)
>  - Shared Library must be Position-Independent

You\'ll have to recompile libmsql.a from the mSQL distribution specifying
the '-fPIC' flag to produce Position-Independent code.
};
	}
    }

    my($sysliblist) = "-L$libdir -lmsql -lm $extralibs";

    my(@headerfiles) = ("$headerdir/msql.h");
    $X{macro} = {$homeVar => $gooddir};
    $X{dynamic_lib} = { OTHERLDFLAGS => "-L$libdir $linkwith" };
    $X{DEFINE}   = "$dbVar $getconf -DMyConnect=${dbiDriver}_dr_connect"
	. " -DMyLogin=${dbiDriver}_dr_login";
    if ($ENV{HOSTNAME} eq 'laptop.ispsoft.de'  &&  $ENV{'LOGNAME'} eq 'joe') {
	$X{'DEFINE'} .= ' -Wall -Wstrict-prototypes';
    }
    $X{LIBS}     = $sysliblist;
    $X{INC}      = "-I../dbd -I$headerdir  -I\$(INSTALLSITEARCH)/auto/DBI"
	. " -I\$(INSTALLARCHLIB)";
    $X{H}        = \@headerfiles;

    my $dir;
    foreach $dir (@INC) {
	if (-f "$dir/auto/DBI/DBIXS.h") {
	    $X{INC} .= " -I$dir/auto/DBI";
	    last;
	}
    }

    \%X;
}


############################################################################
#
#   Name:    Search
#
#   Purpose: Find installed files (headers or libraries)
#
#   Inputs:  $gooddirs - List of directories where to search; these
#                directories are accepted immediately if a file is
#                found there
#            $dirs - List of additional directories where to search;
#                these are accepted only if the users confirms them
#            $files - List of files to search for; any of these will
#                be sufficient
#            $prompt - Prompt for asking the user to confirm a
#                directory
#
#   Returns: List of two directories: The first directory is the basename
#       of "$dir/$file" where $dir is one of $gooddirs or $dirs and $file
#       is one of $files. (Note that the file name may contain preceding
#       directory names!) The second directory is the corresponding dir
#       od $gooddirs or $dirs.
#
############################################################################

sub Search ($$$$) {
    my ($gooddirs, $dirs, $files, $prompt) = @_;
    my ($dir, $file, $realfile);
    foreach $dir (@$gooddirs) {
	foreach $file (@$files) {
	    if (-f ($realfile = "$dir/$file")) {
		return (File::Basename::dirname($realfile), $dir);
	    }
	}
    }
    my ($gooddir);
    foreach $dir (@$dirs) {
	foreach $file (@$files) {
	    if (-f "$dir/$file") {
		$gooddir = $dir;
		last;
	    }
	}
	if ($gooddir) {
	    last;
	}
    }
    $gooddir ||= $$gooddirs[0] || $$dirs[0];

    $gooddir = prompt($prompt, $gooddir)  ||  $gooddir;  # for 5.002;

    foreach $file (@$files) {
	if (-f ($realfile = "$gooddir/$file")) {
	    return (File::Basename::dirname($realfile), $gooddir);
	}
    }

    if (@$files == 1) {
	die "Cannot find " . $$files[0] . " in $gooddir.\n";
    }
    die "Cannot find one of " . join(", ", @$files) . " in $gooddir";
}


############################################################################
#
#    Name:    Init
#
#    Purpose: Setup variables that are manually configurable
#
#    Inputs:  None
#
#    Result:  Nothing; the $MyConfig hash will be modified
#
############################################################################

sub Init () {
    my($reply);

    if (-f ".status") {
	# Read settings from .status file
	require ".status";
	return;
    }

    $MyConfig = { 'VERSION' => $VERSION,
		  'DBD_VERSION' => $DBD_VERSION };

    if ($ENV{'IN_MYSQL_DISTRIBUTION'}) {
	require Data::Dumper;
	$MyConfig->{'install_dbd_mysql'} = 1;
	$MyConfig->{'install_dbd_msql'} = 0;
	$MyConfig->{'install_dbd_msql1'} = 0;
	$MyConfig->{'install_msqlperl'} = 0;
	$MyConfig->{'install_msql1perl'} = 0;
    } else {
	my($ok) = 2;

	print "Checking for DBI, 0.93 or later ... ";
	$@ = '';
	eval "use DBI 0.93 (); require DBI::DBD;";
	if ($@) {
	    $ok = 0;
	    print qq{
You don't have installed the DBI module, version 0.93 or later. I cannot
continue installing the Msql-Mysql modules.
};
        } else {
            print "ok\n";
        }

        print "Checking for Data::Dumper ... ";
        $@ = '';
        eval "require Data::Dumper";
        if ($@) {
	    $ok = 0;
	    print qq{
You don't have installed the Data::Dumper module. I cannot continue
installing the Msql-Mysql modules.
};
        } else {
	    print "ok\n";
        }

        print "Checking for Data::ShowTable ... ";
        $@ = '';
        eval "require Data::ShowTable";
        if ($@) {
	    print qq{
You don't have installed the Data::ShowTable module. You won't be able
to use 'dbimon' the DBI shell.};
            if ($ok == 2) {
	        $ok = 1;
	        print qq{I'll continue installing the Msql-Mysql modules
anyways so that you can install Data::ShowTable at a later time.
};
            }
        } else {
	    print "ok\n";
        }

        if ($ok < 2) {
            print qq{
Missing modules are available from any CPAN mirror, for example

   ftp://ftp.funet.fi/pub/languages/perl/CPAN/modules/by-module
};
	}
        if (!$ok) {
            exit 1;
        }

        my($choice) = 0;
        if (exists $ENV{'IN_MYSQL_DISTRIBUTION'}) {
            $choice = 1;
        }
        while (!$choice) {
	     $reply = prompt(
	         "\n\nWhich DBMS do you want to use?\n\n" .
	         "  1) MySQL\n" .
	         "  2) mSQL (1 or 2)\n" .
	         "  3) Both MySQL and mSQL\n\n" .
                 "  4) mSQL1 and mSQL2\n" .
                 "  5) Everything (MySQL, mSQL1 and mSQL2)\n\n" .
	         "Enter your choice: ", "3");
            if ($reply =~ /(\d+)/) {
                $choice = $1;
                if ($choice < 1  ||  $choice > 5) {
                    $choice = 0;
                }
            }
        }

        $MyConfig->{'install_dbd_mysql'} =
            ($choice == 1 || $choice == 3 || $choice == 5);
        $MyConfig->{'install_dbd_msql'} =
            ($choice == 2 || $choice == 3 || $choice == 4 || $choice == 5);
        $MyConfig->{'install_dbd_msql1'} = ($choice == 4 || $choice == 5);
    }

    if ($MyConfig->{'install_dbd_mysql'}) {
        if ($ENV{'IN_MYSQL_DISTRIBUTION'}) {
	    $MyConfig->{'install_mysqlperl'} = 1;
        } else {
	    $reply = prompt(qq{

Do you want to install the MysqlPerl emulation? This is highly experimental
and can break existing code!}, "y");
            $MyConfig->{'install_mysqlperl'} = ($reply =~ /y/i) ? 1 : 0;
            QueryDb($MyConfig, 'Mysql', 'mysql');
        }
        if (!exists $MyConfig->{'X_mysql'}) {
            $MyConfig->{'X_mysql'} = InitializeMysql();
        }
    }

    $MyConfig->{'files_dbd_mysql'} =
        [ ["dbd/Makefile.PL.in", "Mysql/Makefile.PL"],
          ["dbd/dbdimp.c", "Mysql/dbdimp.c"],
          ["dbd/dbd.xs.in", "Mysql/mysql.xs"],
          ["dbd/dbd.pm.in", "Mysql/mysql.pm"],
          ["tests/00base.t", "Mysql/t/00base.t"],
          ["tests/10dsnlist.t", "Mysql/t/10dsnlist.t"],
          ["tests/20createdrop.t", "Mysql/t/20createdrop.t"],
          ["tests/30insertfetch.t", "Mysql/t/30insertfetch.t"],
          ["tests/40bindparam.t", "Mysql/t/40bindparam.t"],
          ["tests/40blobs.t", "Mysql/t/40blobs.t"],
          ["tests/40listfields.t", "Mysql/t/40listfields.t"],
          ["tests/40nulls.t", "Mysql/t/40nulls.t"],
          ["tests/40numrows.t", "Mysql/t/40numrows.t"],
          ["tests/50chopblanks.t", "Mysql/t/50chopblanks.t"],
          ["tests/50commit.t", "Mysql/t/50commit.t"],
          ["tests/60leaks.t", "Mysql/t/60leaks.t"],
          ["tests/ak-dbd.t", "Mysql/t/ak-dbd.t"],
          ["tests/dbdadmin.t", "Mysql/t/dbdadmin.t"],
          ["tests/lib.pl", "Mysql/t/lib.pl"] ];
    $MyConfig->{'files_mysqlperl'} =
        [ ["tests/akmisc.t", "Mysql/t/akmisc.t"],
          ["tests/mysql.t", "Mysql/t/mysql.t"],
          ["tests/mysql2.t", "Mysql/t/mysql2.t"],
          ["nodbd/bundle.pm.in", "Mysql/lib/Bundle/Mysql.pm"],
          ["nodbd/nodbd.pm.in", "Mysql/lib/Mysql.pm"],
          ["nodbd/statement.pm.in", "Mysql/lib/Mysql/Statement.pm"],
          ["nodbd/pmsql.in", "Mysql/pmysql", 1]];


    if ($MyConfig->{'install_dbd_msql'}) {
	$reply = prompt(qq{

Do you want to install the MsqlPerl emulation? This is highly experimental
and can break existing code!}, "y");
        $MyConfig->{'install_msqlperl'} = ($reply =~ /y/i) ? 1 : 0;
        QueryDb($MyConfig,
                $MyConfig->{'install_dbd_msql1'} ? 'mSQL 2' : 'mSQL',
                'mSQL');
        if (!exists($MyConfig->{X_msql})) {
            $MyConfig->{'X_msql'} =
               InitializeMsql($MyConfig->{'install_dbd_msql1'} ? 2 : 0);
        }
    }

    $MyConfig->{'files_dbd_msql'} =
        [ ["dbd/Makefile.PL.in", "Msql/Makefile.PL"],
          ["dbd/dbdimp.c", "Msql/dbdimp.c"],
          ["dbd/dbd.xs.in", "Msql/mSQL.xs"],
          ["dbd/dbd.pm.in", "Msql/mSQL.pm"],
          ["tests/00base.t", "Msql/t/00base.t"],
          ["tests/10dsnlist.t", "Msql/t/10dsnlist.t"],
          ["tests/20createdrop.t", "Msql/t/20createdrop.t"],
          ["tests/30insertfetch.t", "Msql/t/30insertfetch.t"],
          ["tests/40bindparam.t", "Msql/t/40bindparam.t"],
          ["tests/40blobs.t", "Msql/t/40blobs.t"],
          ["tests/40listfields.t", "Msql/t/40listfields.t"],
          ["tests/40nulls.t", "Msql/t/40nulls.t"],
          ["tests/40numrows.t", "Msql/t/40numrows.t"],
          ["tests/50chopblanks.t", "Msql/t/50chopblanks.t"],
          ["tests/50commit.t", "Msql/t/50commit.t"],
          ["tests/60leaks.t", "Msql/t/60leaks.t"],
          ["tests/ak-dbd.t", "Msql/t/ak-dbd.t"],
          ["tests/dbdadmin.t", "Msql/t/dbdadmin.t"],
          ["tests/lib.pl", "Msql/t/lib.pl"] ];
    $MyConfig->{'files_msqlperl'} =
        [ ["tests/akmisc.t", "Msql/t/akmisc.t"],
          ["tests/msql1.t", "Msql/t/msql1.t"],
          ["tests/msql2.t", "Msql/t/msql2.t"],
          ["nodbd/bundle.pm.in", "Msql/lib/Bundle/Msql.pm"],
          ["nodbd/nodbd.pm.in", "Msql/lib/Msql.pm"],
          ["nodbd/statement.pm.in", "Msql/lib/Msql/Statement.pm"],
          ["nodbd/pmsql.in", "Mysql/pmsql", 1]];


    if ($MyConfig->{'install_dbd_msql1'}) {
	$reply = prompt(qq{

Do you want to install the Msql1Perl emulation? This is highly experimental
and can break existing code!}, "y");
        $MyConfig->{'install_msql1perl'} = ($reply =~ /y/i) ? 1 : 0;
        QueryDb($MyConfig, 'mSQL 1', 'mSQL1');
        if (!exists $MyConfig->{'X_msql1'}) {
            $MyConfig->{'X_msql1'} = InitializeMsql(1);
        }
    }

    $MyConfig->{'files_dbd_msql1'} =
        [ ["dbd/Makefile.PL.in", "Msql1/Makefile.PL"],
          ["dbd/dbdimp.c", "Msql1/dbdimp.c"],
          ["dbd/dbd.xs.in", "Msql1/mSQL1.xs"],
          ["dbd/dbd.pm.in", "Msql1/mSQL1.pm"],
          ["tests/00base.t", "Msql1/t/00base.t"],
          ["tests/10dsnlist.t", "Msql1/t/10dsnlist.t"],
          ["tests/20createdrop.t", "Msql1/t/20createdrop.t"],
          ["tests/30insertfetch.t", "Msql1/t/30insertfetch.t"],
          ["tests/40bindparam.t", "Msql1/t/40bindparam.t"],
          ["tests/40blobs.t", "Msql1/t/40blobs.t"],
          ["tests/40listfields.t", "Msql1/t/40listfields.t"],
          ["tests/40nulls.t", "Msql1/t/40nulls.t"],
          ["tests/40numrows.t", "Msql1/t/40numrows.t"],
          ["tests/50chopblanks.t", "Msql1/t/50chopblanks.t"],
          ["tests/50commit.t", "Msql1/t/50commit.t"],
          ["tests/60leaks.t", "Msql1/t/60leaks.t"],
          ["tests/ak-dbd.t", "Msql1/t/ak-dbd.t"],
          ["tests/dbdadmin.t", "Msql1/t/dbdadmin.t"],
          ["tests/lib.pl", "Msql1/t/lib.pl"] ];
    $MyConfig->{'files_msql1perl'} =
        [ ["tests/akmisc.t", "Msql1/t/akmisc.t"],
          ["tests/msql1.t", "Msql1/t/msql1.t"],
          ["tests/msql2.t", "Msql1/t/msql2.t"],
          ["nodbd/bundle.pm.in", "Msql1/lib/Bundle/Msql1.pm"],
          ["nodbd/nodbd.pm.in", "Msql1/lib/Msql1.pm"],
          ["nodbd/statement.pm.in", "Msql1/lib/Msql1/Statement.pm"],
          ["nodbd/pmsql.in", "Msql1/pmsql1", 1]];

    if ($MyConfig->{'install_dbd_mysql'}) {
        push(@{$MyConfig->{'files_dbd_mysql'}},
	     ["dbd/dbimon.in", "dbimon", 1]);
    } else {
        push(@{$MyConfig->{'files_dbd_msql'}},
	     ["dbd/dbimon.in", "dbimon", 1]);
    }

    MakeDirs();
    $Data::Dumper::Indent = 1;
    if (!open(STATUS, ">.status")
        || !print STATUS Data::Dumper->Dump([$MyConfig], [qw($MyConfig)])
        || !close(STATUS)) {
        die "Cannot create .status file: $!\n";
    }
}


############################################################################
#
#    Name:    MakeDirs
#
#    Purpose: Create the directories Msql, Msql1 and Mysql
#
#    Inputs:  None
#
#    Result:  Nothing; aborts in case of trouble
#
############################################################################

sub CreatePostamble($$$) {
    my($driver, $dbdDriver, $xtractFiles) = @_;
    my($ref);
    my($pa) = '';
    $| = 1;
    if (@$xtractFiles) {
	print "Creating $driver files ";
	foreach $ref (@$xtractFiles) {
	    $pa .= XtractF($ref, $driver, $dbdDriver, "../xtract");
	    Xtract($ref, $driver, $dbdDriver);
	    print ".";
	}
	print "\n";
    }
    $pa;
}

sub MakeDirs () {
    my (@createList);

    if ($MyConfig->{'install_dbd_mysql'}) {
	push(@createList, @{$MyConfig->{'files_dbd_mysql'}});
    }
    if ($MyConfig->{'install_mysqlperl'}) {
	push(@createList, @{$MyConfig->{'files_mysqlperl'}});
    }

    $MyConfig->{'postamble_mysql'} = CreatePostamble('Mysql', 'mysql',
						     \@createList);

    @createList = ();
    if ($MyConfig->{'install_dbd_msql'}) {
	push(@createList, @{$MyConfig->{'files_dbd_msql'}});
    }
    if ($MyConfig->{'install_msqlperl'}) {
	push(@createList, @{$MyConfig->{'files_msqlperl'}});
    }

    $MyConfig->{'postamble_msql'} = CreatePostamble('Msql', 'mSQL',
						    \@createList);

    @createList = ();
    if ($MyConfig->{'install_dbd_msql1'}) {
	push(@createList, @{$MyConfig->{'files_dbd_msql1'}});
    }
    if ($MyConfig->{'install_msql1perl'}) {
	push(@createList, @{$MyConfig->{'files_msql1perl'}});
    }

    $MyConfig->{'postamble_msql1'} = CreatePostamble('Msql1', 'mSQL1',
						    \@createList);
}


############################################################################
#
#   This is main()
#
############################################################################

Init();

my(@dirs);
if ($MyConfig->{'install_dbd_msql'}) {
    push(@dirs, "Msql");
}
if ($MyConfig->{'install_dbd_mysql'}) {
    push(@dirs, "Mysql");
}
if ($MyConfig->{'install_dbd_msql1'}) {
    push(@dirs, "Msql1");
}

my %opts =
    ('NAME'         => 'Msql-Mysql-modules',
     'DIR'          => \@dirs,
     'EXE_FILES'    => [ 'dbimon' ],
     'dist'         => { 'SUFFIX'       => ".gz",
			 'DIST_DEFAULT' => 'all tardist',
			 'COMPRESS'     => "gzip -9f" },
     'VERSION'      => $MyConfig->{'VERSION'},
     'realclean'    => { FILES => 'Mysql/Makefile.PL Msql/Makefile.PL'
			     . ' Msql1/Makefile.PL .status' }
     );

if ($ExtUtils::MakeMaker::VERSION >= 5.43) {
    $opts{ABSTRACT} =
	'mSQL and MySQL drivers for the Perl5 Database Interface (DBI)';
    $opts{AUTHOR} = 'Jochen Wiedmann (joe@ispsoft.de)';
}

ExtUtils::MakeMaker::WriteMakefile(%opts);