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