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