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