This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
More files to exclude from the core-cpan-diff
[perl5.git] / minimod.pl
CommitLineData
8ab87a3d 1#./miniperl -w
3645c8c7 2# minimod.pl writes the contents of miniperlmain.c into the module
fed7345c
AD
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
A
14BEGIN { unshift @INC, "lib" }
15
8ab87a3d
NC
16use strict;
17
fed7345c
AD
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;
3ecadf96 40 /#include "perl.h"/ and print qq/#include "XSUB.h"\n/;
fed7345c
AD
41}
42
43print <<'END';
44EOF!HEAD
45$tail=<<'EOF!TAIL';
46END
47
48while (<MINI>) {
8cc95fdb 49 print unless /dXSUB_SYS/;
fed7345c
AD
50}
51close MINI;
52
53print <<'END';
54EOF!TAIL
55
56sub writemain{
57 my(@exts) = @_;
58
59 my($pname);
60 my($dl) = canon('/','DynaLoader');
61 print $head;
4633a7c4
LW
62
63 foreach $_ (@exts){
64 my($pname) = canon('/', $_);
65 my($mname, $cname);
66 ($mname = $pname) =~ s!/!::!g;
67 ($cname = $pname) =~ s!/!__!g;
6acd907d 68 print "EXTERN_C void boot_${cname} (pTHX_ CV* cv);\n";
4633a7c4
LW
69 }
70
938cfd5c 71 my ($tail1,$tail2,$tail3) = ( $tail =~ /\A(.*{\s*\n)(.*\n)(\s*\}.*)\Z/s );
4633a7c4 72
938cfd5c 73 print $tail1;
e1ec3a88 74 print "\tconst char file[] = __FILE__;\n";
8cc95fdb 75 print "\tdXSUB_SYS;\n" if $] > 5.002;
938cfd5c 76 print $tail2;
8cc95fdb 77
fed7345c
AD
78 foreach $_ (@exts){
79 my($pname) = canon('/', $_);
8e07c86e 80 my($mname, $cname, $ccode);
fed7345c
AD
81 ($mname = $pname) =~ s!/!::!g;
82 ($cname = $pname) =~ s!/!__!g;
4633a7c4 83 print "\t{\n";
fed7345c
AD
84 if ($pname eq $dl){
85 # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
86 # boot_DynaLoader is called directly in DynaLoader.pm
8e07c86e
AD
87 $ccode = "\t/* DynaLoader is a special case */\n
88\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
89 print $ccode unless $SEEN{$ccode}++;
fed7345c 90 } else {
8e07c86e
AD
91 $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
92 print $ccode unless $SEEN{$ccode}++;
fed7345c
AD
93 }
94 print "\t}\n";
95 }
938cfd5c 96 print $tail3;
fed7345c
AD
97}
98
99sub canon{
100 my($as, @ext) = @_;
101 foreach(@ext){
102 # might be X::Y or lib/auto/X/Y/Y.a
103 next if s!::!/!g;
104 s:^(lib|ext)/(auto/)?::;
105 s:/\w+\.\w+$::;
106 }
107 grep(s:/:$as:, @ext) if ($as ne '/');
108 @ext;
109}
110
1111;
864a5fa8 112__END__
222dd4a0 113
864a5fa8
AD
114=head1 NAME
115
222dd4a0 116ExtUtils::Miniperl, writemain - write the C code for perlmain.c
864a5fa8
AD
117
118=head1 SYNOPSIS
119
120C<use ExtUtils::Miniperl;>
121
122C<writemain(@directories);>
123
124=head1 DESCRIPTION
125
126This whole module is written when perl itself is built from a script
127called minimod.PL. In case you want to patch it, please patch
128minimod.PL in the perl distribution instead.
129
130writemain() takes an argument list of directories containing archive
131libraries that relate to perl modules and should be linked into a new
132perl binary. It writes to STDOUT a corresponding perlmain.c file that
133is a plain C file containing all the bootstrap code to make the
134modules associated with the libraries available from within perl.
135
136The typical usage is from within a Makefile generated by
137ExtUtils::MakeMaker. So under normal circumstances you won't have to
138deal with this module directly.
139
140=head1 SEE ALSO
141
142L<ExtUtils::MakeMaker>
143
144=cut
145
fed7345c 146END