Commit | Line | Data |
a0d0e21e |
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 | |
20 | if ($#ARGV > -1 && $ARGV[0] =~ /^[\-\/]trim/i) { |
21 | $do_trim = 1; |
22 | shift @ARGV; |
23 | } |
24 | $infile = $#ARGV > -1 ? shift(@ARGV) : "Descrip.MMS"; |
25 | $outfile = $#ARGV > -1 ? shift(@ARGV) : "Makefile."; |
26 | |
27 | # set any other args in %macros - set VAXC by default |
28 | foreach (@ARGV) { $macros{"\U$_"}=1 } |
29 | |
30 | # consistency check |
31 | $macros{"DECC"} = 1 if $macros{"__AXP__"}; |
32 | |
33 | # set conditions as if there was a .if 1 around whole file |
34 | # [lazy - saves having to check for empty array - just test [0]==1] |
35 | @conditions = (1); |
36 | |
37 | open(INFIL,$infile) || die "Can't open $infile: $!\n"; |
38 | open(OUTFIL,">$outfile") || die "Can't open $outfile: $!\n"; |
39 | |
40 | print OUTFIL "#> This file produced from $infile by $0\n"; |
41 | print OUTFIL "#> Lines beginning with \"#>\" were commented out during the\n"; |
42 | print OUTFIL "#> conversion process. For more information, see $0\n"; |
43 | print OUTFIL "#>\n"; |
44 | |
45 | while (<INFIL>) { |
46 | s/$infile/$outfile/eoi; |
47 | if (/^\#/) { |
48 | if (!/^\#\:/) {print OUTFIL;} |
49 | next; |
50 | } |
51 | |
52 | # look for ".ifdef macro" and push 1 or 0 to head of @conditions |
53 | # push 0 if we are in false branch of another if |
54 | if (/^\.ifdef\s*(.+)/i) |
55 | { |
56 | print OUTFIL "#> ",$_ unless $do_trim; |
57 | unshift @conditions, ($macros{"\U$1"} ? $conditions[0] : 0); |
58 | next; |
59 | } |
60 | |
61 | # reverse $conditions[0] for .else provided surrounding if is active |
62 | if (/^\.else/i) |
63 | { |
64 | print OUTFIL "#> ",$_ unless $do_trim; |
65 | $conditions[0] = $conditions[1] && !$conditions[0]; |
66 | next; |
67 | } |
68 | |
69 | # pop top condition for .endif |
70 | if (/^\.endif/i) |
71 | { |
72 | print OUTFIL "#> ",$_ unless $do_trim; |
73 | shift @conditions; |
74 | next; |
75 | } |
76 | |
77 | next if ($do_trim && !$conditions[0]); |
78 | |
79 | # spot new rule and pick up first source file, since some versions of |
80 | # Make don't provide a macro for this |
81 | if (/[^#!]*:\s+/) { |
82 | if (/:\s+([^\s,]+)/) { $firstsrc = $1 } |
83 | else { $firstsrc = "\$<" } |
84 | } |
85 | |
86 | s/^ +/\t/; |
87 | s/^\.first/\.first:/i; |
88 | s/^\.suffixes/\.suffixes:/i; |
89 | s/\@\[\.vms\]/\$\$\@\[\.vms\]/; |
90 | s/f\$/f\$\$/goi; |
91 | s/\$\(mms\$source\)/$firstsrc/i; |
92 | s/\$\(mms\$target\)/\$\@/i; |
93 | s/\$\(mms\$target_name\)\$\(O\)/\$\@/i; |
94 | s/\$\(mms\$target_name\)/\$\*/i; |
95 | s/sys\$([^\(])/sys\$\$$1/gi; |
96 | print OUTFIL "#> " unless $conditions[0]; |
97 | print OUTFIL $_; |
98 | } |
99 | |
100 | close INFIL; |
101 | close OUTFIL; |
102 | |