home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / D12 / PERL1.TGZ / perl1.tar / usr / lib / perl5 / ExtUtils / Miniperl.pm < prev    next >
Text File  |  1996-06-28  |  4KB  |  173 lines

  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. /*
  17.  * "The Road goes ever on and on, down from the door where it began."
  18.  */
  19.  
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23.  
  24. #include "EXTERN.h"
  25. #include "perl.h"
  26.  
  27. #ifdef __cplusplus
  28. }
  29. #  define EXTERN_C extern "C"
  30. #else
  31. #  define EXTERN_C extern
  32. #endif
  33.  
  34. static void xs_init _((void));
  35. static PerlInterpreter *my_perl;
  36.  
  37. int
  38. #ifdef CAN_PROTOTYPE
  39. main(int argc, char **argv, char **env)
  40. #else
  41. main(argc, argv, env)
  42. int argc;
  43. char **argv;
  44. char **env;
  45. #endif
  46. {
  47.     int exitstatus;
  48.  
  49.     PERL_SYS_INIT(&argc,&argv);
  50.  
  51.     perl_init_i18nl14n(1);
  52.  
  53.     if (!do_undump) {
  54.     my_perl = perl_alloc();
  55.     if (!my_perl)
  56.         exit(1);
  57.     perl_construct( my_perl );
  58.     }
  59.  
  60.     exitstatus = perl_parse( my_perl, xs_init, argc, argv, (char **) NULL );
  61.     if (exitstatus)
  62.     exit( exitstatus );
  63.  
  64.     exitstatus = perl_run( my_perl );
  65.  
  66.     perl_destruct( my_perl );
  67.     perl_free( my_perl );
  68.  
  69.     PERL_SYS_TERM();
  70.  
  71.     exit( exitstatus );
  72. }
  73.  
  74. /* Register any extra external extensions */
  75.  
  76. EOF!HEAD
  77. $tail=<<'EOF!TAIL';
  78.  
  79. static void
  80. xs_init()
  81. {
  82.   dXSUB_SYS;
  83. }
  84. EOF!TAIL
  85.  
  86. sub writemain{
  87.     my(@exts) = @_;
  88.  
  89.     my($pname);
  90.     my($dl) = canon('/','DynaLoader');
  91.     print $head;
  92.  
  93.     foreach $_ (@exts){
  94.     my($pname) = canon('/', $_);
  95.     my($mname, $cname);
  96.     ($mname = $pname) =~ s!/!::!g;
  97.     ($cname = $pname) =~ s!/!__!g;
  98.     print "EXTERN_C void boot_${cname} _((CV* cv));\n";
  99.     }
  100.  
  101.     my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s );
  102.     print $tail1;
  103.  
  104.     print "    char *file = __FILE__;\n";
  105.     foreach $_ (@exts){
  106.     my($pname) = canon('/', $_);
  107.     my($mname, $cname, $ccode);
  108.     ($mname = $pname) =~ s!/!::!g;
  109.     ($cname = $pname) =~ s!/!__!g;
  110.     print "\t{\n";
  111.     if ($pname eq $dl){
  112.         # Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
  113.         # boot_DynaLoader is called directly in DynaLoader.pm
  114.         $ccode = "\t/* DynaLoader is a special case */\n
  115. \tnewXS(\"${mname}::boot_${cname}\", boot_${cname}, file);\n";
  116.         print $ccode unless $SEEN{$ccode}++;
  117.     } else {
  118.         $ccode = "\tnewXS(\"${mname}::bootstrap\", boot_${cname}, file);\n";
  119.         print $ccode unless $SEEN{$ccode}++;
  120.     }
  121.     print "\t}\n";
  122.     }
  123.     print $tail2;
  124. }
  125.  
  126. sub canon{
  127.     my($as, @ext) = @_;
  128.     foreach(@ext){
  129.         # might be X::Y or lib/auto/X/Y/Y.a
  130.         next if s!::!/!g;
  131.         s:^(lib|ext)/(auto/)?::;
  132.         s:/\w+\.\w+$::;
  133.     }
  134.     grep(s:/:$as:, @ext) if ($as ne '/');
  135.     @ext;
  136. }
  137.  
  138. 1;
  139. __END__
  140.  
  141. =head1 NAME
  142.  
  143. ExtUtils::Miniperl, writemain - write the C code for perlmain.c
  144.  
  145. =head1 SYNOPSIS
  146.  
  147. C<use ExtUtils::Miniperl;>
  148.  
  149. C<writemain(@directories);>
  150.  
  151. =head1 DESCRIPTION
  152.  
  153. This whole module is written when perl itself is built from a script
  154. called minimod.PL. In case you want to patch it, please patch
  155. minimod.PL in the perl distribution instead.
  156.  
  157. writemain() takes an argument list of directories containing archive
  158. libraries that relate to perl modules and should be linked into a new
  159. perl binary. It writes to STDOUT a corresponding perlmain.c file that
  160. is a plain C file containing all the bootstrap code to make the
  161. modules associated with the libraries available from within perl.
  162.  
  163. The typical usage is from within a Makefile generated by
  164. ExtUtils::MakeMaker. So under normal circumstances you won't have to
  165. deal with this module directly.
  166.  
  167. =head1 SEE ALSO
  168.  
  169. L<ExtUtils::MakeMaker>
  170.  
  171. =cut
  172.  
  173.