diff --git a/Changes b/Changes index 67fd6da..c2a9f3f 100644 --- a/Changes +++ b/Changes @@ -18,7 +18,8 @@ Changes for Perl extension DBD-SQLite primary key column names (ISHIGAKI) - You can now retrieve some of the statement handle attributes before you execute. (ISHIGAKI) - - Added preamble to generate ::sqlite3_[hc] modules to allow + - Added preamble to copy sqlite3.[hc] files into a share + directory (where you can access via File::ShareDir) to allow extension authors to use the same C source/header as they used to build DBD::SQLite itself. (ISHIGAKI) diff --git a/Makefile.PL b/Makefile.PL index 666cf61..05a4897 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -190,46 +190,6 @@ if ( 0 ) { @ARGV = grep( ! /SQLITE_LOCATION|USE_LOCAL_SQLITE/, @ARGV ); -foreach my $file (qw/sqlite3.h sqlite3.c/) { - (my $pm = $file) =~ tr/./_/; - print "generating lib/DBD/SQLite/$pm.pm\n"; - open my $fh, '>', "lib/DBD/SQLite/$pm.pm" or die $!; - print $fh <<"EOT"; -package DBD::SQLite::$pm; - -use strict; -our \$CODE = do { local \$/; }; - -sub get { - my (\$class, \$file, \$out) = \@_; - my \$got; - if (\$file) { - (\$got) = \$CODE =~ m{( - /\\*+[ ]Begin[ ]file[ ]\$file[ ]\\*+ - .+? - /\\*+[ ]End[ ]of[ ]\$file[ ]\\*+/ - )}sx; - } - else { - \$got = \$CODE; - } - if (\$got && \$out) { - open my \$fh, '>', \$out or die \$!; - print \$fh \$got; - } - return \$got ? \$got : ''; -} - -1; -\__DATA__ -EOT - print $fh do { - local $/; - open my $in, '<', $file or die $!; - <$in>; - }; -} - ##################################################################### # Prepare Compiler Options @@ -275,10 +235,6 @@ my @CC_OPTIONS = ( ) : () ), ); - - - - ##################################################################### # Hand off to ExtUtils::MakeMaker @@ -361,9 +317,19 @@ use Config; sub postamble { require DBI; require DBI::DBD; - eval { + my $postamble = eval { DBI::DBD::dbd_postamble(@_) }; + my $S = $^O eq 'MSWin32' ? '\\' : '/'; # only Win32 (not cygwin) + my $share = "\$(INST_LIB)${S}auto${S}share${S}dist${S}\$(DISTNAME)"; + $postamble .= <<"SHARE"; +config :: +\t\$(NOECHO) \$(MKPATH) "$share" +\t\$(NOECHO) \$(CHMOD) \$(PERM_DIR) "$share" +\t\$(NOECHO) \$(CP) "sqlite3.c" "$share${S}sqlite3.c" +\t\$(NOECHO) \$(CP) "sqlite3.h" "$share${S}sqlite3.h" +SHARE + return $postamble; } sub libscan { diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index b95dc12..bb8ea45 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -1601,23 +1601,31 @@ need to call the L method directly. Since 1.30_01, you can retrieve the bundled sqlite C source and/or header like this: - use DBD::SQLite::sqlite3_h; - use DBD::SQLite::sqlite3_c; + use File::ShareDir 'dist_dir'; + use File::Spec::Functions 'catfile'; - # the whole sqlite3_h header - my $sqlite3_h = DBD::SQLite::sqlite3_h->get; # the whole header + # the whole sqlite3.h header + my $sqlite3_h = catfile(dist_dir('DBD-SQLite'), 'sqlite3.h'); # or only a particular header, amalgamated in sqlite3.c - my $parse_h = DBD::SQLite::sqlite3_c->get('parse.h'); - - # you even write it to a file (if 'include' directory exists). - DBD::SQLite::sqlite3_c->get('parse.h' => 'include/parse.h'); + my $what_i_want = 'parse.h'; + my $sqlite3_c = catfile(dist_dir('DBD-SQLite'), 'sqlite3.c'); + open my $fh, '<', $sqlite3_c or die $!; + my $code = do { local $/; <$fh> }; + my ($parse_h) = $code =~ m{( + /\*+[ ]Begin[ ]file[ ]$what_i_want[ ]\*+ + .+? + /\*+[ ]End[ ]of[ ]$what_i_want[ ]\*+/ + )}sx; + open my $out, '>', $what_i_want or die $!; + print $out $parse_h; + close $out; -You usually want to use this feature in your extension's C, +You usually want to use this in your extension's C, and you may want to add DBD::SQLite to your extension's C -to allow your extension users to use the same C source/header they -use to build DBD::SQLite itself (instead of the ones installed -in their system). +to ensure your extension users use the same C source/header they use +to build DBD::SQLite itself (instead of the ones installed in their +system). =head1 TO DO diff --git a/t/43_source_files.t b/t/43_source_files.t deleted file mode 100644 index e40614e..0000000 --- a/t/43_source_files.t +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/perl - -use strict; -BEGIN { - $| = 1; - $^W = 1; -} - -use t::lib::Test qw/connect_ok @CALL_FUNCS/; -use Test::More; -use Test::NoWarnings; - -plan tests => 6; - -use_ok('DBD::SQLite::sqlite3_h'); -use_ok('DBD::SQLite::sqlite3_c'); - -my $header = DBD::SQLite::sqlite3_h->get; -like $header => qr/define _SQLITE3_H_/, 'got whole file'; - -my $hwtime_h = DBD::SQLite::sqlite3_c->get('hwtime.h'); -like $hwtime_h => qr/Begin file hwtime.h/, 'has Begin file'; -unlike $hwtime_h => qr/Begin file [^h][^w]/, 'has no other Begin file';