chiark / gitweb /
This repository needs to have a copy of mkfiles.pl, although really
[sgt-puzzles.git] / mkfiles.pl
1 #!/usr/bin/env perl
2 #
3 # Cross-platform Makefile generator.
4 #
5 # Reads the file `Recipe' to determine the list of generated
6 # executables and their component objects. Then reads the source
7 # files to compute #include dependencies. Finally, writes out the
8 # various target Makefiles.
9
10 # PuTTY specifics which could still do with removing:
11 #  - Mac makefile is not portabilised at all. Include directories
12 #    are hardwired, and also the libraries are fixed. This is
13 #    mainly because I was too scared to go anywhere near it.
14 #  - sbcsgen.pl is still run at startup.
15
16 use FileHandle;
17 use Cwd;
18
19 open IN, "Recipe" or do {
20     # We want to deal correctly with being run from one of the
21     # subdirs in the source tree. So if we can't find Recipe here,
22     # try one level up.
23     chdir "..";
24     open IN, "Recipe" or die "unable to open Recipe file\n";
25 };
26
27 # HACK: One of the source files in `charset' is auto-generated by
28 # sbcsgen.pl. We need to generate that _now_, before attempting
29 # dependency analysis.
30 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
31
32 @srcdirs = ("./");
33
34 $divert = undef; # ref to scalar in which text is currently being put
35 $help = ""; # list of newline-free lines of help text
36 $project_name = "project"; # this is a good enough default
37 %makefiles = (); # maps makefile types to output makefile pathnames
38 %makefile_extra = (); # maps makefile types to extra Makefile text
39 %programs = (); # maps prog name + type letter to listref of objects/resources
40 %groups = (); # maps group name to listref of objects/resources
41
42 while (<IN>) {
43   # Skip comments (unless the comments belong, for example because
44   # they're part of a diversion).
45   next if /^\s*#/ and !defined $divert;
46
47   chomp;
48   split;
49   if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
50   if ($_[0] eq "!end") { $divert = undef; next; }
51   if ($_[0] eq "!name") { $project_name = $_[1]; next; }
52   if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
53   if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
54   if ($_[0] eq "!begin") {
55       if (&mfval($_[1])) {
56           $divert = \$makefile_extra{$_[1]};
57       } else {
58           $divert = \$dummy;
59       }
60       next;
61   }
62   # If we're gathering help text, keep doing so.
63   if (defined $divert) { ${$divert} .= "$_\n"; next; }
64   # Ignore blank lines.
65   next if scalar @_ == 0;
66
67   # Now we have an ordinary line. See if it's an = line, a : line
68   # or a + line.
69   @objs = @_;
70
71   if ($_[0] eq "+") {
72     $listref = $lastlistref;
73     $prog = undef;
74     die "$.: unexpected + line\n" if !defined $lastlistref;
75   } elsif ($_[1] eq "=") {
76     $groups{$_[0]} = [] if !defined $groups{$_[0]};
77     $listref = $groups{$_[0]};
78     $prog = undef;
79     shift @objs; # eat the group name
80   } elsif ($_[1] eq ":") {
81     $listref = [];
82     $prog = $_[0];
83     shift @objs; # eat the program name
84   } else {
85     die "$.: unrecognised line type\n";
86   }
87   shift @objs; # eat the +, the = or the :
88
89   while (scalar @objs > 0) {
90     $i = shift @objs;
91     if ($groups{$i}) {
92       foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
93     } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
94               $i eq "[X]" or $i eq "[U]") and defined $prog) {
95       $type = substr($i,1,1);
96     } else {
97       push @$listref, $i;
98     }
99   }
100   if ($prog and $type) {
101     die "multiple program entries for $prog [$type]\n"
102         if defined $programs{$prog . "," . $type};
103     $programs{$prog . "," . $type} = $listref;
104   }
105   $lastlistref = $listref;
106 }
107
108 close IN;
109
110 # Now retrieve the complete list of objects and resource files, and
111 # construct dependency data for them. While we're here, expand the
112 # object list for each program, and complain if its type isn't set.
113 @prognames = sort keys %programs;
114 %depends = ();
115 @scanlist = ();
116 foreach $i (@prognames) {
117   ($prog, $type) = split ",", $i;
118   # Strip duplicate object names.
119   $prev = undef;
120   @list = grep { $status = ($prev ne $_); $prev=$_; $status }
121           sort @{$programs{$i}};
122   $programs{$i} = [@list];
123   foreach $j (@list) {
124     # Dependencies for "x" start with "x.c".
125     # Dependencies for "x.res" start with "x.rc".
126     # Dependencies for "x.rsrc" start with "x.r".
127     # Both types of file are pushed on the list of files to scan.
128     # Libraries (.lib) don't have dependencies at all.
129     if ($j =~ /^(.*)\.res$/) {
130       $file = "$1.rc";
131       $depends{$j} = [$file];
132       push @scanlist, $file;
133     } elsif ($j =~ /^(.*)\.rsrc$/) {
134       $file = "$1.r";
135       $depends{$j} = [$file];
136       push @scanlist, $file;
137     } elsif ($j =~ /\.lib$/) {
138       # libraries don't have dependencies
139     } else {
140       $file = "$j.c";
141       $depends{$j} = [$file];
142       push @scanlist, $file;
143     }
144   }
145 }
146
147 # Scan each file on @scanlist and find further inclusions.
148 # Inclusions are given by lines of the form `#include "otherfile"'
149 # (system headers are automatically ignored by this because they'll
150 # be given in angle brackets). Files included by this method are
151 # added back on to @scanlist to be scanned in turn (if not already
152 # done).
153 #
154 # Resource scripts (.rc) can also include a file by means of a line
155 # ending `ICON "filename"'. Files included by this method are not
156 # added to @scanlist because they can never include further files.
157 #
158 # In this pass we write out a hash %further which maps a source
159 # file name into a listref containing further source file names.
160
161 %further = ();
162 while (scalar @scanlist > 0) {
163   $file = shift @scanlist;
164   next if defined $further{$file}; # skip if we've already done it
165   $resource = ($file =~ /\.rc$/ ? 1 : 0);
166   $further{$file} = [];
167   $dirfile = &findfile($file);
168   open IN, "$dirfile" or die "unable to open source file $file\n";
169   while (<IN>) {
170     chomp;
171     /^\s*#include\s+\"([^\"]+)\"/ and do {
172       push @{$further{$file}}, $1;
173       push @scanlist, $1;
174       next;
175     };
176     /ICON\s+\"([^\"]+)\"\s*$/ and do {
177       push @{$further{$file}}, $1;
178       next;
179     }
180   }
181   close IN;
182 }
183
184 # Now we're ready to generate the final dependencies section. For
185 # each key in %depends, we must expand the dependencies list by
186 # iteratively adding entries from %further.
187 foreach $i (keys %depends) {
188   %dep = ();
189   @scanlist = @{$depends{$i}};
190   foreach $i (@scanlist) { $dep{$i} = 1; }
191   while (scalar @scanlist > 0) {
192     $file = shift @scanlist;
193     foreach $j (@{$further{$file}}) {
194       if ($dep{$j} != 1) {
195         $dep{$j} = 1;
196         push @{$depends{$i}}, $j;
197         push @scanlist, $j;
198       }
199     }
200   }
201 #  printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
202 }
203
204 # Validation of input.
205
206 sub mfval($) {
207     my ($type) = @_;
208     # Returns true if the argument is a known makefile type. Otherwise,
209     # prints a warning and returns false;
210     if (grep { $type eq $_ }
211         ("vc","vcproj","cygwin","borland","lcc","gtk","mpw")) {
212             return 1;
213         }
214     warn "$.:unknown makefile type '$type'\n";
215     return 0;
216 }
217
218 # Utility routines while writing out the Makefiles.
219
220 sub dirpfx {
221     my ($path) = shift @_;
222     my ($sep) = shift @_;
223     my $ret = "", $i;
224     while (($i = index $path, $sep) >= 0) {
225         $path = substr $path, ($i + length $sep);
226         $ret .= "..$sep";
227     }
228     return $ret;
229 }
230
231 sub findfile {
232   my ($name) = @_;
233   my $dir, $i, $outdir = "";
234   unless (defined $findfilecache{$name}) {
235     $i = 0;
236     foreach $dir (@srcdirs) {
237       $outdir = $dir, $i++ if -f "$dir$name";
238     }
239     die "multiple instances of source file $name\n" if $i > 1;
240     $findfilecache{$name} = $outdir . $name;
241   }
242   return $findfilecache{$name};
243 }
244
245 sub objects {
246   my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
247   my @ret;
248   my ($i, $x, $y);
249   @ret = ();
250   foreach $i (@{$programs{$prog}}) {
251     $x = "";
252     if ($i =~ /^(.*)\.(res|rsrc)/) {
253       $y = $1;
254       ($x = $rtmpl) =~ s/X/$y/;
255     } elsif ($i =~ /^(.*)\.lib/) {
256       $y = $1;
257       ($x = $ltmpl) =~ s/X/$y/;
258     } else {
259       ($x = $otmpl) =~ s/X/$i/;
260     }
261     push @ret, $x if $x ne "";
262   }
263   return join " ", @ret;
264 }
265
266 sub splitline {
267   my ($line, $width, $splitchar) = @_;
268   my ($result, $len);
269   $len = (defined $width ? $width : 76);
270   $splitchar = (defined $splitchar ? $splitchar : '\\');
271   while (length $line > $len) {
272     $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
273     $result .= $1 . " ${splitchar}\n\t\t";
274     $line = $2;
275     $len = 60;
276   }
277   return $result . $line;
278 }
279
280 sub deps {
281   my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
282   my ($i, $x, $y);
283   my @deps, @ret;
284   @ret = ();
285   $depchar ||= ':';
286   foreach $i (sort keys %depends) {
287     if ($i =~ /^(.*)\.(res|rsrc)/) {
288       next if !defined $rtmpl;
289       $y = $1;
290       ($x = $rtmpl) =~ s/X/$y/;
291     } else {
292       ($x = $otmpl) =~ s/X/$i/;
293     }
294     @deps = @{$depends{$i}};
295     @deps = map {
296       $_ = &findfile($_);
297       s/\//$dirsep/g;
298       $_ = $prefix . $_;
299     } @deps;
300     push @ret, {obj => $x, deps => [@deps]};
301   }
302   return @ret;
303 }
304
305 sub prognames {
306   my ($types) = @_;
307   my ($n, $prog, $type);
308   my @ret;
309   @ret = ();
310   foreach $n (@prognames) {
311     ($prog, $type) = split ",", $n;
312     push @ret, $n if index($types, $type) >= 0;
313   }
314   return @ret;
315 }
316
317 sub progrealnames {
318   my ($types) = @_;
319   my ($n, $prog, $type);
320   my @ret;
321   @ret = ();
322   foreach $n (@prognames) {
323     ($prog, $type) = split ",", $n;
324     push @ret, $prog if index($types, $type) >= 0;
325   }
326   return @ret;
327 }
328
329 sub manpages {
330   my ($types,$suffix) = @_;
331
332   # assume that all UNIX programs have a man page
333   if($suffix eq "1" && $types =~ /X/) {
334     return map("$_.1", &progrealnames($types));
335   }
336   return ();
337 }
338
339 # Now we're ready to output the actual Makefiles.
340
341 if (defined $makefiles{'cygwin'}) {
342     $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
343
344     ##-- CygWin makefile
345     open OUT, ">$makefiles{'cygwin'}"; select OUT;
346     print
347     "# Makefile for $project_name under cygwin.\n".
348     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
349     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
350     # gcc command line option is -D not /D
351     ($_ = $help) =~ s/=\/D/=-D/gs;
352     print $_;
353     print
354     "\n".
355     "# You can define this path to point at your tools if you need to\n".
356     "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
357     "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
358     "CC = \$(TOOLPATH)gcc\n".
359     "RC = \$(TOOLPATH)windres\n".
360     "# Uncomment the following two lines to compile under Winelib\n".
361     "# CC = winegcc\n".
362     "# RC = wrc\n".
363     "# You may also need to tell windres where to find include files:\n".
364     "# RCINC = --include-dir c:\\cygwin\\include\\\n".
365     "\n".
366     &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
367       " -D_NO_OLDNAMES -DNO_MULTIMON " .
368                (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
369                "\n".
370     "LDFLAGS = -mno-cygwin -s\n".
371     &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
372       " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
373     "\n".
374     ".SUFFIXES:\n".
375     "\n".
376     "%.o: %.c\n".
377     "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
378     "\n".
379     "%.res.o: %.rc\n".
380     "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
381     "\n";
382     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
383     print "\n\n";
384     foreach $p (&prognames("GC")) {
385       ($prog, $type) = split ",", $p;
386       $objstr = &objects($p, "X.o", "X.res.o", undef);
387       print &splitline($prog . ".exe: " . $objstr), "\n";
388       my $mw = $type eq "G" ? " -mwindows" : "";
389       $libstr = &objects($p, undef, undef, "-lX");
390       print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
391                        "-Wl,-Map,$prog.map " .
392                        $objstr . " $libstr", 69), "\n\n";
393     }
394     foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
395       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
396         "\n";
397     }
398     print "\n";
399     print $makefile_extra{'cygwin'};
400     print "\nclean:\n".
401     "\trm -f *.o *.exe *.res.o *.map\n".
402     "\n";
403     select STDOUT; close OUT;
404
405 }
406
407 ##-- Borland makefile
408 if (defined $makefiles{'borland'}) {
409     $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
410
411     %stdlibs = (  # Borland provides many Win32 API libraries intrinsically
412       "advapi32" => 1,
413       "comctl32" => 1,
414       "comdlg32" => 1,
415       "gdi32" => 1,
416       "imm32" => 1,
417       "shell32" => 1,
418       "user32" => 1,
419       "winmm" => 1,
420       "winspool" => 1,
421       "wsock32" => 1,
422     );
423     open OUT, ">$makefiles{'borland'}"; select OUT;
424     print
425     "# Makefile for $project_name under Borland C.\n".
426     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
427     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
428     # bcc32 command line option is -D not /D
429     ($_ = $help) =~ s/=\/D/=-D/gs;
430     print $_;
431     print
432     "\n".
433     "# If you rename this file to `Makefile', you should change this line,\n".
434     "# so that the .rsp files still depend on the correct makefile.\n".
435     "MAKEFILE = Makefile.bor\n".
436     "\n".
437     "# C compilation flags\n".
438     "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
439     "\n".
440     "# Get include directory for resource compiler\n".
441     "!if !\$d(BCB)\n".
442     "BCB = \$(MAKEDIR)\\..\n".
443     "!endif\n".
444     "\n".
445     ".c.obj:\n".
446     &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
447                " \$(XFLAGS) \$(CFLAGS) ".
448                (join " ", map {"-I$dirpfx$_"} @srcdirs) .
449                " /c \$*.c",69)."\n".
450     ".rc.res:\n".
451     &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
452       " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
453     "\n";
454     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
455     print "\n\n";
456     foreach $p (&prognames("GC")) {
457       ($prog, $type) = split ",", $p;
458       $objstr = &objects($p, "X.obj", "X.res", undef);
459       print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
460       my $ap = ($type eq "G") ? "-aa" : "-ap";
461       print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
462     }
463     foreach $p (&prognames("GC")) {
464       ($prog, $type) = split ",", $p;
465       print $prog, ".rsp: \$(MAKEFILE)\n";
466       $objstr = &objects($p, "X.obj", undef, undef);
467       @objlist = split " ", $objstr;
468       @objlines = ("");
469       foreach $i (@objlist) {
470         if (length($objlines[$#objlines] . " $i") > 50) {
471           push @objlines, "";
472         }
473         $objlines[$#objlines] .= " $i";
474       }
475       $c0w = ($type eq "G") ? "c0w32" : "c0x32";
476       print "\techo $c0w + > $prog.rsp\n";
477       for ($i=0; $i<=$#objlines; $i++) {
478         $plus = ($i < $#objlines ? " +" : "");
479         print "\techo$objlines[$i]$plus >> $prog.rsp\n";
480       }
481       print "\techo $prog.exe >> $prog.rsp\n";
482       $objstr = &objects($p, "X.obj", "X.res", undef);
483       @libs = split " ", &objects($p, undef, undef, "X");
484       @libs = grep { !$stdlibs{$_} } @libs;
485       unshift @libs, "cw32", "import32";
486       $libstr = join ' ', @libs;
487       print "\techo nul,$libstr, >> $prog.rsp\n";
488       print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
489       print "\n";
490     }
491     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
492       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
493         "\n";
494     }
495     print "\n";
496     print $makefile_extra{'borland'};
497     print "\nclean:\n".
498     "\t-del *.obj\n".
499     "\t-del *.exe\n".
500     "\t-del *.res\n".
501     "\t-del *.pch\n".
502     "\t-del *.aps\n".
503     "\t-del *.il*\n".
504     "\t-del *.pdb\n".
505     "\t-del *.rsp\n".
506     "\t-del *.tds\n".
507     "\t-del *.\$\$\$\$\$\$\n";
508     select STDOUT; close OUT;
509 }
510
511 if (defined $makefiles{'vc'}) {
512     $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
513
514     ##-- Visual C++ makefile
515     open OUT, ">$makefiles{'vc'}"; select OUT;
516     print
517       "# Makefile for $project_name under Visual C.\n".
518       "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
519       "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
520     print $help;
521     print
522       "\n".
523       "# If you rename this file to `Makefile', you should change this line,\n".
524       "# so that the .rsp files still depend on the correct makefile.\n".
525       "MAKEFILE = Makefile.vc\n".
526       "\n".
527       "# C compilation flags\n".
528       "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
529       "LFLAGS = /incremental:no /fixed\n".
530       "\n".
531       ".c.obj:\n".
532       "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
533       ".rc.res:\n".
534       "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
535       "\n";
536     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
537     print "\n\n";
538     foreach $p (&prognames("GC")) {
539         ($prog, $type) = split ",", $p;
540         $objstr = &objects($p, "X.obj", "X.res", undef);
541         print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
542         print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
543     }
544     foreach $p (&prognames("GC")) {
545         ($prog, $type) = split ",", $p;
546         print $prog, ".rsp: \$(MAKEFILE)\n";
547         $objstr = &objects($p, "X.obj", "X.res", "X.lib");
548         @objlist = split " ", $objstr;
549         @objlines = ("");
550         foreach $i (@objlist) {
551             if (length($objlines[$#objlines] . " $i") > 50) {
552                 push @objlines, "";
553             }
554             $objlines[$#objlines] .= " $i";
555         }
556         $subsys = ($type eq "G") ? "windows" : "console";
557         print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
558         for ($i=0; $i<=$#objlines; $i++) {
559             print "\techo$objlines[$i] >> $prog.rsp\n";
560         }
561         print "\n";
562     }
563     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
564         print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
565           "\n";
566     }
567     print "\n";
568     print $makefile_extra{'vc'};
569     print "\nclean: tidy\n".
570       "\t-del *.exe\n\n".
571       "tidy:\n".
572       "\t-del *.obj\n".
573       "\t-del *.res\n".
574       "\t-del *.pch\n".
575       "\t-del *.aps\n".
576       "\t-del *.ilk\n".
577       "\t-del *.pdb\n".
578       "\t-del *.rsp\n".
579       "\t-del *.dsp\n".
580       "\t-del *.dsw\n".
581       "\t-del *.ncb\n".
582       "\t-del *.opt\n".
583       "\t-del *.plg\n".
584       "\t-del *.map\n".
585       "\t-del *.idb\n".
586       "\t-del debug.log\n";
587     select STDOUT; close OUT;
588 }
589
590 if (defined $makefiles{'vcproj'}) {
591
592     $orig_dir = cwd;
593
594     ##-- MSVC 6 Workspace and projects
595     #
596     # Note: All files created in this section are written in binary
597     # mode, because although MSVC's command-line make can deal with
598     # LF-only line endings, MSVC project files really _need_ to be
599     # CRLF. Hence, in order for mkfiles.pl to generate usable project
600     # files even when run from Unix, I make sure all files are binary
601     # and explicitly write the CRLFs.
602     #
603     # Create directories if necessary
604     mkdir $makefiles{'vcproj'}
605         if(! -d $makefiles{'vcproj'});
606     chdir $makefiles{'vcproj'};
607     @deps = &deps("X.obj", "X.res", "", "\\");
608     %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
609     # Create the project files
610     # Get names of all Windows projects (GUI and console)
611     my @prognames = &prognames("GC");
612     foreach $progname (@prognames) {
613         create_project(\%all_object_deps, $progname);
614     }
615     # Create the workspace file
616     open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
617     print
618     "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
619     "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
620     "\r\n".
621     "###############################################################################\r\n".
622     "\r\n";
623     # List projects
624     foreach $progname (@prognames) {
625       ($windows_project, $type) = split ",", $progname;
626         print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
627     }
628     print
629     "\r\n".
630     "Package=<5>\r\n".
631     "{{{\r\n".
632     "}}}\r\n".
633     "\r\n".
634     "Package=<4>\r\n".
635     "{{{\r\n".
636     "}}}\r\n".
637     "\r\n".
638     "###############################################################################\r\n".
639     "\r\n".
640     "Global:\r\n".
641     "\r\n".
642     "Package=<5>\r\n".
643     "{{{\r\n".
644     "}}}\r\n".
645     "\r\n".
646     "Package=<3>\r\n".
647     "{{{\r\n".
648     "}}}\r\n".
649     "\r\n".
650     "###############################################################################\r\n".
651     "\r\n";
652     select STDOUT; close OUT;
653     chdir $orig_dir;
654
655     sub create_project {
656         my ($all_object_deps, $progname) = @_;
657         # Construct program's dependency info
658         %seen_objects = ();
659         %lib_files = ();
660         %source_files = ();
661         %header_files = ();
662         %resource_files = ();
663         @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
664         foreach $object_file (@object_files) {
665             next if defined $seen_objects{$object_file};
666             $seen_objects{$object_file} = 1;
667             if($object_file =~ /\.lib$/io) {
668                 $lib_files{$object_file} = 1;
669                 next;
670             }
671             $object_deps = $all_object_deps{$object_file};
672             foreach $object_dep (@$object_deps) {
673                 if($object_dep =~ /\.c$/io) {
674                     $source_files{$object_dep} = 1;
675                     next;
676                 }
677                 if($object_dep =~ /\.h$/io) {
678                     $header_files{$object_dep} = 1;
679                     next;
680                 }
681                 if($object_dep =~ /\.(rc|ico)$/io) {
682                     $resource_files{$object_dep} = 1;
683                     next;
684                 }
685             }
686         }
687         $libs = join " ", sort keys %lib_files;
688         @source_files = sort keys %source_files;
689         @header_files = sort keys %header_files;
690         @resources = sort keys %resource_files;
691         ($windows_project, $type) = split ",", $progname;
692         mkdir $windows_project
693             if(! -d $windows_project);
694         chdir $windows_project;
695         $subsys = ($type eq "G") ? "windows" : "console";
696         open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
697         print
698         "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
699         "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
700         "# ** DO NOT EDIT **\r\n".
701         "\r\n".
702         "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
703         "\r\n".
704         "CFG=$windows_project - Win32 Debug\r\n".
705         "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
706         "!MESSAGE use the Export Makefile command and run\r\n".
707         "!MESSAGE \r\n".
708         "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
709         "!MESSAGE \r\n".
710         "!MESSAGE You can specify a configuration when running NMAKE\r\n".
711         "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
712         "!MESSAGE \r\n".
713         "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
714         "!MESSAGE \r\n".
715         "!MESSAGE Possible choices for configuration are:\r\n".
716         "!MESSAGE \r\n".
717         "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
718         "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
719         "!MESSAGE \r\n".
720         "\r\n".
721         "# Begin Project\r\n".
722         "# PROP AllowPerConfigDependencies 0\r\n".
723         "# PROP Scc_ProjName \"\"\r\n".
724         "# PROP Scc_LocalPath \"\"\r\n".
725         "CPP=cl.exe\r\n".
726         "MTL=midl.exe\r\n".
727         "RSC=rc.exe\r\n".
728         "\r\n".
729         "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
730         "\r\n".
731         "# PROP BASE Use_MFC 0\r\n".
732         "# PROP BASE Use_Debug_Libraries 0\r\n".
733         "# PROP BASE Output_Dir \"Release\"\r\n".
734         "# PROP BASE Intermediate_Dir \"Release\"\r\n".
735         "# PROP BASE Target_Dir \"\"\r\n".
736         "# PROP Use_MFC 0\r\n".
737         "# PROP Use_Debug_Libraries 0\r\n".
738         "# PROP Output_Dir \"Release\"\r\n".
739         "# PROP Intermediate_Dir \"Release\"\r\n".
740         "# PROP Ignore_Export_Lib 0\r\n".
741         "# PROP Target_Dir \"\"\r\n".
742         "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
743         "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
744         "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
745         "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
746         "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
747         "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
748         "BSC32=bscmake.exe\r\n".
749         "# ADD BASE BSC32 /nologo\r\n".
750         "# ADD BSC32 /nologo\r\n".
751         "LINK32=link.exe\r\n".
752         "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:$subsys /machine:I386\r\n".
753         "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
754         "# SUBTRACT LINK32 /pdb:none\r\n".
755         "\r\n".
756         "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
757         "\r\n".
758         "# PROP BASE Use_MFC 0\r\n".
759         "# PROP BASE Use_Debug_Libraries 1\r\n".
760         "# PROP BASE Output_Dir \"Debug\"\r\n".
761         "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
762         "# PROP BASE Target_Dir \"\"\r\n".
763         "# PROP Use_MFC 0\r\n".
764         "# PROP Use_Debug_Libraries 1\r\n".
765         "# PROP Output_Dir \"Debug\"\r\n".
766         "# PROP Intermediate_Dir \"Debug\"\r\n".
767         "# PROP Ignore_Export_Lib 0\r\n".
768         "# PROP Target_Dir \"\"\r\n".
769         "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
770         "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
771         "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
772         "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
773         "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
774         "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
775         "BSC32=bscmake.exe\r\n".
776         "# ADD BASE BSC32 /nologo\r\n".
777         "# ADD BSC32 /nologo\r\n".
778         "LINK32=link.exe\r\n".
779         "# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
780         "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
781         "# SUBTRACT LINK32 /pdb:none\r\n".
782         "\r\n".
783         "!ENDIF \r\n".
784         "\r\n".
785         "# Begin Target\r\n".
786         "\r\n".
787         "# Name \"$windows_project - Win32 Release\"\r\n".
788         "# Name \"$windows_project - Win32 Debug\"\r\n".
789         "# Begin Group \"Source Files\"\r\n".
790         "\r\n".
791         "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
792         foreach $source_file (@source_files) {
793             print
794               "# Begin Source File\r\n".
795               "\r\n".
796               "SOURCE=..\\..\\$source_file\r\n";
797             if($source_file =~ /ssh\.c/io) {
798                 # Disable 'Edit and continue' as Visual Studio can't handle the macros
799                 print
800                   "\r\n".
801                   "!IF  \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
802                   "\r\n".
803                   "!ELSEIF  \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
804                   "\r\n".
805                   "# ADD CPP /Zi\r\n".
806                   "\r\n".
807                   "!ENDIF \r\n".
808                   "\r\n";
809             }
810             print "# End Source File\r\n";
811         }
812         print
813         "# End Group\r\n".
814         "# Begin Group \"Header Files\"\r\n".
815         "\r\n".
816         "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
817         foreach $header_file (@header_files) {
818             print
819               "# Begin Source File\r\n".
820               "\r\n".
821               "SOURCE=..\\..\\$header_file\r\n".
822               "# End Source File\r\n";
823         }
824         print
825         "# End Group\r\n".
826         "# Begin Group \"Resource Files\"\r\n".
827         "\r\n".
828         "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
829         foreach $resource_file (@resources) {
830             print
831               "# Begin Source File\r\n".
832               "\r\n".
833               "SOURCE=..\\..\\$resource_file\r\n".
834               "# End Source File\r\n";
835         }
836         print
837         "# End Group\r\n".
838         "# End Target\r\n".
839         "# End Project\r\n";
840         select STDOUT; close OUT;
841         chdir "..";
842     }
843 }
844
845 if (defined $makefiles{'gtk'}) {
846     $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
847
848     ##-- X/GTK/Unix makefile
849     open OUT, ">$makefiles{'gtk'}"; select OUT;
850     print
851     "# Makefile for $project_name under X/GTK and Unix.\n".
852     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
853     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
854     # gcc command line option is -D not /D
855     ($_ = $help) =~ s/=\/D/=-D/gs;
856     print $_;
857     print
858     "\n".
859     "# You can define this path to point at your tools if you need to\n".
860     "# TOOLPATH = /opt/gcc/bin\n".
861     "CC = \$(TOOLPATH)cc\n".
862     "\n".
863     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
864                (join " ", map {"-I$dirpfx$_"} @srcdirs) .
865                " `gtk-config --cflags`")."\n".
866     "XLDFLAGS = `gtk-config --libs`\n".
867     "ULDFLAGS =#\n".
868     "INSTALL=install\n",
869     "INSTALL_PROGRAM=\$(INSTALL)\n",
870     "INSTALL_DATA=\$(INSTALL)\n",
871     "prefix=/usr/local\n",
872     "exec_prefix=\$(prefix)\n",
873     "bindir=\$(exec_prefix)/bin\n",
874     "mandir=\$(prefix)/man\n",
875     "man1dir=\$(mandir)/man1\n",
876     "\n".
877     ".SUFFIXES:\n".
878     "\n".
879     "%.o:\n".
880     "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
881     "\n";
882     print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
883     print "\n\n";
884     foreach $p (&prognames("XU")) {
885       ($prog, $type) = split ",", $p;
886       $objstr = &objects($p, "X.o", undef, undef);
887       print &splitline($prog . ": " . $objstr), "\n";
888       $libstr = &objects($p, undef, undef, "-lX");
889       print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
890                        $objstr . " $libstr", 69), "\n\n";
891     }
892     foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
893       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
894           "\n";
895     }
896     print "\n";
897     print $makefile_extra{'gtk'};
898     print "\nclean:\n".
899     "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n";
900     select STDOUT; close OUT;
901 }
902
903 if (defined $makefiles{'mpw'}) {
904     ##-- MPW Makefile
905     open OUT, ">$makefiles{'mpw'}"; select OUT;
906     print
907     "# Makefile for $project_name under MPW.\n#\n".
908     "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
909     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
910     # MPW command line option is -d not /D
911     ($_ = $help) =~ s/=\/D/=-d /gs;
912     print $_;
913     print "\n\n".
914     "ROptions     = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
915     "\n".
916     "C_68K = {C}\n".
917     "C_CFM68K = {C}\n".
918     "C_PPC = {PPCC}\n".
919     "C_Carbon = {PPCC}\n".
920     "\n".
921     "# -w 35 disables \"unused parameter\" warnings\n".
922     "COptions     = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
923     "          -notOnce\n".
924     "COptions_68K = {COptions} -model far -opt time\n".
925     "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
926     "# _\$LDIVT and _\$LMODT.\n".
927     "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
928     "COptions_PPC = {COptions} -opt size -traceback\n".
929     "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
930     "\n".
931     "Link_68K = ILink\n".
932     "Link_CFM68K = ILink\n".
933     "Link_PPC = PPCLink\n".
934     "Link_Carbon = PPCLink\n".
935     "\n".
936     "LinkOptions = -c 'pTTY'\n".
937     "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
938     "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
939     "LinkOptions_PPC = {LinkOptions}\n".
940     "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
941     "\n".
942     "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
943     "           \"{Libraries}MacRuntime.o\" \xb6\n".
944     "           \"{Libraries}MathLib.far.o\" \xb6\n".
945     "           \"{Libraries}IntEnv.far.o\" \xb6\n".
946     "           \"{Libraries}Interface.o\" \xb6\n".
947     "           \"{Libraries}Navigation.far.o\" \xb6\n".
948     "           \"{Libraries}OpenTransport.o\" \xb6\n".
949     "           \"{Libraries}OpenTransportApp.o\" \xb6\n".
950     "           \"{Libraries}OpenTptInet.o\" \xb6\n".
951     "           \"{Libraries}UnicodeConverterLib.far.o\"\n".
952     "\n".
953     "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
954     "           \"{SharedLibraries}StdCLib\" \xb6\n".
955     "           \"{SharedLibraries}AppearanceLib\" \xb6\n".
956     "                   -weaklib AppearanceLib \xb6\n".
957     "           \"{SharedLibraries}NavigationLib\" \xb6\n".
958     "                   -weaklib NavigationLib \xb6\n".
959     "           \"{SharedLibraries}TextCommon\" \xb6\n".
960     "                   -weaklib TextCommon \xb6\n".
961     "           \"{SharedLibraries}UnicodeConverter\" \xb6\n".
962     "                   -weaklib UnicodeConverter\n".
963     "\n".
964     "Libs_CFM68K =      {Libs_CFM} \xb6\n".
965     "           \"{CFM68KLibraries}NuMacRuntime.o\"\n".
966     "\n".
967     "Libs_PPC = {Libs_CFM} \xb6\n".
968     "           \"{SharedLibraries}ControlsLib\" \xb6\n".
969     "                   -weaklib ControlsLib \xb6\n".
970     "           \"{SharedLibraries}WindowsLib\" \xb6\n".
971     "                   -weaklib WindowsLib \xb6\n".
972     "           \"{SharedLibraries}OpenTransportLib\" \xb6\n".
973     "                   -weaklib OTClientLib \xb6\n".
974     "                   -weaklib OTClientUtilLib \xb6\n".
975     "           \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
976     "                   -weaklib OTInetClientLib \xb6\n".
977     "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
978     "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
979     "           \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
980     "           \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
981     "           \"{PPCLibraries}OpenTptInetPPC.o\"\n".
982     "\n".
983     "Libs_Carbon =      \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
984     "           \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
985     "           \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
986     "           \"{SharedLibraries}CarbonLib\" \xb6\n".
987     "           \"{SharedLibraries}StdCLib\"\n".
988     "\n";
989     print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
990     print "\n\n";
991     foreach $p (&prognames("M")) {
992       ($prog, $type) = split ",", $p;
993
994       print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
995                    undef, "\xb6"), "\n\n";
996
997       $rsrc = &objects($p, "", "X.rsrc", undef);
998
999       foreach $arch (qw(68K CFM68K PPC Carbon)) {
1000           $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1001           print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1002           print "\n";
1003           print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1004           print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1005                        "{LinkOptions_$arch} " .
1006                        $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1007           print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1008       }
1009
1010     }
1011     foreach $d (&deps("", "X.rsrc", "::", ":")) {
1012       next unless $d->{obj};
1013       print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1014                    undef, "\xb6"), "\n";
1015       print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1016     }
1017     foreach $arch (qw(68K CFM68K)) {
1018         foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1019          next unless $d->{obj};
1020         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1021                                  join " ", @{$d->{deps}}),
1022                          undef, "\xb6"), "\n";
1023          print "\t{C_$arch} ", $d->{deps}->[0],
1024                " -o {Targ} {COptions_$arch}\n\n";
1025          }
1026     }
1027     foreach $arch (qw(PPC Carbon)) {
1028         foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1029          next unless $d->{obj};
1030         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1031                                  join " ", @{$d->{deps}}),
1032                          undef, "\xb6"), "\n";
1033          # The odd stuff here seems to stop afpd getting confused.
1034          print "\techo -n > {Targ}\n";
1035          print "\tsetfile -t XCOF {Targ}\n";
1036          print "\t{C_$arch} ", $d->{deps}->[0],
1037                " -o {Targ} {COptions_$arch}\n\n";
1038          }
1039     }
1040     select STDOUT; close OUT;
1041 }
1042
1043 if (defined $makefiles{'lcc'}) {
1044     $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1045
1046     ##-- lcc makefile
1047     open OUT, ">$makefiles{'lcc'}"; select OUT;
1048     print
1049     "# Makefile for $project_name under lcc.\n".
1050     "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1051     "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1052     # lcc command line option is -D not /D
1053     ($_ = $help) =~ s/=\/D/=-D/gs;
1054     print $_;
1055     print
1056     "\n".
1057     "# If you rename this file to `Makefile', you should change this line,\n".
1058     "# so that the .rsp files still depend on the correct makefile.\n".
1059     "MAKEFILE = Makefile.lcc\n".
1060     "\n".
1061     "# C compilation flags\n".
1062     "CFLAGS = -D_WINDOWS " .
1063       (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1064       "\n".
1065     "\n".
1066     "# Get include directory for resource compiler\n".
1067     "\n".
1068     ".c.obj:\n".
1069     &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
1070       " \$(XFLAGS) \$(CFLAGS)  \$*.c",69)."\n".
1071     ".rc.res:\n".
1072     &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
1073     "\n";
1074     print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
1075     print "\n\n";
1076     foreach $p (&prognames("GC")) {
1077       ($prog, $type) = split ",", $p;
1078       $objstr = &objects($p, "X.obj", "X.res", undef);
1079       print &splitline("$prog.exe: " . $objstr ), "\n";
1080       $subsystemtype = undef;
1081       if ($type eq "G") { $subsystemtype = "-subsystem  windows"; }
1082       my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1083       print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1084       print "\n\n";
1085     }
1086
1087     foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1088       print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1089         "\n";
1090     }
1091     print "\n";
1092     print $makefile_extra{'lcc'};
1093     print "\nclean:\n".
1094     "\t-del *.obj\n".
1095     "\t-del *.exe\n".
1096     "\t-del *.res\n";
1097
1098     select STDOUT; close OUT;
1099 }