1#! /usr/bin/perl -w
2use strict;
3use vars qw($VERSION);
4$VERSION = "0.12";
5
6use ExtUtils::MakeMaker;
7# See lib/ExtUtils/MakeMaker.pm for details of how to influence
8# the contents of the Makefile that is written.
9
10my $xs   = eval 'use Heap::Simple::XS;   $Heap::Simple::XS::VERSION   || 0.01';
11my $perl = eval 'use Heap::Simple::Perl; $Heap::Simple::Perl::VERSION || 0.01';
12
13my %want;
14my $simple = "lib/Heap/Simple.pm";
15open(local *SIMPLE, "< $simple") || die "Could not open $simple: $!";
16while (<SIMPLE>) {
17    while (/\bHeap::Simple::(\w+)\(([^\)]+)\)/g) {
18        die "Found a demand for both version $2 and $want{1} of Heap::Simple::$1 in $simple" if exists $want{$1} && $want{$1} ne $2;
19        $want{$1} = $2;
20    }
21}
22exists $want{XS} ||
23    die "Found no minimum version for Heap::Simple::XS in $simple";
24exists $want{Perl} ||
25    die "Found no minimum version for Heap::Simple::Perl in $simple";
26
27if ($xs) {
28    if ($xs < $want{XS}) {
29        print <<"EOT"
30
31I would like to use 'Heap::Simple::XS' on your setup, but you only have version
32$xs, while I need at least $want{XS}, so I won't as things stand now. This is
33a runtime decission though, so I will if you later upgrade Heap::Simple::XS.
34However, to avoid a period where the XS version won't get selected you might
35prefer to upgrade Heap::Simple::XS first.
36
37EOT
38    } else {
39        print <<"EOT"
40
41I will probably use 'Heap::Simple::XS' on your setup. Very good.
42(the actual decission is deferred to runtime).
43
44EOT
45    }
46} elsif (!($xs && $xs >= $want{XS}) && $perl) {
47    if ($perl < $want{Perl}) {
48        print <<'EOT'
49
50I would like to use 'Heap::Simple::Perl' on your setup, but you only have
51version $perl, while I need at least $want{Perl}, so I won't as things stand
52now. This is a runtime decission though, so I will if you later upgrade
53Heap::Simple::Perl. However, to avoid a period where the XS version won't get
54selected you might prefer to upgrade Heap::Simple::Perl first.
55
56EOT
57    } else {
58        print <<'EOT'
59
60I will probably use 'Heap::Simple::Perl' on your setup, which is perfectly fine
61(the actual decission is deferred to runtime). You might consider also
62installing 'Heap::Simple::XS' though
63
64EOT
65    }
66}
67unless ($xs || $perl) {
68    print <<'EOT'
69
70You seem to have neither 'Heap::Simple::XS' nor 'Heap::Simple::Perl' installed.
71That should not stop this package from getting installed (in fact, you'll need
72to install this package before you can install any of the other two).
73However, this package won't be usable until you install one (or both) of these
74two.
75
76EOT
77}
78WriteMakefile
79    (NAME		=> 'Heap::Simple',
80     VERSION_FROM	=> "lib/Heap/Simple/Package.pm",
81     PREREQ_PM		=> {}, # e.g., Module::Name => 1.1
82     ($] >= 5.005 ?	## Add these new keywords supported since 5.005
83      (AUTHOR		=> 'Ton Hospel <Heap-Simple@ton.iguana.be>') : ()),
84     $^O eq "MSWin32" ? (
85         PM_FILTER	=> '$(PERL) -p -e1',
86     ) : (),
87     clean		=> {
88         FILES => '$(DISTNAME).ppd ppm cover_db',
89     },
90);
91
92# START MY
93# autogenerated by release_pm
94package MY;
95sub postamble {
96    return shift->SUPER::postamble() . <<"EOF";
97ppm: \$(DISTNAME).ppd
98
99\$(DISTNAME).ppd: all ppd
100	makeppd.pl "--perl=\$(PERL)" --min_version=1.013 "--zip=\$(ZIP)" "--tar=\$(TAR)" "--compress=\$(COMPRESS)" --leave=ppm \$(DISTNAME).ppd \$(VERSION)
101
102cover:
103	cover -delete
104	-HARNESS_PERL_SWITCHES=-MDevel::Cover make test
105	cover
106
107ppm_install: \$(DISTNAME).ppd
108	ppm install ppm/\$(DISTNAME).ppd
109
110ppm_uninstall:
111	ppm uninstall \$(DISTNAME)
112EOF
113}
114# END MY
115