1package FC_Solve::InlineWrap;
2
3use 5.014;
4use strict;
5use warnings;
6
7use Config;
8use Inline;
9
10use FC_Solve::Paths qw( $IS_WIN bin_file src_file );
11
12sub import
13{
14    my ( $self, %args ) = @_;
15
16    my ($pkg) = caller(0);
17
18    my $src  = delete( $args{C} );
19    my $libs = delete( $args{l} ) // '';
20
21    my @workaround_for_a_heisenbug =
22        ( $IS_WIN ? ( optimize => '-g' ) : () );
23
24    my $ccflags = "$Config{ccflags} -std=gnu99";
25    if ($IS_WIN)
26    {
27        $ccflags =~ s#(^|\s)-[Of][a-zA-Z0-9_\-]*#$1#gms;
28    }
29
30    my @inline_params = (
31        C    => $src,
32        name => $pkg,
33        NAME => $pkg,
34        INC  => join( " ",
35            map     { "-I$_" }
36                map { bin_file($_), src_file($_) }
37                ( ["include"], ["rinutils/rinutils/include"], [] ) ),
38        CCFLAGS           => $ccflags,
39        CLEAN_AFTER_BUILD => 0,
40        LIBS              => "-L$ENV{FCS_PATH} $libs",
41        @workaround_for_a_heisenbug,
42        %args,
43    );
44
45=begin debug
46
47    if ($IS_WIN)
48    {
49        require Data::Dumper;
50        print STDERR "inline_params = <<<<<\n", Data::Dumper::Dumper( \@inline_params ),
51            ">>>>>>\n";
52    }
53
54=end debug
55
56=cut
57
58    eval "{ package $pkg; Inline->bind(\@inline_params); }";
59
60    if ($@)
61    {
62        die $@;
63    }
64
65    return;
66}
67
681;
69