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