File: Makefile.PL

package info (click to toggle)
libuuid-perl 0.28-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 128 kB
  • sloc: perl: 17; makefile: 5
file content (330 lines) | stat: -rw-r--r-- 9,572 bytes parent folder | download
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
use strict;
use warnings;
use Devel::CheckLib;
use ExtUtils::MakeMaker;

BEGIN {
    local $/;
    open my $fh, '<', 'UUID.pm' or die $!;
    my $content = <$fh>;
    $main::DEV_VERSION = $content =~ /VERSION\s+=\s+\S+_/;

    $main::USE_DEBUG = 0;
    @ARGV = map {
        ( /^UUID_DEBUG=(.+)/ and (($main::USE_DEBUG=$1) or 1) ) ? () : $_
    } @ARGV;
}

use constant DEBUG => $ENV{UUID_DEBUG}
    || ( $main::USE_DEBUG ? 1 : 0 )
    || ( $ENV{AUTOMATED_TESTING} && $main::DEV_VERSION )
    || 0
;


# buffering will ruin your day!
select STDERR; $|=1;
select STDOUT; $|=1;


# ARRRRR!.. there are _at_least_ 4 different UUID interfaces:
# Free/NetBSD/MacOSX, Windows, e2fsprogs, and OSSP.
# ... this is gonna suck!
warn "#\n" if DEBUG;


my @hfiles;
# Look for uuid/uuid.h first. uuid.h is known to contain the slower OSSP
# interface on CentOS7.
for my $try (qw{ uuid/uuid.h uuid.h rpc.h }) {
    warn "# ===> Checking for #include <${try}>\n" if DEBUG;
    eval { assert_lib(
        #lib      => $link_lib,  <-- dont link yet
        header   => $try,
        debug    => DEBUG,
    )};
    unless ( $@ ) {
        push @hfiles, $try;
        warn "# ===> Found!\n" if DEBUG;
    }
    warn "#\n" if DEBUG;
}

bail('No headers found.') unless @hfiles;


my $header;
my $defs = [];
my $libs = [];

HEADER: while ( $header = shift @hfiles ) {
    # Look for uuid interface before ossp-uuid.
    # Our implementation with ossp is slower.
    for my $try_lib (qw{ rpcrt4 uuid ossp-uuid c }) {
        try_rpc(  $header, $try_lib ) and last HEADER;
        try_e2fs( $header, $try_lib ) and last HEADER;
        try_ossp( $header, $try_lib ) and last HEADER;
        try_win(  $header, $try_lib ) and last HEADER;
    }
}

bail('No interface found.') unless $header;


sub try_rpc {
    my ( $hdr, $tlib ) = @_;
    warn "# ===> Checking for RPC interface in $hdr with -l$tlib\n" if DEBUG;
    eval { assert_lib(
        lib      => $tlib,
        header   => $hdr,
        debug    => DEBUG,
        libpath  => '/lib64 /usr/lib64',
        function => qq/
            char *str,buff[37];
            uuid_t u1,u2;
            int32_t r,s;
            str=buff;
            uuid_create(&u1,&s);
            uuid_create_nil(&u2,&s);
            uuid_from_string(str,&u1,&s);
            uuid_to_string(&u1,&str,&s);
            r = uuid_compare(&u1,&u2,&s);
            r = uuid_equal(&u1,&u2,&s);
            r = uuid_is_nil(&u1,&s);
            return 0;
        /,
    )};
    if ($@) { my $L = length $@; warn "# ===> Err($L): \"$@\"\n" if DEBUG; return 0 }
    push @$defs, '-DPERL__UUID__RPC_INT';
    push @$libs, "-l$tlib";
    warn "# ===> Found!\n" if DEBUG;
    warn "#\n" if DEBUG;
    return 1;
}

