xref: /openbsd-src/gnu/usr.bin/perl/cpan/DB_File/Makefile.PL (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1b39c5158Smillert#! perl -w
2b39c5158Smillert
3b39c5158Smillertuse strict ;
4b39c5158Smillertuse ExtUtils::MakeMaker 5.16 ;
5b39c5158Smillertuse Config ;
6b39c5158Smillert
7b8851fccSafresh1die "DB_File needs Perl 5.8.3 or better. This is $]\n"
8b8851fccSafresh1    if $] < 5.008003;
9b39c5158Smillert
10b39c5158Smillertmy $VER_INFO ;
11b39c5158Smillertmy $LIB_DIR ;
12b39c5158Smillertmy $INC_DIR ;
13b39c5158Smillertmy $DB_NAME ;
14b39c5158Smillertmy $LIBS ;
15b39c5158Smillertmy $COMPAT185 = "" ;
16b39c5158Smillert
17b39c5158SmillertParseCONFIG() ;
18b39c5158Smillert
19b39c5158Smillertmy @files = ('DB_File.pm', glob "t/*.t") ;
20b39c5158SmillertUpDowngrade(@files);
21b39c5158Smillert
22b39c5158Smillertif (defined $DB_NAME)
23b39c5158Smillert  { $LIBS = $DB_NAME }
24b39c5158Smillertelse {
25b39c5158Smillert    if ($^O eq 'MSWin32')
26b39c5158Smillert      { $LIBS = $Config{cc} =~ /gcc/ ? '-ldb' : '-llibdb' }
27b39c5158Smillert    else
28b39c5158Smillert      { $LIBS = '-ldb' }
29b39c5158Smillert}
30b39c5158Smillert
31b39c5158Smillert# Solaris is special.
32b39c5158Smillert#$LIBS .= " -lthread" if $^O eq 'solaris' ;
33b39c5158Smillert
34b39c5158Smillert# AIX is special.
35b39c5158Smillert$LIBS .= " -lpthread" if $^O eq 'aix' ;
36b39c5158Smillert
37b39c5158Smillert# OS2 is a special case, so check for it now.
38b39c5158Smillertmy $OS2 = "" ;
39b39c5158Smillert$OS2 = "-DOS2" if $Config{'osname'} eq 'os2' ;
40b39c5158Smillert
41b39c5158Smillertmy $WALL = '' ;
42b39c5158Smillert#$WALL = ' -Wall ';
43b39c5158Smillert
44b46d8ef2Safresh1# Only want ppport.h t to be used by DB_File.xs when not
45b46d8ef2Safresh1# building this module with the perl source distribution.
46b46d8ef2Safresh1my $CORE = $ENV{PERL_CORE} ? '' : '-D_NOT_CORE';
47b46d8ef2Safresh1
48b39c5158SmillertWriteMakefile(
49b39c5158Smillert        NAME            => 'DB_File',
50b39c5158Smillert        LIBS            => ["-L${LIB_DIR} $LIBS"],
51b39c5158Smillert        INC             => "-I$INC_DIR",
52b39c5158Smillert        VERSION_FROM    => 'DB_File.pm',
53b39c5158Smillert        XS_VERSION      => eval MM->parse_version('DB_File.pm'),
54b39c5158Smillert        XSPROTOARG      => '-noprototypes',
55b46d8ef2Safresh1        DEFINE          => "$CORE $OS2 $VER_INFO $COMPAT185 $WALL",
56b39c5158Smillert        OBJECT          => 'version$(OBJ_EXT) DB_File$(OBJ_EXT)',
57b39c5158Smillert    ((ExtUtils::MakeMaker->VERSION() gt '6.30')
58b39c5158Smillert        ?  ('LICENSE'  => 'perl')
59b39c5158Smillert        : ()
60b39c5158Smillert    ),
61b39c5158Smillert    (
62b39c5158Smillert    $] >= 5.005
63b39c5158Smillert        ? (ABSTRACT_FROM => 'DB_File.pm',
64b39c5158Smillert            AUTHOR       => 'Paul Marquess <pmqs@cpan.org>')
65b39c5158Smillert        : ()
66b39c5158Smillert    ),
67b39c5158Smillert
686fb12b70Safresh1    ($] < 5.008 || $] > 5.011)
696fb12b70Safresh1        ? (INSTALLDIRS => 'site')
706fb12b70Safresh1        : (INSTALLDIRS => 'perl'),
71b39c5158Smillert
72b39c5158Smillert        #OPTIMIZE       => '-g',
73b39c5158Smillert        'depend'        => { 'Makefile'          => 'config.in',
74b39c5158Smillert                             'version$(OBJ_EXT)' => 'version.c'},
75*eac174f2Safresh1        'clean'         => { FILES => 'constants.h constants.xs *.bak t/*.t.bak' },
766fb12b70Safresh1        'macro'         => { my_files => "@files" },
77b39c5158Smillert        'dist'          => { COMPRESS => 'gzip', SUFFIX => 'gz',
78b39c5158Smillert                             DIST_DEFAULT => 'MyDoubleCheck tardist'},
7956d68f1eSafresh1
8056d68f1eSafresh1     ( eval { ExtUtils::MakeMaker->VERSION(6.46) }
8156d68f1eSafresh1        ? ( META_MERGE  => {
8256d68f1eSafresh1
8356d68f1eSafresh1                "meta-spec" => { version => 2 },
8456d68f1eSafresh1
8556d68f1eSafresh1                resources   => {
8656d68f1eSafresh1
8756d68f1eSafresh1                    bugtracker  => {
8856d68f1eSafresh1                        web     => 'https://github.com/pmqs/DB_File/issues'
8956d68f1eSafresh1                    },
9056d68f1eSafresh1
9156d68f1eSafresh1                    homepage    => 'https://github.com/pmqs/DB_File',
9256d68f1eSafresh1
9356d68f1eSafresh1                    repository  => {
9456d68f1eSafresh1                        type    => 'git',
9556d68f1eSafresh1                        url     => 'git://github.com/pmqs/DB_File.git',
9656d68f1eSafresh1                        web     => 'https://github.com/pmqs/DB_File',
9756d68f1eSafresh1                    },
9856d68f1eSafresh1                },
9956d68f1eSafresh1            }
10056d68f1eSafresh1            )
10156d68f1eSafresh1        : ()
10256d68f1eSafresh1    ),
10356d68f1eSafresh1
10456d68f1eSafresh1
105b39c5158Smillert        );
106b39c5158Smillert
107b39c5158Smillert
108b39c5158Smillertmy @names = qw(
109b39c5158Smillert        BTREEMAGIC
110b39c5158Smillert        BTREEVERSION
111b39c5158Smillert        DB_LOCK
112b39c5158Smillert        DB_SHMEM
113b39c5158Smillert        DB_TXN
114b39c5158Smillert        HASHMAGIC
115b39c5158Smillert        HASHVERSION
116b39c5158Smillert        MAX_PAGE_NUMBER
117b39c5158Smillert        MAX_PAGE_OFFSET
118b39c5158Smillert        MAX_REC_NUMBER
119b39c5158Smillert        RET_ERROR
120b39c5158Smillert        RET_SPECIAL
121b39c5158Smillert        RET_SUCCESS
122b39c5158Smillert        R_CURSOR
123b39c5158Smillert        R_DUP
124b39c5158Smillert        R_FIRST
125b39c5158Smillert        R_FIXEDLEN
126b39c5158Smillert        R_IAFTER
127b39c5158Smillert        R_IBEFORE
128b39c5158Smillert        R_LAST
129b39c5158Smillert        R_NEXT
130b39c5158Smillert        R_NOKEY
131b39c5158Smillert        R_NOOVERWRITE
132b39c5158Smillert        R_PREV
133b39c5158Smillert        R_RECNOSYNC
134b39c5158Smillert        R_SETCURSOR
135b39c5158Smillert        R_SNAPSHOT
136b39c5158Smillert        __R_UNUSED
137b39c5158Smillert        );
138b39c5158Smillert
139b39c5158Smillertif (eval {require ExtUtils::Constant; 1}) {
140b39c5158Smillert    # Check the constants above all appear in @EXPORT in DB_File.pm
141b39c5158Smillert    my %names = map { $_, 1} @names;
142b39c5158Smillert    open F, "<DB_File.pm" or die "Cannot open DB_File.pm: $!\n";
143b39c5158Smillert    while (<F>)
144b39c5158Smillert    {
145b39c5158Smillert        last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
146b39c5158Smillert    }
147b39c5158Smillert
148b39c5158Smillert    while (<F>)
149b39c5158Smillert    {
150b39c5158Smillert        last if /^\s*\)/ ;
151b39c5158Smillert        /(\S+)/ ;
152b39c5158Smillert        delete $names{$1} if defined $1 ;
153b39c5158Smillert    }
154b39c5158Smillert    close F ;
155b39c5158Smillert
156b39c5158Smillert    if ( keys %names )
157b39c5158Smillert    {
158b39c5158Smillert        my $missing = join ("\n\t", sort keys %names) ;
159b39c5158Smillert        die "The following names are missing from \@EXPORT in DB_File.pm\n" .
160b39c5158Smillert            "\t$missing\n" ;
161b39c5158Smillert    }
162b39c5158Smillert
163b39c5158Smillert
164b39c5158Smillert    ExtUtils::Constant::WriteConstants(
165b39c5158Smillert                                     NAME => 'DB_File',
166b39c5158Smillert                                     NAMES => \@names,
167b39c5158Smillert                                     C_FILE  => 'constants.h',
168b39c5158Smillert                                     XS_FILE  => 'constants.xs',
169b39c5158Smillert
170b39c5158Smillert                                    );
171b39c5158Smillert}
172b39c5158Smillertelse {
173b39c5158Smillert    use File::Copy;
174b39c5158Smillert    copy ('fallback.h', 'constants.h')
175b39c5158Smillert      or die "Can't copy fallback.h to constants.h: $!";
176b39c5158Smillert    copy ('fallback.xs', 'constants.xs')
177b39c5158Smillert      or die "Can't copy fallback.xs to constants.xs: $!";
178b39c5158Smillert}
179b39c5158Smillert
180b39c5158Smillertexit;
181b39c5158Smillert
182b39c5158Smillert
183b39c5158Smillertsub MY::libscan
184b39c5158Smillert{
185b39c5158Smillert    my $self = shift ;
186b39c5158Smillert    my $path = shift ;
187b39c5158Smillert
188b39c5158Smillert    return undef
189b39c5158Smillert        if $path =~ /(~|\.bak)$/ ||
190b39c5158Smillert           $path =~ /^\..*\.swp$/ ;
191b39c5158Smillert
192b39c5158Smillert    return $path;
193b39c5158Smillert}
194b39c5158Smillert
195b39c5158Smillert
196b39c5158Smillertsub MY::postamble { <<'EOM' } ;
197b39c5158Smillert
198b39c5158SmillertMyDoubleCheck:
199b39c5158Smillert	@echo Checking config.in is setup for a release
200b39c5158Smillert	@(grep "^LIB.*/usr/local/BerkeleyDB" config.in &&       \
201b39c5158Smillert	grep "^INCLUDE.*/usr/local/BerkeleyDB" config.in &&     \
202b39c5158Smillert	grep "^#DBNAME.*" config.in) >/dev/null ||              \
203b39c5158Smillert	    (echo config.in needs fixing ; exit 1)
204b39c5158Smillert	@echo config.in is ok
205b39c5158Smillert	@echo
206b39c5158Smillert	@echo Checking DB_File.xs is ok for a release.
207b39c5158Smillert	@(perl -ne ' exit 1 if /^\s*#\s*define\s+TRACE/ ; ' DB_File.xs || \
208b39c5158Smillert	    (echo DB_File.xs needs fixing ; exit 1))
209b39c5158Smillert	@echo DB_File.xs is ok
210b39c5158Smillert	@echo
211b39c5158Smillert	@echo Checking for $$^W in files: $(my_files)
212b39c5158Smillert	@perl -ne '                                             \
213b39c5158Smillert	    exit 1 if /^\s*local\s*\(\s*\$$\^W\s*\)/;' $(my_files) ||   \
214b39c5158Smillert	    (echo found unexpected $$^W ; exit 1)
215b39c5158Smillert	@echo No $$^W found.
216b39c5158Smillert	@echo
217b39c5158Smillert	@echo Checking for 'use vars' in files: $(my_files)
218b39c5158Smillert	@perl -ne '                                             \
219b39c5158Smillert	    exit 0 if /^__(DATA|END)__/;                \
220b39c5158Smillert	    exit 1 if /^\s*use\s+vars/;' $(my_files) || \
221b39c5158Smillert	    (echo found unexpected "use vars"; exit 1)
222b39c5158Smillert	@echo No 'use vars' found.
223b39c5158Smillert	@echo
224b39c5158Smillert	@echo All files are OK for a release.
225b39c5158Smillert	@echo
226b39c5158Smillert
227b39c5158SmillertEOM
228b39c5158Smillert
229b39c5158Smillert
230b39c5158Smillert
231b39c5158Smillertsub ParseCONFIG
232b39c5158Smillert{
233b39c5158Smillert    my ($k, $v) ;
234b39c5158Smillert    my @badkey = () ;
235b39c5158Smillert    my %Info = () ;
236b39c5158Smillert    my @Options = qw( INCLUDE LIB PREFIX HASH DBNAME COMPAT185 ) ;
237b39c5158Smillert    my %ValidOption = map {$_, 1} @Options ;
238b39c5158Smillert    my %Parsed = %ValidOption ;
239b39c5158Smillert    my $CONFIG = 'config.in' ;
240b39c5158Smillert
241b39c5158Smillert    print "Parsing $CONFIG...\n" ;
242b39c5158Smillert
243b39c5158Smillert    # DBNAME & COMPAT185 are optional, so pretend they  have
244b39c5158Smillert    # been parsed.
245b39c5158Smillert    delete $Parsed{'DBNAME'} ;
246b39c5158Smillert    delete $Parsed{'COMPAT185'} ;
247b39c5158Smillert    $Info{COMPAT185} = "No" ;
248b39c5158Smillert
249b39c5158Smillert
250b39c5158Smillert    open(F, "$CONFIG") or die "Cannot open file $CONFIG: $!\n" ;
251b39c5158Smillert    while (<F>) {
252b39c5158Smillert        s/^\s*|\s*$//g ;
253b39c5158Smillert        next if /^\s*$/ or /^\s*#/ ;
254b39c5158Smillert        s/\s*#\s*$// ;
255b39c5158Smillert
256b39c5158Smillert        ($k, $v) = split(/\s+=\s+/, $_, 2) ;
257b39c5158Smillert        $k = uc $k ;
258b39c5158Smillert        if ($ValidOption{$k}) {
259b39c5158Smillert            delete $Parsed{$k} ;
260b39c5158Smillert            $Info{$k} = $v ;
261b39c5158Smillert        }
262b39c5158Smillert        else {
263b39c5158Smillert            push(@badkey, $k) ;
264b39c5158Smillert        }
265b39c5158Smillert    }
266b39c5158Smillert    close F ;
267b39c5158Smillert
268b39c5158Smillert    print "Unknown keys in $CONFIG ignored [@badkey]\n"
269b39c5158Smillert        if @badkey ;
270b39c5158Smillert
271b39c5158Smillert    # check parsed values
272b39c5158Smillert    my @missing = () ;
273b39c5158Smillert    die "The following keys are missing from $CONFIG file: [@missing]\n"
274b39c5158Smillert        if @missing = keys %Parsed ;
275b39c5158Smillert
276b39c5158Smillert    $INC_DIR = $ENV{'DB_FILE_INCLUDE'} || $Info{'INCLUDE'} ;
277b39c5158Smillert    $LIB_DIR = $ENV{'DB_FILE_LIB'} || $Info{'LIB'} ;
278b39c5158Smillert    $DB_NAME = $ENV{'DB_FILE_NAME'} || $Info{'DBNAME'} ;
279b39c5158Smillert    $COMPAT185 = "-DCOMPAT185 -DDB_LIBRARY_COMPATIBILITY_API"
280b39c5158Smillert        if (defined $ENV{'DB_FILE_COMPAT185'} &&
281b39c5158Smillert                $ENV{'DB_FILE_COMPAT185'} =~ /^\s*(on|true|1)\s*$/i) ||
282b39c5158Smillert                $Info{'COMPAT185'} =~ /^\s*(on|true|1)\s*$/i ;
283b39c5158Smillert    my $PREFIX  = $Info{'PREFIX'} ;
284b39c5158Smillert    my $HASH    = $Info{'HASH'} ;
285b39c5158Smillert
286b39c5158Smillert    $VER_INFO = "-DmDB_Prefix_t=${PREFIX} -DmDB_Hash_t=${HASH}" ;
287b39c5158Smillert
288b39c5158Smillert    print <<EOM if 0 ;
289b39c5158Smillert    INCLUDE     [$INC_DIR]
290b39c5158Smillert    LIB         [$LIB_DIR]
291b39c5158Smillert    HASH        [$HASH]
292b39c5158Smillert    PREFIX      [$PREFIX]
293b39c5158Smillert    DBNAME      [$DB_NAME]
294b39c5158Smillert
295b39c5158SmillertEOM
296b39c5158Smillert
297b39c5158Smillert    print "Looks Good.\n" ;
298b39c5158Smillert
299b39c5158Smillert}
300b39c5158Smillert
301b39c5158Smillertsub UpDowngrade
302b39c5158Smillert{
303b39c5158Smillert    my @files = @_ ;
304b39c5158Smillert
305b39c5158Smillert    # our      is stable from 5.6.0 onward
306b39c5158Smillert    # warnings is stable from 5.6.1 onward
307b39c5158Smillert
308b39c5158Smillert    # Note: this code assumes that each statement it modifies is not
309b39c5158Smillert    #       split across multiple lines.
310b39c5158Smillert
311b39c5158Smillert
312b39c5158Smillert    my $warn_sub ;
313b39c5158Smillert    my $our_sub ;
314b39c5158Smillert
315b39c5158Smillert    if ($] < 5.006001) {
316b39c5158Smillert        # From: use|no warnings "blah"
317b39c5158Smillert        # To:   local ($^W) = 1; # use|no warnings "blah"
318b39c5158Smillert        #
319b39c5158Smillert        # and
320b39c5158Smillert        #
321b39c5158Smillert        # From: warnings::warnif(x,y);
322b39c5158Smillert        # To:   $^W && carp(y); # warnif -- x
323b39c5158Smillert        $warn_sub = sub {
324b39c5158Smillert            s/^(\s*)(no\s+warnings)/${1}local (\$^W) = 0; #$2/ ;
325b39c5158Smillert            s/^(\s*)(use\s+warnings)/${1}local (\$^W) = 1; #$2/ ;
326b39c5158Smillert
327b39c5158Smillert            s/^(\s*)warnings::warnif\s*\((.*?)\s*,\s*(.*?)\)\s*;/${1}\$^W && carp($3); # warnif - $2/ ;
328b39c5158Smillert          };
329b39c5158Smillert    }
330b39c5158Smillert    else {
331b39c5158Smillert        # From: local ($^W) = 1; # use|no warnings "blah"
332b39c5158Smillert        # To:   use|no warnings "blah"
333b39c5158Smillert        #
334b39c5158Smillert        # and
335b39c5158Smillert        #
336b39c5158Smillert        # From: $^W && carp(y); # warnif -- x
337b39c5158Smillert        # To:   warnings::warnif(x,y);
338b39c5158Smillert        $warn_sub = sub {
339b39c5158Smillert            s/^(\s*)local\s*\(\$\^W\)\s*=\s*\d+\s*;\s*#\s*((no|use)\s+warnings.*)/$1$2/ ;
340b39c5158Smillert            s/^(\s*)\$\^W\s+\&\&\s*carp\s*\((.*?)\)\s*;\s*#\s*warnif\s*-\s*(.*)/${1}warnings::warnif($3, $2);/ ;
341b39c5158Smillert          };
342b39c5158Smillert    }
343b39c5158Smillert
344b39c5158Smillert    if ($] < 5.006000) {
345b39c5158Smillert        $our_sub = sub {
346b39c5158Smillert            if ( /^(\s*)our\s+\(\s*([^)]+\s*)\)/ ) {
347b39c5158Smillert                my $indent = $1;
348b39c5158Smillert                my $vars = join ' ', split /\s*,\s*/, $2;
349b39c5158Smillert                $_ = "${indent}use vars qw($vars);\n";
350b39c5158Smillert            }
351b39c5158Smillert          };
352b39c5158Smillert    }
353b39c5158Smillert    else {
354b39c5158Smillert        $our_sub = sub {
355b39c5158Smillert            if ( /^(\s*)use\s+vars\s+qw\((.*?)\)/ ) {
356b39c5158Smillert                my $indent = $1;
357b39c5158Smillert                my $vars = join ', ', split ' ', $2;
358b39c5158Smillert                $_ = "${indent}our ($vars);\n";
359b39c5158Smillert            }
360b39c5158Smillert          };
361b39c5158Smillert    }
362b39c5158Smillert
363b39c5158Smillert    foreach (@files)
364b39c5158Smillert      { doUpDown($our_sub, $warn_sub, $_) }
365b39c5158Smillert}
366b39c5158Smillert
367b39c5158Smillert
368b39c5158Smillertsub doUpDown
369b39c5158Smillert{
370b39c5158Smillert    my $our_sub = shift;
371b39c5158Smillert    my $warn_sub = shift;
372b39c5158Smillert
373b39c5158Smillert    local ($^I) = ".bak" ;
374b39c5158Smillert    local (@ARGV) = shift;
375b39c5158Smillert
376b39c5158Smillert    while (<>)
377b39c5158Smillert    {
378b39c5158Smillert        print, last if /^__(END|DATA)__/ ;
379b39c5158Smillert
380b39c5158Smillert        &{ $our_sub }();
381b39c5158Smillert        &{ $warn_sub }();
382b39c5158Smillert        print ;
383b39c5158Smillert    }
384b39c5158Smillert
385b39c5158Smillert    return if eof ;
386b39c5158Smillert
387b39c5158Smillert    while (<>)
388b39c5158Smillert      { print }
389b39c5158Smillert}
390b39c5158Smillert
391b39c5158Smillert# end of file Makefile.PL
392