|
| 1 | +# This Makefile.PL stolen from Params::Validate |
| 2 | +# |
| 3 | +# The perl/C checking voodoo is stolen from Graham Barr's |
| 4 | +# Scalar-List-Utils distribution. |
| 5 | + |
| 6 | +use strict; |
| 7 | + |
| 8 | +use Config qw(%Config); |
| 9 | +use ExtUtils::MakeMaker; |
| 10 | +use File::Temp qw/tempdir tempfile/; |
| 11 | + |
| 12 | +if ($] < 5.006002) { |
| 13 | + die <<'EOL' |
| 14 | +Perl 5.006002 required. Please install version-0.9906 if you need |
| 15 | +to support an earlier Perl release. |
| 16 | +EOL |
| 17 | +} |
| 18 | + |
| 19 | +use vars qw ($no_xs $force_xs); |
| 20 | +unlink 'pm_to_blib'; # belts and braces |
| 21 | + |
| 22 | +if ($ENV{PERL_ONLY}) { |
| 23 | + $no_xs = 1; |
| 24 | +} |
| 25 | + |
| 26 | +for (@ARGV) |
| 27 | +{ |
| 28 | + /^--perl_only/ and $no_xs = 1; |
| 29 | + /^--perl-only/ and $no_xs = 1; |
| 30 | + /^--xs/ and $force_xs = 1; |
| 31 | +} |
| 32 | + |
| 33 | +if ($] < 5.010) { # support pure Perl only |
| 34 | + $no_xs = 1; |
| 35 | +} |
| 36 | + |
| 37 | +unless (defined $no_xs or $force_xs) |
| 38 | +{ |
| 39 | + check_for_compiler() |
| 40 | + or no_cc(); |
| 41 | + |
| 42 | +} |
| 43 | + |
| 44 | +write_makefile(); |
| 45 | + |
| 46 | +sub write_makefile |
| 47 | +{ |
| 48 | + my %prereq = ( |
| 49 | + 'ExtUtils::MakeMaker' => 6.17, |
| 50 | + 'Test::More' => 0.45, |
| 51 | + 'File::Temp' => 0.13, |
| 52 | + 'parent' => 0.221, |
| 53 | + ); |
| 54 | + |
| 55 | + WriteMakefile( VERSION => '0.9916', |
| 56 | + NAME => 'version', |
| 57 | + LICENSE => 'perl', |
| 58 | + MIN_PERL_VERSION=> 5.006002, |
| 59 | + PREREQ_PM => \%prereq, |
| 60 | + NORECURS => $no_xs, |
| 61 | + ABSTRACT => 'Structured version objects', |
| 62 | + AUTHOR => 'John Peacock <[email protected]>', |
| 63 | + ( $] >= 5.009001 && $] < 5.011000 ? |
| 64 | + ( INSTALLDIRS => 'perl' ) : |
| 65 | + () |
| 66 | + ), |
| 67 | + ( ($] < 5.012 |
| 68 | + && ! $ENV{PERL_NO_HIGHLANDER} |
| 69 | + && ! ( $ENV{PERL_MM_OPT} |
| 70 | + && $ENV{PERL_MM_OPT} =~ /(?:INSTALL_BASE|PREFIX)/ ) |
| 71 | + && ! grep { /INSTALL_BASE/ || /PREFIX/ } @ARGV ) ? |
| 72 | + ( UNINST => 1 ) : |
| 73 | + () |
| 74 | + ), |
| 75 | + PM => |
| 76 | + {'lib/version.pm' => '$(INST_LIBDIR)/version.pm', |
| 77 | + 'lib/version.pod' => '$(INST_LIBDIR)/version.pod', |
| 78 | + 'lib/version/regex.pm' => |
| 79 | + '$(INST_LIBDIR)/version/regex.pm', |
| 80 | + 'lib/version/Internals.pod' => |
| 81 | + '$(INST_LIBDIR)/version/Internals.pod', |
| 82 | + 'vperl/vpp.pm' => '$(INST_LIBDIR)/version/vpp.pm', |
| 83 | + }, |
| 84 | + PL_FILES => {}, |
| 85 | + C => [], |
| 86 | + ( $no_xs ? |
| 87 | + () : |
| 88 | + ( DIR => ['vutil']) |
| 89 | + ), |
| 90 | + dist => { |
| 91 | + COMPRESS => 'gzip -9f', |
| 92 | + SUFFIX => 'gz', |
| 93 | + PREOP => ( |
| 94 | + 'hg log --style changelog > Changes' |
| 95 | + ), |
| 96 | + }, |
| 97 | + META_MERGE => { |
| 98 | + "meta-spec" => { version => 2 }, |
| 99 | + resources => { |
| 100 | + repository => { |
| 101 | + type => 'hg', |
| 102 | + url => 'https://bitbucket.org/jpeacock/version' |
| 103 | + }, |
| 104 | + bugtracker => { |
| 105 | + web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=version', |
| 106 | + |
| 107 | + }, |
| 108 | + }, |
| 109 | + no_index => { |
| 110 | + package => ['charstar'], |
| 111 | + }, |
| 112 | + }, |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +sub no_cc |
| 117 | +{ |
| 118 | + $no_xs = 1; |
| 119 | + print <<'EOF'; |
| 120 | +
|
| 121 | + I cannot determine if you have a C compiler |
| 122 | + so I will install a perl-only implementation |
| 123 | +
|
| 124 | + You can force installation of the XS version with |
| 125 | +
|
| 126 | + perl Makefile.PL --xs |
| 127 | +
|
| 128 | +EOF |
| 129 | + |
| 130 | +} |
| 131 | + |
| 132 | +sub check_for_compiler |
| 133 | +{ |
| 134 | + # IMPORTANT NOTE: This is NOT used to determine how to compile |
| 135 | + # extensions properly; EU::MM does that for us. This is only |
| 136 | + # intended to see if that is likely to succeed. We do not try |
| 137 | + # to do anything here except compile (not even link). If you |
| 138 | + # want this to be a full featured test, feel free to submit a |
| 139 | + # patch or do something useful. |
| 140 | + |
| 141 | + print "Testing if you have a C compiler\n"; |
| 142 | + |
| 143 | + eval { require ExtUtils::CBuilder }; |
| 144 | + if ($@) |
| 145 | + { |
| 146 | + return _check_for_compiler_manually(); |
| 147 | + } |
| 148 | + else |
| 149 | + { |
| 150 | + return _check_for_compiler_with_cbuilder(); |
| 151 | + } |
| 152 | +} |
| 153 | + |
| 154 | +sub _check_for_compiler_with_cbuilder |
| 155 | +{ |
| 156 | + my $cb = ExtUtils::CBuilder->new( quiet => 1 ); |
| 157 | + |
| 158 | + return $cb->have_compiler; |
| 159 | +} |
| 160 | + |
| 161 | +sub _check_for_compiler_manually |
| 162 | +{ |
| 163 | + unless ( open F, ">test.c" ) |
| 164 | + { |
| 165 | + warn "Cannot write test.c, skipping test compilation and installing pure Perl version.\n"; |
| 166 | + return 0; |
| 167 | + } |
| 168 | + |
| 169 | + print F <<'EOF'; |
| 170 | +int main() { return 0; } |
| 171 | +EOF |
| 172 | + |
| 173 | + close F or return 0; |
| 174 | + |
| 175 | + my ($cc, $ccflags, $obj_ext) = map { $Config{$_} } qw/cc ccflags obj_ext/; |
| 176 | + |
| 177 | + my $command; |
| 178 | + if ($^O =~ /(dos|win32)/i && $Config{'cc'} =~ /^cl/) { |
| 179 | + $command = "$cc $ccflags /c test.c"; |
| 180 | + } |
| 181 | + elsif ($Config{gccversion}) { |
| 182 | + $command = "$cc $ccflags -o test$obj_ext test.c"; |
| 183 | + } |
| 184 | + else { |
| 185 | + warn "Unsupported system: can't test compiler availability. Patches welcome..."; |
| 186 | + return 0; |
| 187 | + } |
| 188 | + |
| 189 | + my $retval = system( $command ); |
| 190 | + map { unlink $_ if -f $_ } ('test.c',"test$obj_ext"); |
| 191 | + |
| 192 | + return not($retval); # system returns -1 |
| 193 | +} |
0 commit comments