File: MyBuilder.pm

package info (click to toggle)
libhash-fieldhash-perl 0.15-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,249; ansic: 207; makefile: 10
file content (81 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download | duplicates (5)
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
package builder::MyBuilder;
use strict;
use warnings;
use warnings FATAL => qw(recursion);
use parent qw(Module::Build);

use File::Basename;
use Devel::PPPort;

my $xs_src   = 'src';
my $xs_build = '_xs_build';

sub new {
    my($class, %args) = @_;

    Devel::PPPort::WriteFile("$xs_src/ppport.h");

    my $so_prefix = $args{module_name};
    $so_prefix =~ s/::\w+$//;
    $so_prefix =~ s{::}{/}g;

    #$args{c_source} = $xs_src;
    $args{needs_compiler} = 1;
    $args{xs_files} = {
        map { $_ => "./$xs_build/" . $_ }
        glob("$xs_src/*.xs"),
    };

    $args{extra_compiler_flags} = ["-I$xs_src"];

    return $class->SUPER::new(%args);
}

sub process_xs_files {
    my($self) = @_;

    # NOTE:
    # XS modules are consist of not only *.xs, but also *.c, *.xsi, and etc.
    foreach my $from(glob "$xs_src/*.{c,cpp,cxx,xsi,xsh}") {
        my $to = "$xs_build/$from";
        $self->add_to_cleanup($to);
        $self->copy_if_modified(from => $from, to => $to);
    }

    $self->SUPER::process_xs_files();
}

sub _infer_xs_spec {
    my($self, $xs_file) = @_;

    my $spec = $self->SUPER::_infer_xs_spec($xs_file);

    $spec->{module_name} = $self->module_name;

    my @d = split /::/, $spec->{module_name};

    my $basename = pop @d;

    # NOTE:
    # They've been infered from the XS filename, but it's a bad idea!
    # That's because these names are used by XSLoader, which
    # deduces filenames from the module name, not an XS filename.

    $spec->{archdir} = File::Spec->catfile(
        $self->blib, 'arch', 'auto',
        @d, $basename);

    $spec->{bs_file}    = File::Spec->catfile(
        $spec->{archdir},
        $basename . '.bs');

    $spec->{lib_file}    = File::Spec->catfile(
        $spec->{archdir},
        $basename . '.' . $self->{config}->get('dlext'));

    #use Data::Dumper; print Dumper $spec;

    return $spec;
}

1;