Rather more natural (if much more complex) Mac Filename implementation.
[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
2dc6356a 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.
17eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
18
19@incdirs = ("", "charset/", "unix/", "mac/");
f7f27309 20
7603011f 21$help = ""; # list of newline-free lines of help text
c282cde3 22%programs = (); # maps prog name + type letter to listref of objects/resources
7603011f 23%groups = (); # maps group name to listref of objects/resources
3d541627 24
3d541627 25while (<IN>) {
7603011f 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
3d541627 30 chomp;
7603011f 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 ":") {
c282cde3 53 $listref = [];
7603011f 54 $prog = $_[0];
55 shift @objs; # eat the program name
3d541627 56 } else {
7603011f 57 die "$.: unrecognised line type\n";
3d541627 58 }
7603011f 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; }
a86a2725 65 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
32bb2723 66 $i eq "[X]" or $i eq "[U]") and defined $prog) {
c282cde3 67 $type = substr($i,1,1);
7603011f 68 } else {
69 push @$listref, $i;
70 }
71 }
c282cde3 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 }
7603011f 77 $lastlistref = $listref;
3d541627 78}
7603011f 79
3d541627 80close IN;
7603011f 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 = ();
88foreach $i (@prognames) {
c282cde3 89 ($prog, $type) = split ",", $i;
7603011f 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".
c88dc003 98 # Dependencies for "x.rsrc" start with "x.r".
7603011f 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;
c88dc003 105 } elsif ($j =~ /^(.*)\.rsrc$/) {
106 $file = "$1.r";
107 $depends{$j} = [$file];
108 push @scanlist, $file;
7603011f 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 = ();
134while (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} = [];
f7f27309 139 $dirfile = &findfile($file);
140 open IN, "$dirfile" or die "unable to open source file $file\n";
7603011f 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;
3d541627 154}
155
7603011f 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.
159foreach $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}};
3d541627 174}
175
7603011f 176# Utility routines while writing out the Makefiles.
177
f7f27309 178sub 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
7603011f 189sub objects {
f7f27309 190 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
7603011f 191 my @ret;
192 my ($i, $x, $y);
193 @ret = ();
194 foreach $i (@{$programs{$prog}}) {
f7f27309 195 $x = "";
c88dc003 196 if ($i =~ /^(.*)\.(res|rsrc)/) {
7603011f 197 $y = $1;
198 ($x = $rtmpl) =~ s/X/$y/;
7603011f 199 } elsif ($i =~ /^(.*)\.lib/) {
200 $y = $1;
201 ($x = $ltmpl) =~ s/X/$y/;
7603011f 202 } else {
203 ($x = $otmpl) =~ s/X/$i/;
7603011f 204 }
f7f27309 205 push @ret, $x if $x ne "";
7603011f 206 }
207 return join " ", @ret;
3d541627 208}
209
7603011f 210sub splitline {
a86a2725 211 my ($line, $width, $splitchar) = @_;
7603011f 212 my ($result, $len);
213 $len = (defined $width ? $width : 76);
a86a2725 214 $splitchar = (defined $splitchar ? $splitchar : '\\');
7603011f 215 while (length $line > $len) {
216 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
a86a2725 217 $result .= $1 . " ${splitchar}\n\t\t";
7603011f 218 $line = $2;
219 $len = 60;
220 }
221 return $result . $line;
222}
223
224sub deps {
a86a2725 225 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
7603011f 226 my ($i, $x, $y);
a86a2725 227 my @deps, @ret;
228 @ret = ();
229 $depchar ||= ':';
7603011f 230 foreach $i (sort keys %depends) {
c88dc003 231 if ($i =~ /^(.*)\.(res|rsrc)/) {
f7f27309 232 next if !defined $rtmpl;
7603011f 233 $y = $1;
234 ($x = $rtmpl) =~ s/X/$y/;
235 } else {
236 ($x = $otmpl) =~ s/X/$i/;
237 }
f7f27309 238 @deps = @{$depends{$i}};
239 @deps = map {
240 $_ = &findfile($_);
241 s/\//$dirsep/g;
242 $_ = $prefix . $_;
243 } @deps;
a86a2725 244 push @ret, {obj => $x, deps => [@deps]};
7603011f 245 }
a86a2725 246 return @ret;
3d541627 247}
248
f7f27309 249sub prognames {
250 my ($types) = @_;
c282cde3 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
261sub progrealnames {
262 my ($types) = @_;
263 my ($n, $prog, $type);
f7f27309 264 my @ret;
265 @ret = ();
266 foreach $n (@prognames) {
c282cde3 267 ($prog, $type) = split ",", $n;
268 push @ret, $prog if index($types, $type) >= 0;
f7f27309 269 }
270 return @ret;
271}
272
c76d309d 273sub 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
7603011f 283# Now we're ready to output the actual Makefiles.
284
3d541627 285##-- CygWin makefile
286open OUT, ">Makefile.cyg"; select OUT;
287print
7603011f 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";
3d541627 291# gcc command line option is -D not /D
7603011f 292($_ = $help) =~ s/=\/D/=-D/gs;
3d541627 293print $_;
294print
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".
3ea61c49 301"# Uncomment the following two lines to compile under Winelib\n".
302"# CC = winegcc\n".
303"# RC = wrc\n".
3d541627 304"# You may also need to tell windres where to find include files:\n".
305"# RCINC = --include-dir c:\\cygwin\\include\\\n".
306"\n".
7603011f 307&splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
308 " -DNO_SECURITY -D_NO_OLDNAMES -DNO_MULTIMON -I.")."\n".
f730b86a 309"LDFLAGS = -mno-cygwin -s\n".
7603011f 310&splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
311 " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
3d541627 312"\n".
313".SUFFIXES:\n".
314"\n".
201e9294 315"%.o: %.c\n".
cf03419b 316"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
3d541627 317"\n".
f730b86a 318"%.res.o: %.rc\n".
6ed3635b 319"\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
3d541627 320"\n";
c282cde3 321print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
14232990 322print "\n\n";
f7f27309 323foreach $p (&prognames("GC")) {
c282cde3 324 ($prog, $type) = split ",", $p;
7603011f 325 $objstr = &objects($p, "X.o", "X.res.o", undef);
c282cde3 326 print &splitline($prog . ".exe: " . $objstr), "\n";
327 my $mw = $type eq "G" ? " -mwindows" : "";
7603011f 328 $libstr = &objects($p, undef, undef, "-lX");
329 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
330 $objstr . " $libstr", 69), "\n\n";
3d541627 331}
a86a2725 332foreach $d (&deps("X.o", "X.res.o", "", "/")) {
333 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
334 "\n";
335}
3d541627 336print
337"\n".
74091dff 338"version.o: FORCE;\n".
3d541627 339"# Hack to force version.o to be rebuilt always\n".
340"FORCE:\n".
7603011f 341"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c version.c\n".
3d541627 342"clean:\n".
7603011f 343"\trm -f *.o *.exe *.res.o\n".
3d541627 344"\n";
345select STDOUT; close OUT;
346
347##-- Borland makefile
7603011f 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);
3d541627 360open OUT, ">Makefile.bor"; select OUT;
361print
7603011f 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";
3d541627 365# bcc32 command line option is -D not /D
7603011f 366($_ = $help) =~ s/=\/D/=-D/gs;
3d541627 367print $_;
368print
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".
a401e5f3 374"# C compilation flags\n".
95912ebc 375"CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
a401e5f3 376"\n".
3d541627 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".
8aa5bfd9 383&splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
7603011f 384 " \$(XFLAGS) \$(CFLAGS) /c \$*.c",69)."\n".
3d541627 385".rc.res:\n".
7603011f 386&splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
387 " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
3d541627 388"\n";
c282cde3 389print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
3d541627 390print "\n\n";
f7f27309 391foreach $p (&prognames("GC")) {
c282cde3 392 ($prog, $type) = split ",", $p;
7603011f 393 $objstr = &objects($p, "X.obj", "X.res", undef);
c282cde3 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";
3d541627 397}
f7f27309 398foreach $p (&prognames("GC")) {
c282cde3 399 ($prog, $type) = split ",", $p;
400 print $prog, ".rsp: \$(MAKEFILE)\n";
7603011f 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 }
c282cde3 410 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
411 print "\techo $c0w + > $prog.rsp\n";
a7088bde 412 for ($i=0; $i<=$#objlines; $i++) {
413 $plus = ($i < $#objlines ? " +" : "");
c282cde3 414 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
3d541627 415 }
c282cde3 416 print "\techo $prog.exe >> $prog.rsp\n";
7603011f 417 $objstr = &objects($p, "X.obj", "X.res", undef);
418 @libs = split " ", &objects($p, undef, undef, "X");
419 @libs = grep { !$stdlibs{$_} } @libs;
6d2d5e8d 420 unshift @libs, "cw32", "import32";
421 $libstr = join ' ', @libs;
c282cde3 422 print "\techo nul,$libstr, >> $prog.rsp\n";
423 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
3d541627 424 print "\n";
425}
a86a2725 426foreach $d (&deps("X.obj", "X.res", "", "\\")) {
427 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
428 "\n";
429}
3d541627 430print
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".
2e792012 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";
3d541627 447select STDOUT; close OUT;
7603011f 448
449##-- Visual C++ makefile
450open OUT, ">Makefile.vc"; select OUT;
451print
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";
455print $help;
456print
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";
c282cde3 471print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("GC"));
7603011f 472print "\n\n";
f7f27309 473foreach $p (&prognames("GC")) {
c282cde3 474 ($prog, $type) = split ",", $p;
7603011f 475 $objstr = &objects($p, "X.obj", "X.res", undef);
c282cde3 476 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
477 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
7603011f 478}
f7f27309 479foreach $p (&prognames("GC")) {
c282cde3 480 ($prog, $type) = split ",", $p;
481 print $prog, ".rsp: \$(MAKEFILE)\n";
7603011f 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 }
c282cde3 491 $subsys = ($type eq "G") ? "windows" : "console";
492 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
7603011f 493 for ($i=0; $i<=$#objlines; $i++) {
c282cde3 494 print "\techo$objlines[$i] >> $prog.rsp\n";
7603011f 495 }
496 print "\n";
497}
a86a2725 498foreach $d (&deps("X.obj", "X.res", "", "\\")) {
499 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
500 "\n";
501}
7603011f 502print
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";
525select STDOUT; close OUT;
f7f27309 526
527##-- X/GTK/Unix makefile
528open OUT, ">unix/Makefile.gtk"; select OUT;
529print
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;
535print $_;
536print
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".
a168f366 542&splitline("CFLAGS = -Wall -Werror -g -I. -I.. -I../charset `gtk-config --cflags`")."\n".
32bb2723 543"XLDFLAGS = `gtk-config --libs`\n".
544"ULDFLAGS =#\n".
c76d309d 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",
f7f27309 553"\n".
554".SUFFIXES:\n".
555"\n".
1709795f 556"%.o:\n".
f7f27309 557"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
558"\n";
32bb2723 559print &splitline("all:" . join "", map { " $_" } &progrealnames("XU"));
f7f27309 560print "\n\n";
32bb2723 561foreach $p (&prognames("XU")) {
c282cde3 562 ($prog, $type) = split ",", $p;
f7f27309 563 $objstr = &objects($p, "X.o", undef, undef);
c282cde3 564 print &splitline($prog . ": " . $objstr), "\n";
f7f27309 565 $libstr = &objects($p, undef, undef, "-lX");
32bb2723 566 print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
f7f27309 567 $objstr . " $libstr", 69), "\n\n";
568}
a86a2725 569foreach $d (&deps("X.o", undef, "../", "/")) {
570 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
571 "\n";
572}
f7f27309 573print
574"\n".
575"version.o: FORCE;\n".
576"# Hack to force version.o to be rebuilt always\n".
577"FORCE:\n".
c282cde3 578"\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) \$(VER) -c ../version.c\n".
f7f27309 579"clean:\n".
32bb2723 580"\trm -f *.o". (join "", map { " $_" } &progrealnames("XU")) . "\n".
c76d309d 581"\n",
582"install:\n",
32bb2723 583map("\t\$(INSTALL_PROGRAM) -m 755 $_ \$(bindir)/$_\n", &progrealnames("XU")),
584map("\t\$(INSTALL_DATA) -m 644 $_ \$(man1dir)/$_\n", &manpages("XU", "1")),
c76d309d 585"\n",
586"install-strip:\n",
587"\t\$(MAKE) install INSTALL_PROGRAM=\"\$(INSTALL_PROGRAM) -s\"\n",
f7f27309 588"\n";
589select STDOUT; close OUT;
a86a2725 590
591##-- MPW Makefile
592open OUT, ">mac/Makefile.mpw"; select OUT;
593print <<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.
598END
599# MPW command line option is -d not /D
600($_ = $help) =~ s/=\/D/=-d /gs;
601print $_;
602print <<END;
603
2afa5f5d 604ROptions = `Echo "{VER}" | StreamEdit -e "1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6"' \xa81 '\xb6\xb6\xb6\xb6\xb6"'"`
605
f8422c0b 606# -w 35 disables "unused parameter" warnings
1ad5fcb0 607COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6
608 -notOnce
084f31bc 609COptions_68K = {COptions} -model far -opt time
c1324500 610# Enabling "-opt space" for CFM-68K gives me undefined references to
611# _$LDIVT and _$LMODT.
612COptions_CFM68K = {COptions} -model cfmSeg -opt time
f8422c0b 613COptions_PPC = {COptions} -opt size
614
eb6d356b 615LinkOptions = -c 'pTTY' -fragname PuTTY
f8422c0b 616LinkOptions_68K = {LinkOptions} -br 68k -model far -compact
c1324500 617LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact
f8422c0b 618LinkOptions_PPC = {LinkOptions}
a86a2725 619
728c2c88 620Libs_68K = "{CLibraries}StdCLib.far.o" \xb6
a86a2725 621 "{Libraries}MacRuntime.o" \xb6
622 "{Libraries}MathLib.far.o" \xb6
728c2c88 623 "{Libraries}IntEnv.far.o" \xb6
a86a2725 624 "{Libraries}Interface.o" \xb6
27a3458f 625 "{Libraries}OpenTransport.o" \xb6
626 "{Libraries}OpenTransportApp.o" \xb6
627 "{Libraries}OpenTptInet.o" \xb6
8768ce31 628 "{Libraries}UnicodeConverterLib.far.o"
a86a2725 629
f8422c0b 630Libs_CFM = "{SharedLibraries}InterfaceLib" \xb6
a86a2725 631 "{SharedLibraries}StdCLib" \xb6
a86a2725 632 "{SharedLibraries}AppearanceLib" \xb6
633 -weaklib AppearanceLib \xb6
f8422c0b 634 "{SharedLibraries}TextCommon" \xb6
635 -weaklib TextCommon \xb6
636 "{SharedLibraries}UnicodeConverter" \xb6
637 -weaklib UnicodeConverter
638
c1324500 639Libs_CFM68K = {Libs_CFM} \xb6
eb6d356b 640 "{CFM68KLibraries}NuMacRuntime.o"
c1324500 641
f8422c0b 642Libs_PPC = {Libs_CFM} \xb6
1fc898ea 643 "{SharedLibraries}ControlsLib" \xb6
644 -weaklib ControlsLib \xb6
645 "{SharedLibraries}WindowsLib" \xb6
646 -weaklib WindowsLib \xb6
27a3458f 647 "{SharedLibraries}OpenTransportLib" \xb6
648 -weaklib OTClientLib \xb6
649 -weaklib OTClientUtilLib \xb6
27a3458f 650 "{SharedLibraries}OpenTptInternetLib" \xb6
651 -weaklib OTInetClientLib \xb6
a86a2725 652 "{PPCLibraries}StdCRuntime.o" \xb6
653 "{PPCLibraries}PPCCRuntime.o" \xb6
27a3458f 654 "{PPCLibraries}CarbonAccessors.o" \xb6
655 "{PPCLibraries}OpenTransportAppPPC.o" \xb6
656 "{PPCLibraries}OpenTptInetPPC.o"
a86a2725 657
a86a2725 658END
659print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
660print "\n\n";
661foreach $p (&prognames("M")) {
662 ($prog, $type) = split ",", $p;
f8422c0b 663
3bb01891 664 print &splitline("$prog \xc4 $prog.68k $prog.ppc",
c1324500 665 undef, "\xb6"), "\n\n";
f8422c0b 666
c88dc003 667 $rsrc = &objects($p, "", "X.rsrc", undef);
668
669 $objstr = &objects($p, "X.68k.o", "", undef);
670 print &splitline("$prog.68k \xc4 $objstr $rsrc", undef, "\xb6"), "\n";
671 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
f8422c0b 672 print &splitline("\tILink -o {Targ} {LinkOptions_68K} " .
eb6d356b 673 $objstr . " {Libs_68K}", 69, "\xb6"), "\n";
c99b88a4 674 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
f8422c0b 675
c88dc003 676 $objstr = &objects($p, "X.cfm68k.o", "", undef);
2afa5f5d 677 print &splitline("$prog.cfm68k \xc4 $objstr $rsrc", undef, "\xb6"), "\n";
c88dc003 678 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
c1324500 679 print &splitline("\tILink -o {Targ} {LinkOptions_CFM68K} " .
eb6d356b 680 $objstr . " {Libs_CFM68K}", 69, "\xb6"), "\n";
c99b88a4 681 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
c1324500 682
c88dc003 683 $objstr = &objects($p, "X.ppc.o", "", undef);
2afa5f5d 684 print &splitline("$prog.ppc \xc4 $objstr $rsrc", undef, "\xb6"), "\n";
c88dc003 685 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
f8422c0b 686 print &splitline("\tPPCLink -o {Targ} {LinkOptions_PPC} " .
eb6d356b 687 $objstr . " {Libs_PPC}", 69, "\xb6"), "\n";
c99b88a4 688 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
a86a2725 689}
c88dc003 690foreach $d (&deps("", "X.rsrc", "::", ":")) {
691 next unless $d->{obj};
692 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
693 undef, "\xb6"), "\n";
694 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
695}
696foreach $d (&deps("X.68k.o", "", "::", ":")) {
697 next unless $d->{obj};
a86a2725 698 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
699 undef, "\xb6"), "\n";
700 print "\t{C} ", $d->{deps}->[0], " -o {Targ} {COptions_68K}\n\n";
701}
c88dc003 702foreach $d (&deps("X.cfm68k.o", "", "::", ":")) {
703 next unless $d->{obj};
c1324500 704 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
705 undef, "\xb6"), "\n";
706 print "\t{C} ", $d->{deps}->[0], " -o {Targ} {COptions_CFM68K}\n\n";
707}
c88dc003 708foreach $d (&deps("X.ppc.o", "", "::", ":")) {
709 next unless $d->{obj};
a86a2725 710 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
711 undef, "\xb6"), "\n";
712 # The odd stuff here seems to stop afpd getting confused.
713 print "\techo -n > {Targ}\n";
714 print "\tsetfile -t XCOF {Targ}\n";
715 print "\t{PPCC} ", $d->{deps}->[0], " -o {Targ} {COptions_PPC}\n\n";
716}
717select STDOUT; close OUT;