forked from eserte/bbbike
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBBBikeBuildUtil.pm
More file actions
115 lines (101 loc) · 3.33 KB
/
BBBikeBuildUtil.pm
File metadata and controls
115 lines (101 loc) · 3.33 KB
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
# -*- perl -*-
#
# Author: Slaven Rezic
#
# Copyright (C) 2014,2017,2018,2021 Slaven Rezic. All rights reserved.
# This package is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
# Mail: slaven@rezic.de
# WWW: http://www.rezic.de/eserte/
#
package BBBikeBuildUtil;
use strict;
use vars qw($VERSION @EXPORT_OK);
$VERSION = '0.05';
use Exporter 'import';
@EXPORT_OK = qw(get_pmake module_path module_version get_modern_perl);
use File::Glob qw(bsd_glob);
use version ();
use BBBikeUtil qw(is_in_path);
# Get a BSD make
sub get_pmake (;@) {
my %opt = @_;
my $fallback = exists $opt{fallback} ? delete $opt{fallback} : 1;
die "Unhandled args: " . join(" ", %opt) if %opt;
(
$^O =~ m{bsd}i ? "make" # standard BSD make
: $^O eq 'darwin' && is_in_path('bsdmake') ? 'bsdmake' # homebrew bsdmake package
: is_in_path("fmake") ? "fmake" # debian jessie .. buster (package freebsd-buildutils)
: is_in_path("freebsd-make") ? "freebsd-make" # debian wheezy and earlier
: -x '/usr/bin/pmake' ? '/usr/bin/pmake' # debian jessie and later (package bmake)
: !$fallback ? die "No BSD make found on this system --- try to install bsdmake, fmake, pmake, or something similar"
: "pmake" # self-compiled BSD make, maybe. Note that pmake may also be a script that comes with the CPAN module Make.pm, which is not a BSD make
);
}
# REPO BEGIN
# REPO NAME module_path /home/eserte/src/srezic-repository
# REPO MD5 ac5f3ce48a524d09d92085d12ae26e8c
sub module_path {
my($filename) = @_;
$filename =~ s{::}{/}g;
$filename .= ".pm";
foreach my $prefix (@INC) {
my $realfilename = "$prefix/$filename";
if (-r $realfilename) {
return $realfilename;
}
}
return undef;
}
# REPO END
# Return module version without loading the module
# (may fail in some situations)
sub module_version {
my($module) = @_;
require ExtUtils::MakeMaker;
MM->parse_version(module_path($module));
}
sub get_modern_perl (;@) {
my %opt = @_;
my %required_modules;
if (exists $opt{required_modules}) {
%required_modules = %{ delete $opt{required_modules} };
}
die "Unhandled args: " . join(" ", %opt) if %opt;
# Convention: perls are available as /opt/perl-5.X.Y/bin/perl
# Do not use bleadperl or RCs.
# The required modules check is quite rudimentary and
# tries to avoid actually running code or loading modules.
my @perldir_candidates =
map { $_->[1] }
sort { $b->[0] cmp $a->[0] }
map { [ do {
if (m{/perl-(5\.\d+\.\d+)$}) {
version->new($1);
} else {
0;
}
}, $_] }
grep { m{/perl-5\.(\d+)\.\d+$} && $1 % 2 == 0 }
bsd_glob("/opt/perl-5.*.*");
PERL_CANDIDATE:
for my $perldir_candidate (@perldir_candidates) {
my $perlpath = "$perldir_candidate/bin/perl";
if (-x $perlpath) {
for my $required_module (keys %required_modules) {
local @INC = grep { -d } (
bsd_glob("$perldir_candidate/lib/site_perl/*/*$^O*"),
bsd_glob("$perldir_candidate/lib/site_perl/*"),
); # only check for site_perl here
if (!module_path($required_module)) {
next PERL_CANDIDATE;
}
}
return $perlpath;
}
}
return $^X;
}
1;
__END__