Set the default directory to somewhere useful (the PuTTY saved sessions
[u/mdw/putty] / mkfiles.pl
CommitLineData
3d541627 1#!/usr/bin/env perl
2#
7603011f 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
f7f27309 10use FileHandle;
11
7603011f 12open IN, "Recipe" or die "unable to open Recipe file\n";
13
615f7a0d 14@incdirs = ("", "unix/", "mac/");
f7f27309 15
7603011f 16$help = ""; # list of newline-free lines of help text
c282cde3 17%programs = (); # maps prog name + type letter to listref of objects/resources
7603011f 18%groups = (); # maps group name to listref of objects/resources
3d541627 19
3d541627 20while (<IN>) {
7603011f 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
3d541627 25 chomp;
7603011f 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 ":") {
c282cde3 48 $listref = [];
7603011f 49 $prog = $_[0];
50 shift @objs; # eat the program name
3d541627 51 } else {
7603011f 52 die "$.: unrecognised line type\n";
3d541627 53 }
7603011f 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; }
a86a2725 60 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
32bb2723 61 $i eq "[X]" or $i eq "[U]") and defined $prog) {
c282cde3 62 $type = substr($i,1,1);
7603011f 63 } else {
64 push @$listref, $i;
65 }
66 }
c282cde3 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 }
7603011f 72 $lastlistref = $listref;
3d541627 73}
7603011f 74
3d541627 75close IN;
7603011f 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 = ();
83foreach $i (@prognames) {
c282cde3 84 ($prog, $type) = split ",", $i;
7603011f 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".
c88dc003 93 # Dependencies for "x.rsrc" start with "x.r".
7603011f 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;
c88dc003 100 } elsif ($j =~ /^(.*)\.rsrc$/) {
101 $file = "$1.r";
102 $depends{$j} = [$file];
103 push @scanlist, $file;
7603011f 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 = ();
129while (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} = [];
f7f27309 134 $dirfile = &findfile($file);
135 open IN, "$dirfile" or die "unable to open source file $file\n";
7603011f 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;
3d541627 149}
150
7603011f 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.
154foreach $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}};
3d541627 169}
170
7603011f 171# Utility routines while writing out the Makefiles.
172
f7f27309 173sub 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
7603011f 184sub objects {
f7f27309 185 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
7603011f 186 my @ret;
187 my ($i, $x, $y);
188 @ret = ();
189 foreach $i (@{$programs{$prog}}) {
f7f27309 190 $x = "";
c88dc003 191 if ($i =~ /^(.*)\.(res|rsrc)/) {
7603011f 192 $y = $1;
193 ($x = $rtmpl) =~ s/X/$y/;
7603011f 194 } elsif ($i =~ /^(.*)\.lib/) {
195 $y = $1;
196 ($x = $ltmpl) =~ s/X/$y/;
7603011f 197 } else {
198 ($x = $otmpl) =~ s/X/$i/;
7603011f 199 }
f7f27309 200 push @ret, $x if $x ne "";
7603011f 201 }
202 return join " ", @ret;
3d541627 203}
204
7603011f 205sub splitline {
a86a2725 206 my ($line, $width, $splitchar) = @_;
7603011f 207 my ($result, $len);
208 $len = (defined $width ? $width : 76);
a86a2725 209 $splitchar = (defined $splitchar ? $splitchar : '\\');
7603011f 210 while (length $line > $len) {
211 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
a86a2725 212 $result .= $1 . " ${splitchar}\n\t\t";
7603011f 213 $line = $2;
214 $len = 60;
215 }
216 return $result . $line;
217}
218
219sub deps {
a86a2725 220 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
7603011f 221 my ($i, $x, $y);
a86a2725 222 my @deps, @ret;
223 @ret = ();
224 $depchar ||= ':';
7603011f 225 foreach $i (sort keys %depends) {
c88dc003 226 if ($i =~ /^(.*)\.(res|rsrc)/) {
f7f27309 227 next if !defined $rtmpl;
7603011f 228 $y = $1;
229 ($x = $rtmpl) =~ s/X/$y/;
230 } else {
231 ($x = $otmpl) =~ s/X/$i/;
232 }
f7f27309 233 @deps = @{$depends{$i}};
234 @deps = map {
235 $_ = &findfile($_);
236 s/\//$dirsep/g;
237 $_ = $prefix . $_;
238 } @deps;
a86a2725 239 push @ret, {obj => $x, deps => [@deps]};
7603011f 240 }
a86a2725 241 return @ret;
3d541627 242}
243
f7f27309 244sub prognames {
245 my ($types) = @_;
c282cde3 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
256sub progrealnames {
257 my ($types) = @_;
258 my ($n, $prog, $type);
f7f27309 259 my @ret;
260 @ret = ();
261 foreach $n (@prognames) {
c282cde3 262 ($prog, $type) = split ",", $n;
263 push @ret, $prog if index($types, $type) >= 0;
f7f27309 264 }
265 return @ret;
266}
267
c76d309d 268sub 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
7603011f 278# Now we're ready to output the actual Makefiles.
279
3d541627 280##-- CygWin makefile
281open OUT, ">Makefile.cyg"; select OUT;
282print
7603011f 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";
3d541627 286# gcc command line option is -D not /D
7603011f 287($_ = $help) =~ s/=\/D/=-D/gs;
3d541627 288print $_;
289print
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"# You may also need to tell windres where to find include files:\n".
297"# RCINC = --include-dir c:\\cygwin\\include\\\n".
298"\n".
7603011f 299&splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
300 " -DNO_SECURITY -D_NO_OLDNAMES -DNO_MULTIMON -I.")."\n".
f730b86a 301"LDFLAGS = -mno-cygwin -s\n".
7603011f 302&splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
303 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
3d541627 304"\n".
305".SUFFIXES:\n".
306"\n".
201e9294 307"%.o: %.c\n".
cf03419b 308"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
3d541627 309"\n".
f730b86a 310"%.res.o: %.rc\n".
6ed3635b 311"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
3d541627 312"\n";
c282cde3 313print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
14232990 314print "\n\n";
f7f27309 315foreach $p (&prognames("GC")) {
c282cde3 316 ($prog, $type) = split ",", $p;
7603011f 317 $objstr = &objects($p, "X.o", "X.res.o", undef);
c282cde3 318 print &splitline($prog . ".exe: " . $objstr), "\n";
319 my $mw = $type eq "G" ? " -mwindows" : "";
7603011f 320 $libstr = &objects($p, undef, undef, "-lX");
321 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
322 $objstr . " $libstr", 69), "\n\n";
3d541627 323}
a86a2725 324foreach $d (&deps("X.o", "X.res.o", "", "/")) {
325 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
326 "\n";
327}
3d541627 328print
329"\n".
74091dff 330"version.o: FORCE;\n".
3d541627 331"# Hack to force version.o to be rebuilt always\n".
332"FORCE:\n".
7603011f 333"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n".
3d541627 334"clean:\n".
7603011f 335"\trm -f *.o *.exe *.res.o\n".
3d541627 336"\n";
337select STDOUT; close OUT;
338
339##-- Borland makefile
7603011f 340%stdlibs = ( # Borland provides many Win32 API libraries intrinsically
341 "advapi32" => 1,
342 "comctl32" => 1,
343 "comdlg32" => 1,
344 "gdi32" => 1,
345 "imm32" => 1,
346 "shell32" => 1,
347 "user32" => 1,
348 "winmm" => 1,
349 "winspool" => 1,
350 "wsock32" => 1,
351);
3d541627 352open OUT, ">Makefile.bor"; select OUT;
353print
7603011f 354"# Makefile for PuTTY under Borland C.\n".
355"#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
356"# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
3d541627 357# bcc32 command line option is -D not /D
7603011f 358($_ = $help) =~ s/=\/D/=-D/gs;
3d541627 359print $_;
360print
361"\n".
362"# If you rename this file to `Makefile', you should change this line,\n".
363"# so that the .rsp files still depend on the correct makefile.\n".
364"MAKEFILE = Makefile.bor\n".
365"\n".
a401e5f3 366"# C compilation flags\n".
95912ebc 367"CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
a401e5f3 368"\n".
3d541627 369"# Get include directory for resource compiler\n".
370"!if !\$d(BCB)\n".
371"BCB = \$(MAKEDIR)\\..\n".
372"!endif\n".
373"\n".
374".c.obj:\n".
8aa5bfd9 375&splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
7603011f 376 " \$(XFLAGS) \$(CFLAGS) /c \$*.c",69)."\n".
3d541627 377".rc.res:\n".
7603011f 378&splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
379 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
3d541627 380"\n";
c282cde3 381print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
3d541627 382print "\n\n";
f7f27309 383foreach $p (&prognames("GC")) {
c282cde3 384 ($prog, $type) = split ",", $p;
7603011f 385 $objstr = &objects($p, "X.obj", "X.res", undef);
c282cde3 386 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
387 my $ap = ($type eq "G") ? "-aa" : "-ap";
388 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
3d541627 389}
f7f27309 390foreach $p (&prognames("GC")) {
c282cde3 391 ($prog, $type) = split ",", $p;
392 print $prog, ".rsp: \$(MAKEFILE)\n";
7603011f 393 $objstr = &objects($p, "X.obj", undef, undef);
394 @objlist = split " ", $objstr;
395 @objlines = ("");
396 foreach $i (@objlist) {
397 if (length($objlines[$#objlines] . " $i") > 50) {
398 push @objlines, "";
399 }
400 $objlines[$#objlines] .= " $i";
401 }
c282cde3 402 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
403 print "\techo $c0w + > $prog.rsp\n";
a7088bde 404 for ($i=0; $i<=$#objlines; $i++) {
405 $plus = ($i < $#objlines ? " +" : "");
c282cde3 406 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
3d541627 407 }
c282cde3 408 print "\techo $prog.exe >> $prog.rsp\n";
7603011f 409 $objstr = &objects($p, "X.obj", "X.res", undef);
410 @libs = split " ", &objects($p, undef, undef, "X");
411 @libs = grep { !$stdlibs{$_} } @libs;
6d2d5e8d 412 unshift @libs, "cw32", "import32";
413 $libstr = join ' ', @libs;
c282cde3 414 print "\techo nul,$libstr, >> $prog.rsp\n";
415 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
3d541627 416 print "\n";
417}
a86a2725 418foreach $d (&deps("X.obj", "X.res", "", "\\")) {
419 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
420 "\n";
421}
3d541627 422print
423"\n".
424"version.o: FORCE\n".
425"# Hack to force version.o to be rebuilt always\n".
426"FORCE:\n".
427"\tbcc32 \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
428"clean:\n".
2e792012 429"\t-del *.obj\n".
430"\t-del *.exe\n".
431"\t-del *.res\n".
432"\t-del *.pch\n".
433"\t-del *.aps\n".
434"\t-del *.il*\n".
435"\t-del *.pdb\n".
436"\t-del *.rsp\n".
437"\t-del *.tds\n".
438"\t-del *.\$\$\$\$\$\$\n";
3d541627 439select STDOUT; close OUT;
7603011f 440
441##-- Visual C++ makefile
442open OUT, ">Makefile.vc"; select OUT;
443print
444"# Makefile for PuTTY under Visual C.\n".
445"#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
446"# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
447print $help;
448print
449"\n".
450"# If you rename this file to `Makefile', you should change this line,\n".
451"# so that the .rsp files still depend on the correct makefile.\n".
452"MAKEFILE = Makefile.vc\n".
453"\n".
454"# C compilation flags\n".
455"CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
456"LFLAGS = /incremental:no /fixed\n".
457"\n".
458".c.obj:\n".
459"\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
460".rc.res:\n".
461"\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
462"\n";
c282cde3 463print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
7603011f 464print "\n\n";
f7f27309 465foreach $p (&prognames("GC")) {
c282cde3 466 ($prog, $type) = split ",", $p;
7603011f 467 $objstr = &objects($p, "X.obj", "X.res", undef);
c282cde3 468 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
469 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
7603011f 470}
f7f27309 471foreach $p (&prognames("GC")) {
c282cde3 472 ($prog, $type) = split ",", $p;
473 print $prog, ".rsp: \$(MAKEFILE)\n";
7603011f 474 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
475 @objlist = split " ", $objstr;
476 @objlines = ("");
477 foreach $i (@objlist) {
478 if (length($objlines[$#objlines] . " $i") > 50) {
479 push @objlines, "";
480 }
481 $objlines[$#objlines] .= " $i";
482 }
c282cde3 483 $subsys = ($type eq "G") ? "windows" : "console";
484 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
7603011f 485 for ($i=0; $i<=$#objlines; $i++) {
c282cde3 486 print "\techo$objlines[$i] >> $prog.rsp\n";
7603011f 487 }
488 print "\n";
489}
a86a2725 490foreach $d (&deps("X.obj", "X.res", "", "\\")) {
491 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
492 "\n";
493}
7603011f 494print
495"\n".
496"# Hack to force version.o to be rebuilt always\n".
497"version.obj: *.c *.h *.rc\n".
498"\tcl \$(FWHACK) \$(VER) \$(CFLAGS) /c version.c\n\n".
499"clean: tidy\n".
500"\t-del *.exe\n\n".
501"tidy:\n".
502"\t-del *.obj\n".
503"\t-del *.res\n".
504"\t-del *.pch\n".
505"\t-del *.aps\n".
506"\t-del *.ilk\n".
507"\t-del *.pdb\n".
508"\t-del *.rsp\n".
509"\t-del *.dsp\n".
510"\t-del *.dsw\n".
511"\t-del *.ncb\n".
512"\t-del *.opt\n".
513"\t-del *.plg\n".
514"\t-del *.map\n".
515"\t-del *.idb\n".
516"\t-del debug.log\n";
517select STDOUT; close OUT;
f7f27309 518
519##-- X/GTK/Unix makefile
520open OUT, ">unix/Makefile.gtk"; select OUT;
521print
522"# Makefile for PuTTY under X/GTK and Unix.\n".
523"#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
524"# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
525# gcc command line option is -D not /D
526($_ = $help) =~ s/=\/D/=-D/gs;
527print $_;
528print
529"\n".
530"# You can define this path to point at your tools if you need to\n".
531"# TOOLPATH = /opt/gcc/bin\n".
532"CC = \$(TOOLPATH)cc\n".
533"\n".
1709795f 534&splitline("CFLAGS = -Wall -g -I. -I.. `gtk-config --cflags`")."\n".
32bb2723 535"XLDFLAGS = `gtk-config --libs`\n".
536"ULDFLAGS =#\n".
c76d309d 537"INSTALL=install\n",
538"INSTALL_PROGRAM=\$(INSTALL)\n",
539"INSTALL_DATA=\$(INSTALL)\n",
540"prefix=/usr/local\n",
541"exec_prefix=\$(prefix)\n",
542"bindir=\$(exec_prefix)/bin\n",
543"mandir=\$(prefix)/man\n",
544"man1dir=\$(mandir)/man1\n",
f7f27309 545"\n".
546".SUFFIXES:\n".
547"\n".
1709795f 548"%.o:\n".
f7f27309 549"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
550"\n";
32bb2723 551print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
f7f27309 552print "\n\n";
32bb2723 553foreach $p (&prognames("XU")) {
c282cde3 554 ($prog, $type) = split ",", $p;
f7f27309 555 $objstr = &objects($p, "X.o", undef, undef);
c282cde3 556 print &splitline($prog . ": " . $objstr), "\n";
f7f27309 557 $libstr = &objects($p, undef, undef, "-lX");
32bb2723 558 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
f7f27309 559 $objstr . " $libstr", 69), "\n\n";
560}
a86a2725 561foreach $d (&deps("X.o", undef, "../", "/")) {
562 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
563 "\n";
564}
f7f27309 565print
566"\n".
567"version.o: FORCE;\n".
568"# Hack to force version.o to be rebuilt always\n".
569"FORCE:\n".
c282cde3 570"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c ../version.c\n".
f7f27309 571"clean:\n".
32bb2723 572"\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n".
c76d309d 573"\n",
574"install:\n",
32bb2723 575map("\t\$(INSTALL_PROGRAM) -m 755 $_ \$(bindir)/$_\n", &progrealnames("XU")),
576map("\t\$(INSTALL_DATA) -m 644 $_ \$(man1dir)/$_\n", &manpages("XU", "1")),
c76d309d 577"\n",
578"install-strip:\n",
579"\t\$(MAKE) install INSTALL_PROGRAM=\"\$(INSTALL_PROGRAM) -s\"\n",
f7f27309 580"\n";
581select STDOUT; close OUT;
a86a2725 582
583##-- MPW Makefile
584open OUT, ">mac/Makefile.mpw"; select OUT;
585print <<END;
586# Makefile for PuTTY under MPW.
587#
588# This file was created by `mkfiles.pl' from the `Recipe' file.
589# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.
590END
591# MPW command line option is -d not /D
592($_ = $help) =~ s/=\/D/=-d /gs;
593print $_;
594print <<END;
595
f8422c0b 596# -w 35 disables "unused parameter" warnings
597COptions = -i : -i :: -w 35 -w err -proto strict
598COptions_68K = {COptions} -model far -opt space
c1324500 599# Enabling "-opt space" for CFM-68K gives me undefined references to
600# _$LDIVT and _$LMODT.
601COptions_CFM68K = {COptions} -model cfmSeg -opt time
f8422c0b 602COptions_PPC = {COptions} -opt size
603
eb6d356b 604LinkOptions = -c 'pTTY' -fragname PuTTY
f8422c0b 605LinkOptions_68K = {LinkOptions} -br 68k -model far -compact
c1324500 606LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact
f8422c0b 607LinkOptions_PPC = {LinkOptions}
a86a2725 608
728c2c88 609Libs_68K = "{CLibraries}StdCLib.far.o" \xb6
a86a2725 610 "{Libraries}MacRuntime.o" \xb6
611 "{Libraries}MathLib.far.o" \xb6
728c2c88 612 "{Libraries}IntEnv.far.o" \xb6
a86a2725 613 "{Libraries}Interface.o" \xb6
8768ce31 614 "{Libraries}UnicodeConverterLib.far.o"
a86a2725 615
f8422c0b 616Libs_CFM = "{SharedLibraries}InterfaceLib" \xb6
a86a2725 617 "{SharedLibraries}StdCLib" \xb6
a86a2725 618 "{SharedLibraries}AppearanceLib" \xb6
619 -weaklib AppearanceLib \xb6
f8422c0b 620 "{SharedLibraries}TextCommon" \xb6
621 -weaklib TextCommon \xb6
622 "{SharedLibraries}UnicodeConverter" \xb6
623 -weaklib UnicodeConverter
624
c1324500 625Libs_CFM68K = {Libs_CFM} \xb6
eb6d356b 626 "{CFM68KLibraries}NuMacRuntime.o"
c1324500 627
f8422c0b 628Libs_PPC = {Libs_CFM} \xb6
a86a2725 629 "{PPCLibraries}StdCRuntime.o" \xb6
630 "{PPCLibraries}PPCCRuntime.o" \xb6
c1324500 631 "{PPCLibraries}CarbonAccessors.o"
a86a2725 632
a86a2725 633END
634print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
635print "\n\n";
636foreach $p (&prognames("M")) {
637 ($prog, $type) = split ",", $p;
f8422c0b 638
c1324500 639 print &splitline("$prog \xc4 $prog.68k $prog.cfm68k $prog.ppc",
640 undef, "\xb6"), "\n\n";
f8422c0b 641
c88dc003 642 $rsrc = &objects($p, "", "X.rsrc", undef);
643
644 $objstr = &objects($p, "X.68k.o", "", undef);
645 print &splitline("$prog.68k \xc4 $objstr $rsrc", undef, "\xb6"), "\n";
646 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
f8422c0b 647 print &splitline("\tILink -o {Targ} {LinkOptions_68K} " .
eb6d356b 648 $objstr . " {Libs_68K}", 69, "\xb6"), "\n";
649 print &splitline("\tSetFile -a BM {Targ}", 69, "\xb6"), "\n\n";
f8422c0b 650
c88dc003 651 $objstr = &objects($p, "X.cfm68k.o", "", undef);
c1324500 652 print &splitline("$prog.cfm68k \xc4 $objstr", undef, "\xb6"), "\n";
c88dc003 653 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
c1324500 654 print &splitline("\tILink -o {Targ} {LinkOptions_CFM68K} " .
eb6d356b 655 $objstr . " {Libs_CFM68K}", 69, "\xb6"), "\n";
656 print &splitline("\tSetFile -a BM {Targ}", 69, "\xb6"), "\n\n";
c1324500 657
c88dc003 658 $objstr = &objects($p, "X.ppc.o", "", undef);
f8422c0b 659 print &splitline("$prog.ppc \xc4 $objstr", undef, "\xb6"), "\n";
c88dc003 660 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
f8422c0b 661 print &splitline("\tPPCLink -o {Targ} {LinkOptions_PPC} " .
eb6d356b 662 $objstr . " {Libs_PPC}", 69, "\xb6"), "\n";
663 print &splitline("\tSetFile -a BM {Targ}", 69, "\xb6"), "\n\n";
a86a2725 664}
c88dc003 665foreach $d (&deps("", "X.rsrc", "::", ":")) {
666 next unless $d->{obj};
667 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
668 undef, "\xb6"), "\n";
669 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
670}
671foreach $d (&deps("X.68k.o", "", "::", ":")) {
672 next unless $d->{obj};
a86a2725 673 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
674 undef, "\xb6"), "\n";
675 print "\t{C} ", $d->{deps}->[0], " -o {Targ} {COptions_68K}\n\n";
676}
c88dc003 677foreach $d (&deps("X.cfm68k.o", "", "::", ":")) {
678 next unless $d->{obj};
c1324500 679 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
680 undef, "\xb6"), "\n";
681 print "\t{C} ", $d->{deps}->[0], " -o {Targ} {COptions_CFM68K}\n\n";
682}
c88dc003 683foreach $d (&deps("X.ppc.o", "", "::", ":")) {
684 next unless $d->{obj};
a86a2725 685 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
686 undef, "\xb6"), "\n";
687 # The odd stuff here seems to stop afpd getting confused.
688 print "\techo -n > {Targ}\n";
689 print "\tsetfile -t XCOF {Targ}\n";
690 print "\t{PPCC} ", $d->{deps}->[0], " -o {Targ} {COptions_PPC}\n\n";
691}
692select STDOUT; close OUT;