So ... I wonder if there's some way that I can make bar.h, baz.h, bar.c and baz.c visible to the build process without having to move them to the build directory ?
Not that I can see.
So we're left with the option of having Inline automatically copy our '.h' and '.c' files to the required location.
The required patch to C.pm changes to:
--- C.pm_orig 2021-12-20 22:11:48 +1100
+++ C.pm 2022-06-28 22:08:10 +1000
@@ -177,6 +177,20 @@
$o->{ILSM}{XS}{PREFIX} = $value;
next;
}
+ if($key eq 'OBJECT') {
+ $o->mkpath($o->{API}{build_dir}) unless -d $o->{API}{buil
+d_dir};
+ require File::Copy;
+ $o->add_string($o->{ILSM}{MAKEFILE}, 'OBJECT', '$(O_FILES
+)');
+ die "'OBJECT' must specify an array reference"
+ unless ref($value) eq 'ARRAY';
+ for my $fn(@$value) {
+ File::Copy::copy("${fn}.h", $o->{API}{build_dir} . "/${
+fn}.h")
+ if -e "${fn}.h";
+ File::Copy::copy("${fn}.c", $o->{API}{build_dir} . "/${
+fn}.c")
+ if -e "${fn}.c";
+ }
+ next;
+ }
if ($key eq 'FILTERS') {
next if $value eq '1' or $value eq '0'; # ignore ENABLE,
+DISABLE
$value = [$value] unless ref($value) eq 'ARRAY';
@@ -374,7 +388,7 @@
open $lockfh, '>', $file or die "lockfile $file: $!";
flock($lockfh, LOCK_EX) or die "flock: $!\n" if $^O !~ /^VMS|
+riscos|VOS$/;
}
- $o->mkpath($o->{API}{build_dir});
+ $o->mkpath($o->{API}{build_dir}) unless -d $o->{API}{build_dir};
$o->call('preprocess', 'Build Preprocess');
$o->call('parse', 'Build Parse');
$o->call('write_XS', 'Build Glue 1');
And instead of providing the OBJECT config option as OBJECT => '$(O_FILES)', we now have to do something like:
OBJECT => ['./bar', './baz'],
That's assuming that the '.h' and '.c' files are in the cwd. Otherwise, modify accordingly. ... oops ... I'll modify the patch later to allow for files not being in the cwd. )
The demo I provided earlier therefore becomes:
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1,
OBJECT => ['./bar', './baz'],
;
use Inline C =><<'EOC';
#include "bar.h"
#include "baz.h"
void foo(int i) {
printf("bar: %d\n", bar(i));
printf("baz: %d\n", baz(i));
}
EOC
foo(42);
And that works fine straight away.
Thoughts ?
Cheers, Rob |