David Nickerson reports odd behaviour involving a drag start point
[sgt-puzzles/ydirson.git] / mkfiles.pl
blob5bb0d392552bb4f05ecdb4c0ddf448cd3ae62ea0
1 #!/usr/bin/env perl
3 # Cross-platform Makefile generator.
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.
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.
16 # Other things undone:
17 # - special-define objects (foo.o[PREPROCSYMBOL]) are not
18 # supported in the mac or vcproj makefiles.
20 use warnings;
21 use IO::Handle;
22 use Cwd;
24 @filestack = ();
25 $in = new IO::Handle;
26 open $in, "Recipe" or do {
27 # We want to deal correctly with being run from one of the
28 # subdirs in the source tree. So if we can't find Recipe here,
29 # try one level up.
30 chdir "..";
31 open $in, "Recipe" or die "unable to open Recipe file\n";
33 push @filestack, $in;
35 # HACK: One of the source files in `charset' is auto-generated by
36 # sbcsgen.pl. We need to generate that _now_, before attempting
37 # dependency analysis.
38 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
40 @srcdirs = ("./");
42 $divert = undef; # ref to scalar in which text is currently being put
43 $help = ""; # list of newline-free lines of help text
44 $project_name = "project"; # this is a good enough default
45 %makefiles = (); # maps makefile types to output makefile pathnames
46 %makefile_extra = (); # maps makefile types to extra Makefile text
47 %programs = (); # maps prog name + type letter to listref of objects/resources
48 %groups = (); # maps group name to listref of objects/resources
50 @allobjs = (); # all object file names
52 readinput: while (1) {
53 $in = $filestack[$#filestack];
54 while (not defined ($_ = <$in>)) {
55 close $filestack[$#filestack];
56 pop @filestack;
57 last readinput if 0 == scalar @filestack;
58 $in = $filestack[$#filestack];
60 chomp;
61 @_ = split;
63 # If we're gathering help text, keep doing so.
64 if (defined $divert) {
65 if ((defined $_[0]) && $_[0] eq "!end") {
66 $divert = undef;
67 } else {
68 ${$divert} .= "$_\n";
70 next;
72 # Skip comments and blank lines.
73 next if /^\s*#/ or scalar @_ == 0;
75 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
76 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
77 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
78 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
79 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
80 if ($_[0] eq "!begin") {
81 if ($_[1] =~ /^>(.*)/) {
82 $divert = \$auxfiles{$1};
83 } elsif (&mfval($_[1])) {
84 $divert = \$makefile_extra{$_[1]};
86 next;
88 if ($_[0] eq "!include") {
89 @newfiles = ();
90 for ($i = 1; $i <= $#_; $i++) {
91 push @newfiles, (sort glob $_[$i]);
93 for ($i = $#newfiles; $i >= 0; $i--) {
94 $file = $newfiles[$i];
95 $f = new IO::Handle;
96 open $f, "<$file" or die "unable to open include file '$file'\n";
97 push @filestack, $f;
99 next;
102 # Now we have an ordinary line. See if it's an = line, a : line
103 # or a + line.
104 @objs = @_;
106 if ($_[0] eq "+") {
107 $listref = $lastlistref;
108 $prog = undef;
109 die "$.: unexpected + line\n" if !defined $lastlistref;
110 } elsif ($_[1] eq "=") {
111 $groups{$_[0]} = [];
112 $listref = $groups{$_[0]};
113 $prog = undef;
114 shift @objs; # eat the group name
115 } elsif ($_[1] eq "+=") {
116 $groups{$_[0]} = [] if !defined $groups{$_[0]};
117 $listref = $groups{$_[0]};
118 $prog = undef;
119 shift @objs; # eat the group name
120 } elsif ($_[1] eq ":") {
121 $listref = [];
122 $prog = $_[0];
123 shift @objs; # eat the program name
124 } else {
125 die "$.: unrecognised line type: '$_'\n";
127 shift @objs; # eat the +, the = or the :
129 while (scalar @objs > 0) {
130 $i = shift @objs;
131 if ($groups{$i}) {
132 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
133 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
134 $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
135 $type = substr($i,1,(length $i)-2);
136 } else {
137 if ($i =~ /\?$/) {
138 # Object files with a trailing question mark are optional:
139 # the build can proceed fine without them, so we only use
140 # them if their primary source files are present.
141 $i =~ s/\?$//;
142 $i = undef unless defined &finddep($i);
143 } elsif ($i =~ /\|/) {
144 # Object file descriptions containing a vertical bar are
145 # lists of choices: we use the _first_ one whose primary
146 # source file is present.
147 @options = split /\|/, $i;
148 $j = undef;
149 foreach $k (@options) {
150 $j=$k, last if defined &finddep($k);
152 die "no alternative found for $i\n" unless defined $j;
153 $i = $j;
155 if (defined $i) {
156 push @$listref, $i;
157 push @allobjs, $i;
161 if ($prog and $type) {
162 die "multiple program entries for $prog [$type]\n"
163 if defined $programs{$prog . "," . $type};
164 $programs{$prog . "," . $type} = $listref;
166 $lastlistref = $listref;
169 foreach $aux (sort keys %auxfiles) {
170 open AUX, ">$aux";
171 print AUX $auxfiles{$aux};
172 close AUX;
175 # Find object file names with predefines (in square brackets after
176 # the module name), and decide on actual object names for them.
177 foreach $i (@allobjs) {
178 if ($i !~ /\[/) {
179 $objname{$i} = $i;
180 $srcname{$i} = $i;
181 $usedobjname{$i} = 1;
184 foreach $i (@allobjs) {
185 if ($i =~ /^(.*)\[([^\]]*)/) {
186 $defs{$i} = [ split ",",$2 ];
187 $srcname{$i} = $s = $1;
188 $index = 1;
189 while (1) {
190 $maxlen = length $s;
191 $maxlen = 8 if $maxlen < 8;
192 $chop = $maxlen - length $index;
193 $chop = length $s if $chop > length $s;
194 $chop = 0 if $chop < 0;
195 $name = substr($s, 0, $chop) . $index;
196 $index++, next if $usedobjname{$name};
197 $objname{$i} = $name;
198 $usedobjname{$name} = 1;
199 last;
204 # Now retrieve the complete list of objects and resource files, and
205 # construct dependency data for them. While we're here, expand the
206 # object list for each program, and complain if its type isn't set.
207 @prognames = sort keys %programs;
208 %depends = ();
209 @scanlist = ();
210 foreach $i (@prognames) {
211 ($prog, $type) = split ",", $i;
212 # Strip duplicate object names.
213 $prev = '';
214 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
215 sort @{$programs{$i}};
216 $programs{$i} = [@list];
217 foreach $jj (@list) {
218 $j = $srcname{$jj};
219 $file = &finddep($j);
220 if (defined $file) {
221 $depends{$jj} = [$file];
222 push @scanlist, $file;
227 # Scan each file on @scanlist and find further inclusions.
228 # Inclusions are given by lines of the form `#include "otherfile"'
229 # (system headers are automatically ignored by this because they'll
230 # be given in angle brackets). Files included by this method are
231 # added back on to @scanlist to be scanned in turn (if not already
232 # done).
234 # Resource scripts (.rc) can also include a file by means of a line
235 # ending `ICON "filename"'. Files included by this method are not
236 # added to @scanlist because they can never include further files.
238 # In this pass we write out a hash %further which maps a source
239 # file name into a listref containing further source file names.
241 %further = ();
242 while (scalar @scanlist > 0) {
243 $file = shift @scanlist;
244 next if defined $further{$file}; # skip if we've already done it
245 $further{$file} = [];
246 $dirfile = &findfile($file);
247 open IN, "$dirfile" or die "unable to open source file $file\n";
248 while (<IN>) {
249 chomp;
250 /^\s*#include\s+\"([^\"]+)\"/ and do {
251 push @{$further{$file}}, $1;
252 push @scanlist, $1;
253 next;
255 /ICON\s+\"([^\"]+)\"\s*$/ and do {
256 push @{$further{$file}}, $1;
257 next;
260 close IN;
263 # Now we're ready to generate the final dependencies section. For
264 # each key in %depends, we must expand the dependencies list by
265 # iteratively adding entries from %further.
266 foreach $i (keys %depends) {
267 %dep = ();
268 @scanlist = @{$depends{$i}};
269 foreach $i (@scanlist) { $dep{$i} = 1; }
270 while (scalar @scanlist > 0) {
271 $file = shift @scanlist;
272 foreach $j (@{$further{$file}}) {
273 if (!$dep{$j}) {
274 $dep{$j} = 1;
275 push @{$depends{$i}}, $j;
276 push @scanlist, $j;
280 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
283 # Validation of input.
285 sub mfval($) {
286 my ($type) = @_;
287 # Returns true if the argument is a known makefile type. Otherwise,
288 # prints a warning and returns false;
289 if (grep { $type eq $_ }
290 ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","nestedvm","osx","wce")) {
291 return 1;
293 warn "$.:unknown makefile type '$type'\n";
294 return 0;
297 # Utility routines while writing out the Makefiles.
299 sub dirpfx {
300 my ($path) = shift @_;
301 my ($sep) = shift @_;
302 my $ret = "";
303 my $i;
304 while (($i = index $path, $sep) >= 0) {
305 $path = substr $path, ($i + length $sep);
306 $ret .= "..$sep";
308 return $ret;
311 sub findfile {
312 my ($name) = @_;
313 my $dir;
314 my $i;
315 my $outdir = undef;
316 unless (defined $findfilecache{$name}) {
317 $i = 0;
318 foreach $dir (@srcdirs) {
319 $outdir = $dir, $i++ if -f "$dir$name";
321 die "multiple instances of source file $name\n" if $i > 1;
322 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
324 return $findfilecache{$name};
327 sub finddep {
328 my $j = shift @_;
329 my $file;
330 # Find the first dependency of an object.
332 # Dependencies for "x" start with "x.c" or "x.m" (depending on
333 # which one exists).
334 # Dependencies for "x.res" start with "x.rc".
335 # Dependencies for "x.rsrc" start with "x.r".
336 # Both types of file are pushed on the list of files to scan.
337 # Libraries (.lib) don't have dependencies at all.
338 if ($j =~ /^(.*)\.res$/) {
339 $file = "$1.rc";
340 } elsif ($j =~ /^(.*)\.rsrc$/) {
341 $file = "$1.r";
342 } elsif ($j !~ /\./) {
343 $file = "$j.c";
344 $file = "$j.m" unless &findfile($file);
345 } else {
346 # For everything else, we assume it's its own dependency.
347 $file = $j;
349 $file = undef unless &findfile($file);
350 return $file;
353 sub objects {
354 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
355 my @ret;
356 my ($i, $x, $y);
357 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
358 @ret = ();
359 foreach $ii (@{$programs{$prog}}) {
360 $i = $objname{$ii};
361 $x = "";
362 if ($i =~ /^(.*)\.(res|rsrc)/) {
363 $y = $1;
364 ($x = $rtmpl) =~ s/X/$y/;
365 } elsif ($i =~ /^(.*)\.lib/) {
366 $y = $1;
367 ($x = $ltmpl) =~ s/X/$y/;
368 } elsif ($i !~ /\./) {
369 ($x = $otmpl) =~ s/X/$i/;
371 push @ret, $x if $x ne "";
373 return join " ", @ret;
376 sub special {
377 my ($prog, $suffix) = @_;
378 my @ret;
379 my ($i, $x, $y);
380 @ret = ();
381 foreach $ii (@{$programs{$prog}}) {
382 $i = $objname{$ii};
383 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
384 push @ret, $i;
387 return join " ", @ret;
390 sub splitline {
391 my ($line, $width, $splitchar) = @_;
392 my $result = "";
393 my $len;
394 $len = (defined $width ? $width : 76);
395 $splitchar = (defined $splitchar ? $splitchar : '\\');
396 while (length $line > $len) {
397 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
398 $result .= $1;
399 $result .= " ${splitchar}\n\t\t" if $2 ne '';
400 $line = $2;
401 $len = 60;
403 return $result . $line;
406 sub deps {
407 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
408 my ($i, $x, $y);
409 my @deps;
410 my @ret;
411 @ret = ();
412 $depchar ||= ':';
413 foreach $ii (sort keys %depends) {
414 $i = $objname{$ii};
415 next if $specialobj{$mftyp}->{$i};
416 if ($i =~ /^(.*)\.(res|rsrc)/) {
417 next if !defined $rtmpl;
418 $y = $1;
419 ($x = $rtmpl) =~ s/X/$y/;
420 } else {
421 ($x = $otmpl) =~ s/X/$i/;
423 @deps = @{$depends{$ii}};
424 # Skip things which are their own dependency.
425 next if grep { $_ eq $i } @deps;
426 @deps = map {
427 $_ = &findfile($_);
428 s/\//$dirsep/g;
429 $_ = $prefix . $_;
430 } @deps;
431 push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}};
433 return @ret;
436 sub prognames {
437 my ($types) = @_;
438 my ($n, $prog, $type);
439 my @ret;
440 @ret = ();
441 foreach $n (@prognames) {
442 ($prog, $type) = split ",", $n;
443 push @ret, $n if index(":$types:", ":$type:") >= 0;
445 return @ret;
448 sub progrealnames {
449 my ($types) = @_;
450 my ($n, $prog, $type);
451 my @ret;
452 @ret = ();
453 foreach $n (@prognames) {
454 ($prog, $type) = split ",", $n;
455 push @ret, $prog if index(":$types:", ":$type:") >= 0;
457 return @ret;
460 sub manpages {
461 my ($types,$suffix) = @_;
463 # assume that all UNIX programs have a man page
464 if($suffix eq "1" && $types =~ /:X:/) {
465 return map("$_.1", &progrealnames($types));
467 return ();
470 # Now we're ready to output the actual Makefiles.
472 if (defined $makefiles{'cygwin'}) {
473 $mftyp = 'cygwin';
474 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
476 ##-- CygWin makefile
477 open OUT, ">$makefiles{'cygwin'}"; select OUT;
478 print
479 "# Makefile for $project_name under cygwin.\n".
480 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
481 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
482 # gcc command line option is -D not /D
483 ($_ = $help) =~ s/=\/D/=-D/gs;
484 print $_;
485 print
486 "\n".
487 "# You can define this path to point at your tools if you need to\n".
488 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
489 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
490 "CC = \$(TOOLPATH)gcc\n".
491 "RC = \$(TOOLPATH)windres\n".
492 "# Uncomment the following two lines to compile under Winelib\n".
493 "# CC = winegcc\n".
494 "# RC = wrc\n".
495 "# You may also need to tell windres where to find include files:\n".
496 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
497 "\n".
498 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
499 " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
500 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
501 "\n".
502 "LDFLAGS = -mno-cygwin -s\n".
503 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
504 " --define WINVER=0x0400 --define MINGW32_FIX=1 " .
505 (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n".
506 "\n";
507 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
508 print "\n\n";
509 foreach $p (&prognames("G:C")) {
510 ($prog, $type) = split ",", $p;
511 $objstr = &objects($p, "X.o", "X.res.o", undef);
512 print &splitline($prog . ".exe: " . $objstr), "\n";
513 my $mw = $type eq "G" ? " -mwindows" : "";
514 $libstr = &objects($p, undef, undef, "-lX");
515 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
516 "-Wl,-Map,$prog.map " .
517 $objstr . " $libstr", 69), "\n\n";
519 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
520 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
521 "\n";
522 if ($d->{obj} =~ /\.res\.o$/) {
523 print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
524 } else {
525 $deflist = join "", map { " -D$_" } @{$d->{defs}};
526 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" .
527 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
530 print "\n";
531 print $makefile_extra{'cygwin'};
532 print "\nclean:\n".
533 "\trm -f *.o *.exe *.res.o *.map\n".
534 "\n";
535 select STDOUT; close OUT;
539 ##-- Borland makefile
540 if (defined $makefiles{'borland'}) {
541 $mftyp = 'borland';
542 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
544 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
545 "advapi32" => 1,
546 "comctl32" => 1,
547 "comdlg32" => 1,
548 "gdi32" => 1,
549 "imm32" => 1,
550 "shell32" => 1,
551 "user32" => 1,
552 "winmm" => 1,
553 "winspool" => 1,
554 "wsock32" => 1,
556 open OUT, ">$makefiles{'borland'}"; select OUT;
557 print
558 "# Makefile for $project_name under Borland C.\n".
559 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
560 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
561 # bcc32 command line option is -D not /D
562 ($_ = $help) =~ s/=\/D/=-D/gs;
563 print $_;
564 print
565 "\n".
566 "# If you rename this file to `Makefile', you should change this line,\n".
567 "# so that the .rsp files still depend on the correct makefile.\n".
568 "MAKEFILE = Makefile.bor\n".
569 "\n".
570 "# C compilation flags\n".
571 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
572 "\n".
573 "# Get include directory for resource compiler\n".
574 "!if !\$d(BCB)\n".
575 "BCB = \$(MAKEDIR)\\..\n".
576 "!endif\n".
577 "\n";
578 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
579 print "\n\n";
580 foreach $p (&prognames("G:C")) {
581 ($prog, $type) = split ",", $p;
582 $objstr = &objects($p, "X.obj", "X.res", undef);
583 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
584 my $ap = ($type eq "G") ? "-aa" : "-ap";
585 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
587 foreach $p (&prognames("G:C")) {
588 ($prog, $type) = split ",", $p;
589 print $prog, ".rsp: \$(MAKEFILE)\n";
590 $objstr = &objects($p, "X.obj", undef, undef);
591 @objlist = split " ", $objstr;
592 @objlines = ("");
593 foreach $i (@objlist) {
594 if (length($objlines[$#objlines] . " $i") > 50) {
595 push @objlines, "";
597 $objlines[$#objlines] .= " $i";
599 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
600 print "\techo $c0w + > $prog.rsp\n";
601 for ($i=0; $i<=$#objlines; $i++) {
602 $plus = ($i < $#objlines ? " +" : "");
603 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
605 print "\techo $prog.exe >> $prog.rsp\n";
606 $objstr = &objects($p, "X.obj", "X.res", undef);
607 @libs = split " ", &objects($p, undef, undef, "X");
608 @libs = grep { !$stdlibs{$_} } @libs;
609 unshift @libs, "cw32", "import32";
610 $libstr = join ' ', @libs;
611 print "\techo nul,$libstr, >> $prog.rsp\n";
612 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
613 print "\n";
615 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
616 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
617 "\n";
618 if ($d->{obj} =~ /\.res$/) {
619 print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " .
620 "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32".
621 " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n";
622 } else {
623 $deflist = join "", map { " -D$_" } @{$d->{defs}};
624 print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
625 " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ".
626 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
627 " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
630 print "\n";
631 print $makefile_extra{'borland'};
632 print "\nclean:\n".
633 "\t-del *.obj\n".
634 "\t-del *.exe\n".
635 "\t-del *.res\n".
636 "\t-del *.pch\n".
637 "\t-del *.aps\n".
638 "\t-del *.il*\n".
639 "\t-del *.pdb\n".
640 "\t-del *.rsp\n".
641 "\t-del *.tds\n".
642 "\t-del *.\$\$\$\$\$\$\n";
643 select STDOUT; close OUT;
646 if (defined $makefiles{'vc'}) {
647 $mftyp = 'vc';
648 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
650 ##-- Visual C++ makefile
651 open OUT, ">$makefiles{'vc'}"; select OUT;
652 print
653 "# Makefile for $project_name under Visual C.\n".
654 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
655 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
656 print $help;
657 print
658 "\n".
659 "# If you rename this file to `Makefile', you should change this line,\n".
660 "# so that the .rsp files still depend on the correct makefile.\n".
661 "MAKEFILE = Makefile.vc\n".
662 "\n".
663 "# C compilation flags\n".
664 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401 /I.\n".
665 "LFLAGS = /incremental:no /fixed\n".
666 "\n";
667 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
668 print "\n\n";
669 foreach $p (&prognames("G:C")) {
670 ($prog, $type) = split ",", $p;
671 $objstr = &objects($p, "X.obj", "X.res", undef);
672 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
673 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
675 foreach $p (&prognames("G:C")) {
676 ($prog, $type) = split ",", $p;
677 print $prog, ".rsp: \$(MAKEFILE)\n";
678 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
679 @objlist = split " ", $objstr;
680 @objlines = ("");
681 foreach $i (@objlist) {
682 if (length($objlines[$#objlines] . " $i") > 50) {
683 push @objlines, "";
685 $objlines[$#objlines] .= " $i";
687 $subsys = ($type eq "G") ? "windows" : "console";
688 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
689 for ($i=0; $i<=$#objlines; $i++) {
690 print "\techo$objlines[$i] >> $prog.rsp\n";
692 print "\n";
694 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
695 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
696 "\n";
697 if ($d->{obj} =~ /\.res$/) {
698 print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
699 "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
700 } else {
701 $deflist = join "", map { " /D$_" } @{$d->{defs}};
702 print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
703 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
706 print "\n";
707 print $makefile_extra{'vc'};
708 print "\nclean: tidy\n".
709 "\t-del *.exe\n\n".
710 "tidy:\n".
711 "\t-del *.obj\n".
712 "\t-del *.res\n".
713 "\t-del *.pch\n".
714 "\t-del *.aps\n".
715 "\t-del *.ilk\n".
716 "\t-del *.pdb\n".
717 "\t-del *.rsp\n".
718 "\t-del *.dsp\n".
719 "\t-del *.dsw\n".
720 "\t-del *.ncb\n".
721 "\t-del *.opt\n".
722 "\t-del *.plg\n".
723 "\t-del *.map\n".
724 "\t-del *.idb\n".
725 "\t-del debug.log\n";
726 select STDOUT; close OUT;
729 if (defined $makefiles{'wce'}) {
730 $mftyp = 'wce';
731 $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
733 ##-- eMbedded Visual C PocketPC makefile
734 open OUT, ">$makefiles{'wce'}"; select OUT;
735 print
736 "# Makefile for $project_name on PocketPC using eMbedded Visual C.\n".
737 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
738 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
739 print $help;
740 print
741 "\n".
742 "# If you rename this file to `Makefile', you should change this line,\n".
743 "# so that the .rsp files still depend on the correct makefile.\n".
744 "MAKEFILE = Makefile.wce\n".
745 "\n".
746 "# This makefile expects the environment to have been set up by one\n".
747 "# of the PocketPC batch files wcearmv4.bat and wceemulator.bat. No\n".
748 "# other build targets are currently supported, because they would\n".
749 "# need a section in this if statement.\n".
750 "!if \"\$(TARGETCPU)\" == \"emulator\"\n".
751 "PLATFORM_DEFS=/D \"_i386_\" /D \"i_386_\" /D \"_X86_\" /D \"x86\"\n".
752 "CC=cl\n".
753 "BASELIBS=commctrl.lib coredll.lib corelibc.lib aygshell.lib\n".
754 "MACHINE=IX86\n".
755 "!else\n".
756 "PLATFORM_DEFS=/D \"ARM\" /D \"_ARM_\" /D \"ARMV4\"\n".
757 "CC=clarm\n".
758 "BASELIBS=commctrl.lib coredll.lib aygshell.lib\n".
759 "MACHINE=ARM\n".
760 "!endif\n".
761 "\n".
762 "# C compilation flags\n".
763 "CFLAGS = /nologo /W3 /O1 /MC /D _WIN32_WCE=420 /D \"WIN32_PLATFORM_PSPC=400\" /D UNDER_CE=420 \\\n".
764 " \$(PLATFORM_DEFS) \\\n".
765 " /D \"UNICODE\" /D \"_UNICODE\" /D \"NDEBUG\" /D \"NO_HTMLHELP\"\n".
766 "\n".
767 "LFLAGS = /nologo /incremental:no \\\n".
768 " /base:0x00010000 /stack:0x10000,0x1000 /entry:WinMainCRTStartup \\\n".
769 " /nodefaultlib:libc.lib /nodefaultlib:libcmt.lib /nodefaultlib:msvcrt.lib /nodefaultlib:OLDNAMES.lib \\\n".
770 " /subsystem:windowsce,4.20 /align:4096 /MACHINE:\$(MACHINE)\n".
771 "\n".
772 "RCFL = /d UNDER_CE=420 /d _WIN32_WCE=420 /d \"WIN32_PLATFORM_PSPC=400\" \\\n".
773 " \$(PLATFORM_DEFS) \\\n".
774 " /d \"NDEBUG\" /d \"UNICODE\" /d \"_UNICODE\"\n".
775 "\n";
776 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G"));
777 print "\n\n";
778 foreach $p (&prognames("G")) {
779 ($prog, $type) = split ",", $p;
780 $objstr = &objects($p, "X.obj", "X.res", undef);
781 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
782 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
784 foreach $p (&prognames("G")) {
785 ($prog, $type) = split ",", $p;
786 print $prog, ".rsp: \$(MAKEFILE)\n";
787 $objstr = &objects($p, "X.obj", "X.res", undef);
788 @objlist = split " ", $objstr;
789 @objlines = ("");
790 foreach $i (@objlist) {
791 if (length($objlines[$#objlines] . " $i") > 50) {
792 push @objlines, "";
794 $objlines[$#objlines] .= " $i";
796 print "\techo \$(BASELIBS) > $prog.rsp\n";
797 for ($i=0; $i<=$#objlines; $i++) {
798 print "\techo$objlines[$i] >> $prog.rsp\n";
800 print "\n";
802 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
803 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
804 "\n";
805 if ($d->{obj} =~ /\.res$/) {
806 print "\trc \$(FWHACK) \$(RCFL) -r -fo".
807 $d->{obj}." ".$d->{deps}->[0]."\n";
808 } else {
809 $deflist = join "", map { " /D$_" } @{$d->{defs}};
810 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
811 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
814 print "\n";
815 print $makefile_extra{'wce'};
816 print "\nclean: tidy\n".
817 "\t-del *.exe\n\n".
818 "tidy:\n".
819 "\t-del *.obj\n".
820 "\t-del *.res\n".
821 "\t-del *.pch\n".
822 "\t-del *.aps\n".
823 "\t-del *.ilk\n".
824 "\t-del *.pdb\n".
825 "\t-del *.rsp\n".
826 "\t-del *.dsp\n".
827 "\t-del *.dsw\n".
828 "\t-del *.ncb\n".
829 "\t-del *.opt\n".
830 "\t-del *.plg\n".
831 "\t-del *.map\n".
832 "\t-del *.idb\n".
833 "\t-del debug.log\n";
834 select STDOUT; close OUT;
837 if (defined $makefiles{'vcproj'}) {
838 $mftyp = 'vcproj';
840 $orig_dir = cwd;
842 ##-- MSVC 6 Workspace and projects
844 # Note: All files created in this section are written in binary
845 # mode, because although MSVC's command-line make can deal with
846 # LF-only line endings, MSVC project files really _need_ to be
847 # CRLF. Hence, in order for mkfiles.pl to generate usable project
848 # files even when run from Unix, I make sure all files are binary
849 # and explicitly write the CRLFs.
851 # Create directories if necessary
852 mkdir $makefiles{'vcproj'}
853 if(! -d $makefiles{'vcproj'});
854 chdir $makefiles{'vcproj'};
855 @deps = &deps("X.obj", "X.res", "", "\\");
856 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
857 # Create the project files
858 # Get names of all Windows projects (GUI and console)
859 my @prognames = &prognames("G:C");
860 foreach $progname (@prognames) {
861 create_project(\%all_object_deps, $progname);
863 # Create the workspace file
864 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
865 print
866 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
867 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
868 "\r\n".
869 "###############################################################################\r\n".
870 "\r\n";
871 # List projects
872 foreach $progname (@prognames) {
873 ($windows_project, $type) = split ",", $progname;
874 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
876 print
877 "\r\n".
878 "Package=<5>\r\n".
879 "{{{\r\n".
880 "}}}\r\n".
881 "\r\n".
882 "Package=<4>\r\n".
883 "{{{\r\n".
884 "}}}\r\n".
885 "\r\n".
886 "###############################################################################\r\n".
887 "\r\n".
888 "Global:\r\n".
889 "\r\n".
890 "Package=<5>\r\n".
891 "{{{\r\n".
892 "}}}\r\n".
893 "\r\n".
894 "Package=<3>\r\n".
895 "{{{\r\n".
896 "}}}\r\n".
897 "\r\n".
898 "###############################################################################\r\n".
899 "\r\n";
900 select STDOUT; close OUT;
901 chdir $orig_dir;
903 sub create_project {
904 my ($all_object_deps, $progname) = @_;
905 # Construct program's dependency info
906 %seen_objects = ();
907 %lib_files = ();
908 %source_files = ();
909 %header_files = ();
910 %resource_files = ();
911 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
912 foreach $object_file (@object_files) {
913 next if defined $seen_objects{$object_file};
914 $seen_objects{$object_file} = 1;
915 if($object_file =~ /\.lib$/io) {
916 $lib_files{$object_file} = 1;
917 next;
919 $object_deps = $all_object_deps{$object_file};
920 foreach $object_dep (@$object_deps) {
921 if($object_dep =~ /\.c$/io) {
922 $source_files{$object_dep} = 1;
923 next;
925 if($object_dep =~ /\.h$/io) {
926 $header_files{$object_dep} = 1;
927 next;
929 if($object_dep =~ /\.(rc|ico)$/io) {
930 $resource_files{$object_dep} = 1;
931 next;
935 $libs = join " ", sort keys %lib_files;
936 @source_files = sort keys %source_files;
937 @header_files = sort keys %header_files;
938 @resources = sort keys %resource_files;
939 ($windows_project, $type) = split ",", $progname;
940 mkdir $windows_project
941 if(! -d $windows_project);
942 chdir $windows_project;
943 $subsys = ($type eq "G") ? "windows" : "console";
944 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
945 print
946 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
947 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
948 "# ** DO NOT EDIT **\r\n".
949 "\r\n".
950 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
951 "\r\n".
952 "CFG=$windows_project - Win32 Debug\r\n".
953 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
954 "!MESSAGE use the Export Makefile command and run\r\n".
955 "!MESSAGE \r\n".
956 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
957 "!MESSAGE \r\n".
958 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
959 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
960 "!MESSAGE \r\n".
961 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
962 "!MESSAGE \r\n".
963 "!MESSAGE Possible choices for configuration are:\r\n".
964 "!MESSAGE \r\n".
965 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
966 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
967 "!MESSAGE \r\n".
968 "\r\n".
969 "# Begin Project\r\n".
970 "# PROP AllowPerConfigDependencies 0\r\n".
971 "# PROP Scc_ProjName \"\"\r\n".
972 "# PROP Scc_LocalPath \"\"\r\n".
973 "CPP=cl.exe\r\n".
974 "MTL=midl.exe\r\n".
975 "RSC=rc.exe\r\n".
976 "\r\n".
977 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
978 "\r\n".
979 "# PROP BASE Use_MFC 0\r\n".
980 "# PROP BASE Use_Debug_Libraries 0\r\n".
981 "# PROP BASE Output_Dir \"Release\"\r\n".
982 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
983 "# PROP BASE Target_Dir \"\"\r\n".
984 "# PROP Use_MFC 0\r\n".
985 "# PROP Use_Debug_Libraries 0\r\n".
986 "# PROP Output_Dir \"Release\"\r\n".
987 "# PROP Intermediate_Dir \"Release\"\r\n".
988 "# PROP Ignore_Export_Lib 0\r\n".
989 "# PROP Target_Dir \"\"\r\n".
990 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
991 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
992 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
993 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
994 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
995 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
996 "BSC32=bscmake.exe\r\n".
997 "# ADD BASE BSC32 /nologo\r\n".
998 "# ADD BSC32 /nologo\r\n".
999 "LINK32=link.exe\r\n".
1000 "# 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".
1001 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
1002 "# SUBTRACT LINK32 /pdb:none\r\n".
1003 "\r\n".
1004 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1005 "\r\n".
1006 "# PROP BASE Use_MFC 0\r\n".
1007 "# PROP BASE Use_Debug_Libraries 1\r\n".
1008 "# PROP BASE Output_Dir \"Debug\"\r\n".
1009 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
1010 "# PROP BASE Target_Dir \"\"\r\n".
1011 "# PROP Use_MFC 0\r\n".
1012 "# PROP Use_Debug_Libraries 1\r\n".
1013 "# PROP Output_Dir \"Debug\"\r\n".
1014 "# PROP Intermediate_Dir \"Debug\"\r\n".
1015 "# PROP Ignore_Export_Lib 0\r\n".
1016 "# PROP Target_Dir \"\"\r\n".
1017 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1018 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1019 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1020 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1021 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
1022 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
1023 "BSC32=bscmake.exe\r\n".
1024 "# ADD BASE BSC32 /nologo\r\n".
1025 "# ADD BSC32 /nologo\r\n".
1026 "LINK32=link.exe\r\n".
1027 "# 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".
1028 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
1029 "# SUBTRACT LINK32 /pdb:none\r\n".
1030 "\r\n".
1031 "!ENDIF \r\n".
1032 "\r\n".
1033 "# Begin Target\r\n".
1034 "\r\n".
1035 "# Name \"$windows_project - Win32 Release\"\r\n".
1036 "# Name \"$windows_project - Win32 Debug\"\r\n".
1037 "# Begin Group \"Source Files\"\r\n".
1038 "\r\n".
1039 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
1040 foreach $source_file (@source_files) {
1041 print
1042 "# Begin Source File\r\n".
1043 "\r\n".
1044 "SOURCE=..\\..\\$source_file\r\n";
1045 if($source_file =~ /ssh\.c/io) {
1046 # Disable 'Edit and continue' as Visual Studio can't handle the macros
1047 print
1048 "\r\n".
1049 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1050 "\r\n".
1051 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1052 "\r\n".
1053 "# ADD CPP /Zi\r\n".
1054 "\r\n".
1055 "!ENDIF \r\n".
1056 "\r\n";
1058 print "# End Source File\r\n";
1060 print
1061 "# End Group\r\n".
1062 "# Begin Group \"Header Files\"\r\n".
1063 "\r\n".
1064 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1065 foreach $header_file (@header_files) {
1066 print
1067 "# Begin Source File\r\n".
1068 "\r\n".
1069 "SOURCE=..\\..\\$header_file\r\n".
1070 "# End Source File\r\n";
1072 print
1073 "# End Group\r\n".
1074 "# Begin Group \"Resource Files\"\r\n".
1075 "\r\n".
1076 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1077 foreach $resource_file (@resources) {
1078 print
1079 "# Begin Source File\r\n".
1080 "\r\n".
1081 "SOURCE=..\\..\\$resource_file\r\n".
1082 "# End Source File\r\n";
1084 print
1085 "# End Group\r\n".
1086 "# End Target\r\n".
1087 "# End Project\r\n";
1088 select STDOUT; close OUT;
1089 chdir "..";
1093 if (defined $makefiles{'gtk'}) {
1094 $mftyp = 'gtk';
1095 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1097 ##-- X/GTK/Unix makefile
1098 open OUT, ">$makefiles{'gtk'}"; select OUT;
1099 print
1100 "# Makefile for $project_name under X/GTK and Unix.\n".
1101 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1102 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1103 # gcc command line option is -D not /D
1104 ($_ = $help) =~ s/=\/D/=-D/gs;
1105 print $_;
1106 print
1107 "\n".
1108 "# You can define this path to point at your tools if you need to\n".
1109 "# TOOLPATH = /opt/gcc/bin\n".
1110 "CC := \$(TOOLPATH)\$(CC)\n".
1111 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1112 "# (depending on what works on your system) if you want to enforce\n".
1113 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n".
1114 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1115 "# to 1.2 if it isn't found.\n".
1116 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1117 "\n".
1118 &splitline("CFLAGS := -O2 -Wall -Werror -ansi -pedantic -g " .
1119 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1120 " `\$(GTK_CONFIG) --cflags` \$(CFLAGS)")."\n".
1121 "XLIBS = `\$(GTK_CONFIG) --libs`\n".
1122 "ULIBS =#\n".
1123 "INSTALL=install\n",
1124 "INSTALL_PROGRAM=\$(INSTALL)\n",
1125 "INSTALL_DATA=\$(INSTALL)\n",
1126 "prefix=/usr/local\n",
1127 "exec_prefix=\$(prefix)\n",
1128 "bindir=\$(exec_prefix)/bin\n",
1129 "gamesdir=\$(exec_prefix)/games\n",
1130 "mandir=\$(prefix)/man\n",
1131 "man1dir=\$(mandir)/man1\n",
1132 "\n";
1133 print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
1134 print "\n\n";
1135 foreach $p (&prognames("X:U")) {
1136 ($prog, $type) = split ",", $p;
1137 $objstr = &objects($p, "X.o", undef, undef);
1138 print &splitline($prog . ": " . $objstr), "\n";
1139 $libstr = &objects($p, undef, undef, "-lX");
1140 print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(XLFLAGS) \$(${type}LIBS)", 69),
1141 "\n\n";
1143 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1144 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1145 "\n";
1146 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1147 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1148 " -c \$< -o \$\@\n";
1150 print "\n";
1151 print $makefile_extra{'gtk'};
1152 print "\nclean:\n".
1153 "\trm -f *.o". (join "", map { " $_" } &progrealnames("X:U")) . "\n";
1154 select STDOUT; close OUT;
1157 if (defined $makefiles{'mpw'}) {
1158 $mftyp = 'mpw';
1159 ##-- MPW Makefile
1160 open OUT, ">$makefiles{'mpw'}"; select OUT;
1161 print
1162 "# Makefile for $project_name under MPW.\n#\n".
1163 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1164 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1165 # MPW command line option is -d not /D
1166 ($_ = $help) =~ s/=\/D/=-d /gs;
1167 print $_;
1168 print "\n\n".
1169 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1170 "\n".
1171 "C_68K = {C}\n".
1172 "C_CFM68K = {C}\n".
1173 "C_PPC = {PPCC}\n".
1174 "C_Carbon = {PPCC}\n".
1175 "\n".
1176 "# -w 35 disables \"unused parameter\" warnings\n".
1177 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1178 " -notOnce\n".
1179 "COptions_68K = {COptions} -model far -opt time\n".
1180 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1181 "# _\$LDIVT and _\$LMODT.\n".
1182 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1183 "COptions_PPC = {COptions} -opt size -traceback\n".
1184 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1185 "\n".
1186 "Link_68K = ILink\n".
1187 "Link_CFM68K = ILink\n".
1188 "Link_PPC = PPCLink\n".
1189 "Link_Carbon = PPCLink\n".
1190 "\n".
1191 "LinkOptions = -c 'pTTY'\n".
1192 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1193 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1194 "LinkOptions_PPC = {LinkOptions}\n".
1195 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1196 "\n".
1197 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1198 " \"{Libraries}MacRuntime.o\" \xb6\n".
1199 " \"{Libraries}MathLib.far.o\" \xb6\n".
1200 " \"{Libraries}IntEnv.far.o\" \xb6\n".
1201 " \"{Libraries}Interface.o\" \xb6\n".
1202 " \"{Libraries}Navigation.far.o\" \xb6\n".
1203 " \"{Libraries}OpenTransport.o\" \xb6\n".
1204 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
1205 " \"{Libraries}OpenTptInet.o\" \xb6\n".
1206 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
1207 "\n".
1208 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1209 " \"{SharedLibraries}StdCLib\" \xb6\n".
1210 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
1211 " -weaklib AppearanceLib \xb6\n".
1212 " \"{SharedLibraries}NavigationLib\" \xb6\n".
1213 " -weaklib NavigationLib \xb6\n".
1214 " \"{SharedLibraries}TextCommon\" \xb6\n".
1215 " -weaklib TextCommon \xb6\n".
1216 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1217 " -weaklib UnicodeConverter\n".
1218 "\n".
1219 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1220 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1221 "\n".
1222 "Libs_PPC = {Libs_CFM} \xb6\n".
1223 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1224 " -weaklib ControlsLib \xb6\n".
1225 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1226 " -weaklib WindowsLib \xb6\n".
1227 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1228 " -weaklib OTClientLib \xb6\n".
1229 " -weaklib OTClientUtilLib \xb6\n".
1230 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1231 " -weaklib OTInetClientLib \xb6\n".
1232 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1233 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1234 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1235 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1236 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1237 "\n".
1238 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1239 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1240 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1241 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1242 " \"{SharedLibraries}StdCLib\"\n".
1243 "\n";
1244 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1245 print "\n\n";
1246 foreach $p (&prognames("M")) {
1247 ($prog, $type) = split ",", $p;
1249 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1250 undef, "\xb6"), "\n\n";
1252 $rsrc = &objects($p, "", "X.rsrc", undef);
1254 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1255 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1256 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1257 print "\n";
1258 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1259 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1260 "{LinkOptions_$arch} " .
1261 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1262 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1266 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1267 next unless $d->{obj};
1268 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1269 undef, "\xb6"), "\n";
1270 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1272 foreach $arch (qw(68K CFM68K)) {
1273 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1274 next unless $d->{obj};
1275 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1276 join " ", @{$d->{deps}}),
1277 undef, "\xb6"), "\n";
1278 print "\t{C_$arch} ", $d->{deps}->[0],
1279 " -o {Targ} {COptions_$arch}\n\n";
1282 foreach $arch (qw(PPC Carbon)) {
1283 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1284 next unless $d->{obj};
1285 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1286 join " ", @{$d->{deps}}),
1287 undef, "\xb6"), "\n";
1288 # The odd stuff here seems to stop afpd getting confused.
1289 print "\techo -n > {Targ}\n";
1290 print "\tsetfile -t XCOF {Targ}\n";
1291 print "\t{C_$arch} ", $d->{deps}->[0],
1292 " -o {Targ} {COptions_$arch}\n\n";
1295 select STDOUT; close OUT;
1298 if (defined $makefiles{'lcc'}) {
1299 $mftyp = 'lcc';
1300 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1302 ##-- lcc makefile
1303 open OUT, ">$makefiles{'lcc'}"; select OUT;
1304 print
1305 "# Makefile for $project_name under lcc.\n".
1306 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1307 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1308 # lcc command line option is -D not /D
1309 ($_ = $help) =~ s/=\/D/=-D/gs;
1310 print $_;
1311 print
1312 "\n".
1313 "# If you rename this file to `Makefile', you should change this line,\n".
1314 "# so that the .rsp files still depend on the correct makefile.\n".
1315 "MAKEFILE = Makefile.lcc\n".
1316 "\n".
1317 "# C compilation flags\n".
1318 "CFLAGS = -D_WINDOWS " .
1319 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1320 "\n".
1321 "\n".
1322 "# Get include directory for resource compiler\n".
1323 "\n";
1324 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1325 print "\n\n";
1326 foreach $p (&prognames("G:C")) {
1327 ($prog, $type) = split ",", $p;
1328 $objstr = &objects($p, "X.obj", "X.res", undef);
1329 print &splitline("$prog.exe: " . $objstr ), "\n";
1330 $subsystemtype = undef;
1331 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1332 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1333 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1334 print "\n\n";
1337 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1338 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1339 "\n";
1340 if ($d->{obj} =~ /\.res$/) {
1341 print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
1342 } else {
1343 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1344 print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1345 " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
1348 print "\n";
1349 print $makefile_extra{'lcc'};
1350 print "\nclean:\n".
1351 "\t-del *.obj\n".
1352 "\t-del *.exe\n".
1353 "\t-del *.res\n";
1355 select STDOUT; close OUT;
1358 if (defined $makefiles{'nestedvm'}) {
1359 $mftyp = 'nestedvm';
1360 $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
1362 ##-- NestedVM makefile
1363 open OUT, ">$makefiles{'nestedvm'}"; select OUT;
1364 print
1365 "# Makefile for $project_name under NestedVM.\n".
1366 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1367 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1368 # gcc command line option is -D not /D
1369 ($_ = $help) =~ s/=\/D/=-D/gs;
1370 print $_;
1371 print
1372 "\n".
1373 "# This path points at the nestedvm root directory\n".
1374 "NESTEDVM = /opt/nestedvm\n".
1375 "# You can define this path to point at your tools if you need to\n".
1376 "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
1377 "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
1378 "\n".
1379 &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
1380 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1381 "\n";
1382 print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
1383 print "\n\n";
1384 foreach $p (&prognames("X")) {
1385 ($prog, $type) = split ",", $p;
1386 $objstr = &objects($p, "X.o", undef, undef);
1387 $objstr =~ s/gtk\.o/nestedvm\.o/g;
1388 print &splitline($prog . ".mips: " . $objstr), "\n";
1389 $libstr = &objects($p, undef, undef, "-lX");
1390 print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " .
1391 $objstr . " $libstr -lm", 69), "\n\n";
1393 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1394 $oobjs = $d->{obj};
1395 $ddeps= join " ", @{$d->{deps}};
1396 $oobjs =~ s/gtk/nestedvm/g;
1397 $ddeps =~ s/gtk/nestedvm/g;
1398 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1399 "\n";
1400 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1401 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1402 " -c \$< -o \$\@\n";
1404 print "\n";
1405 print $makefile_extra{'nestedvm'};
1406 print "\nclean:\n".
1407 "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
1408 select STDOUT; close OUT;
1411 if (defined $makefiles{'osx'}) {
1412 $mftyp = 'osx';
1413 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1414 @osxarchs = ('ppc', 'i386');
1416 ##-- Mac OS X makefile
1417 open OUT, ">$makefiles{'osx'}"; select OUT;
1418 print
1419 "# Makefile for $project_name under Mac OS X.\n".
1420 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1421 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1422 # gcc command line option is -D not /D
1423 ($_ = $help) =~ s/=\/D/=-D/gs;
1424 print $_;
1425 print
1426 "CC = \$(TOOLPATH)gcc\n".
1427 "LIPO = \$(TOOLPATH)lipo\n".
1428 "\n".
1429 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1430 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1431 "LDFLAGS = -framework Cocoa\n".
1432 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1433 "\n" .
1434 $makefile_extra{'osx'} .
1435 "\n".
1436 ".SUFFIXES: .o .c .m\n".
1437 "\n";
1438 print "\n\n";
1439 foreach $p (&prognames("MX")) {
1440 ($prog, $type) = split ",", $p;
1441 $icon = &special($p, ".icns");
1442 $infoplist = &special($p, "info.plist");
1443 print "${prog}.app:\n\tmkdir -p \$\@\n";
1444 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1445 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1446 $targets = "${prog}.app/Contents/MacOS/$prog";
1447 if (defined $icon) {
1448 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1449 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1450 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1452 if (defined $infoplist) {
1453 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1454 $targets .= " ${prog}.app/Contents/Info.plist";
1456 $targets .= " \$(${prog}_extra)";
1457 print &splitline("${prog}: $targets", 69) . "\n\n";
1458 $libstr = &objects($p, undef, undef, "-lX");
1459 $archbins = "";
1460 foreach $arch (@osxarchs) {
1461 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1462 print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
1463 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(LDFLAGS) -o \$@ " .
1464 $objstr . " $libstr", 69), "\n\n";
1465 $archbins .= " ${prog}.${arch}.bin";
1467 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1468 "${prog}.app/Contents/MacOS" . $archbins), "\n";
1469 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1471 foreach $p (&prognames("U")) {
1472 ($prog, $type) = split ",", $p;
1473 $libstr = &objects($p, undef, undef, "-lX");
1474 $archbins = "";
1475 foreach $arch (@osxarchs) {
1476 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1477 print &splitline("${prog}.${arch}: " . $objstr), "\n";
1478 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(ULDFLAGS) -o \$@ " .
1479 $objstr . " $libstr", 69), "\n\n";
1480 $archbins .= " ${prog}.${arch}";
1482 print &splitline("${prog}:" . $archbins), "\n";
1483 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1485 foreach $arch (@osxarchs) {
1486 foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) {
1487 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1488 "\n";
1489 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1490 if ($d->{deps}->[0] =~ /\.m$/) {
1491 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.3 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1492 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1493 } else {
1494 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.3 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1495 " -c \$< -o \$\@\n";
1499 print "\nclean:\n".
1500 "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
1501 "\trm -rf *.app\n";
1502 select STDOUT; close OUT;