summaryrefslogtreecommitdiff
path: root/minimod.PL
blob: 740cb2bee0fb7e6db7ac575f3cf3c837b60b762c (plain)
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
82
83
84
85
86
87
88
89
# minimod.PL writes the contents of miniperlmain.c into the module
# ExtUtils::Miniperl for later perusal (when the perl source is
# deleted)
#
# It also writes the subroutine writemain(), which takes as its
# arguments module names that shall be statically linked into perl.
#
# Authors: Andreas Koenig <k@franz.ww.TU-Berlin.DE>, Tim Bunce
#          <Tim.Bunce@ig.co.uk>
#
# Version 1.0, Feb 2nd 1995 by Andreas Koenig

print <<'END';
# This File keeps the contents of miniperlmain.c.
#
# It was generated automatically by minimod.PL from the contents
# of miniperlmain.c. Don't edit this file!
#
#       ANY CHANGES MADE HERE WILL BE LOST! 
#


package ExtUtils::Miniperl;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(&writemain);

$head= <<'EOF!HEAD';
END

open MINI, "miniperlmain.c";
while (<MINI>) {
    last if /Do not delete this line--writemain depends on it/;
    print;
}

print <<'END';
EOF!HEAD
$tail=<<'EOF!TAIL';
END

while (<MINI>) {
    print;
}
close MINI;

print <<'END';
EOF!TAIL

sub writemain{
    my(@exts) = @_;

    my($pname);
    my($dl) = canon('/','DynaLoader');
    print $head;
    print "	char *file = __FILE__;\n";
    foreach $_ (@exts){
	my($pname) = canon('/', $_);
	my($mname, $cname);
	($mname = $pname) =~ s!/!::!g;
	($cname = $pname) =~ s!/!__!g;
	print "\t{   extern void boot_${cname} _((CV* cv));\n";
	if ($pname eq $dl){
	    # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
	    # boot_DynaLoader is called directly in DynaLoader.pm
	    print "\t/* DynaLoader is a special case */\n";
	    print "\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n"
	} else {
	    print "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n"
	}
	print "\t}\n";
    }
    print $tail;
}

sub canon{
    my($as, @ext) = @_;
	foreach(@ext){
	    # might be X::Y or lib/auto/X/Y/Y.a
		next if s!::!/!g;
	    s:^(lib|ext)/(auto/)?::;
	    s:/\w+\.\w+$::;
	}
	grep(s:/:$as:, @ext) if ($as ne '/');
	@ext;
}

1;
END