File: Makefile.PL

package info (click to toggle)
libfile-fcntllock-perl 0.22-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 144 kB
  • ctags: 30
  • sloc: perl: 298; ansic: 116; makefile: 2
file content (189 lines) | stat: -rwxr-xr-x 5,715 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# Copyright (C) 2002-2014 Jens Thoms Toerring <jt@toerring.de>


use strict;
use warnings;
use Config;
use ExtUtils::MakeMaker;


# We need a compiler and, of course, a system that has a fcntl(2) system
# call. Check for both. Then set up things to also create the Pure and
# Inline sub-modules if possible.

check_for_compiler( );
check_for_fcntl( );
link 'lib/File/FcntlLock.pod', 'lib/File/FcntlLock/XS.pod';
assemble_inline( ) if assemble_pure( );


# Finally create the Makefile

WriteMakefile(
    NAME          => 'File::FcntlLock',
    VERSION_FROM  => 'lib/File/FcntlLock.pm',
    ABSTRACT_FROM => 'lib/File/FcntlLock.pod',
    LICENSE       => 'perl',
    AUTHOR        => 'Jens Thoms Toerring jt@toerring.de',
    PREREQ_PM     => { POSIX      => 0,
                       Errno      => 0,
                       Carp       => 0,
                       Exporter   => 0,
                       DynaLoader => 0,
                       Config     => 0 },
    test          => { TESTS => 't/*.t' },
	clean         => { FILES => join ' ', qw{ lib/File/FcntlLock/XS.pod
											  lib/File/FcntlLock/Pure.pm
											  lib/File/FcntlLock/Inline.pm
											  lib/File/FcntlLock/Pure.pod
											  lib/File/FcntlLock/Inline.pod } }
			 );


###########################################################
# Function for testing if the C compiler used for buildimg Perl is
# available on the system, otherwise there's no chance of building
# the module

sub check_for_compiler {
	print "Checking if there's a C compiler\n";

    open my $fh, '>', 'cc_test.c'
        or die "Failed to open a file for writing: $!\n";
    print $fh "int main(void)\n{\nreturn 0;\n}\n";
    close $fh;

    if ( system "$Config{cc} $Config{ccflags} -o cc_test cc_test.c" ) {
        unlink 'cc_test.c';
        die "Can't run C compiler '$Config{cc}'\n";
    }
    unlink 'cc_test';
    unlink 'cc_test.c';
}


###########################################################
# Function for testing if the system has a fcntl(2) function,
# without it this module makes no sense at all.

sub check_for_fcntl {
	print "Checking if there's a fcntl(2) system call\n";

    open my $fh, '>', 'fcntl_test.c'
        or die "Failed to open a file for writing: $!\n";
    print $fh <<EOF;
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main( void ) {
    int fd = fileno( fopen( "fcntl_test.c", "r" ) );
    struct flock f;
    f.l_type   = F_RDLCK;
    f.l_whence = SEEK_SET;
    f.l_start  = 0;
    f.l_len    = 0;
    return fcntl( fd, F_SETLK, &f ) != -1 ? EXIT_SUCCESS : EXIT_FAILURE;
}
EOF
    close $fh;

    if ( system "$Config{cc} $Config{ccflags} -o fcntl_test fcntl_test.c" ) {
        unlink 'fcntl_test.c';
        die "OS unsupported\n";
    }
    unlink 'fcntl_test';
    unlink 'fcntl_test.c';
}


###########################################################
# Function for assembling a "pure Perl" version of the module.
# For that we need to determine the layout of the C flock struct
# used by fcntl(2) and create some Perl code that can fill in such
# a structure via pack() and retrieve its values using unpack().
# This code then is combined with the template file 'Pure/Pure.tmpl'
# to make up the required module. (Failure is not a big issue,
# there are two other ways of attempting to use fcntl(2), one via
# an XS based module and one that attempts to obtain the same kind
# of information in its BEGIN block.)
# Note: there seem to be some 32-bit systems, where the flock struct
#       contails 64-bit off_t members, but there's no 'q' format for
#       Perl's pack() and unpack() function. For these systems I do
#       not know of any proper way of setting up the flock structure
#       using pure Perl...

sub assemble_pure {
    use File::Copy;

	my $success = 0;

    return 0 unless chdir 'Pure_build';

	# Compile with the 'NO_Q_FORMAT' macro defined unless Perl supports
	# the 'q' format for pack() and unpack(). If the system uses a 64-bit
	# off_t type in its flock struct this will make the program for con-
    # structing the code for assembling and disassembling the flock struct
	# output nothing and we abandon trying to  build the "pure Perl" modules.

	my $qflag = eval { pack 'q', 1; };
	$qflag = $@ ? '-DNO_Q_FORMAT' : '';

    goto FAIL
        if system "$Config{cc} $Config{ccflags} $qflag -o builder builder.c";
    goto FAIL unless copy 'Pure.tmpl', 'Pure.pm';
    goto FAIL unless open my $out, '>>', 'Pure.pm';
    goto FAIL unless open my $in, "-|", './builder';
	unless ( my $line = <$in> ) {
		close $in;
		close $out;
		goto FAIL;
	} else {
		print $out $line;
	}

    print $out $_ for <$in>;
    close $in;

    print $out "\n\n1;\n";
    close $out;

    goto FAIL unless move 'Pure.pm', '../lib/File/FcntlLock';

	link '../lib/File/FcntlLock.pod', '../lib/File/FcntlLock/Pure.pod';

	$success = 1;

  FAIL:
	print   "Warning: Support for modules `File::FcntlLock::Pure' and "
		  . "`File::FcntlLock::Inline' had to be disabled\n"
		unless $success;
    unlink 'builder';
    chdir '..';

	return $success;
}


###########################################################
# Function for setting up the Inline package - this only happens
# when we can use pure Perl to setup the flock struct (i.e., if
# the assemble_pure() function was successful).

sub assemble_inline {
    use File::Copy;

	return unless copy 'Inline_build/Inline.pm.in',
		               'lib/File/FcntlLock/Inline.pm';
	link 'lib/File/FcntlLock.pod', 'lib/File/FcntlLock/Inline.pod';
}


# Local variables:
# tab-width: 4
# indent-tabs-mode: nil
# End: