]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - mkfiles.pl
Add some parentheses for general robustness. (In particular I just
[PuTTY.git] / mkfiles.pl
1 #!/usr/bin/env perl
2 #
3 # Makefile generator for PuTTY.
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 use FileHandle;
11
12 open IN, "Recipe" or die "unable to open Recipe file\n";
13
14 # HACK: One of the source files in `charset' is auto-generated by
15 # sbcsgen.pl. We need to generate that _now_, before attempting
16 # dependency analysis.
17 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
18
19 @incdirs = ("", "charset/", "unix/", "mac/");
20
21 $help = ""; # list of newline-free lines of help text
22 %programs = (); # maps prog name + type letter to listref of objects/resources
23 %groups = (); # maps group name to listref of objects/resources
24
25 while (<IN>) {
26   # Skip comments (unless the comments belong, for example because
27   # they're part of the help text).
28   next if /^\s*#/ and !$in_help;
29
30   chomp;
31   split;
32   if ($_[0] eq "!begin" and $_[1] eq "help") { $in_help = 1; next; }
33   if ($_[0] eq "!end" and $in_help) { $in_help = 0; next; }
34   # If we're gathering help text, keep doing so.
35   if ($in_help) { $help .= "$_\n"; next; }
36   # Ignore blank lines.
37   next if scalar @_ == 0;
38
39   # Now we have an ordinary line. See if it's an = line, a : line
40   # or a + line.
41   @objs = @_;
42
43   if ($_[0] eq "+") {
44     $listref = $lastlistref;
45     $prog = undef;
46     die "$.: unexpected + line\n" if !defined $lastlistref;
47   } elsif ($_[1] eq "=") {
48     $groups{$_[0]} = [] if !defined $groups{$_[0]};
49     $listref = $groups{$_[0]};
50     $prog = undef;
51     shift @objs; # eat the group name
52   } elsif ($_[1] eq ":") {
53     $listref = [];
54     $prog = $_[0];
55     shift @objs; # eat the program name
56   } else {
57     die "$.: unrecognised line type\n";
58   }
59   shift @objs; # eat the +, the = or the :
60
61   while (scalar @objs > 0) {
62     $i = shift @objs;
63     if ($groups{$i}) {
64       foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
65     } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
66               $i eq "[X]" or $i eq "[U]") and defined $prog) {
67       $type = substr($i,1,1);
68     } else {
69       push @$listref, $i;
70     }
71   }
72   if ($prog and $type) {
73     die "multiple program entries for $prog [$type]\n"
74         if defined $programs{$prog . "," . $type};
75     $programs{$prog . "," . $type} = $listref;
76   }
77   $lastlistref = $listref;
78 }
79
80 close IN;
81
82 # Now retrieve the complete list of objects and resource files, and
83 # construct dependency data for them. While we're here, expand the
84 # object list for each program, and complain if its type isn't set.
85 @prognames = sort keys %programs;
86 %depends = ();
87 @scanlist = ();
88 foreach $i (@prognames) {
89   ($prog, $type) = split ",", $i;
90   # Strip duplicate object names.
91   $prev = undef;
92   @list = grep { $status = ($prev ne $_); $prev=$_; $status }
93           sort @{$programs{$i}};
94   $programs{$i} = [@list];
95   foreach $j (@list) {
96     # Dependencies for "x" start with "x.c".
97     # Dependencies for "x.res" start with "x.rc".
98     # Dependencies for "x.rsrc" start with "x.r".
99     # Both types of file are pushed on the list of files to scan.
100     # Libraries (.lib) don't have dependencies at all.
101     if ($j =~ /^(.*)\.res$/) {
102       $file = "$1.rc";
103       $depends{$j} = [$file];
104       push @scanlist, $file;
105     } elsif ($j =~ /^(.*)\.rsrc$/) {
106       $file = "$1.r";
107       $depends{$j} = [$file];
108       push @scanlist, $file;
109     } elsif ($j =~ /\.lib$/) {
110       # libraries don't have dependencies
111     } else {
112       $file = "$j.c";
113       $depends{$j} = [$file];
114       push @scanlist, $file;
115     }
116   }
117 }
118
119 # Scan each file on @scanlist and find further inclusions.
120 # Inclusions are given by lines of the form `#include "otherfile"'
121 # (system headers are automatically ignored by this because they'll
122 # be given in angle brackets). Files included by this method are
123 # added back on to @scanlist to be scanned in turn (if not already
124 # done).
125 #
126 # Resource scripts (.rc) can also include a file by means of a line
127 # ending `ICON "filename"'. Files included by this method are not
128 # added to @scanlist because they can never include further files.
129 #
130 # In this pass we write out a hash %further which maps a source
131 # file name into a listref containing further source file names.
132
133 %further = ();
134 while (scalar @scanlist > 0) {
135   $file = shift @scanlist;
136   next if defined $further{$file}; # skip if we've already done it
137   $resource = ($file =~ /\.rc$/ ? 1 : 0);
138   $further{$file} = [];
139   $dirfile = &findfile($file);
140   open IN, "$dirfile" or die "unable to open source file $file\n";
141   while (<IN>) {
142     chomp;
143     /^\s*#include\s+\"([^\"]+)\"/ and do {
144       push @{$further{$file}}, $1;
145       push @scanlist, $1;
146       next;
147     };
148     /ICON\s+\"([^\"]+)\"\s*$/ and do {
149       push @{$further{$file}}, $1;
150       next;
151     }
152   }
153   close IN;
154 }
155
156 # Now we're ready to generate the final dependencies section. For
157 # each key in %depends, we must expand the dependencies list by
158 # iteratively adding entries from %further.
159 foreach $i (keys %depends) {
160   %dep = ();
161   @scanlist = @{$depends{$i}};
162   foreach $i (@scanlist) { $dep{$i} = 1; }
163   while (scalar @scanlist > 0) {
164     $file = shift @scanlist;
165     foreach $j (@{$further{$file}}) {
166       if ($dep{$j} != 1) {
167         $dep{$j} = 1;
168         push @{$depends{$i}}, $j;
169         push @scanlist, $j;
170       }
171     }
172   }
173 #  printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
174 }
175
176 # Utility routines while writing out the Makefiles.
177
178 sub findfile {
179   my ($name) = @_;
180   my $dir, $i, $outdir = "";
181   $i = 0;
182   foreach $dir (@incdirs) {
183     $outdir = $dir, $i++ if -f "$dir$name";
184   }
185   die "multiple instances of source file $name\n" if $i > 1;
186   return "$outdir$name";
187 }
188
189 sub objects {
190   my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
191   my @ret;
192   my ($i, $x, $y);
193   @ret = ();
194   foreach $i (@{$programs{$prog}}) {
195     $x = "";
196     if ($i =~ /^(.*)\.(res|rsrc)/) {
197       $y = $1;
198       ($x = $rtmpl) =~ s/X/$y/;
199     } elsif ($i =~ /^(.*)\.lib/) {
200       $y = $1;
201       ($x = $ltmpl) =~ s/X/$y/;
202     } else {
203       ($x = $otmpl) =~ s/X/$i/;
204     }
205     push @ret, $x if $x ne "";
206   }
207   return join " ", @ret;
208 }
209
210 sub splitline {
211   my ($line, $width, $splitchar) = @_;
212   my ($result, $len);
213   $len = (defined $width ? $width : 76);
214   $splitchar = (defined $splitchar ? $splitchar : '\\');
215   while (length $line > $len) {
216     $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
217     $result .= $1 . " ${splitchar}\n\t\t";
218     $line = $2;
219     $len = 60;
220   }
221   return $result . $line;
222 }
223
224 sub deps {
225   my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
226   my ($i, $x, $y);
227   my @deps, @ret;
228   @ret = ();
229   $depchar ||= ':';
230   foreach $i (sort keys %depends) {
231     if ($i =~ /^(.*)\.(res|rsrc)/) {
232       next if !defined $rtmpl;
233       $y = $1;
234       ($x = $rtmpl) =~ s/X/$y/;
235     } else {
236       ($x = $otmpl) =~ s/X/$i/;
237     }
238     @deps = @{$depends{$i}};
239     @deps = map {
240       $_ = &findfile($_);
241       s/\//$dirsep/g;
242       $_ = $prefix . $_;
243     } @deps;
244     push @ret, {obj => $x, deps => [@deps]};
245   }
246   return @ret;
247 }
248
249 sub prognames {
250   my ($types) = @_;
251   my ($n, $prog, $type);
252   my @ret;
253   @ret = ();
254   foreach $n (@prognames) {
255     ($prog, $type) = split ",", $n;
256     push @ret, $n if index($types, $type) >= 0;
257   }
258   return @ret;
259 }
260
261 sub progrealnames {
262   my ($types) = @_;
263   my ($n, $prog, $type);
264   my @ret;
265   @ret = ();
266   foreach $n (@prognames) {
267     ($prog, $type) = split ",", $n;
268     push @ret, $prog if index($types, $type) >= 0;
269   }
270   return @ret;
271 }
272
273 sub manpages {
274   my ($types,$suffix) = @_;
275
276   # assume that all UNIX programs have a man page
277   if($suffix eq "1" && $types =~ /X/) {
278     return map("$_.1", &progrealnames($types));
279   }
280   return ();
281 }
282
283 # Now we're ready to output the actual Makefiles.
284
285 ##-- CygWin makefile
286 open OUT, ">Makefile.cyg"; select OUT;
287 print
288 "# Makefile for PuTTY under cygwin.\n".
289 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
290 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
291 # gcc command line option is -D not /D
292 ($_ = $help) =~ s/=\/D/=-D/gs;
293 print $_;
294 print
295 "\n".
296 "# You can define this path to point at your tools if you need to\n".
297 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
298 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
299 "CC = \$(TOOLPATH)gcc\n".
300 "RC = \$(TOOLPATH)windres\n".
301 "# Uncomment the following two lines to compile under Winelib\n".
302 "# CC = winegcc\n".
303 "# RC = wrc\n".
304 "# You may also need to tell windres where to find include files:\n".
305 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
306 "\n".
307 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
308   " -DNO_SECURITY -D_NO_OLDNAMES -DNO_MULTIMON -I.")."\n".
309 "LDFLAGS = -mno-cygwin -s\n".
310 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
311   " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
312 "\n".
313 ".SUFFIXES:\n".
314 "\n".
315 "%.o: %.c\n".
316 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
317 "\n".
318 "%.res.o: %.rc\n".
319 "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
320 "\n";
321 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
322 print "\n\n";
323 foreach $p (&prognames("GC")) {
324   ($prog, $type) = split ",", $p;
325   $objstr = &objects($p, "X.o", "X.res.o", undef);
326   print &splitline($prog . ".exe: " . $objstr), "\n";
327   my $mw = $type eq "G" ? " -mwindows" : "";
328   $libstr = &objects($p, undef, undef, "-lX");
329   print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
330                    $objstr . " $libstr", 69), "\n\n";
331 }
332 foreach $d (&deps("X.o", "X.res.o", "", "/")) {
333   print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
334     "\n";
335 }
336 print
337 "\n".
338 "version.o: FORCE;\n".
339 "# Hack to force version.o to be rebuilt always\n".
340 "FORCE:\n".
341 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n".
342 "clean:\n".
343 "\trm -f *.o *.exe *.res.o\n".
344 "\n";
345 select STDOUT; close OUT;
346
347 ##-- Borland makefile
348 %stdlibs = (  # Borland provides many Win32 API libraries intrinsically
349   "advapi32" => 1,
350   "comctl32" => 1,
351   "comdlg32" => 1,
352   "gdi32" => 1,
353   "imm32" => 1,
354   "shell32" => 1,
355   "user32" => 1,
356   "winmm" => 1,
357   "winspool" => 1,
358   "wsock32" => 1,
359 );          
360 open OUT, ">Makefile.bor"; select OUT;
361 print
362 "# Makefile for PuTTY under Borland C.\n".
363 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
364 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
365 # bcc32 command line option is -D not /D
366 ($_ = $help) =~ s/=\/D/=-D/gs;
367 print $_;
368 print
369 "\n".
370 "# If you rename this file to `Makefile', you should change this line,\n".
371 "# so that the .rsp files still depend on the correct makefile.\n".
372 "MAKEFILE = Makefile.bor\n".
373 "\n".
374 "# C compilation flags\n".
375 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
376 "\n".
377 "# Get include directory for resource compiler\n".
378 "!if !\$d(BCB)\n".
379 "BCB = \$(MAKEDIR)\\..\n".
380 "!endif\n".
381 "\n".
382 ".c.obj:\n".
383 &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
384   " \$(XFLAGS) \$(CFLAGS) /c \$*.c",69)."\n".
385 ".rc.res:\n".
386 &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
387   " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
388 "\n";
389 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
390 print "\n\n";
391 foreach $p (&prognames("GC")) {
392   ($prog, $type) = split ",", $p;
393   $objstr = &objects($p, "X.obj", "X.res", undef);
394   print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
395   my $ap = ($type eq "G") ? "-aa" : "-ap";
396   print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
397 }
398 foreach $p (&prognames("GC")) {
399   ($prog, $type) = split ",", $p;
400   print $prog, ".rsp: \$(MAKEFILE)\n";
401   $objstr = &objects($p, "X.obj", undef, undef);
402   @objlist = split " ", $objstr;
403   @objlines = ("");
404   foreach $i (@objlist) {
405     if (length($objlines[$#objlines] . " $i") > 50) {
406       push @objlines, "";
407     }
408     $objlines[$#objlines] .= " $i";
409   }
410   $c0w = ($type eq "G") ? "c0w32" : "c0x32";
411   print "\techo $c0w + > $prog.rsp\n";
412   for ($i=0; $i<=$#objlines; $i++) {
413     $plus = ($i < $#objlines ? " +" : "");
414     print "\techo$objlines[$i]$plus >> $prog.rsp\n";
415   }
416   print "\techo $prog.exe >> $prog.rsp\n";
417   $objstr = &objects($p, "X.obj", "X.res", undef);
418   @libs = split " ", &objects($p, undef, undef, "X");
419   @libs = grep { !$stdlibs{$_} } @libs;
420   unshift @libs, "cw32", "import32";
421   $libstr = join ' ', @libs;
422   print "\techo nul,$libstr, >> $prog.rsp\n";
423   print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
424   print "\n";
425 }
426 foreach $d (&deps("X.obj", "X.res", "", "\\")) {
427   print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
428     "\n";
429 }
430 print
431 "\n".
432 "version.o: FORCE\n".
433 "# Hack to force version.o to be rebuilt always\n".
434 "FORCE:\n".
435 "\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
436 "clean:\n".
437 "\t-del *.obj\n".
438 "\t-del *.exe\n".
439 "\t-del *.res\n".
440 "\t-del *.pch\n".
441 "\t-del *.aps\n".
442 "\t-del *.il*\n".
443 "\t-del *.pdb\n".
444 "\t-del *.rsp\n".
445 "\t-del *.tds\n".
446 "\t-del *.\$\$\$\$\$\$\n";
447 select STDOUT; close OUT;
448
449 ##-- Visual C++ makefile
450 open OUT, ">Makefile.vc"; select OUT;
451 print
452 "# Makefile for PuTTY under Visual C.\n".
453 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
454 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
455 print $help;
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.vc\n".
461 "\n".
462 "# C compilation flags\n".
463 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
464 "LFLAGS = /incremental:no /fixed\n".
465 "\n".
466 ".c.obj:\n".
467 "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
468 ".rc.res:\n".
469 "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
470 "\n";
471 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
472 print "\n\n";
473 foreach $p (&prognames("GC")) {
474   ($prog, $type) = split ",", $p;
475   $objstr = &objects($p, "X.obj", "X.res", undef);
476   print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
477   print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
478 }
479 foreach $p (&prognames("GC")) {
480   ($prog, $type) = split ",", $p;
481   print $prog, ".rsp: \$(MAKEFILE)\n";
482   $objstr = &objects($p, "X.obj", "X.res", "X.lib");
483   @objlist = split " ", $objstr;
484   @objlines = ("");
485   foreach $i (@objlist) {
486     if (length($objlines[$#objlines] . " $i") > 50) {
487       push @objlines, "";
488     }
489     $objlines[$#objlines] .= " $i";
490   }
491   $subsys = ($type eq "G") ? "windows" : "console";
492   print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
493   for ($i=0; $i<=$#objlines; $i++) {
494     print "\techo$objlines[$i] >> $prog.rsp\n";
495   }
496   print "\n";
497 }
498 foreach $d (&deps("X.obj", "X.res", "", "\\")) {
499   print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
500       "\n";
501 }
502 print
503 "\n".
504 "# Hack to force version.o to be rebuilt always\n".
505 "version.obj: *.c *.h *.rc\n".
506 "\tcl \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
507 "clean: tidy\n".
508 "\t-del *.exe\n\n".
509 "tidy:\n".
510 "\t-del *.obj\n".
511 "\t-del *.res\n".
512 "\t-del *.pch\n".
513 "\t-del *.aps\n".
514 "\t-del *.ilk\n".
515 "\t-del *.pdb\n".
516 "\t-del *.rsp\n".
517 "\t-del *.dsp\n".
518 "\t-del *.dsw\n".
519 "\t-del *.ncb\n".
520 "\t-del *.opt\n".
521 "\t-del *.plg\n".
522 "\t-del *.map\n".
523 "\t-del *.idb\n".
524 "\t-del debug.log\n";
525 select STDOUT; close OUT;
526
527 ##-- X/GTK/Unix makefile
528 open OUT, ">unix/Makefile.gtk"; select OUT;
529 print
530 "# Makefile for PuTTY under X/GTK and Unix.\n".
531 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
532 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
533 # gcc command line option is -D not /D
534 ($_ = $help) =~ s/=\/D/=-D/gs;
535 print $_;
536 print
537 "\n".
538 "# You can define this path to point at your tools if you need to\n".
539 "# TOOLPATH = /opt/gcc/bin\n".
540 "CC = \$(TOOLPATH)cc\n".
541 "\n".
542 &splitline("CFLAGS = -Wall -Werror -g -I. -I.. -I../charset `gtk-config --cflags`")."\n".
543 "XLDFLAGS = `gtk-config --libs`\n".
544 "ULDFLAGS =#\n".
545 "INSTALL=install\n",
546 "INSTALL_PROGRAM=\$(INSTALL)\n",
547 "INSTALL_DATA=\$(INSTALL)\n",
548 "prefix=/usr/local\n",
549 "exec_prefix=\$(prefix)\n",
550 "bindir=\$(exec_prefix)/bin\n",
551 "mandir=\$(prefix)/man\n",
552 "man1dir=\$(mandir)/man1\n",
553 "\n".
554 ".SUFFIXES:\n".
555 "\n".
556 "%.o:\n".
557 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
558 "\n";
559 print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
560 print "\n\n";
561 foreach $p (&prognames("XU")) {
562   ($prog, $type) = split ",", $p;
563   $objstr = &objects($p, "X.o", undef, undef);
564   print &splitline($prog . ": " . $objstr), "\n";
565   $libstr = &objects($p, undef, undef, "-lX");
566   print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
567                    $objstr . " $libstr", 69), "\n\n";
568 }
569 foreach $d (&deps("X.o", undef, "../", "/")) {
570   print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
571       "\n";
572 }
573 print
574 "\n".
575 "version.o: FORCE;\n".
576 "# Hack to force version.o to be rebuilt always\n".
577 "FORCE:\n".
578 "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c ../version.c\n".
579 "clean:\n".
580 "\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n".
581 "\n",
582 "install:\n",
583 map("\t\$(INSTALL_PROGRAM) -m 755 $_ \$(bindir)/$_\n", &progrealnames("XU")),
584 map("\t\$(INSTALL_DATA) -m 644 $_ \$(man1dir)/$_\n", &manpages("XU", "1")),
585 "\n",
586 "install-strip:\n",
587 "\t\$(MAKE) install INSTALL_PROGRAM=\"\$(INSTALL_PROGRAM) -s\"\n",
588 "\n";
589 select STDOUT; close OUT;
590
591 ##-- MPW Makefile
592 open OUT, ">mac/Makefile.mpw"; select OUT;
593 print <<END;
594 # Makefile for PuTTY under MPW.
595 #
596 # This file was created by `mkfiles.pl' from the `Recipe' file.
597 # DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.
598 END
599 # MPW command line option is -d not /D
600 ($_ = $help) =~ s/=\/D/=-d /gs;
601 print $_;
602 print <<END;
603
604 ROptions     = `Echo "{VER}" | StreamEdit -e "1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6"' \xa81 '\xb6\xb6\xb6\xb6\xb6"'"`
605
606 C_68K = {C}
607 C_CFM68K = {C}
608 C_PPC = {PPCC}
609 C_Carbon = {PPCC}
610
611 # -w 35 disables "unused parameter" warnings
612 COptions     = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6
613                -notOnce
614 COptions_68K = {COptions} -model far -opt time
615 # Enabling "-opt space" for CFM-68K gives me undefined references to
616 # _\$LDIVT and _\$LMODT.
617 COptions_CFM68K = {COptions} -model cfmSeg -opt time
618 COptions_PPC = {COptions} -opt size -traceback
619 COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON
620
621 Link_68K = ILink
622 Link_CFM68K = ILink
623 Link_PPC = PPCLink
624 Link_Carbon = PPCLink
625
626 LinkOptions = -c 'pTTY'
627 LinkOptions_68K = {LinkOptions} -br 68k -model far -compact
628 LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact
629 LinkOptions_PPC = {LinkOptions}
630 LinkOptions_Carbon = -m __appstart -w {LinkOptions}
631
632 Libs_68K =      "{CLibraries}StdCLib.far.o" \xb6
633                 "{Libraries}MacRuntime.o" \xb6
634                 "{Libraries}MathLib.far.o" \xb6
635                 "{Libraries}IntEnv.far.o" \xb6
636                 "{Libraries}Interface.o" \xb6
637                 "{Libraries}Navigation.far.o" \xb6
638                 "{Libraries}OpenTransport.o" \xb6
639                 "{Libraries}OpenTransportApp.o" \xb6
640                 "{Libraries}OpenTptInet.o" \xb6
641                 "{Libraries}UnicodeConverterLib.far.o"
642
643 Libs_CFM =      "{SharedLibraries}InterfaceLib" \xb6
644                 "{SharedLibraries}StdCLib" \xb6
645                 "{SharedLibraries}AppearanceLib" \xb6
646                         -weaklib AppearanceLib \xb6
647                 "{SharedLibraries}NavigationLib" \xb6
648                         -weaklib NavigationLib \xb6
649                 "{SharedLibraries}TextCommon" \xb6
650                         -weaklib TextCommon \xb6
651                 "{SharedLibraries}UnicodeConverter" \xb6
652                         -weaklib UnicodeConverter
653
654 Libs_CFM68K =   {Libs_CFM} \xb6
655                 "{CFM68KLibraries}NuMacRuntime.o"
656
657 Libs_PPC =      {Libs_CFM} \xb6
658                 "{SharedLibraries}ControlsLib" \xb6
659                         -weaklib ControlsLib \xb6
660                 "{SharedLibraries}WindowsLib" \xb6
661                         -weaklib WindowsLib \xb6
662                 "{SharedLibraries}OpenTransportLib" \xb6
663                         -weaklib OTClientLib \xb6
664                         -weaklib OTClientUtilLib \xb6
665                 "{SharedLibraries}OpenTptInternetLib" \xb6
666                         -weaklib OTInetClientLib \xb6
667                 "{PPCLibraries}StdCRuntime.o" \xb6
668                 "{PPCLibraries}PPCCRuntime.o" \xb6
669                 "{PPCLibraries}CarbonAccessors.o" \xb6
670                 "{PPCLibraries}OpenTransportAppPPC.o" \xb6
671                 "{PPCLibraries}OpenTptInetPPC.o"
672
673 Libs_Carbon =   "{PPCLibraries}CarbonStdCLib.o" \xb6
674                 "{PPCLibraries}StdCRuntime.o" \xb6
675                 "{PPCLibraries}PPCCRuntime.o" \xb6
676                 "{SharedLibraries}CarbonLib" \xb6
677                 "{SharedLibraries}StdCLib"
678
679 END
680 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
681 print "\n\n";
682 foreach $p (&prognames("M")) {
683   ($prog, $type) = split ",", $p;
684
685   print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
686                    undef, "\xb6"), "\n\n";
687
688   $rsrc = &objects($p, "", "X.rsrc", undef);
689
690   foreach $arch (qw(68K CFM68K PPC Carbon)) {
691       $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
692       print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
693       print "\n";
694       print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
695       print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
696                        "{LinkOptions_$arch} " .
697                        $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
698       print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
699   }
700
701 }
702 foreach $d (&deps("", "X.rsrc", "::", ":")) {
703   next unless $d->{obj};
704   print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
705                    undef, "\xb6"), "\n";
706   print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
707 }
708 foreach $arch (qw(68K CFM68K)) {
709     foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
710          next unless $d->{obj};
711         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
712                                  join " ", @{$d->{deps}}),
713                          undef, "\xb6"), "\n";
714          print "\t{C_$arch} ", $d->{deps}->[0],
715                " -o {Targ} {COptions_$arch}\n\n";
716      }
717 }
718 foreach $arch (qw(PPC Carbon)) {
719     foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
720          next unless $d->{obj};
721         print &splitline(sprintf("%s \xc4 %s", $d->{obj},
722                                  join " ", @{$d->{deps}}),
723                          undef, "\xb6"), "\n";
724          # The odd stuff here seems to stop afpd getting confused.
725          print "\techo -n > {Targ}\n";
726          print "\tsetfile -t XCOF {Targ}\n";
727          print "\t{C_$arch} ", $d->{deps}->[0],
728                " -o {Targ} {COptions_$arch}\n\n";
729      }
730 }
731 select STDOUT; close OUT;