home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / perlcc.bat < prev    next >
Encoding:
DOS Batch File  |  1999-10-16  |  26.9 KB  |  920 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. goto endofperl
  11. @rem ';
  12. #!perl
  13. #line 14
  14.     eval 'exec P:\Apps\ActivePerl\temp\bin\MSWin32-x86-object\perl.exe -S $0 ${1+"$@"}'
  15.     if $running_under_some_shell;
  16.  
  17. use Config;
  18. use strict;
  19. use FileHandle;
  20. use File::Basename qw(&basename &dirname);
  21. use Cwd;
  22.  
  23. use Getopt::Long;
  24.  
  25. $Getopt::Long::bundling_override = 1;
  26. $Getopt::Long::passthrough = 0;
  27. $Getopt::Long::ignore_case = 0;
  28.  
  29. my $options = {};
  30. my $_fh;
  31.  
  32. main();
  33.  
  34. sub main
  35. {
  36.  
  37.     GetOptions
  38.             (
  39.             $options,   "L:s",
  40.                         "I:s",
  41.                         "C:s",
  42.                         "o:s",
  43.                         "e:s",
  44.                         "regex:s",
  45.                         "verbose:s",
  46.                         "log:s",
  47.                         "argv:s",
  48.                         "gen",
  49.                         "sav",
  50.                         "run",
  51.                         "prog",
  52.                         "mod"
  53.             );
  54.  
  55.  
  56.     my $key;
  57.  
  58.     local($") = "|";
  59.  
  60.     _usage() if (!_checkopts());
  61.     push(@ARGV, _maketempfile()) if ($options->{'e'});
  62.  
  63.     _usage() if (!@ARGV);
  64.                 
  65.     my $file;
  66.     foreach $file (@ARGV)
  67.     {
  68.         _print("
  69. --------------------------------------------------------------------------------
  70. Compiling $file:
  71. --------------------------------------------------------------------------------
  72. ", 36 );
  73.         _doit($file);
  74.     }
  75. }
  76.         
  77. sub _doit
  78. {
  79.     my ($file) = @_;
  80.  
  81.     my ($program_ext, $module_ext) = _getRegexps();
  82.     my ($obj, $objfile, $so, $type);
  83.  
  84.     if  (
  85.             (($file =~ m"@$program_ext") && ($file !~ m"@$module_ext"))
  86.             || (defined($options->{'prog'}) || defined($options->{'run'}))
  87.         )
  88.     {
  89.         $objfile = ($options->{'C'}) ?     $options->{'C'} : "$file.c";
  90.         $type = 'program';
  91.  
  92.         $obj =         ($options->{'o'})?     $options->{'o'} : 
  93.                                             _getExecutable( $file,$program_ext);
  94.  
  95.         return() if (!$obj);
  96.  
  97.     }
  98.     elsif (($file =~ m"@$module_ext") || ($options->{'mod'}))
  99.     {
  100.         die "Shared objects are not supported on Win32 yet!!!!\n"
  101.                                       if ($Config{'osname'} eq 'MSWin32');
  102.  
  103.         $obj =         ($options->{'o'})?    $options->{'o'} :
  104.                                             _getExecutable($file, $module_ext);
  105.         $so = "$obj.$Config{so}";
  106.         $type = 'sharedlib';
  107.         return() if (!$obj);
  108.         $objfile = ($options->{'C'}) ?     $options->{'C'} : "$file.c";
  109.     }
  110.     else
  111.     {
  112.         _error("noextension", $file, $program_ext, $module_ext);
  113.         return();
  114.     }
  115.  
  116.     if ($type eq 'program')
  117.     {
  118.         _print("Making C($objfile) for $file!\n", 36 );
  119.  
  120.         my $errcode = _createCode($objfile, $file);
  121.         (_print( "ERROR: In generating code for $file!\n", -1), return()) 
  122.                                                                 if ($errcode);
  123.  
  124.         _print("Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
  125.         $errcode = _compileCode($file, $objfile, $obj) 
  126.                                             if (!$options->{'gen'});
  127.  
  128.         if ($errcode)
  129.         {
  130.             _print( "ERROR: In compiling code for $objfile !\n", -1);
  131.             my $ofile = File::Basename::basename($objfile);
  132.             $ofile =~ s"\.c$"\.o"s;
  133.             
  134.             _removeCode("$ofile"); 
  135.             return()
  136.         }
  137.     
  138.         _runCode($obj) if ($options->{'run'});
  139.  
  140.         _removeCode($objfile) if (!$options->{'sav'} || 
  141.                                     ($options->{'e'} && !$options->{'C'}));
  142.  
  143.         _removeCode($file) if ($options->{'e'}); 
  144.  
  145.         _removeCode($obj) if (($options->{'e'}
  146.                    && !$options->{'sav'}
  147.                    && !$options->{'o'})
  148.                   || ($options->{'run'} && !$options->{'sav'}));
  149.     }
  150.     else
  151.     {
  152.         _print( "Making C($objfile) for $file!\n", 36 );
  153.         my $errcode = _createCode($objfile, $file, $obj);
  154.         (_print( "ERROR: In generating code for $file!\n", -1), return()) 
  155.                                                                 if ($errcode);
  156.     
  157.         _print( "Compiling C($so) for $file!\n", 36 ) if (!$options->{'gen'});
  158.  
  159.         my $errorcode = 
  160.             _compileCode($file, $objfile, $obj, $so ) if (!$options->{'gen'});
  161.  
  162.         (_print( "ERROR: In compiling code for $objfile!\n", -1), return()) 
  163.                                                                 if ($errcode);
  164.     }
  165. }
  166.  
  167. sub _getExecutable
  168. {
  169.     my ($sourceprog, $ext) = @_;
  170.     my ($obj);
  171.  
  172.     if (defined($options->{'regex'}))
  173.     {
  174.         eval("(\$obj = \$sourceprog) =~ $options->{'regex'}");
  175.         return(0) if (_error('badeval', $@));
  176.         return(0) if (_error('equal', $obj, $sourceprog));
  177.     }
  178.     elsif (defined ($options->{'ext'}))
  179.     {
  180.         ($obj = $sourceprog) =~ s"@$ext"$options->{ext}"g;        
  181.         return(0) if (_error('equal', $obj, $sourceprog));
  182.     }
  183.     elsif (defined ($options->{'run'}))
  184.     {
  185.         $obj = "perlc$$";
  186.     }
  187.     else
  188.     {
  189.         ($obj = $sourceprog) =~ s"@$ext""g;
  190.         return(0) if (_error('equal', $obj, $sourceprog));
  191.     }
  192.     return($obj);
  193. }
  194.  
  195. sub _createCode
  196. {
  197.     my ( $generated_cfile, $file, $final_output ) = @_;
  198.     my $return;
  199.  
  200.     local($") = " -I";
  201.  
  202.     if (@_ == 2)                                   # compiling a program   
  203.     {
  204.         _print( "$^X -I@INC -MO=CC,-o$generated_cfile $file\n", 36);
  205.         $return =  _run("$ -I@INC -MO=CC,-o$generated_cfile $file", 9);
  206.         $return;
  207.     }
  208.     else                                           # compiling a shared object
  209.     {            
  210.         _print( 
  211.             "$ -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file\n", 36);
  212.         $return = 
  213.         _run("$ -I@INC -MO=CC,-m$final_output,-o$generated_cfile $file", 9);
  214.         $return;
  215.     }
  216. }
  217.  
  218. sub _compileCode
  219. {
  220.     my ($sourceprog, $generated_cfile, $output_executable, $shared_object) = @_;
  221.     my @return;
  222.  
  223.     if (@_ == 3)                            # just compiling a program 
  224.     {
  225.         $return[0] = 
  226.         _ccharness('static', $sourceprog, "-o", $output_executable, $generated_cfile);  
  227.         $return[0];
  228.     }
  229.     else
  230.     {
  231.         my $object_file = $generated_cfile;
  232.         $object_file =~ s"\.c$"$Config{_o}";   
  233.  
  234.         $return[0] = _ccharness('compile', $sourceprog, "-c", $generated_cfile);
  235.         $return[1] = _ccharness
  236.                             (
  237.                 'dynamic', 
  238.                                 $sourceprog, "-o", 
  239.                                 $shared_object, $object_file 
  240.                             );
  241.         return(1) if (grep ($_, @return));
  242.         return(0);
  243.     }
  244. }
  245.  
  246. sub _runCode
  247. {
  248.     my ($executable) = @_;
  249.     _print("$executable $options->{'argv'}\n", 36);
  250.     _run("$executable $options->{'argv'}", -1 );
  251. }
  252.  
  253. sub _removeCode
  254. {
  255.     my ($file) = @_;
  256.     unlink($file) if (-e $file);
  257. }
  258.  
  259. sub _ccharness
  260. {
  261.     my $type = shift;
  262.     my (@args) = @_;
  263.     local($") = " ";
  264.  
  265.     my $sourceprog = shift(@args);
  266.     my ($libdir, $incdir);
  267.  
  268.     if (-d "$Config{installarchlib}/CORE")
  269.     {
  270.         $libdir = "-L$Config{installarchlib}/CORE";
  271.         $incdir = "-I$Config{installarchlib}/CORE";
  272.     }
  273.     else
  274.     {
  275.         $libdir = "-L.. -L."; 
  276.         $incdir = "-I.. -I.";
  277.     }
  278.  
  279.     $libdir .= " -L$options->{L}" if (defined($options->{L}));
  280.     $incdir .= " -I$options->{L}" if (defined($options->{L}));
  281.  
  282.     my $linkargs = '';
  283.  
  284.     if (!grep(/^-[cS]$/, @args))
  285.     {
  286.     my $lperl = $^O eq 'os2' ? '-llibperl' : '-lperl';
  287.     my $flags = $type eq 'dynamic' ? $Config{lddlflags} : $Config{ldflags};
  288.         $linkargs = "$flags $libdir $lperl @Config{libs}";
  289.     }
  290.  
  291.     my @sharedobjects = _getSharedObjects($sourceprog); 
  292.  
  293.     my $cccmd = 
  294.         "$Config{cc} @Config{qw(ccflags optimize)} $incdir @sharedobjects @args $linkargs";
  295.  
  296.  
  297.     _print ("$cccmd\n", 36);
  298.     _run("$cccmd", 18 );
  299. }
  300.  
  301. sub _getSharedObjects
  302. {
  303.     my ($sourceprog) = @_;
  304.     my ($tmpfile, $incfile);
  305.     my (@return);
  306.     local($") = " -I";
  307.  
  308.     if ($Config{'osname'} eq 'MSWin32') 
  309.     { 
  310.         # _addstuff;    
  311.     }
  312.     else
  313.     {
  314.         my ($tmpprog);
  315.         ($tmpprog = $sourceprog) =~ s"(.*)[\/\\](.*)"$2";
  316.         $tmpfile = "/tmp/$tmpprog.tst";
  317.         $incfile = "/tmp/$tmpprog.val";
  318.     }
  319.  
  320.     my $fd = new FileHandle("> $tmpfile") || die "Couldn't open $tmpfile!\n";
  321.     my $fd2 = 
  322.         new FileHandle("$sourceprog") || die "Couldn't open $sourceprog!\n";
  323.  
  324.     my $perl = <$fd2>;  # strip off header;
  325.  
  326.     print $fd 
  327. <<"EOF";
  328.         use FileHandle;
  329.         my \$fh3  = new FileHandle("> $incfile") 
  330.                                         || die "Couldn't open $incfile\\n";
  331.  
  332.         my \$key;
  333.         foreach \$key (keys(\%INC)) { print \$fh3 "\$key:\$INC{\$key}\\n"; }
  334.         close(\$fh3);
  335.         exit();
  336. EOF
  337.  
  338.     print $fd (   <$fd2>    );
  339.     close($fd);
  340.  
  341.     _print("$ -I@INC $tmpfile\n", 36);
  342.     _run("$ -I@INC $tmpfile", 9 );
  343.  
  344.     $fd = new FileHandle ("$incfile"); 
  345.     my @lines = <$fd>;    
  346.  
  347.     unlink($tmpfile);
  348.     unlink($incfile);
  349.  
  350.     my $line;
  351.     my $autolib;
  352.  
  353.     foreach $line (@lines) 
  354.     {
  355.         chomp($line);
  356.         my ($modname, $modpath) = split(':', $line);
  357.         my ($dir, $file) = ($modpath=~ m"(.*)[\\/]($modname)");
  358.         
  359.         if ($autolib = _lookforAuto($dir, $file))
  360.         {
  361.             push(@return, $autolib);
  362.         }
  363.     }
  364.  
  365.     return(@return);
  366. }
  367.  
  368. sub _maketempfile
  369. {
  370.     my $return;
  371.  
  372. #    if ($Config{'osname'} eq 'MSWin32') 
  373. #            { $return = "C:\\TEMP\\comp$$.p"; }
  374. #    else
  375. #            { $return = "/tmp/comp$$.p"; }
  376.  
  377.     $return = "comp$$.p"; 
  378.  
  379.     my $fd = new FileHandle( "> $return") || die "Couldn't open $return!\n";
  380.     print $fd $options->{'e'};
  381.     close($fd);
  382.  
  383.     return($return);
  384. }
  385.     
  386.     
  387. sub _lookforAuto
  388. {
  389.     my ($dir, $file) = @_;    
  390.  
  391.     my $relshared;
  392.     my $return;
  393.  
  394.     ($relshared = $file) =~ s"(.*)\.pm"$1";
  395.  
  396.     my ($tmp, $modname) = ($relshared =~ m"(?:(.*)[\\/]){0,1}(.*)"s);
  397.  
  398.     $relshared .= 
  399.         ($Config{'osname'} eq 'MSWin32')? "\\$modname.dll" : "/$modname.so";
  400.     
  401.  
  402.  
  403.     if (-e ($return = "$Config{'installarchlib'}/auto/$relshared") )
  404.     {
  405.         return($return);    
  406.     }
  407.     elsif (-e ($return = "$Config{'installsitearch'}/auto/$relshared"))
  408.     {
  409.         return($return);
  410.     }
  411.     elsif (-e ($return = "$dir/arch/auto/$relshared"))
  412.     {
  413.         return($return);    
  414.     }
  415.     else
  416.     {
  417.         return(undef);
  418.     }
  419. }
  420.  
  421. sub _getRegexps    # make the appropriate regexps for making executables, 
  422. {                  # shared libs
  423.  
  424.     my ($program_ext, $module_ext) = ([],[]); 
  425.  
  426.  
  427.     @$program_ext = ($ENV{PERL_SCRIPT_EXT})? split(':', $ENV{PERL_SCRIPT_EXT}) :
  428.                                             ('.p$', '.pl$', '.bat$');
  429.  
  430.  
  431.     @$module_ext  = ($ENV{PERL_MODULE_EXT})? split(':', $ENV{PERL_MODULE_EXT}) :
  432.                                             ('.pm$');
  433.  
  434.  
  435.     _mungeRegexp( $program_ext );
  436.     _mungeRegexp( $module_ext  );    
  437.  
  438.     return($program_ext, $module_ext);
  439. }
  440.  
  441. sub _mungeRegexp
  442. {
  443.     my ($regexp) = @_;
  444.  
  445.     grep(s:(^|[^\\])\.:$1\x00\\.:g, @$regexp);
  446.     grep(s:(^|[^\x00])\\\.:$1\.:g,  @$regexp);
  447.     grep(s:\x00::g,                 @$regexp);
  448. }
  449.  
  450.  
  451. sub _error
  452. {
  453.     my ($type, @args) = @_;
  454.  
  455.     if ($type eq 'equal')
  456.     {
  457.             
  458.         if ($args[0] eq $args[1])
  459.         {
  460.             _print ("ERROR: The object file '$args[0]' does not generate a legitimate executable file! Skipping!\n", -1);
  461.             return(1);
  462.         }
  463.     }
  464.     elsif ($type eq 'badeval')
  465.     {
  466.         if ($args[0])
  467.         {
  468.             _print ("ERROR: $args[0]\n", -1);
  469.             return(1);
  470.         }
  471.     }
  472.     elsif ($type eq 'noextension')
  473.     {
  474.         my $progext = join(',', @{$args[1]});
  475.         my $modext  = join(',', @{$args[2]});
  476.  
  477.         $progext =~ s"\\""g;
  478.         $modext  =~ s"\\""g;
  479.  
  480.         $progext =~ s"\$""g;
  481.         $modext  =~ s"\$""g;
  482.  
  483.         _print 
  484.         (
  485. "
  486. ERROR: '$args[0]' does not have a proper extension! Proper extensions are:
  487.  
  488.     PROGRAM:       $progext 
  489.     SHARED OBJECT: $modext
  490.  
  491. Use the '-prog' flag to force your files to be interpreted as programs.
  492. Use the '-mod' flag to force your files to be interpreted as modules.
  493. ", -1
  494.         );
  495.         return(1);
  496.     }
  497.  
  498.     return(0);
  499. }
  500.  
  501. sub _checkopts
  502. {
  503.     my @errors;
  504.     local($") = "\n";
  505.  
  506.     if ($options->{'log'})
  507.     {
  508.         $_fh = new FileHandle(">> $options->{'log'}") || push(@errors, "ERROR: Couldn't open $options->{'log'}\n");
  509.     }
  510.  
  511.     if (($options->{'c'}) && (@ARGV > 1) && ($options->{'sav'} ))
  512.     {
  513.         push(@errors, 
  514. "ERROR: The '-sav' and '-C' options are incompatible when you have more than 
  515.        one input file! ('-C' explicitly names resulting C code, '-sav' saves it,
  516.        and hence, with more than one file, the c code will be overwritten for 
  517.        each file that you compile)\n");
  518.     }
  519.     if (($options->{'o'}) && (@ARGV > 1))
  520.     {
  521.         push(@errors, 
  522. "ERROR: The '-o' option is incompatible when you have more than one input file! 
  523.        (-o explicitly names the resulting executable, hence, with more than 
  524.        one file the names clash)\n");
  525.     }
  526.  
  527.     if ($options->{'e'} && $options->{'sav'} && !$options->{'o'} && 
  528.                                                             !$options->{'C'})
  529.     {
  530.         push(@errors, 
  531. "ERROR: You need to specify where you are going to save the resulting 
  532.        executable or C code,  when using '-sav' and '-e'. Use '-o' or '-C'.\n");
  533.     }
  534.  
  535.     if (($options->{'regex'} || $options->{'run'} || $options->{'o'}) 
  536.                                                     && $options->{'gen'})
  537.     {
  538.         push(@errors, 
  539. "ERROR: The options '-regex', '-run', and '-o' are incompatible with '-gen'. 
  540.        '-gen' says to stop at C generation, and the other three modify the 
  541.        compilation and/or running process!\n");
  542.     }
  543.  
  544.     if ($options->{'run'} && $options->{'mod'})
  545.     {
  546.         push(@errors, 
  547. "ERROR: Can't run modules that you are compiling! '-run' and '-mod' are 
  548.        incompatible!\n"); 
  549.     }
  550.  
  551.     if ($options->{'e'} && @ARGV)
  552.     {
  553.         push (@errors, 
  554. "ERROR: The option '-e' needs to be all by itself without any other 
  555.        file arguments!\n");
  556.     }
  557.     if ($options->{'e'} && !($options->{'o'} || $options->{'run'}))
  558.     {
  559.         $options->{'run'} = 1;
  560.     }
  561.  
  562.     if (!defined($options->{'verbose'})) 
  563.     { 
  564.         $options->{'verbose'} = ($options->{'log'})? 64 : 7; 
  565.     }
  566.  
  567.     my $verbose_error;
  568.  
  569.     if ($options->{'verbose'} =~ m"[^tagfcd]" && 
  570.             !( $options->{'verbose'} eq '0' || 
  571.                 ($options->{'verbose'} < 64 && $options->{'verbose'} > 0)))
  572.     {
  573.         $verbose_error = 1;
  574.         push(@errors, 
  575. "ERROR: Illegal verbosity level.  Needs to have either the letters 
  576.        't','a','g','f','c', or 'd' in it or be between 0 and 63, inclusive.\n");
  577.     }
  578.  
  579.     $options->{'verbose'} = ($options->{'verbose'} =~ m"[tagfcd]")? 
  580.                             ($options->{'verbose'} =~ m"d") * 32 +     
  581.                             ($options->{'verbose'} =~ m"c") * 16 +     
  582.                             ($options->{'verbose'} =~ m"f") * 8     +     
  583.                             ($options->{'verbose'} =~ m"t") * 4     +     
  584.                             ($options->{'verbose'} =~ m"a") * 2     +     
  585.                             ($options->{'verbose'} =~ m"g") * 1     
  586.                                                     : $options->{'verbose'};
  587.  
  588.     if     (!$verbose_error && (    $options->{'log'} && 
  589.                                 !(
  590.                                     ($options->{'verbose'} & 8)   || 
  591.                                     ($options->{'verbose'} & 16)  || 
  592.                                     ($options->{'verbose'} & 32 ) 
  593.                                 )
  594.                             )
  595.         )
  596.     {
  597.         push(@errors, 
  598. "ERROR: The verbosity level '$options->{'verbose'}' does not output anything 
  599.        to a logfile, and you specified '-log'!\n");
  600.     } # }
  601.  
  602.     if     (!$verbose_error && (    !$options->{'log'} && 
  603.                                 (
  604.                                     ($options->{'verbose'} & 8)   || 
  605.                                     ($options->{'verbose'} & 16)  || 
  606.                                     ($options->{'verbose'} & 32)  || 
  607.                                     ($options->{'verbose'} & 64)
  608.                                 )
  609.                             )
  610.         )
  611.     {
  612.         push(@errors, 
  613. "ERROR: The verbosity level '$options->{'verbose'}' requires that you also 
  614.        specify a logfile via '-log'\n");
  615.     } # }
  616.  
  617.  
  618.     (_print( "\n". join("\n", @errors), -1), return(0)) if (@errors);
  619.     return(1);
  620. }
  621.  
  622. sub _print
  623. {
  624.     my ($text, $flag ) = @_;
  625.     
  626.     my $logflag = int($flag/8) * 8;
  627.     my $regflag = $flag % 8;
  628.  
  629.     if ($flag == -1 || ($flag & $options->{'verbose'}))
  630.     {
  631.         my $dolog = ((($logflag & $options->{'verbose'}) || $flag == -1) 
  632.                                                         && $options->{'log'}); 
  633.  
  634.         my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1);
  635.         
  636.         if ($doreg) { print( STDERR $text ); }
  637.         if ($dolog) { print $_fh $text; }
  638.     }
  639. }
  640.  
  641. sub _run
  642. {
  643.     my ($command, $flag) = @_;
  644.  
  645.     my $logflag = ($flag != -1)? int($flag/8) * 8 : 0;
  646.     my $regflag = $flag % 8;
  647.  
  648.     if ($flag == -1 || ($flag & $options->{'verbose'}))
  649.     {
  650.         my $dolog = ($logflag & $options->{'verbose'} && $options->{'log'});
  651.         my $doreg = (($regflag & $options->{'verbose'}) || $flag == -1);
  652.  
  653.         if ($doreg && !$dolog) 
  654.             { system("$command"); }
  655.  
  656.         elsif ($doreg && $dolog) 
  657.             { my $text = `$command 2>&1`; print $_fh $text; print STDERR $text;}
  658.         else 
  659.             { my $text = `$command 2>&1`; print $_fh $text; }
  660.     }
  661.     else 
  662.     {
  663.         `$command 2>&1`; 
  664.     }
  665.     return($?);
  666. }
  667.  
  668. sub _usage
  669. {
  670.     _print
  671.     ( 
  672.     <<"EOF"
  673.  
  674. Usage: $0 <file_list> 
  675.  
  676.     Flags with arguments
  677.         -L       < extra library dirs for installation (form of 'dir1:dir2') >
  678.         -I       < extra include dirs for installation (form of 'dir1:dir2') >
  679.         -C       < explicit name of resulting C code > 
  680.         -o       < explicit name of resulting executable >
  681.         -e       < to compile 'one liners'. Need executable name (-o) or '-run'>
  682.         -regex   < rename regex, -regex 's/\.p/\.exe/' compiles a.p to a.exe >
  683.         -verbose < verbose level (1-63, or following letters 'gatfcd' >
  684.         -argv    < arguments for the executables to be run via '-run' or '-e' > 
  685.  
  686.     Boolean flags
  687.         -gen     ( to just generate the c code. Implies '-sav' )
  688.         -sav     ( to save intermediate c code, (and executables with '-run'))
  689.         -run     ( to run the compiled program on the fly, as were interpreted.)
  690.         -prog    ( to indicate that the files on command line are programs )
  691.         -mod     ( to indicate that the files on command line are modules  )
  692.  
  693. EOF
  694. , -1
  695.  
  696.     );
  697.     exit(255);
  698. }
  699.  
  700.  
  701. __END__
  702.  
  703. =head1 NAME
  704.  
  705. perlcc - frontend for perl compiler
  706.  
  707. =head1 SYNOPSIS
  708.  
  709.     %prompt  perlcc a.p        # compiles into executable 'a'
  710.  
  711.     %prompt  perlcc A.pm       # compile into 'A.so'
  712.  
  713.     %prompt  perlcc a.p -o execute  # compiles 'a.p' into 'execute'.
  714.  
  715.     %prompt  perlcc a.p -o execute -run # compiles 'a.p' into execute, runs on
  716.                                         # the fly
  717.  
  718.     %prompt  perlcc a.p -o execute -run -argv 'arg1 arg2 arg3' 
  719.                                         # compiles into execute, runs with 
  720.                                         # arg1 arg2 arg3 as @ARGV
  721.  
  722.     %prompt perlcc a.p b.p c.p -regex 's/\.p/\.exe'
  723.                                         # compiles into 'a.exe','b.exe','c.exe'.
  724.  
  725.     %prompt perlcc a.p -log compilelog  # compiles into 'a', saves compilation
  726.                                         # info into compilelog, as well
  727.                                         # as mirroring to screen
  728.  
  729.     %prompt perlcc a.p -log compilelog -verbose cdf 
  730.                                         # compiles into 'a', saves compilation
  731.                                         # info into compilelog, being silent
  732.                                         # on screen.
  733.  
  734.     %prompt perlcc a.p -C a.c -gen      # generates C code (into a.c) and 
  735.                                         # stops without compile.
  736.  
  737.     %prompt perlcc a.p -L ../lib a.c 
  738.                                         # Compiles with the perl libraries 
  739.                                         # inside ../lib included.
  740.  
  741. =head1 DESCRIPTION
  742.  
  743. 'perlcc' is the frontend into the perl compiler. Typing 'perlcc a.p'
  744. compiles the code inside a.p into a standalone executable, and 
  745. perlcc A.pm will compile into a shared object, A.so, suitable for inclusion 
  746. into a perl program via "use A".
  747.  
  748. There are quite a few flags to perlcc which help with such issues as compiling 
  749. programs in bulk, testing compiled programs for compatibility with the 
  750. interpreter, and controlling.
  751.  
  752. =head1 OPTIONS 
  753.  
  754. =over 4
  755.  
  756. =item -L < library_directories >
  757.  
  758. Adds directories in B<library_directories> to the compilation command.
  759.  
  760. =item -I  < include_directories > 
  761.  
  762. Adds directories inside B<include_directories> to the compilation command.
  763.  
  764. =item -C   < c_code_name > 
  765.  
  766. Explicitly gives the name B<c_code_name> to the generated c code which is to 
  767. be compiled. Can only be used if compiling one file on the command line.
  768.  
  769. =item -o   < executable_name >
  770.  
  771. Explicitly gives the name B<executable_name> to the executable which is to be
  772. compiled. Can only be used if compiling one file on the command line.
  773.  
  774. =item -e   < perl_line_to_execute>
  775.  
  776. Compiles 'one liners', in the same way that B<perl -e> runs text strings at 
  777. the command line. Default is to have the 'one liner' be compiled, and run all
  778. in one go (see B<-run>); giving the B<-o> flag saves the resultant executable, 
  779. rather than throwing it away. Use '-argv' to pass arguments to the executable
  780. created.
  781.  
  782. =item -regex   <rename_regex>
  783.  
  784. Gives a rule B<rename_regex> - which is a legal perl regular expression - to 
  785. create executable file names.
  786.  
  787. =item -verbose <verbose_level>
  788.  
  789. Show exactly what steps perlcc is taking to compile your code. You can change 
  790. the verbosity level B<verbose_level> much in the same way that the '-D' switch 
  791. changes perl's debugging level, by giving either a number which is the sum of 
  792. bits you want or a list of letters representing what you wish to see. Here are 
  793. the verbosity levels so far :
  794.  
  795.     Bit 1(g):      Code Generation Errors to STDERR
  796.     Bit 2(a):      Compilation Errors to STDERR
  797.     Bit 4(t):      Descriptive text to STDERR 
  798.     Bit 8(f):      Code Generation Errors to file (B<-log> flag needed)
  799.     Bit 16(c):     Compilation Errors to file (B<-log> flag needed)
  800.     Bit 32(d):     Descriptive text to file (B<-log> flag needed) 
  801.  
  802. If the B<-log> tag is given, the default verbose level is 63 (ie: mirroring 
  803. all of perlcc's output to both the screen and to a log file). If no B<-log>
  804. tag is given, then the default verbose level is 7 (ie: outputting all of 
  805. perlcc's output to STDERR).
  806.  
  807. NOTE: Because of buffering concerns, you CANNOT shadow the output of '-run' to
  808. both a file, and to the screen! Suggestions are welcome on how to overcome this
  809. difficulty, but for now it simply does not work properly, and hence will only go
  810. to the screen.
  811.  
  812. =item -log <logname>
  813.  
  814. Opens, for append, a logfile to save some or all of the text for a given 
  815. compile command. No rewrite version is available, so this needs to be done 
  816. manually.
  817.  
  818. =item -argv <arguments>
  819.  
  820. In combination with '-run' or '-e', tells perlcc to run the resulting 
  821. executable with the string B<arguments> as @ARGV.
  822.  
  823. =item -sav
  824.  
  825. Tells perl to save the intermediate C code. Usually, this C code is the name
  826. of the perl code, plus '.c'; 'perlcode.p' gets generated in 'perlcode.p.c',
  827. for example. If used with the '-e' operator, you need to tell perlcc where to 
  828. save resulting executables.
  829.  
  830. =item -gen
  831.  
  832. Tells perlcc to only create the intermediate C code, and not compile the 
  833. results. Does an implicit B<-sav>, saving the C code rather than deleting it.
  834.  
  835. =item -run
  836.  
  837. Immediately run the perl code that has been generated. NOTE: IF YOU GIVE THE 
  838. B<-run> FLAG TO B<perlcc>, THEN THE REST OF @ARGV WILL BE INTERPRETED AS 
  839. ARGUMENTS TO THE PROGRAM THAT YOU ARE COMPILING.
  840.  
  841. =item -prog
  842.  
  843. Indicate that the programs at the command line are programs, and should be
  844. compiled as such. B<perlcc> will automatically determine files to be 
  845. programs if they have B<.p>, B<.pl>, B<.bat> extensions.
  846.  
  847. =item -mod
  848.  
  849. Indicate that the programs at the command line are modules, and should be
  850. compiled as such. B<perlcc> will automatically determine files to be 
  851. modules if they have the extension B<.pm>.
  852.  
  853. =back
  854.  
  855. =head1 ENVIRONMENT
  856.  
  857. Most of the work of B<perlcc> is done at the command line. However, you can 
  858. change the heuristic which determines what is a module and what is a program.
  859. As indicated above, B<perlcc> assumes that the extensions:
  860.  
  861. .p$, .pl$, and .bat$
  862.  
  863. indicate a perl program, and:
  864.  
  865. .pm$
  866.  
  867. indicate a library, for the purposes of creating executables. And furthermore,
  868. by default, these extensions will be replaced (and dropped ) in the process of 
  869. creating an executable. 
  870.  
  871. To change the extensions which are programs, and which are modules, set the
  872. environmental variables:
  873.  
  874. PERL_SCRIPT_EXT
  875. PERL_MODULE_EXT
  876.  
  877. These two environmental variables take colon-separated, legal perl regular 
  878. expressions, and are used by perlcc to decide which objects are which. 
  879. For example:
  880.  
  881. setenv PERL_SCRIPT_EXT  '.prl$:.perl$'
  882. prompt%   perlcc sample.perl
  883.  
  884. will compile the script 'sample.perl' into the executable 'sample', and
  885.  
  886. setenv PERL_MODULE_EXT  '.perlmod$:.perlmodule$'
  887.  
  888. prompt%   perlcc sample.perlmod
  889.  
  890. will  compile the module 'sample.perlmod' into the shared object 
  891. 'sample.so'
  892.  
  893. NOTE: the '.' in the regular expressions for PERL_SCRIPT_EXT and PERL_MODULE_EXT
  894. is a literal '.', and not a wild-card. To get a true wild-card, you need to 
  895. backslash the '.'; as in:
  896.  
  897. setenv PERL_SCRIPT_EXT '\.\.\.\.\.'
  898.  
  899. which would have the effect of compiling ANYTHING (except what is in 
  900. PERL_MODULE_EXT) into an executable with 5 less characters in its name.
  901.  
  902. =head1 FILES
  903.  
  904. 'perlcc' uses a temporary file when you use the B<-e> option to evaluate 
  905. text and compile it. This temporary file is 'perlc$$.p'. The temporary C code is
  906. perlc$$.p.c, and the temporary executable is perlc$$.
  907.  
  908. When you use '-run' and don't save your executable, the temporary executable is
  909. perlc$$
  910.  
  911. =head1 BUGS
  912.  
  913. perlcc currently cannot compile shared objects on Win32. This should be fixed
  914. by perl5.005.
  915.  
  916. =cut
  917.  
  918. __END__
  919. :endofperl
  920.