-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalienfile
174 lines (146 loc) · 4.54 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
use alienfile;
use Config;
use Text::ParseWords qw( shellwords );
# this alienfile requires Alien::Build 0.26 for features and bugfixes
configure { requires 'Alien::Build' => '2.10' };
plugin 'Probe::Vcpkg' => 'libffi';
plugin 'PkgConfig' => 'libffi';
share {
plugin 'Download::GitHub' => (
github_user => 'libffi',
github_repo => 'libffi',
asset => 1,
);
plugin 'Build::Autoconf' => ();
my $configure = '--disable-shared --enable-static --disable-builddir';
if($^O eq 'MSWin32')
{
my $bits = $Config{archname} =~ /^MSWin32-x64/ ? 64 : 32;
$configure .= ' --build=x86_64-pc-mingw64' if $bits == 64;
if(meta->prop->{platform}->{compiler_type} eq 'microsoft')
{
# Visual C++ is "special"
$configure .= ' LD=link CPP="cl -nologo -EP"';
if($bits == 64)
{ $configure .= ' CC="%{cwd}/msvcc.sh -m64"' }
else
{ $configure .= ' CC=%{cwd}/msvcc.sh' }
# 3.2.x broke Visual C++ for some reason.
# hopefully 3.3.x or 4.x will fix it.
# otherwise this will start failing again
meta->around_hook( prefer => sub {
my $orig = shift;
my $ret = $orig->(@_);
$ret->{list} = [
grep { $_->{version} ne '3.3' }
grep { $_->{version} ne '3.2' }
grep { $_->{version} !~ /^3\.2\./ }
@{ $ret->{list} }
];
$ret;
});
requires 'Path::Tiny' => '0.077';
patch sub {
my($build) = @_;
my $libffi_pc = Path::Tiny->new('libffi.pc.in');
if(-f $libffi_pc)
{
# I think the actual error is somewhere other
# than the .pc file, but this works around it
# at least in the way that we use it.
$build->log('edit libffi.pc.in');
$libffi_pc->copy('libffi.pc.in.orig');
$libffi_pc->edit_lines(sub {
s/^toolexeclibdir=.*$/toolexeclibdir=\${libdir\}/;
});
}
};
meta->after_hook( gather_share => sub {
my($build) = @_;
$build->runtime_prop->{$_} .= " -DFFI_BUILDING" for qw( cflags cflags_static );
$build->runtime_prop->{$_} =~ s{-L}{-LIBPATH:}g for qw( libs libs_static );
$build->runtime_prop->{$_} =~ s{-l([A-Za-z]+)}{$1.LIB}g for qw( libs libs_static );
});
}
}
if($^O eq 'darwin')
{
my @ldflags = shellwords $Config{ldflags};
my @arch;
while(@ldflags)
{
my $arg = shift @ldflags;
next unless $arg eq "-arch";
push @arch, $arg, shift @ldflags;
}
if(@arch)
{
$configure .= " LDFLAGS='@arch'";
$configure .= " CFLAGS='@arch'";
}
}
if($^O eq 'openbsd')
{
unless($Config{usethreads})
{
meta->after_hook( gather_share => sub {
my($build) = @_;
$build->runtime_prop->{$_} .= " /usr/lib/libpthread.a" for qw( libs libs_static );
});
}
}
if($Config{archname} =~ /^aarch64-linux/)
{
# libffi 3.4.3 broke Linux Arm64
# https://github.com/PerlFFI/FFI-Platypus/issues/374
# For now not black listing it for other Arm64
# systems (like macOS) because I did not see the
# errors there.
meta->around_hook( prefer => sub {
my $orig = shift;
my $ret = $orig->(@_);
$ret->{list} = [
grep { $_->{version} ne '3.4.3' }
@{ $ret->{list} }
];
$ret;
});
}
if($Config{archname} =~ /^i[3456]86/)
{
my %flags;
# TODO: This probe will not work on systems without /proc
if(-f '/proc/cpuinfo')
{
my $fh;
open($fh, '<', '/proc/cpuinfo');
my($flags) = map { my $x = $_; $x =~ s/^.*:\s+//; $x } grep /^flags/, <$fh>;
close $fh;
chomp $flags;
%flags = map { $_ => 1 } split /\s+/, $flags;
}
if($flags{avx} && $flags{aes})
{
log "You seem to have avx and aes flags, allowing libffi to detect the CPU";
log "see https://github.com/PerlFFI/Alien-FFI/issues/6"
}
else
{
# disable avx and aes instructions as the detection logic for libffi seems
# to be broken. See https://github.com/PerlFFI/Alien-FFI/issues/6
log "Could not detect avx and aes flags. The detection logic is pretty dumb, and may be wrong.";
log "Please let us know if we got it wrong, and how we can improve it.";
log "see https://github.com/PerlFFI/Alien-FFI/issues/6";
$configure .= " --with-gcc-arch=pentium4";
}
}
build [
sub {
my($build) = @_;
$build->runtime_prop->{my_configure} = "%{configure} $configure";
},
"%{configure} $configure",
'%{make}',
'%{make} install',
];
};