DBD-Firebird
view release on metacpan or search on metacpan
inc/FirebirdMaker.pm view on Meta::CPAN
foreach my $dir (@bd) {
if ( -d $dir ) {
# File names specific to the Firebird/bin dir
my @fb_files = qw{fbsql isql-fb isql};
# fbsql not yet! but 'isql' is
# used by Virtuoso and UnixODBC
# That's why Debian ships it as
# isql-fb
my $found = 0;
while ( !$found ) {
my $file = shift @fb_files or last;
$file = File::Spec->catfile( $dir, 'bin', $file );
if ( -f $file and -x $file ) {
# Located
my $out = `echo 'quit;' | $file -z 2>&1`;
next unless $out =~ /firebird/si; # Firebird's isql?
check_and_set_devlibs($dir);
last;
}
}
}
}
return;
}
=head2 check_and_set_devlibs
Check and set global variables for home, inc and lib (?...).
=cut
sub check_and_set_devlibs {
my $fb_dir = shift;
$FB::HOME = File::Spec->canonpath($fb_dir);
$FB::INC = $FB::INC || File::Spec->catdir( $FB::HOME, 'include' );
$FB::INC = alternative_locations('inc') if !-d $FB::INC || !-f File::Spec->catfile($FB::INC, "ibase.h");
$FB::LIB = $FB::LIB || File::Spec->catdir( $FB::HOME, 'lib' );
$FB::LIB = alternative_locations('lib') if !-d $FB::LIB;
detect_firebird_api_version();
for my $dir ( split(/ /, $Config{libpth} ), $FB::LIB||() ) {
if ( -e File::Spec->catfile( $dir, 'libfbembed.so' ) ) {
$FB::libfbembed_available = 1;
print "libfbembed.so found in $dir\n";
last;
}
}
die "libfbembed.so not found\n"
if $ENV{DBD_FIREBIRD_REQUIRE_EMBEDDED}
and not $FB::libfbembed_available
and $FB::API_VER < 30;
return;
}
=head2 alternative_locations
Search lib and inc in alternative locations.
=cut
sub alternative_locations {
my $find_what = shift;
my @fid = ();
@fid = search_fb_lib_dirs() if $find_what eq q{lib};
@fid = search_fb_inc_dirs() if $find_what eq q{inc};
foreach my $dir ( @fid ) {
return $dir if -d $dir;
}
help_message();
die "Firebird '$find_what' dir not located!";
}
=head2 search_fb_home_dirs
Common places for the Firebird home dir.
=cut
sub search_fb_home_dirs {
# Add other standard paths here
return (
qw{
/opt/firebird
/usr/local/firebird
/usr/local
/usr/lib/firebird
/usr
},
);
}
=head2 search_fb_inc_dirs
Common places for the Firebird include dir.
=cut
sub search_fb_inc_dirs {
# Add other standard paths here for include
return (
qw{
/usr/include/firebird
/usr/local/include/firebird
inc/FirebirdMaker.pm view on Meta::CPAN
MSG
print $msg unless $use_libfbembed;
}
sub copy_mangled {
my ( $src, $p ) = @_;
my $dir = 'embed';
my $df = $p->{new_path} || File::Spec->catfile( $dir, $p->{name} || $src );
open( my $dfh, '>', $df ) or die "Unable to open $df for writing: $!\n";
open( my $sfh, '<', $src ) or die "Unable to open $src: $!\n";
my ($prefix, $skip_shebang);
if ( $src =~ /\.(?:xs|[ch])$/ ) {
$prefix = '//';
$skip_shebang = 0;
} elsif ( $src =~ /\.pl$/i ) {
$prefix = '#';
$skip_shebang = 1;
}
else {
$prefix = '#';
$skip_shebang = 0;
}
my $header_warning = sub {
my $line = '*' x 60;
print $dfh "\n" if $skip_shebang;
print $dfh "$prefix $line\n";
print $dfh "$prefix This is an automaticaly generated file.\n";
print $dfh "$prefix If needed, edit $src in the parent directory\n";
print $dfh "$prefix and run perl Makefile.PL to re-generate it.\n";
print $dfh "$prefix $line\n\n";
};
my $line_no = 0;
while ( defined( $_ = <$sfh> ) ) {
&$header_warning if $line_no++ == $skip_shebang;
last if $p->{last} and &{ $p->{last} }($_);
&{ $p->{mangle} }($_) if $p->{mangle};
print $dfh $_;
}
close($dfh) or die "Error closing $df: $!\n";
close($sfh) or die "Error closing $src: $!\n";
}
sub create_embedded_files {
my $dir = "embed";
unless (-d $dir) {
mkdir($dir) or die "Error creating directory $dir: $!\n";
}
# Makefile.PL
copy_mangled(
'Makefile.PL' => {
last => sub { $_[0] =~ /^exit 0/ },
mangle => sub { $_[0] =~ s/(?<=^our \$EMBEDDED = )0/1/ },
}
);
# Simple copies
for my $f (qw( dbdimp.h )) {
copy_mangled($f);
}
copy_mangled(
'Firebird.h' => {
name => 'FirebirdEmbedded.h',
},
);
# dbdimp.c
copy_mangled(
'dbdimp.c' => {
mangle =>
sub { $_[0] =~ s/(?<=^#include "Firebird)\.h"/Embedded.h"/ },
},
);
my $next_is_last = 0;
copy_mangled(
'Firebird.pm' => {
name => 'FirebirdEmbedded.pm',
last => sub {
return 1 if $next_is_last;
if ( $_[0] =~ /^=head1 DESCRIPTION$/ ) {
$next_is_last = 1;
$_[0] .= <<EOT;
B<DBD::FirebirdEmbedded> is a variant of L<DBD::Firebird>, linked with the
Firebird embedded library, F<libfbembed>. In addition to the ability to work
with remote Firebird servers (which DBD::Firebird has, being linked with the
Firebird client library, F<libfbclient>), DBD::FirebirdEmbedded can be used to
work with Firebird databases without the need of a dedicated Firebird server.
The following things should be set up first:
=over
=item Username/password
These should be unset. Both in the C<< DBI->connection(...) >> call and in the
environment (C<ISC_USER>, C<ISC_PASSWORD>, C<DBI_USER>, C<DBI_PASSWORD> variables).
=item Firebird lock directory
The C<FIREBIRD_LOCK> environment variable should be set to some place where the
process can write. Note that if you plan for several processes to access the
database file directly, they all should have C<FIREBIRD_LOCK> set to the same
directory, or else database corruption will occur.
=item No C<host> in the DSN
Obviously, do not set any host when calling C<< DBI->connection(...) >>, not
even C<localhost>.
=item Permissions to read/write the database
( run in 1.221 second using v1.01-cache-2.11-cpan-71847e10f99 )