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