| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use feature qw( say ); |
| 4 |
use Path::Tiny qw( path ); |
| 5 |
use Git::Wrapper; |
| 6 |
use File::chdir; |
| 7 |
use JSON::PP (); |
| 8 |
|
| 9 |
# Only intended for use by the Platypus maintainer! |
| 10 |
# Sometimes detecting the ABIs from the C compiler pre-processor is unreliable |
| 11 |
# so we can look in the libffi source for all possible ABIs for all possible |
| 12 |
# platforms and just try them all. This computes the list from the latest |
| 13 |
# source (or libffi directory as specified by LIBFFI_ROOT). This list will |
| 14 |
# used by the config step to detect ABIs available on your platform. |
| 15 |
|
| 16 |
my $libffi_root; |
| 17 |
|
| 18 |
if(defined $ENV{LIBFFI_ROOT}) |
| 19 |
{ |
| 20 |
die "no such directory: $ENV{LIBFFI_ROOT}" unless -d $ENV{LIBFFI_ROOT}; |
| 21 |
$libffi_root = path($ENV{LIBFFI_ROOT}); |
| 22 |
} |
| 23 |
else |
| 24 |
{ |
| 25 |
require Git::Wrapper; |
| 26 |
$libffi_root = Path::Tiny->tempdir; |
| 27 |
my $git = Git::Wrapper->new($libffi_root); |
| 28 |
$git->clone('--depth=2', 'https://github.com/libffi/libffi.git', $libffi_root); |
| 29 |
} |
| 30 |
|
| 31 |
say $libffi_root; |
| 32 |
|
| 33 |
my %abis; |
| 34 |
|
| 35 |
$libffi_root->visit( |
| 36 |
sub { |
| 37 |
my($path) = @_; |
| 38 |
return if $path->is_dir; |
| 39 |
return unless $path->basename eq 'ffitarget.h'; |
| 40 |
say ' ' . $path->relative($libffi_root); |
| 41 |
|
| 42 |
my $c = $path->slurp; |
| 43 |
if($c =~ m/typedef\s+enum\s+ffi_abi\s+{(.*?)}/s) |
| 44 |
{ |
| 45 |
my $c = $1; |
| 46 |
while($c =~ s/FFI_([A-Z_0-9]+)//) |
| 47 |
{ |
| 48 |
my $abi = $1; |
| 49 |
next if $abi =~ /^(FIRST|LAST|DEFAULT)_ABI$/; |
| 50 |
say ' ', $abi; |
| 51 |
$abis{$abi}++; |
| 52 |
} |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
say ' no abis'; |
| 57 |
} |
| 58 |
}, |
| 59 |
{ recurse => 1 }, |
| 60 |
); |
| 61 |
|
| 62 |
path(__FILE__)->parent->child("abis-all.json")->spew_raw(JSON::PP->new->pretty(1)->encode([sort keys %abis])); |