home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / perl / Perl / vms / mms2make.pl < prev    next >
Perl Script  |  1995-03-06  |  4KB  |  121 lines

  1. #!/usr/bin/perl
  2. #
  3. #  mms2make.pl - convert Descrip.MMS file to Makefile
  4. #  Version 2.0 29-Sep-1994
  5. #  David Denholm <denholm@conmat.phys.soton.ac.uk>
  6. #
  7. #  1.0  06-Aug-1994  Charles Bailey  bailey@genetics.upenn.edu
  8. #    - original version
  9. #  2.0  29-Sep-1994  David Denholm <denholm@conmat.phys.soton.ac.uk>
  10. #    - take action based on MMS .if / .else / .endif
  11. #      any command line options after filenames are set in an assoc array %macros
  12. #      maintain "@condition as a stack of current conditions
  13. #      we unshift a 0 or 1 to front of @conditions at an .ifdef
  14. #      we invert top of stack at a .else
  15. #      we pop at a .endif
  16. #      we deselect any other line if $conditions[0] is 0
  17. #      I'm being very lazy - push a 1 at start, then dont need to check for
  18. #      an empty @conditions [assume nesting in descrip.mms is correct] 
  19. #  2.1  26-Feb-1995  Charles Bailey  bailey@genetics.upenn.edu
  20. #    - handle MMS macros generated by MakeMaker
  21.  
  22. if ($#ARGV > -1 && $ARGV[0] =~ /^[\-\/]trim/i) {
  23.   $do_trim = 1;
  24.   shift @ARGV;
  25. }
  26. $infile  = $#ARGV > -1 ? shift(@ARGV) : "Descrip.MMS";
  27. $outfile = $#ARGV > -1 ? shift(@ARGV) : "Makefile.";
  28.  
  29. # set any other args in %macros - set VAXC by default
  30. foreach (@ARGV) { $macros{"\U$_"}=1 }
  31.  
  32. # consistency check
  33. $macros{"DECC"} = 1 if $macros{"__AXP__"};
  34.  
  35. # set conditions as if there was a .if 1  around whole file
  36. # [lazy - saves having to check for empty array - just test [0]==1]
  37. @conditions = (1);
  38.  
  39. open(INFIL,$infile) || die "Can't open $infile: $!\n"; 
  40. open(OUTFIL,">$outfile") || die "Can't open $outfile: $!\n"; 
  41.  
  42. print OUTFIL "#> This file produced from $infile by $0\n";
  43. print OUTFIL "#> Lines beginning with \"#>\" were commented out during the\n";
  44. print OUTFIL "#> conversion process.  For more information, see $0\n";
  45. print OUTFIL "#>\n";
  46.  
  47. while (<INFIL>) {
  48.   s/$infile/$outfile/eoi;
  49.   if (/^\#/) { 
  50.     if (!/^\#\:/) {print OUTFIL;}
  51.     next;
  52.   }
  53.  
  54. # look for ".ifdef macro" and push 1 or 0 to head of @conditions
  55. # push 0 if we are in false branch of another if
  56.   if (/^\.ifdef\s*(.+)/i)
  57.   {
  58.      print OUTFIL "#> ",$_ unless $do_trim;
  59.      unshift @conditions, ($macros{"\U$1"} ? $conditions[0] : 0);
  60.      next;
  61.   }
  62.  
  63. # reverse $conditions[0] for .else provided surrounding if is active
  64.   if (/^\.else/i)
  65.   {
  66.       print OUTFIL "#> ",$_ unless $do_trim;
  67.       $conditions[0] = $conditions[1] && !$conditions[0];
  68.       next;
  69.   }
  70.  
  71. # pop top condition for .endif
  72.   if (/^\.endif/i)
  73.   {
  74.      print OUTFIL "#> ",$_ unless $do_trim;
  75.      shift @conditions;
  76.      next;
  77.   }
  78.  
  79.   next if ($do_trim && !$conditions[0]);
  80.  
  81. # spot new rule and pick up first source file, since some versions of
  82. # Make don't provide a macro for this
  83.   if (/[^#!]*:\s+/) {
  84.     if (/:\s+([^\s,]+)/) { $firstsrc = $1 }
  85.     else { $firstsrc = "\$<" }
  86.   }
  87.  
  88. #convert macros we expect to see in MakeMaker-generated Descrip.MMSs
  89.   s#/Descrip=\s*\n#-f \nMMS = make\n#;
  90.   s#/Macro=\(# #;
  91.   s#MACROEND = \)#MACROEND = #;
  92.   if (m#\$\(USEMACROS\)(.*)(\$\(MACROEND\))?#) {
  93.     while (1) {
  94.       my($macros,$end) = ($1,$2);
  95.       $macros =~ s/,/ /g;  # We're hosed if there're commas within a macro -
  96.                            # someday, check for "" and skip contents
  97.       last if $end;
  98.       print OUTFIL $conditions[0] ? "#> " : "",$_;
  99.       $_ = <INFIL>;
  100.       m#(.*)(\$\(MACROEND\))?#;
  101.     }
  102.   }
  103.  
  104.   s/^ +/\t/;
  105.   s/^\.first/\.first:/i;
  106.   s/^\.suffixes/\.suffixes:/i;
  107.   s/\@\[\.vms\]/\$\$\@\[\.vms\]/;
  108.   s/f\$/f\$\$/goi;
  109.   s/\$\(mms\$source\)/$firstsrc/i;
  110.   s/\$\(mms\$target\)/\$\@/i;
  111.   s/\$\(mms\$target_name\)\$\(O\)/\$\@/i;
  112.   s/\$\(mms\$target_name\)/\$\*/i;
  113.   s/sys\$([^\(])/sys\$\$$1/gi;
  114.   print OUTFIL "#> " unless $conditions[0];
  115.   print OUTFIL $_;
  116. }
  117.  
  118. close INFIL;
  119. close OUTFIL;
  120.  
  121.