Commit | Line | Data |
---|---|---|
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 |
14 | BEGIN { unshift @INC, "lib" } |
15 | ||
8ab87a3d NC |
16 | use strict; |
17 | ||
fed7345c AD |
18 | print <<'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 | ||
28 | package ExtUtils::Miniperl; | |
29 | require Exporter; | |
30 | @ISA = qw(Exporter); | |
31 | @EXPORT = qw(&writemain); | |
32 | ||
33 | $head= <<'EOF!HEAD'; | |
34 | END | |
35 | ||
36 | open MINI, "miniperlmain.c"; | |
37 | while (<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 | ||
43 | print <<'END'; | |
44 | EOF!HEAD | |
45 | $tail=<<'EOF!TAIL'; | |
46 | END | |
47 | ||
48 | while (<MINI>) { | |
8cc95fdb | 49 | print unless /dXSUB_SYS/; |
fed7345c AD |
50 | } |
51 | close MINI; | |
52 | ||
53 | print <<'END'; | |
54 | EOF!TAIL | |
55 | ||
56 | sub 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; |
1b773500 | 74 | print "\tstatic const 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 | ||
99 | sub 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 | ||
111 | 1; | |
864a5fa8 | 112 | __END__ |
222dd4a0 | 113 | |
864a5fa8 AD |
114 | =head1 NAME |
115 | ||
222dd4a0 | 116 | ExtUtils::Miniperl, writemain - write the C code for perlmain.c |
864a5fa8 AD |
117 | |
118 | =head1 SYNOPSIS | |
119 | ||
120 | C<use ExtUtils::Miniperl;> | |
121 | ||
122 | C<writemain(@directories);> | |
123 | ||
124 | =head1 DESCRIPTION | |
125 | ||
126 | This whole module is written when perl itself is built from a script | |
127 | called minimod.PL. In case you want to patch it, please patch | |
128 | minimod.PL in the perl distribution instead. | |
129 | ||
130 | writemain() takes an argument list of directories containing archive | |
131 | libraries that relate to perl modules and should be linked into a new | |
132 | perl binary. It writes to STDOUT a corresponding perlmain.c file that | |
133 | is a plain C file containing all the bootstrap code to make the | |
134 | modules associated with the libraries available from within perl. | |
135 | ||
136 | The typical usage is from within a Makefile generated by | |
137 | ExtUtils::MakeMaker. So under normal circumstances you won't have to | |
138 | deal with this module directly. | |
139 | ||
140 | =head1 SEE ALSO | |
141 | ||
142 | L<ExtUtils::MakeMaker> | |
143 | ||
144 | =cut | |
145 | ||
fed7345c | 146 | END |