sub try_e2fs {
    my ( $hdr, $tlib ) = @_;
    warn "# ===> Checking for e2fs interface in $hdr with -l$tlib\n" if DEBUG;
    eval { assert_lib(
        lib      => $tlib,
        header   => $hdr,
        debug    => DEBUG,
        libpath  => '/lib64 /usr/lib64',
        function => qq/
            int i;
            char s[37];
            uuid_t u,uu;
            uuid_generate(u);
            uuid_generate_random(u);
            uuid_generate_time(u);
            uuid_unparse(u,s);
            uuid_parse(s,u);
            uuid_clear(u);
            uuid_copy(uu,u);
            i = uuid_compare(u,uu);
            i = uuid_is_null(u);
            return 0;
        /,
    )};
    if ($@) { my $L = length $@; warn "# ===> Err($L): \"$@\"\n" if DEBUG; return 0 }
    push @$defs, '-DPERL__UUID__E2FS_INT';
    push @$libs, "-l$tlib";
    warn "# ===> Found!\n" if DEBUG;
    warn "#\n" if DEBUG;
    return 1;
}

sub try_ossp {
    my ( $hdr, $tlib ) = @_;
    warn "# ===> Checking for ossp interface in $hdr with -l$tlib\n" if DEBUG;
    eval { assert_lib(
        lib      => $tlib,
        header   => $hdr,
        debug    => DEBUG,
        libpath  => '/lib64 /usr/lib64',
        function => qq{
            int i;
            size_t len;
            uuid_rc_t rc;
            char s[37];
            uuid_t *u,*uu;
            uuid_create(&u);
            uuid_create(&uu);
            rc = uuid_make(u,UUID_MAKE_V1|UUID_MAKE_MC); /* uuid_generate */
            rc = uuid_make(u,UUID_MAKE_V1); /* uuid_generate_time */
            rc = uuid_make(u,UUID_MAKE_V4); /* for uuid_generate_random */
            len = 36;
            uuid_export(u,UUID_FMT_STR,s,&len);
            uuid_import(u,UUID_FMT_STR,s,36);
            rc = uuid_load(u,"nil");
            rc = uuid_clone(uu,&u);
            rc = uuid_compare(u,uu,&i);
            rc = uuid_isnil(u,&i);
            uuid_destroy(u);
            uuid_destroy(uu);
            return 0;
        },
    )};
    if ($@) { my $L = length $@; warn "# ===> Err($L): \"$@\"\n" if DEBUG; return 0 }
    push @$defs, '-DPERL__UUID__OSSP_INT';
    push @$libs, "-l$tlib";
    warn "# ===> Found!\n" if DEBUG;
    warn "#\n" if DEBUG;
    return 1;
}

sub try_win {
    my ( $hdr, $tlib ) = @_;
    warn "# ===> Checking for Win interface in $hdr with -l$tlib\n" if DEBUG;
    eval { assert_lib(
        lib      => $tlib,
        header   => [ $hdr, 'rpcdce.h' ],
        debug    => DEBUG,
        libpath  => '/lib64 /usr/lib64',
        function => qq/
            int i;
            UUID u,uu;
            RPC_CSTR cs;
            RPC_STATUS st;
            unsigned char *s;
            i  = UuidCompare(&u,&uu,&st);
            st = UuidCreate(&u);
            st = UuidCreateNil(&uu);
            st = UuidCreateSequential(&uu);
            i  = UuidEqual(&u,&uu,&st);
            st = UuidFromString(cs,&u);
            i  = UuidIsNil(&u,&st);
            st = UuidToString(&u,&s);
            return 0;
        /,
    )};
    if ($@) { my $L = length $@; warn "# ===> Err($L): \"$@\"\n" if DEBUG; return 0 }
    push @$defs, '-DPERL__UUID__WIN_INT';
    push @$libs, "-l$tlib";
    warn "# ===> Found!\n" if DEBUG;
    warn "#\n" if DEBUG;
    return 1;
}

