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