Commit | Line | Data |
7a958ec3 |
1 | # genmk95.pl - uses miniperl to generate a makefile that command.com will |
2 | # understand given one that cmd.exe will understand |
8ec44883 |
3 | |
4 | # Author: Benjamin K. Stuhl |
7a958ec3 |
5 | # Date: 10-16-1999 |
8ec44883 |
6 | |
7 | # how it works: |
8 | # dmake supports an alternative form for its recipes, called "group |
7a958ec3 |
9 | # recipes", in which all elements of a recipe are run with only one shell. |
10 | # This program converts the standard dmake makefile.mk to one using group |
11 | # recipes. This is done so that lines using && or || (which command.com |
12 | # doesn't understand) may be split into two lines that will still be run |
13 | # with one shell. |
8ec44883 |
14 | |
15 | my ($filein, $fileout) = @ARGV; |
16 | |
7a958ec3 |
17 | open my $in, $filein or die "Error opening input file: $!\n"; |
18 | open my $out, "> $fileout" or die "Error opening output file: $!\n"; |
8ec44883 |
19 | |
20 | print $out <<_EOH_; |
21 | # *** Warning: this file is autogenerated from $filein by $0 *** |
22 | # *** Do not edit this file - edit $filein instead *** |
23 | |
7a958ec3 |
24 | _HOME_DIR := \$(PWD) |
25 | |
8ec44883 |
26 | _EOH_ |
27 | |
28 | my $inrec = 0; |
29 | |
30 | while (<$in>) |
31 | { |
32 | chomp; |
7a958ec3 |
33 | if (/^[^#.\t][^#=]*?:(?:[^=]|$)/) |
8ec44883 |
34 | { |
35 | if (! $inrec) |
36 | { |
37 | print $out "$_\n"; |
7a958ec3 |
38 | while (/\\\s*$/) |
8ec44883 |
39 | { |
40 | chomp($_ = <$in>); |
41 | print $out "$_\n"; |
42 | } |
43 | print $out "@[\n"; |
44 | $inrec = 1; |
45 | next; |
46 | } |
47 | else { |
5db10396 |
48 | if (!/^\t/) { |
49 | seek ($out, -4, 2); # no recipe, so back up and undo grouping |
50 | # should be -3, but MS has its CR/LF thing... |
51 | $inrec = 0; |
52 | } |
8ec44883 |
53 | print $out "$_\n"; |
8ec44883 |
54 | next; |
55 | } |
56 | } |
57 | if ((/^\s*$/ || /^[^#.\t][^#=]*?:/) && $inrec) |
58 | { |
59 | print $out "]\n"; |
60 | print $out "$_\n"; |
61 | $inrec = 0; |
62 | next; |
63 | } |
64 | if (/^(.*?)(&&|\|\|)(.*)$/) # two commands separated by && or || |
65 | { |
66 | my ($one, $sep, $two) = ($1, $2, $3); |
ab5f7a04 |
67 | $one =~ s/^\t(?:-(?!-))?\@?(.*?)$/\t$1/; # no -,@ in group recipes |
8ec44883 |
68 | LINE_CONT: |
69 | if ($two =~ /\\\s*$/) |
70 | { |
71 | chomp ($two .= "\n" . scalar <$in>); |
72 | goto LINE_CONT; |
73 | } |
74 | s/^\s*// for ($one, $two); |
75 | print $out "\t$one\n\t$two\n" if ($sep eq "&&"); |
76 | print $out "\t$one\n\tif errorlevel 1 $two\n" if ($sep eq "||"); |
7a958ec3 |
77 | print $out "\tcd \$(_HOME_DIR)\n"; |
8ec44883 |
78 | next; |
79 | } |
80 | # fall through - no need for special handling |
ab5f7a04 |
81 | s/^\t(?:-(?!-))?\@?(.*?)$/\t$1/; # no -,@ in group recipes |
8ec44883 |
82 | print $out "$_\n"; |
83 | } |
84 | print $out "]\n" if ($inrec); |
85 | |
7a958ec3 |
86 | close $in or warn "Error closing \$in: $!\n"; |
87 | close $out or warn "Error closing \$out: $!\n"; |