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