xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/minimod.pl (revision 0:68f95e015346)
1*0Sstevel@tonic-gate# minimod.PL writes the contents of miniperlmain.c into the module
2*0Sstevel@tonic-gate# ExtUtils::Miniperl for later perusal (when the perl source is
3*0Sstevel@tonic-gate# deleted)
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# It also writes the subroutine writemain(), which takes as its
6*0Sstevel@tonic-gate# arguments module names that shall be statically linked into perl.
7*0Sstevel@tonic-gate#
8*0Sstevel@tonic-gate# Authors: Andreas Koenig <k@franz.ww.TU-Berlin.DE>, Tim Bunce
9*0Sstevel@tonic-gate#          <Tim.Bunce@ig.co.uk>
10*0Sstevel@tonic-gate#
11*0Sstevel@tonic-gate# Version 1.0, Feb 2nd 1995 by Andreas Koenig
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gateprint <<'END';
14*0Sstevel@tonic-gate# This File keeps the contents of miniperlmain.c.
15*0Sstevel@tonic-gate#
16*0Sstevel@tonic-gate# It was generated automatically by minimod.PL from the contents
17*0Sstevel@tonic-gate# of miniperlmain.c. Don't edit this file!
18*0Sstevel@tonic-gate#
19*0Sstevel@tonic-gate#       ANY CHANGES MADE HERE WILL BE LOST!
20*0Sstevel@tonic-gate#
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gatepackage ExtUtils::Miniperl;
24*0Sstevel@tonic-gaterequire Exporter;
25*0Sstevel@tonic-gate@ISA = qw(Exporter);
26*0Sstevel@tonic-gate@EXPORT = qw(&writemain);
27*0Sstevel@tonic-gate
28*0Sstevel@tonic-gate$head= <<'EOF!HEAD';
29*0Sstevel@tonic-gateEND
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gateopen MINI, "miniperlmain.c";
32*0Sstevel@tonic-gatewhile (<MINI>) {
33*0Sstevel@tonic-gate    last if /Do not delete this line--writemain depends on it/;
34*0Sstevel@tonic-gate    print;
35*0Sstevel@tonic-gate}
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gateprint <<'END';
38*0Sstevel@tonic-gateEOF!HEAD
39*0Sstevel@tonic-gate$tail=<<'EOF!TAIL';
40*0Sstevel@tonic-gateEND
41*0Sstevel@tonic-gate
42*0Sstevel@tonic-gatewhile (<MINI>) {
43*0Sstevel@tonic-gate    print unless /dXSUB_SYS/;
44*0Sstevel@tonic-gate}
45*0Sstevel@tonic-gateclose MINI;
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gateprint <<'END';
48*0Sstevel@tonic-gateEOF!TAIL
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gatesub writemain{
51*0Sstevel@tonic-gate    my(@exts) = @_;
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gate    my($pname);
54*0Sstevel@tonic-gate    my($dl) = canon('/','DynaLoader');
55*0Sstevel@tonic-gate    print $head;
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate    foreach $_ (@exts){
58*0Sstevel@tonic-gate	my($pname) = canon('/', $_);
59*0Sstevel@tonic-gate	my($mname, $cname);
60*0Sstevel@tonic-gate	($mname = $pname) =~ s!/!::!g;
61*0Sstevel@tonic-gate	($cname = $pname) =~ s!/!__!g;
62*0Sstevel@tonic-gate        print "EXTERN_C void boot_${cname} (pTHX_ CV* cv);\n";
63*0Sstevel@tonic-gate    }
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate    my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s );
66*0Sstevel@tonic-gate    print $tail1;
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate    print "\tchar *file = __FILE__;\n";
69*0Sstevel@tonic-gate    print "\tdXSUB_SYS;\n" if $] > 5.002;
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gate    foreach $_ (@exts){
72*0Sstevel@tonic-gate	my($pname) = canon('/', $_);
73*0Sstevel@tonic-gate	my($mname, $cname, $ccode);
74*0Sstevel@tonic-gate	($mname = $pname) =~ s!/!::!g;
75*0Sstevel@tonic-gate	($cname = $pname) =~ s!/!__!g;
76*0Sstevel@tonic-gate	print "\t{\n";
77*0Sstevel@tonic-gate	if ($pname eq $dl){
78*0Sstevel@tonic-gate	    # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
79*0Sstevel@tonic-gate	    # boot_DynaLoader is called directly in DynaLoader.pm
80*0Sstevel@tonic-gate	    $ccode = "\t/* DynaLoader is a special case */\n
81*0Sstevel@tonic-gate\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
82*0Sstevel@tonic-gate	    print $ccode unless $SEEN{$ccode}++;
83*0Sstevel@tonic-gate	} else {
84*0Sstevel@tonic-gate	    $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
85*0Sstevel@tonic-gate	    print $ccode unless $SEEN{$ccode}++;
86*0Sstevel@tonic-gate	}
87*0Sstevel@tonic-gate	print "\t}\n";
88*0Sstevel@tonic-gate    }
89*0Sstevel@tonic-gate    print $tail2;
90*0Sstevel@tonic-gate}
91*0Sstevel@tonic-gate
92*0Sstevel@tonic-gatesub canon{
93*0Sstevel@tonic-gate    my($as, @ext) = @_;
94*0Sstevel@tonic-gate	foreach(@ext){
95*0Sstevel@tonic-gate	    # might be X::Y or lib/auto/X/Y/Y.a
96*0Sstevel@tonic-gate		next if s!::!/!g;
97*0Sstevel@tonic-gate	    s:^(lib|ext)/(auto/)?::;
98*0Sstevel@tonic-gate	    s:/\w+\.\w+$::;
99*0Sstevel@tonic-gate	}
100*0Sstevel@tonic-gate	grep(s:/:$as:, @ext) if ($as ne '/');
101*0Sstevel@tonic-gate	@ext;
102*0Sstevel@tonic-gate}
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate1;
105*0Sstevel@tonic-gate__END__
106*0Sstevel@tonic-gate
107*0Sstevel@tonic-gate=head1 NAME
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gateExtUtils::Miniperl, writemain - write the C code for perlmain.c
110*0Sstevel@tonic-gate
111*0Sstevel@tonic-gate=head1 SYNOPSIS
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gateC<use ExtUtils::Miniperl;>
114*0Sstevel@tonic-gate
115*0Sstevel@tonic-gateC<writemain(@directories);>
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate=head1 DESCRIPTION
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gateThis whole module is written when perl itself is built from a script
120*0Sstevel@tonic-gatecalled minimod.PL. In case you want to patch it, please patch
121*0Sstevel@tonic-gateminimod.PL in the perl distribution instead.
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gatewritemain() takes an argument list of directories containing archive
124*0Sstevel@tonic-gatelibraries that relate to perl modules and should be linked into a new
125*0Sstevel@tonic-gateperl binary. It writes to STDOUT a corresponding perlmain.c file that
126*0Sstevel@tonic-gateis a plain C file containing all the bootstrap code to make the
127*0Sstevel@tonic-gatemodules associated with the libraries available from within perl.
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gateThe typical usage is from within a Makefile generated by
130*0Sstevel@tonic-gateExtUtils::MakeMaker. So under normal circumstances you won't have to
131*0Sstevel@tonic-gatedeal with this module directly.
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate=head1 SEE ALSO
134*0Sstevel@tonic-gate
135*0Sstevel@tonic-gateL<ExtUtils::MakeMaker>
136*0Sstevel@tonic-gate
137*0Sstevel@tonic-gate=cut
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gateEND
140