Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | # This File keeps the contents of miniperlmain.c. |
2 | # | |
3 | # It was generated automatically by minimod.PL from the contents | |
4 | # of miniperlmain.c. Don't edit this file! | |
5 | # | |
6 | # ANY CHANGES MADE HERE WILL BE LOST! | |
7 | # | |
8 | ||
9 | ||
10 | package ExtUtils::Miniperl; | |
11 | require Exporter; | |
12 | @ISA = qw(Exporter); | |
13 | @EXPORT = qw(&writemain); | |
14 | ||
15 | $head= <<'EOF!HEAD'; | |
16 | /* miniperlmain.c | |
17 | * | |
18 | * Copyright (c) 1997-2002, Larry Wall | |
19 | * | |
20 | * You may distribute under the terms of either the GNU General Public | |
21 | * License or the Artistic License, as specified in the README file. | |
22 | * | |
23 | */ | |
24 | ||
25 | /* | |
26 | * "The Road goes ever on and on, down from the door where it began." | |
27 | */ | |
28 | ||
29 | #ifdef OEMVS | |
30 | #ifdef MYMALLOC | |
31 | /* sbrk is limited to first heap segement so make it big */ | |
32 | #pragma runopts(HEAP(8M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON)) | |
33 | #else | |
34 | #pragma runopts(HEAP(2M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON)) | |
35 | #endif | |
36 | #endif | |
37 | ||
38 | ||
39 | #include "EXTERN.h" | |
40 | #define PERL_IN_MINIPERLMAIN_C | |
41 | #include "perl.h" | |
42 | ||
43 | static void xs_init (pTHX); | |
44 | static PerlInterpreter *my_perl; | |
45 | ||
46 | #if defined (__MINT__) || defined (atarist) | |
47 | /* The Atari operating system doesn't have a dynamic stack. The | |
48 | stack size is determined from this value. */ | |
49 | long _stksize = 64 * 1024; | |
50 | #endif | |
51 | ||
52 | int | |
53 | main(int argc, char **argv, char **env) | |
54 | { | |
55 | int exitstatus; | |
56 | ||
57 | #ifdef PERL_GLOBAL_STRUCT | |
58 | #define PERLVAR(var,type) /**/ | |
59 | #define PERLVARA(var,type) /**/ | |
60 | #define PERLVARI(var,type,init) PL_Vars.var = init; | |
61 | #define PERLVARIC(var,type,init) PL_Vars.var = init; | |
62 | #include "perlvars.h" | |
63 | #undef PERLVAR | |
64 | #undef PERLVARA | |
65 | #undef PERLVARI | |
66 | #undef PERLVARIC | |
67 | #endif | |
68 | ||
69 | /* if user wants control of gprof profiling off by default */ | |
70 | /* noop unless Configure is given -Accflags=-DPERL_GPROF_CONTROL */ | |
71 | PERL_GPROF_MONCONTROL(0); | |
72 | ||
73 | PERL_SYS_INIT3(&argc,&argv,&env); | |
74 | ||
75 | #if defined(USE_5005THREADS) || defined(USE_ITHREADS) | |
76 | /* XXX Ideally, this should really be happening in perl_alloc() or | |
77 | * perl_construct() to keep libperl.a transparently fork()-safe. | |
78 | * It is currently done here only because Apache/mod_perl have | |
79 | * problems due to lack of a call to cancel pthread_atfork() | |
80 | * handlers when shared objects that contain the handlers may | |
81 | * be dlclose()d. This forces applications that embed perl to | |
82 | * call PTHREAD_ATFORK() explicitly, but if and only if it hasn't | |
83 | * been called at least once before in the current process. | |
84 | * --GSAR 2001-07-20 */ | |
85 | PTHREAD_ATFORK(Perl_atfork_lock, | |
86 | Perl_atfork_unlock, | |
87 | Perl_atfork_unlock); | |
88 | #endif | |
89 | ||
90 | if (!PL_do_undump) { | |
91 | my_perl = perl_alloc(); | |
92 | if (!my_perl) | |
93 | exit(1); | |
94 | perl_construct(my_perl); | |
95 | PL_perl_destruct_level = 0; | |
96 | } | |
97 | PL_exit_flags |= PERL_EXIT_DESTRUCT_END; | |
98 | exitstatus = perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); | |
99 | if (!exitstatus) | |
100 | perl_run(my_perl); | |
101 | ||
102 | exitstatus = perl_destruct(my_perl); | |
103 | ||
104 | perl_free(my_perl); | |
105 | ||
106 | PERL_SYS_TERM(); | |
107 | ||
108 | exit(exitstatus); | |
109 | return exitstatus; | |
110 | } | |
111 | ||
112 | /* Register any extra external extensions */ | |
113 | ||
114 | EOF!HEAD | |
115 | $tail=<<'EOF!TAIL'; | |
116 | ||
117 | static void | |
118 | xs_init(pTHX) | |
119 | { | |
120 | } | |
121 | EOF!TAIL | |
122 | ||
123 | sub writemain{ | |
124 | my(@exts) = @_; | |
125 | ||
126 | my($pname); | |
127 | my($dl) = canon('/','DynaLoader'); | |
128 | print $head; | |
129 | ||
130 | foreach $_ (@exts){ | |
131 | my($pname) = canon('/', $_); | |
132 | my($mname, $cname); | |
133 | ($mname = $pname) =~ s!/!::!g; | |
134 | ($cname = $pname) =~ s!/!__!g; | |
135 | print "EXTERN_C void boot_${cname} (pTHX_ CV* cv);\n"; | |
136 | } | |
137 | ||
138 | my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s ); | |
139 | print $tail1; | |
140 | ||
141 | print "\tchar *file = __FILE__;\n"; | |
142 | print "\tdXSUB_SYS;\n" if $] > 5.002; | |
143 | ||
144 | foreach $_ (@exts){ | |
145 | my($pname) = canon('/', $_); | |
146 | my($mname, $cname, $ccode); | |
147 | ($mname = $pname) =~ s!/!::!g; | |
148 | ($cname = $pname) =~ s!/!__!g; | |
149 | print "\t{\n"; | |
150 | if ($pname eq $dl){ | |
151 | # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'! | |
152 | # boot_DynaLoader is called directly in DynaLoader.pm | |
153 | $ccode = "\t/* DynaLoader is a special case */\n | |
154 | \tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n"; | |
155 | print $ccode unless $SEEN{$ccode}++; | |
156 | } else { | |
157 | $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n"; | |
158 | print $ccode unless $SEEN{$ccode}++; | |
159 | } | |
160 | print "\t}\n"; | |
161 | } | |
162 | print $tail2; | |
163 | } | |
164 | ||
165 | sub canon{ | |
166 | my($as, @ext) = @_; | |
167 | foreach(@ext){ | |
168 | # might be X::Y or lib/auto/X/Y/Y.a | |
169 | next if s!::!/!g; | |
170 | s:^(lib|ext)/(auto/)?::; | |
171 | s:/\w+\.\w+$::; | |
172 | } | |
173 | grep(s:/:$as:, @ext) if ($as ne '/'); | |
174 | @ext; | |
175 | } | |
176 | ||
177 | 1; | |
178 | __END__ | |
179 | ||
180 | =head1 NAME | |
181 | ||
182 | ExtUtils::Miniperl, writemain - write the C code for perlmain.c | |
183 | ||
184 | =head1 SYNOPSIS | |
185 | ||
186 | C<use ExtUtils::Miniperl;> | |
187 | ||
188 | C<writemain(@directories);> | |
189 | ||
190 | =head1 DESCRIPTION | |
191 | ||
192 | This whole module is written when perl itself is built from a script | |
193 | called minimod.PL. In case you want to patch it, please patch | |
194 | minimod.PL in the perl distribution instead. | |
195 | ||
196 | writemain() takes an argument list of directories containing archive | |
197 | libraries that relate to perl modules and should be linked into a new | |
198 | perl binary. It writes to STDOUT a corresponding perlmain.c file that | |
199 | is a plain C file containing all the bootstrap code to make the | |
200 | modules associated with the libraries available from within perl. | |
201 | ||
202 | The typical usage is from within a Makefile generated by | |
203 | ExtUtils::MakeMaker. So under normal circumstances you won't have to | |
204 | deal with this module directly. | |
205 | ||
206 | =head1 SEE ALSO | |
207 | ||
208 | L<ExtUtils::MakeMaker> | |
209 | ||
210 | =cut | |
211 |