main trunk version is wrong
[bioperl-db.git] / Build.PL
blob68d75d7dad50424b11976ebdb92de2fb105d2108
1 #!/usr/bin/perl -w
3 # This is a Module::Build script for BioPerl-DB installation.
4 # See http://search.cpan.org/~kwilliams/Module-Build/lib/Module/Build.pm
6 use strict;
7 use warnings;
8 use Module::Build;
9 use File::Spec;
10 use File::Basename;
12 my $build = Module::Build->new(
13 module_name => 'Bio::DB',
14 dist_name => 'BioPerl-DB',
15 dist_version => '1.006900',
16 dist_author => 'BioPerl Team <bioperl-l@bioperl.org>',
17 dist_abstract => 'BioPerl-DB - package for biological databases',
18 license => 'perl',
19 requires => {
20 'perl' => '5.6.1',
21 'Bio::Root::Version' => '1.006009',
22 'DBI' => 0
24 get_options => {
25 accept => { }
27 dynamic_config => 1,
28 create_makefile_pl => 'passthrough'
31 my $accept = $build->args->{accept};
33 # Ask questions for db configuration (Harness file)
34 biosql_conf();
36 # Optionally have script files installed.
37 if ($accept ? 0 : $build->y_n("Install scripts? y/n", 'n')) {
38 my $files = $build->_find_file_by_type('pl', 'scripts');
40 my $script_build = File::Spec->catdir($build->blib, 'script');
42 my @tobp;
43 while (my ($file, $dest) = each %$files) {
44 $dest = 'bp_'.File::Basename::basename($dest);
45 $dest = File::Spec->catfile($script_build, $dest);
46 $build->copy_if_modified(from => $file, to => $dest);
47 push @tobp, $dest;
50 $build->script_files(\@tobp);
53 # Create the build script and exit
54 $build->create_build_script;
56 exit;
58 # setup t/DBHarness.biosql.conf
59 sub biosql_conf {
60 my $continue = $accept || $build->y_n("Have you already installed BioSQL? y/n", 'y');
61 $continue || die "\nBioSQL must be installed prior to installation of bioperl-db; see the INSTALL file\n";
63 my $config_file = File::Spec->catfile('t', 'DBHarness.biosql.conf');
64 if (-e $config_file) {
65 ($accept || $build->y_n("Do you want to use the existing '$config_file' config file? y/n", 'y')) && return;
66 unlink($config_file);
69 open(my $out, ">", $config_file) or die "Error: could not write to config file '$config_file'\n";
71 my %config = (driver => 'mysql',
72 host => '127.0.0.1',
73 user => 'root',
74 port => 3306,
75 password => '',
76 dbname => 'bioseqdb',
77 database => 'biosql',
78 schema_sql => '../biosql-schema/sql/biosqldb-mysql.sql');
80 $config{driver} = $build->prompt("DBD driver to use (mandatory)?", $config{driver});
81 $config{host} = $build->prompt("Machine to connect to (mandatory)?", $config{host});
82 $config{user} = $build->prompt("User to connect to server as (mandatory)?", $config{user});
84 $config{port} = $build->prompt("Port the server is running on (optional, '' for undef/none)?", $config{port});
85 $config{port} = undef if $config{port} eq "''";
87 $config{password} = $build->prompt("Password (optional)?", $config{password} || 'undef');
88 $config{password} = '' if $config{password} eq 'undef';
90 $build->log_info("
91 # The next answer will be used to identify the database name in
92 # the connect string, e.g., using database=, dbname=, or sid=,
93 # depending on the driver.
94 # If this is not set the test scripts will build a temporary
95 # database from scratch at the beginning and destroy it at the
96 # end. Conversely, if you do set it then the database must exist,
97 # or else the tests will fail.
98 # Generally, it is preferred to pre-build the database, simply for
99 # efficiency reasons, and it will also enable debugging your
100 # schema content if some test acts up.
101 \n");
102 $config{dbname} = $build->prompt("Name of your existing Biosql database, as it is known to your RDBMS (optional, '' for none)?", $config{dbname});
103 $config{dbname} = '' if $config{dbname} eq "''";
105 unless ($config{dbname}) {
106 $config{schema_sql} = $build->prompt("Set schema_sql to use the version appropriate for your RDBMS (mandatory)", $config{schema_sql});
108 $config{schema_sql} = "['$config{schema_sql}']"; # don't know why it is stored as an array ref, is this correct?
110 $build->log_info("
111 # The next answer does not refer to the schema or RDBMS; it only
112 # identifies which of the databases supported in bioperl-db you
113 # want to be using. Since at present bioperl-db only supports biosql,
114 # this must be biosql.
115 \n");
116 $config{database} = $build->prompt("The name of the database within bioperl-db?", $config{database});
118 print $out "{\n";
119 while (my ($key, $val) = each %config) {
120 # no empty strings, undefined conf setting should be undef (w/o quotes)
121 $val = "'$val'" unless $key eq 'schema_sql' || !defined($val);
122 if (!defined($val)) {
123 $val = 'undef';
125 print $out "\t'$key' => $val,\n";
127 print $out "}\n";
128 close($out);
130 # we deliberately don't add the config file to cleanup, but it shouldn't
131 # cause problems because it is in MANIFEST.SKIP