File: Makefile.PL

package info (click to toggle)
libversion-perl 1%3A0.9900-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 516 kB
  • sloc: perl: 1,852; ansic: 834; makefile: 2
file content (164 lines) | stat: -rw-r--r-- 3,863 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# This Makefile.PL stolen from Params::Validate
#
# The perl/C checking voodoo is stolen from Graham Barr's
# Scalar-List-Utils distribution.

use strict;

use ExtUtils::MakeMaker;
use Config qw(%Config);
use File::Spec;

use vars qw ($no_xs $force_xs);

if ( $] >= 5.009_001 && $] < 5.010_000 ) {
    die "The CPAN module cannot be tested with Perl $]\n".
    	"Please update to the latest bleadperl...";
}

for (@ARGV)
{
    /^--perl_only/ and $no_xs = 1;
    /^--perl-only/ and $no_xs = 1;
    /^--xs/ and $no_xs = 0;
}

map { unlink $_ if -f $_ } <vutil/Makefile*>;

unless (defined $no_xs)
{
    check_for_compiler()
        or no_cc();
}

write_makefile();

sub write_makefile
{
    my %prereq = ( 'Test::More' => 0.45, 'File::Temp' => 0.13 );

    WriteMakefile( VERSION_FROM    => 'lib/version.pm',
                   NAME            => 'version',
                   LICENSE         => 'perl',
                   PREREQ_PM       => \%prereq,
                   CONFIGURE       => \&init,
                   ( $] >= 5.005 ?
                     ( ABSTRACT    => 'Structured version objects',
                       AUTHOR      => 'John Peacock <jpeacock@cpan.org>') :
                     ()
                   ), 
		   ( $] >= 5.009001 && $] < 5.011000 ?
		     ( INSTALLDIRS => 'perl' ) :
		     ()
		   ),
                   PM              => 
                       {'lib/version.pm'  => '$(INST_LIBDIR)/version.pm',
                        'lib/version.pod' => '$(INST_LIBDIR)/version.pod',
                        'lib/version/Internals.pod' =>
			    '$(INST_LIBDIR)/version/Internals.pod'},
                   PL_FILES        => {},
                   C               => [],
                   clean           => { FILES => 'vutil/Makefile.PL' },
                   dist            => {
                       COMPRESS => 'gzip -9f', 
                       SUFFIX => 'gz',
                       PREOP  => (
                          'hg log --style changelog > Changes'
                       ),
                   },

                 );
}

sub init
{
    my $hash = $_[1];

    if ($no_xs) {
        $hash->{'PM'}->{'vperl/vpp.pm'} = '$(INST_LIBDIR)/version/vpp.pm';
    }
    else {
        open MAKEFILE, '>vutil/Makefile.PL';
        while (<DATA>) {
            print MAKEFILE $_;
        }
        close MAKEFILE;
        sleep(1);
        @{ $hash }{ 'DIR' } = ['vutil'];
    }

    return $hash;
}

sub no_cc
{
    $no_xs = 1;
    print <<'EOF';

 I cannot determine if you have a C compiler
 so I will install a perl-only implementation

 You can force installation of the XS version with

    perl Makefile.PL --xs

EOF

}

sub check_for_compiler
{
    print "Testing if you have a C compiler\n";

    eval { require ExtUtils::CBuilder };
    if ($@)
    {
        return _check_for_compiler_manually();
    }
    else
    {
        return _check_for_compiler_with_cbuilder();
    }
}

sub _check_for_compiler_with_cbuilder
{
    my $cb = ExtUtils::CBuilder->new( quiet => 1 );

    return $cb->have_compiler;
}

sub _check_for_compiler_manually
{
    unless ( open F, ">test.c" )
    {
        warn "Cannot write test.c, skipping test compilation and installing pure Perl version.\n";
        return 0;
    }

    print F <<'EOF';
int main() { return 0; }
EOF

    close F or return 0;

    my $cc = $Config{cc};

    my $retval = system( "$cc -c -o test$Config{obj_ext} test.c" );
    map { unlink $_ if -f $_ } ('test.c',"test$Config{obj_ext}");

    return not($retval); # system returns -1
}

__DATA__
#!/usr/bin/perl -w
use strict;
use ExtUtils::MakeMaker;

WriteMakefile(
    NAME                => 'version::vxs',
    AUTHOR              => 'John Peacock <jpeacock@cpan.org>',
    VERSION_FROM        => 'lib/version/vxs.pm',
    OBJECT              => q/$(O_FILES)/,
    TYPEMAPS            => ['../lib/version/typemap'],
);