2 package ExtUtils::Miniperl;
5 use ExtUtils::Embed qw(xsi_header xsi_protos xsi_body);
7 use vars qw($VERSION @ISA @EXPORT);
10 @EXPORT = qw(writemain);
23 printf $fh <<'EOF!HEAD', xsi_header();
26 * Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003,
27 * 2004, 2005, 2006, 2007, by Larry Wall and others
29 * You may distribute under the terms of either the GNU General Public
30 * License or the Artistic License, as specified in the README file.
35 * The Road goes ever on and on
36 * Down from the door where it began.
38 * [Bilbo on p.35 of _The Lord of the Rings_, I/i: "A Long-Expected Party"]
39 * [Frodo on p.73 of _The Lord of the Rings_, I/iii: "Three Is Company"]
42 /* This file contains the main() function for the perl interpreter.
43 * Note that miniperlmain.c contains main() for the 'miniperl' binary,
44 * while perlmain.c contains main() for the 'perl' binary.
46 * Miniperl is like perl except that it does not support dynamic loading,
47 * and in fact is used to build the dynamic modules needed for the 'real'
53 /* sbrk is limited to first heap segment so make it big */
54 #pragma runopts(HEAP(8M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
56 #pragma runopts(HEAP(2M,500K,ANYWHERE,KEEP,8K,4K) STACK(,,ANY,) ALL31(ON))
60 #define PERL_IN_MINIPERLMAIN_C
62 static void xs_init (pTHX);
63 static PerlInterpreter *my_perl;
65 #if defined(PERL_GLOBAL_STRUCT_PRIVATE)
66 /* The static struct perl_vars* may seem counterproductive since the
67 * whole idea PERL_GLOBAL_STRUCT_PRIVATE was to avoid statics, but note
68 * that this static is not in the shared perl library, the globals PL_Vars
69 * and PL_VarsPtr will stay away. */
70 static struct perl_vars* my_plvarsp;
71 struct perl_vars* Perl_GetVarsPrivate(void) { return my_plvarsp; }
74 #ifdef NO_ENV_ARRAY_IN_MAIN
75 extern char **environ;
77 main(int argc, char **argv)
80 main(int argc, char **argv, char **env)
85 #ifdef PERL_GLOBAL_STRUCT
86 struct perl_vars *plvarsp = init_global_struct();
87 # ifdef PERL_GLOBAL_STRUCT_PRIVATE
88 my_vars = my_plvarsp = plvarsp;
90 #endif /* PERL_GLOBAL_STRUCT */
91 #ifndef NO_ENV_ARRAY_IN_MAIN
94 #ifndef PERL_USE_SAFE_PUTENV
95 PL_use_safe_putenv = FALSE;
96 #endif /* PERL_USE_SAFE_PUTENV */
98 /* if user wants control of gprof profiling off by default */
99 /* noop unless Configure is given -Accflags=-DPERL_GPROF_CONTROL */
100 PERL_GPROF_MONCONTROL(0);
102 #ifdef NO_ENV_ARRAY_IN_MAIN
103 PERL_SYS_INIT3(&argc,&argv,&environ);
105 PERL_SYS_INIT3(&argc,&argv,&env);
108 #if defined(USE_ITHREADS)
109 /* XXX Ideally, this should really be happening in perl_alloc() or
110 * perl_construct() to keep libperl.a transparently fork()-safe.
111 * It is currently done here only because Apache/mod_perl have
112 * problems due to lack of a call to cancel pthread_atfork()
113 * handlers when shared objects that contain the handlers may
114 * be dlclose()d. This forces applications that embed perl to
115 * call PTHREAD_ATFORK() explicitly, but if and only if it hasn't
116 * been called at least once before in the current process.
117 * --GSAR 2001-07-20 */
118 PTHREAD_ATFORK(Perl_atfork_lock,
124 my_perl = perl_alloc();
127 perl_construct(my_perl);
128 PL_perl_destruct_level = 0;
130 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
131 exitstatus = perl_parse(my_perl, xs_init, argc, argv, (char **)NULL);
136 /* Unregister our signal handler before destroying my_perl */
137 for (i = 1; PL_sig_name[i]; i++) {
138 if (rsignal_state(PL_sig_num[i]) == (Sighandler_t) PL_csighandlerp) {
139 rsignal(PL_sig_num[i], (Sighandler_t) SIG_DFL);
144 exitstatus = perl_destruct(my_perl);
148 #if defined(USE_ENVIRON_ARRAY) && defined(PERL_TRACK_MEMPOOL) && !defined(NO_ENV_ARRAY_IN_MAIN)
150 * The old environment may have been freed by perl_free()
151 * when PERL_TRACK_MEMPOOL is defined, but without having
152 * been restored by perl_destruct() before (this is only
153 * done if destruct_level > 0).
155 * It is important to have a valid environment for atexit()
156 * routines that are eventually called.
163 #ifdef PERL_GLOBAL_STRUCT
164 free_global_struct(plvarsp);
165 #endif /* PERL_GLOBAL_STRUCT */
171 /* Register any extra external extensions */
175 print $fh xsi_protos(@exts), <<'EOT', xsi_body(@exts), "}\n";
188 ExtUtils::Miniperl - write the C code for perlmain.c
192 use ExtUtils::Miniperl;
193 writemain(@directories);
195 writemain($fh, @directories);
199 C<writemain()> takes an argument list of directories containing archive
200 libraries that relate to perl modules and should be linked into a new
201 perl binary. It writes a corresponding F<perlmain.c> file that
202 is a plain C file containing all the bootstrap code to make the
203 modules associated with the libraries available from within perl.
204 If the first argument to C<writemain()> is a reference, it
205 is used as the file handle to write to. Otherwise output is to C<STDOUT>.
207 The typical usage is from within a Makefile generated by
208 L<ExtUtils::MakeMaker>. So under normal circumstances you won't have to
209 deal with this module directly.
213 L<ExtUtils::MakeMaker>
218 # c-indentation-style: bsd
220 # indent-tabs-mode: nil
223 # ex: set ts=8 sts=4 sw=4 et: