File: Makefile.PL

package info (click to toggle)
libbsd-resource-perl 1.2911-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 372 kB
  • sloc: perl: 134; makefile: 5
file content (225 lines) | stat: -rw-r--r-- 4,760 bytes parent folder | download | duplicates (3)
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
#
# Makefile.PL
#
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
#

require 5.002;

use vars qw($PACKAGE $DEFINE $LIBS);

$PACKAGE = 'BSD::Resource';

use Config;
use ExtUtils::MakeMaker;
use File::Basename;

$| = 1;

my $CC;

sub try_compile_and_link {
    my ($c, %opt) = @_;

    my ($ok) = 0;
    my ($tmp) = "tmp$$";
    local(*TMPC);

    my $cccmd;

    unlink("$tmp.c", "$tmp.o");

    if (open(TMPC, ">$tmp.c")) {
	print TMPC $c;
	close(TMPC);
	my @cc;
	if ($CC) {
	    push @cc, $CC;
	} else {
	    if (exists $ENV{CC}) {
		push @cc, $ENV{CC};
		print STDERR "(trying first the CC from your environment)\n";
	    }
	    push @cc, $Config{'cc'};
	}
	while (my $cc = shift @cc) {
	    unless (-x $cc) {
		# They might have a different compiler
		# than what Perl was compiled with (easy
		# if using gcc), or their $cc has more
		# than just the compiler name (say, options)
		my ($b, $s, $r) = ($cc =~ /^(\S+)(\s*)(.*)/);
		$cc = basename($b) . $s . $r;
	    }
	    $cccmd =
		"$cc -c -o $tmp.o -I$Config{'archlibexp'}/CORE $Config{'ccflags'}";
	    $cccmd .= " 2>/dev/null" unless $ENV{VERBOSE};
	    print STDERR "[cccmd = $cccmd]\n" if $ENV{VERBOSE};
	    if (system("$cccmd $tmp.c") == 0) {
		$ok = -s "$tmp.o";
		$CC = $cc;
	    }
	    last if $ok;
	}
	unlink("$tmp.c", "$tmp.o");
    }
    
    return $ok;
}

sub has_resource_h () {
    print "Checking whether you have certain header files...\n";

    if (try_compile_and_link(<<EOM)) {
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <sys/resource.h>
static int foo;
EOM
        print "You do have <sys/resource.h>.  Excellent.\n";
        return 1;
    }
    
    # Solaris 1 weirdo header

    if (try_compile_and_link(<<EOM)) {
#include <sys/rusage.h>
static int foo;
EOM
        print "You have <sys/rusage.h>.  Are you an old Solaris by any chance?\n";
        return 2;
    }

    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>.

(Run "perl Makefile.PL" with the environment variable VERBOSE set to 1 (one)
 too see in more detail what went wrong.)

There is no way $PACKAGE is going to work.

I am awfully sorry but I cannot go further.

Aborting configuration of $PACKAGE.
EOM

    $DEFINE = '';

    # Needed for NCR MP-RAS; should be harmless for others.
    if ($Config{'osname'} eq 'svr4') {
      $DEFINE = ' -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED=1';
    }

    # old Solarises had this oddity.
    $DEFINE .= ' -DI_SYS_RUSAGE' if (-r '/usr/include/sys/rusage.h');

    # ucb is poison for Solaris, and bsd may be on IRIX.
    if ($Config{'osname'} eq 'solaris') {
      $LIBS = [''];
    } elsif (($Config{'osname'} eq 'irix') &&
	     ($Config{'ccflags'} =~ m/-D_BSD_TIME/) &&
	     ($Config{'ccflags'} =~ m/-D_BSD_TYPES/)) {
      $LIBS = [''];
    } elsif ($Config{'osname'} eq 'svr4') {
      $LIBS = ['-lc89'];
    }
}

sub find_Rlim_t {
	my $tmp      = "rlim$$";
	my $not      = 0;

        print "Checking to see whether you have rlim_t...\n";
        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
#ifdef I_SYS_RUSAGE
#include <sys/rusage.h>
#else
#include <sys/resource.h>
#endif
static rlim_t foo = 0;
EOM
        if ($has) {
            $DEFINE .= " -DRlim_t=rlim_t";
        } else {
	    $not = 1;
	}

	print "You seem ";
	print "not " if $not;
	print "to have rlim_t defined (";
	print $not ? "this is okay" : "which is nice";
	print ").\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'.
If some tests fail, please rerun the tests (see INSTALL).

EOM
}

&main;

# EOF