sub get_struct_size {
    my ( $hdrs, $libs ) = @_;
    my $rv;
    warn "# ===> Checking binary struct size\n" if DEBUG;
    ( my $lib = $libs->[0] ) =~ s/-l//;
    check_lib(
        lib      => $lib,
        header   => $hdrs,
        debug    => DEBUG,
        libpath  => '/lib64 /usr/lib64',
        function => ( $lib =~ /ossp/ )
            ? qq{
                return 16;
            }
            : qq{
                return sizeof(uuid_t);
            },
    );
    $rv = $? >> 8;
    warn "# ===> $rv\n" if DEBUG;
    warn "#\n" if DEBUG;
    return $rv;
}

my $size = get_struct_size( $header, $libs )
    || bail( "Impossible struct size." );
push @$defs, "-DPERL__UUID__STRUCT_SZ=$size";


($header = '-DPERL__UUID__'. uc $header ) =~ y{/.}{__};
push @$defs, $header;


warn "# ===> Writing Makefile\n" if DEBUG;

WriteMakefile1(
    'NAME'               => 'UUID',
    'AUTHOR'             => 'Rick Myers <jrm@cpan.org>',
    'VERSION_FROM'       => 'UUID.pm',
    'ABSTRACT_FROM'      => 'UUID.pm',
    'LICENSE'            => 'artistic_2',
    'MIN_PERL_VERSION'   => '5.005',
    'LIBS'               => $libs,
    'DEFINE'             => join(' ', @$defs), #$header,
    'INC'                => '',
    'PREREQ_PM'          => {},
    'CONFIGURE_REQUIRES' => {
        'Devel::CheckLib' => '1.02',
    },
    'TEST_REQUIRES' => {
        'Test::More' => 0,
    },
    #'META_MERGE'       => {
    #    'resources' => {
    #        #repository => 'URL to repository here',
    #    },
    #},
    #BUILD_REQUIRES => {
    #},
);

sub WriteMakefile1 {  #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
    my %params=@_;
    my $eumm_version=$ExtUtils::MakeMaker::VERSION;
    $eumm_version=eval $eumm_version;
    die "EXTRA_META is deprecated" if exists $params{EXTRA_META};
    die "License not specified" if not exists $params{LICENSE};
    if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) {
        #EUMM 6.5502 has problems with BUILD_REQUIRES
        $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} };
        delete $params{BUILD_REQUIRES};
    }
    delete $params{TEST_REQUIRES} if $eumm_version < 6.64;
    delete $params{CONFIGURE_REQUIRES} if $eumm_version < 6.52;
    delete $params{MIN_PERL_VERSION} if $eumm_version < 6.48;
    delete $params{META_MERGE} if $eumm_version < 6.46;
    delete $params{META_ADD} if $eumm_version < 6.46;
    delete $params{LICENSE} if $eumm_version < 6.31;
    delete $params{AUTHOR} if $] < 5.005;
    delete $params{ABSTRACT_FROM} if $] < 5.005;
    delete $params{BINARY_LOCATION} if $] < 5.005;

    WriteMakefile(%params);
}

sub bail {
    my $msg = shift;
    # need some explanatory text here for missing system libs
    warn join '', "
#######################################################################
#
# Bailing out. Can't continue.
#
#   ** $msg
", ( DEBUG ? '' : "#
# It's likely the UUID prerequisite library isn't installed.
#
# On some platforms you can use your package manager to install these.
# In particular, the uuid-dev, libuuid-devel, or uuid-devel packages
# on Linux.
#
# More information about this failure can be found with the UUID_DEBUG
# flag.
# 
#   perl Makefile.PL UUID_DEBUG=1
" ), "# 
#######################################################################
";
    exit 0;   # used in Devel::CheckLib::check_lib_or_exit()
    exit 255; # same as die() which is suggested in CPAN::Authors FAQ
}

# stay calm. don't blink.
# this is just for me :-)
sub MY::postamble {
    return <<EOP;
readme:
	pod2text UUID.pm README
	perl -i -pe's{\\*(\\S+)\\*}{\\1}g' README
EOP
}