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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
use ExtUtils::MakeMaker qw(
WriteMakefile
prompt
);
use Config;
use Cwd;
use Getopt::Long qw(
GetOptions
);
my $pwd = getcwd();
unlink 'Makefile'; # remove Makefile to stabilize CC test
#
# get any command line arguments
#
my($useXS);
GetOptions(
'xs!' => \$useXS,
'pm' => sub {
warn "\n\t".'WARNING: Use of "--pm" is deprecated, use "-noxs" instead'."\n\n";
$useXS = 0;
},
);
if ($^O eq 'MSWin32') {
$useXS = 0; # force NOXS mode for windows
}
my $pkg = 'NetAddr::IP::Util';
$pkg =~ /[^:]+$/;
my $module = $& .'.pm';
my $cfile = $& .'.c';
my %makeparms = (
NAME => $pkg,
VERSION_FROM => $module, # finds $VERSION
depend => {$cfile => q[xs_include/miniSocket.inc localconf.h config.h localperl.h],
},
# PREREQ_PM => {Test::More => 0,
# },
LIBS => [],
XS => {},
C => [],
clean => { FILES => "*.bs *.o *.c *~ tmp* Util_IS.pm localperl.h auto*"},
realclean => { FILES => "config.h config.log config.status"},
dist => {COMPRESS=>'gzip', SUFFIX=>'gz'}
);
#
# Check if we have a C compiler
unless (defined $useXS) {
if (test_cc()) {
print "You have a working compiler.\n";
$useXS = 1;
# $makeparms{'MYEXTLIB'} = 'netdns$(LIB_EXT)',
} else {
$useXS = 0;
print <<END;
I cannot determine if you have a C compiler. I will install the
perl-only implementation.
You can force installation of the XS version with:
perl Makefile.PL --xs
END
# $makeparms{'MYEXTLIB'} = '',
}
}
my $begin = '';
if ($useXS) {
# turn the XS bits on.
delete $makeparms{'XS'};
delete $makeparms{'C'};
unless (-e './config.h') {
system $Config{sh}, 'configure';
}
my @LIBS;
open(F,'config.h') or die "could not open config.h\n";
foreach(<F>) {
if ($_ =~ /^#define LIBS([ a-zA-Z-]+)/) {
@LIBS = ($1 =~ /[a-zA-Z0-9-]+/g);
$makeparms{LIBS} = [$1];
last;
}
}
close F;
my $link = '';
foreach(@libs) {
if ($Config{libs} =~ /$_\b/) {
$link .= $_ .' ';
}
}
chop $link;
$makeparms{LIBS} = [$link];
open(F,'>localperl.h') or die "could not open localperl.h for write\n";
print F q|
/* Written by Makefile.PL
*
* Do not modify this file, modify Makefile.PL instead
*
*/
|;
close F;
$begin = q|
config :: config.h
@$(NOOP)
config.h :
$(SHELL) configure
|;
}
open(F,'>Util_IS.pm');
print F q|#!/usr/bin/perl
#
# DO NOT ALTER THIS FILE
# IT IS WRITTEN BY Makefile.PL
# EDIT THAT INSTEAD
#
package NetAddr::IP::Util_IS;
use vars qw($VERSION);
$VERSION = 1.00;
sub pure {
return |, (($useXS) ? 0 : 1), q|;
}
sub not_pure {
return |, (($useXS) ? 1 : 0), q|;
}
1;
__END__
=head1 NAME
NetAddr::IP::Util_IS - Tell about Pure Perl
=head1 SYNOPSIS
use NetAddr::IP::Util_IS;
$rv = NetAddr::IP::Util_IS->pure;
$rv = NetAddr::IP::Util_IS->not_pure;
=head1 DESCRIPTION
Util_IS indicates whether or not B<NetAddr::IP::Util> was compiled in Pure
Perl mode.
=over 4
=item * $rv = NetAddr::IP::Util_IS->pure;
Returns true if PurePerl mode, else false.
=item * $rv = NetAddr::IP::Util_IS->not_pure;
Returns true if NOT PurePerl mode, else false
=back
=cut
1;
|;
sub test_cc {
#
# The perl/C check borrowed and modified from
# Graham Barr's Scalar-List-Utils distribution.
#
print "Testing if you have a C compiler and the needed header files....\n";
unless (open(F, ">compile.c")) {
warn "Cannot write compile.c, skipping test compilation and installing pure Perl version.\n";
return;
}
my $CC = $ENV{CC} || $Config{ccname};
my $command = qq|$CC compile.c -o compile.output|;
print F <<'EOF';
int main() { return 0; }
EOF
close(F) or return;
print STDERR $command,"\n";
my $rv = system($command);
foreach my $file (glob('compile*')) {
unlink($file) || warn "Could not delete $file: $!\n";
}
return ($rv == 0);
}
sub MY::top_targets {
package MY;
my $inherited = shift->SUPER::top_targets(@_);
$inherited =~ s/(pure_all\s+::.+)/$1 README/;
$begin . $inherited;
}
sub MY::post_constants {
my $post_constants = q|
MY_POD2TEXT = |. $Config{scriptdirexp} .'/pod2text' .q|
|;
}
sub MY::postamble {
package MY;
my $postamble = q|
README : |. $module .q|
@$(MY_POD2TEXT) |. $module .q| > README
|;
}
WriteMakefile(%makeparms);
|