-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalienfile
182 lines (167 loc) · 4.7 KB
/
alienfile
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
use alienfile;
use Config;
use File::Which qw( which );
use Path::Tiny qw( path );
use Capture::Tiny qw( capture );
use File::Spec;
# NOTE: you can set ALIEN_CMAKE_FROM_SOURCE to force a build from source
# even on platforms which have binary versions of cmake available. Normally
# you should only need this for testing the build from source capability of
# this alienfile.
configure {
requires 'Alien::Build' => '0.92';
requires 'File::Which';
requires 'Path::Tiny';
requires 'Capture::Tiny';
};
probe sub {
my($build) = @_;
my $old_cmake = $build->install_prop->{my_old_cmake} = which 'cmake';
if($old_cmake)
{
$build->log("found existing cmake: $old_cmake");
my $old_cmake_version = $build->install_prop->{my_old_cmake_version} = do {
my($out, undef, $old_cmake) = capture { system $old_cmake, '--version' };
$out =~ /cmake version ([0-9\.]+)/
? $1
: undef;
};
if($old_cmake_version)
{
my($major) = $old_cmake_version =~ /^([0-9])\./;
if($major >= 3)
{
$build->install_prop->{my_old_cmake_use} = 1;
$build->log("GOOD found cmake version $old_cmake_version");
return 'system' unless $ENV{ALIEN_CMAKE_FROM_SOURCE};
}
else
{
$build->log("TOO OLD found cmake version $old_cmake_version");
}
}
else
{
$build->log("BAD unable to determine cmake version");
}
}
else
{
$build->log("no existing cmake found");
}
'share';
};
my $binary_release_name;
my $binary_format;
# use binary release on Linux, Windws 32/64 bit
# do not use binary release on OS X as it comes as a .app bundle
# TODO: add aarch64 detection
if($^O eq 'linux' && $Config{archname} =~ /^x86_64/)
{
$binary_release_name = 'linux-x86_64';
$binary_format = 'tar.gz';
}
elsif($^O eq 'linux' && $Config{archname} =~ /^aarch64/)
{
$binary_release_name = 'linux-aarch64';
$binary_format = 'tar.gz';
}
elsif($^O eq 'MSWin32' && $Config{ptrsize} == 4)
{
$binary_release_name = 'windows-i386';
$binary_format = 'zip';
}
elsif($^O eq 'MSWin32' && $Config{ptrsize} == 8)
{
$binary_release_name = 'windows-x86_64';
$binary_format = 'zip';
}
elsif($^O eq 'darwin' && $Config{ptrsize} == 8)
{
my($major, $minor, $patch) = map {
my $v = $_;
$v =~ s/^\s+//;
$v =~ s/\s+$//;
$v;
} split /\./, [split /:/, `sw_vers|grep ProductVersion`]->[1];
if($major >= 11 || ($major == 10 && $minor >= 13))
{
$binary_release_name = 'macos-universal';
}
else
{
$binary_release_name = 'macos10.10-universal';
}
$binary_format = 'tar.gz';
}
share {
# For platforms where there is a binary release, use that:
if($binary_release_name && !$ENV{ALIEN_CMAKE_FROM_SOURCE})
{
start_url 'https://cmake.org/download/';
plugin Download => (
filter => qr/^cmake-[0-9\.]+-\Q$binary_release_name\E\.\Q$binary_format\E$/,
version => qr/([0-9\.]+)/,
($^O eq 'MSWin32' ? (bootstrap_ssl => 1) : ()),
);
plugin Extract => $binary_format;
if($^O eq 'MSWin32')
{
build sub {
my($build) = @_;
# This is a rare case where we actually want the borked windows
# type paths with backslashes
my $stage = File::Spec->catdir($build->install_prop->{stage});
path($stage)->mkpath unless -d $stage;
$build->system("xcopy . $stage /E");
};
}
elsif($^O eq 'darwin')
{
build [
'cp -a CMake.app/Contents/* %{.install.stage}',
sub { shift->runtime_prop->{style} = 'binary' },
];
}
else
{
build [
'cp -ar * %{.install.stage}',
sub { shift->runtime_prop->{style} = 'binary' },
];
}
}
# For platforms without a (recent) binary release, build it from source
else
{
start_url 'https://cmake.org/download/';
plugin Download => (
filter => qr/^cmake-[0-9\.]+\.tar.gz$/,
version => qr/([0-9\.]+)/,
);
plugin Extract => 'tar.gz';
# CONSIDER: in the case where there is an older version of cmake
# found in the probe step above (stored in my_old_cmake), using
# the older version of cmake to build cmake instead of using the
# autoconf compat script.
plugin 'Build::Autoconf' => ( with_pic => 0 );
build [
'%{configure}',
'%{make}',
'%{make} install',
sub { shift->runtime_prop->{style} = 'source' },
];
}
gather sub {
my($build) = @_;
$build->runtime_prop->{command} = 'cmake';
};
};
sys {
gather sub {
my($build) = @_;
$build->runtime_prop->{version} = $build->install_prop->{my_old_cmake_version};
$build->runtime_prop->{command} = $build->install_prop->{my_old_cmake};
$build->runtime_prop->{style} = "system";
};
};