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
|
#
# Makefile.PL
#
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
#
require 5.002;
$PACKAGE = 'BSD::Resource';
use Config;
use ExtUtils::MakeMaker;
use File::Basename;
sub try_compile_and_link {
my ($c, %opt) = @_;
my ($ok) = 0;
my ($tmp) = "tmp$$";
local(*TMPC);
unlink("$tmp.c", "$tmp.o");
if (open(TMPC, ">$tmp.c")) {
print TMPC $c;
close(TMPC);
my $cc = exists $ENV{CC} ? $ENV{CC} : $Config{'cc'};
$cc = basename($cc) unless -x $cc;
my $cccmd = "$cc -c -o $tmp.o $Config{'ccflags'} $tmp.c 2>/dev/null";
if (system($cccmd) == 0) {
$ok = -s "$tmp.o";
}
unlink("$tmp.c", "$tmp.o");
}
$ok;
}
# This is unused for now.
sub try_cpp_and_grep {
my ($c, %opt) = @_;
my @g;
my ($tmp) = "tmp$$";
local(*TMPC);
unlink("$tmp.c", "$tmp.o");
if (open(TMPC, ">$tmp.c")) {
print TMPC $c;
close(TMPC);
my $cc = $Config{'cc'};
$cc = basename($cc) unless -x $cc;
my $cccmd = "$cc -E $Config{'ccflags'} $tmp.c 2>/dev/null";
local(*TMPE);
if (open(TMPE, "$cccmd|")) {
while (<TMPE>) {
push @g, /$opt{re}/g;
}
close(TMPE);
}
unlink("$tmp.c");
}
@g;
}
sub has_resource_h () {
return 1 if
try_compile_and_link(<<EOM);
#include <sys/resource.h>
static int foo;
EOM
return 2 if
try_compile_and_link(<<EOM);
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
static int foo;
EOM
# Solaris 1 weirdo header
return 3 if
try_compile_and_link(<<EOM);
#include <sys/rusage.h>
static int foo;
EOM
return 0;
}
sub init {
die <<EOM unless has_resource_h();
Your operating system does not seem to have <sys/resource.h> or <sys/rusage.h>.
There is no way $PACKAGE is going to work.
I am awfully sorry but I cannot go further.
Aborting configuration of $PACKAGE.
EOM
$DEFINE = '';
# old Solarises had this oddity.
$DEFINE .= ' -DI_SYS_RUSAGE' if (-r '/usr/include/sys/rusage.h');
# ucb is poison for Solaris.
$LIBS = $Config{'osname'} eq 'solaris' ? [''] : ['-lucb -lbsd'];
}
sub find_Rlim_t {
my ($tmp) = "rlim$$";
my ($worrynot) = 0;
print "You seem ";
my $has = try_compile_and_link(<<EOM);
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef I_SYS_TYPES
#include <sys/types.h>
#endif
#include <sys/resource.h>
static rlim_t foo = 0;
EOM
if ($has) {
$DEFINE .= ' -DRlim_t=rlim_t';
} else {
print "not ";
$worrynot = 1;
}
print "to have rlim_t defined (";
print $worrynot ? "this is okay" : "which is nice";
print ").\n\n";
}
sub configure {
find_Rlim_t;
if ($^O eq 'solaris' &&
$Config{ccflags} =~ /-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64/ &&
$Config{use64bitall} ne 'define') {
if (open(PROCFS, "/usr/include/sys/procfs.h")) {
my $noprocfs;
while (<PROCFS>) {
if (/^#error.*Cannot use.*procfs.*large file.*/) {
$noprocfs = 1;
last;
}
}
close(PROCFS);
if ($noprocfs) {
$DEFINE .= ' -DSOLARIS_NO_PROCFS';
}
}
}
}
sub doMakefile {
print <<EOM if ($$LIBS[0] ne '');
Looking for libraries...
Note: it is ok if none of the libraries '@$LIBS' is found.
EOM
WriteMakefile(
'NAME' => $PACKAGE,
'VERSION_FROM' => 'Resource.pm',
'LIBS' => $LIBS,
'DEFINE' => $DEFINE,
# do not even think about 'INC' => '-I/usr/ucbinclude', Solaris will avenge.
'dist' => { 'COMPRESS' => 'gzip' },
);
}
sub main {
print <<EOM;
Configuring $PACKAGE...
EOM
init;
configure;
doMakefile;
print <<EOM;
Done configuring $PACKAGE.
Now you may issue 'make'. Do not forget also 'make test'.
EOM
}
&main;
# EOF
|