| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use File::Basename qw( basename ); |
| 4 |
use File::Path qw( mkpath ); |
| 5 |
use File::Copy qw( copy ); |
| 6 |
use lib 'inc'; |
| 7 |
use My::Config; |
| 8 |
use lib 'lib'; |
| 9 |
use FFI::Build; |
| 10 |
use Config (); |
| 11 |
|
| 12 |
my $config = My::Config->new; |
| 13 |
|
| 14 |
my $include = "blib/lib/auto/share/dist/FFI-Platypus/include"; |
| 15 |
mkpath $include, 0, 0755; |
| 16 |
foreach my $h (qw( ffi_platypus_config.h ffi_platypus_bundle.h )) |
| 17 |
{ |
| 18 |
my $from = "include/$h"; |
| 19 |
my $to = "$include/$h"; |
| 20 |
|
| 21 |
if(-f $to) |
| 22 |
{ |
| 23 |
next if slurp($from) eq slurp($to); |
| 24 |
} |
| 25 |
|
| 26 |
copy($from => $to) || die "unable to copy $from => $to $!"; |
| 27 |
} |
| 28 |
|
| 29 |
my $lib = FFI::Build->new( |
| 30 |
'plfill', |
| 31 |
source => ['ffi/*.c'], |
| 32 |
verbose => 1, |
| 33 |
dir => 'blib/lib/auto/share/dist/FFI-Platypus/lib', |
| 34 |
platform => $config->platform, |
| 35 |
alien => [$config->alien], |
| 36 |
cflags => '-Iblib/lib/auto/share/dist/FFI-Platypus/include -Iinclude', |
| 37 |
)->build; |
| 38 |
|
| 39 |
my $name = basename($lib->basename); |
| 40 |
|
| 41 |
foreach my $dir ( 'FFI/Platypus/Memory','FFI/Platypus/Record/Meta', 'FFI/Platypus/Constant' ) |
| 42 |
{ |
| 43 |
my($file) = $dir =~ m{/([^/]+)$}; |
| 44 |
mkpath("blib/arch/auto/$dir", 0, 0755); |
| 45 |
my $txtfile = "blib/arch/auto/$dir/$file.txt"; |
| 46 |
my $fh; |
| 47 |
open($fh, '>', $txtfile) || die "unable to write to $txtfile $!"; |
| 48 |
print $fh "FFI::Build\@auto/share/dist/FFI-Platypus/lib/$name\n"; |
| 49 |
close $fh; |
| 50 |
} |
| 51 |
|
| 52 |
sub slurp |
| 53 |
{ |
| 54 |
my($filename) = @_; |
| 55 |
my $fh; |
| 56 |
open $fh, '<', $filename; |
| 57 |
binmode $fh; |
| 58 |
my $content = do { local $/; <$fh> }; |
| 59 |
close $fh; |
| 60 |
$content; |
| 61 |
} |