This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
XS-APItest/t/caller.t: mark two passing tests
[perl5.git] / minimod.pl
... / ...
CommitLineData
1#./miniperl -w
2# minimod.pl writes the contents of miniperlmain.c into the module
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
14BEGIN { unshift @INC, "lib" }
15
16use strict;
17
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 /#include "perl.h"/ and print qq/#include "XSUB.h"\n/;
41}
42
43print <<'END';
44EOF!HEAD
45$tail=<<'EOF!TAIL';
46END
47
48while (<MINI>) {
49 print unless /dXSUB_SYS/;
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;
62
63 foreach $_ (@exts){
64 my($pname) = canon('/', $_);
65 my($mname, $cname);
66 ($mname = $pname) =~ s!/!::!g;
67 ($cname = $pname) =~ s!/!__!g;
68 print "EXTERN_C void boot_${cname} (pTHX_ CV* cv);\n";
69 }
70
71 my ($tail1,$tail2,$tail3) = ( $tail =~ /\A(.*{\s*\n)(.*\n)(\s*\}.*)\Z/s );
72
73 print $tail1;
74 print "\tconst char file[] = __FILE__;\n";
75 print "\tdXSUB_SYS;\n" if $] > 5.002;
76 print $tail2;
77
78 foreach $_ (@exts){
79 my($pname) = canon('/', $_);
80 my($mname, $cname, $ccode);
81 ($mname = $pname) =~ s!/!::!g;
82 ($cname = $pname) =~ s!/!__!g;
83 print "\t{\n";
84 if ($pname eq $dl){
85 # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
86 # boot_DynaLoader is called directly in DynaLoader.pm
87 $ccode = "\t/* DynaLoader is a special case */\n
88\tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
89 print $ccode unless $SEEN{$ccode}++;
90 } else {
91 $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
92 print $ccode unless $SEEN{$ccode}++;
93 }
94 print "\t}\n";
95 }
96 print $tail3;
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;
112__END__
113
114=head1 NAME
115
116ExtUtils::Miniperl, writemain - write the C code for perlmain.c
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
146END