Stop the analysis pass in Loopy's redraw routine from being
[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 warnings;
21 use IO::Handle;
22 use Cwd;
23
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";
32 };
33 push @filestack, $in;
34
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 ".."';
39
40 @srcdirs = ("./");
41
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
49
50 @allobjs = (); # all object file names
51
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];
59 }
60 chomp;
61 @_ = split;
62
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";
69 }
70 next;
71 }
72 # Skip comments and blank lines.
73 next if /^\s*#/ or scalar @_ == 0;
74
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]};
85 }
86 next;
87 }
88 if ($_[0] eq "!include") {
89 @newfiles = ();
90 for ($i = 1; $i <= $#_; $i++) {
91 push @newfiles, (sort glob $_[$i]);
92 }
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;
98 }
99 next;
100 }
101
102 # Now we have an ordinary line. See if it's an = line, a : line
103 # or a + line.
104 @objs = @_;
105
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";
126 }
127 shift @objs; # eat the +, the = or the :
128
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);
151 }
152 die "no alternative found for $i\n" unless defined $j;
153 $i = $j;
154 }
155 if (defined $i) {
156 push @$listref, $i;
157 push @allobjs, $i;
158 }
159 }
160 }
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;
165 }
166 $lastlistref = $listref;
167 }
168
169 foreach $aux (sort keys %auxfiles) {
170 open AUX, ">$aux";
171 print AUX $auxfiles{$aux};
172 close AUX;
173 }
174
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;
182 }
183 }
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;
200 }
201 }
202 }
203
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;
223 }
224 }
225 }
226
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).
233 #
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.
237 #
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.
240
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;
254 };
255 /ICON\s+\"([^\"]+)\"\s*$/ and do {
256 push @{$further{$file}}, $1;
257 next;
258 }
259 }
260 close IN;
261 }
262
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;
277 }
278 }
279 }
280 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
281 }
282
283 # Validation of input.
284
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","gnustep")) {
291 return 1;
292 }
293 warn "$.:unknown makefile type '$type'\n";
294 return 0;
295 }
296
297 # Utility routines while writing out the Makefiles.
298
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";
307 }
308 return $ret;
309 }
310
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";
320 }
321 die "multiple instances of source file $name\n" if $i > 1;
322 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
323 }
324 return $findfilecache{$name};
325 }
326
327 sub finddep {
328 my $j = shift @_;
329 my $file;
330 # Find the first dependency of an object.
331
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;
348 }
349 $file = undef unless &findfile($file);
350 return $file;
351 }
352
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/;
370 }
371 push @ret, $x if $x ne "";
372 }
373 return join " ", @ret;
374 }
375
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;
385 }
386 }
387 return join " ", @ret;
388 }
389
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;
402 }
403 return $result . $line;
404 }
405
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/;
422 }
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}};
432 }
433 return @ret;
434 }
435
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;
444 }
445 return @ret;
446 }
447
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;
456 }
457 return @ret;
458 }
459
460 sub manpages {
461 my ($types,$suffix) = @_;
462
463 # assume that all UNIX programs have a man page
464 if($suffix eq "1" && $types =~ /:X:/) {
465 return map("$_.1", &progrealnames($types));
466 }
467 return ();
468 }
469
470 # Now we're ready to output the actual Makefiles.
471
472 if (defined $makefiles{'cygwin'}) {
473 $mftyp = 'cygwin';
474 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
475
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";
518 }
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";
528 }
529 }
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;
536
537 }
538
539 ##-- Borland makefile
540 if (defined $makefiles{'borland'}) {
541 $mftyp = 'borland';
542 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
543
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,
555 );
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";
586 }
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, "";
596 }
597 $objlines[$#objlines] .= " $i";
598 }
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";
604 }
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";
614 }
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";
628 }
629 }
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;
644 }
645
646 if (defined $makefiles{'vc'}) {
647 $mftyp = 'vc';
648 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
649
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";
674 }
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, "";
684 }
685 $objlines[$#objlines] .= " $i";
686 }
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";
691 }
692 print "\n";
693 }
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";
704 }
705 }
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;
727 }
728
729 if (defined $makefiles{'wce'}) {
730 $mftyp = 'wce';
731 $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
732
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";
783 }
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, "";
793 }
794 $objlines[$#objlines] .= " $i";
795 }
796 print "\techo \$(BASELIBS) > $prog.rsp\n";
797 for ($i=0; $i<=$#objlines; $i++) {
798 print "\techo$objlines[$i] >> $prog.rsp\n";
799 }
800 print "\n";
801 }
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";
812 }
813 }
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;
835 }
836
837 if (defined $makefiles{'vcproj'}) {
838 $mftyp = 'vcproj';
839
840 $orig_dir = cwd;
841
842 ##-- MSVC 6 Workspace and projects
843 #
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.
850 #
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);
862 }
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";
875 }
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;
902
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;
918 }
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;
924 }
925 if($object_dep =~ /\.h$/io) {
926 $header_files{$object_dep} = 1;
927 next;
928 }
929 if($object_dep =~ /\.(rc|ico)$/io) {
930 $resource_files{$object_dep} = 1;
931 next;
932 }
933 }
934 }
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";
1057 }
1058 print "# End Source File\r\n";
1059 }
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";
1071 }
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";
1083 }
1084 print
1085 "# End Group\r\n".
1086 "# End Target\r\n".
1087 "# End Project\r\n";
1088 select STDOUT; close OUT;
1089 chdir "..";
1090 }
1091 }
1092
1093 if (defined $makefiles{'gtk'}) {
1094 $mftyp = 'gtk';
1095 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1096
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` -lm\n".
1122 "ULIBS = -lm#\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 { " \$(BINPREFIX)$_" }
1134 &progrealnames("X:U"));
1135 print "\n\n";
1136 foreach $p (&prognames("X:U")) {
1137 ($prog, $type) = split ",", $p;
1138 $objstr = &objects($p, "X.o", undef, undef);
1139 print &splitline("\$(BINPREFIX)" . $prog . ": " . $objstr), "\n";
1140 $libstr = &objects($p, undef, undef, "-lX");
1141 print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(XLFLAGS) \$(${type}LIBS)", 69),
1142 "\n\n";
1143 }
1144 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1145 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1146 "\n";
1147 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1148 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1149 " -c \$< -o \$\@\n";
1150 }
1151 print "\n";
1152 print $makefile_extra{'gtk'} || "";
1153 print "\nclean:\n".
1154 "\trm -f *.o". (join "", map { " \$(BINPREFIX)$_" } &progrealnames("X:U")) . "\n";
1155 select STDOUT; close OUT;
1156 }
1157
1158 if (defined $makefiles{'mpw'}) {
1159 $mftyp = 'mpw';
1160 ##-- MPW Makefile
1161 open OUT, ">$makefiles{'mpw'}"; select OUT;
1162 print
1163 "# Makefile for $project_name under MPW.\n#\n".
1164 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1165 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1166 # MPW command line option is -d not /D
1167 ($_ = $help) =~ s/=\/D/=-d /gs;
1168 print $_;
1169 print "\n\n".
1170 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1171 "\n".
1172 "C_68K = {C}\n".
1173 "C_CFM68K = {C}\n".
1174 "C_PPC = {PPCC}\n".
1175 "C_Carbon = {PPCC}\n".
1176 "\n".
1177 "# -w 35 disables \"unused parameter\" warnings\n".
1178 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1179 " -notOnce\n".
1180 "COptions_68K = {COptions} -model far -opt time\n".
1181 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1182 "# _\$LDIVT and _\$LMODT.\n".
1183 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1184 "COptions_PPC = {COptions} -opt size -traceback\n".
1185 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1186 "\n".
1187 "Link_68K = ILink\n".
1188 "Link_CFM68K = ILink\n".
1189 "Link_PPC = PPCLink\n".
1190 "Link_Carbon = PPCLink\n".
1191 "\n".
1192 "LinkOptions = -c 'pTTY'\n".
1193 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1194 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1195 "LinkOptions_PPC = {LinkOptions}\n".
1196 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1197 "\n".
1198 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1199 " \"{Libraries}MacRuntime.o\" \xb6\n".
1200 " \"{Libraries}MathLib.far.o\" \xb6\n".
1201 " \"{Libraries}IntEnv.far.o\" \xb6\n".
1202 " \"{Libraries}Interface.o\" \xb6\n".
1203 " \"{Libraries}Navigation.far.o\" \xb6\n".
1204 " \"{Libraries}OpenTransport.o\" \xb6\n".
1205 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
1206 " \"{Libraries}OpenTptInet.o\" \xb6\n".
1207 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
1208 "\n".
1209 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1210 " \"{SharedLibraries}StdCLib\" \xb6\n".
1211 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
1212 " -weaklib AppearanceLib \xb6\n".
1213 " \"{SharedLibraries}NavigationLib\" \xb6\n".
1214 " -weaklib NavigationLib \xb6\n".
1215 " \"{SharedLibraries}TextCommon\" \xb6\n".
1216 " -weaklib TextCommon \xb6\n".
1217 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1218 " -weaklib UnicodeConverter\n".
1219 "\n".
1220 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1221 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1222 "\n".
1223 "Libs_PPC = {Libs_CFM} \xb6\n".
1224 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1225 " -weaklib ControlsLib \xb6\n".
1226 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1227 " -weaklib WindowsLib \xb6\n".
1228 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1229 " -weaklib OTClientLib \xb6\n".
1230 " -weaklib OTClientUtilLib \xb6\n".
1231 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1232 " -weaklib OTInetClientLib \xb6\n".
1233 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1234 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1235 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1236 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1237 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1238 "\n".
1239 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1240 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1241 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1242 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1243 " \"{SharedLibraries}StdCLib\"\n".
1244 "\n";
1245 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1246 print "\n\n";
1247 foreach $p (&prognames("M")) {
1248 ($prog, $type) = split ",", $p;
1249
1250 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1251 undef, "\xb6"), "\n\n";
1252
1253 $rsrc = &objects($p, "", "X.rsrc", undef);
1254
1255 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1256 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1257 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1258 print "\n";
1259 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1260 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1261 "{LinkOptions_$arch} " .
1262 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1263 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1264 }
1265
1266 }
1267 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1268 next unless $d->{obj};
1269 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1270 undef, "\xb6"), "\n";
1271 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1272 }
1273 foreach $arch (qw(68K CFM68K)) {
1274 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1275 next unless $d->{obj};
1276 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1277 join " ", @{$d->{deps}}),
1278 undef, "\xb6"), "\n";
1279 print "\t{C_$arch} ", $d->{deps}->[0],
1280 " -o {Targ} {COptions_$arch}\n\n";
1281 }
1282 }
1283 foreach $arch (qw(PPC Carbon)) {
1284 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1285 next unless $d->{obj};
1286 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1287 join " ", @{$d->{deps}}),
1288 undef, "\xb6"), "\n";
1289 # The odd stuff here seems to stop afpd getting confused.
1290 print "\techo -n > {Targ}\n";
1291 print "\tsetfile -t XCOF {Targ}\n";
1292 print "\t{C_$arch} ", $d->{deps}->[0],
1293 " -o {Targ} {COptions_$arch}\n\n";
1294 }
1295 }
1296 select STDOUT; close OUT;
1297 }
1298
1299 if (defined $makefiles{'lcc'}) {
1300 $mftyp = 'lcc';
1301 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1302
1303 ##-- lcc makefile
1304 open OUT, ">$makefiles{'lcc'}"; select OUT;
1305 print
1306 "# Makefile for $project_name under lcc.\n".
1307 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1308 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1309 # lcc command line option is -D not /D
1310 ($_ = $help) =~ s/=\/D/=-D/gs;
1311 print $_;
1312 print
1313 "\n".
1314 "# If you rename this file to `Makefile', you should change this line,\n".
1315 "# so that the .rsp files still depend on the correct makefile.\n".
1316 "MAKEFILE = Makefile.lcc\n".
1317 "\n".
1318 "# C compilation flags\n".
1319 "CFLAGS = -D_WINDOWS " .
1320 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1321 "\n".
1322 "\n".
1323 "# Get include directory for resource compiler\n".
1324 "\n";
1325 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1326 print "\n\n";
1327 foreach $p (&prognames("G:C")) {
1328 ($prog, $type) = split ",", $p;
1329 $objstr = &objects($p, "X.obj", "X.res", undef);
1330 print &splitline("$prog.exe: " . $objstr ), "\n";
1331 $subsystemtype = undef;
1332 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1333 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1334 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1335 print "\n\n";
1336 }
1337
1338 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1339 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1340 "\n";
1341 if ($d->{obj} =~ /\.res$/) {
1342 print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
1343 } else {
1344 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1345 print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1346 " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
1347 }
1348 }
1349 print "\n";
1350 print $makefile_extra{'lcc'} || "";
1351 print "\nclean:\n".
1352 "\t-del *.obj\n".
1353 "\t-del *.exe\n".
1354 "\t-del *.res\n";
1355
1356 select STDOUT; close OUT;
1357 }
1358
1359 if (defined $makefiles{'nestedvm'}) {
1360 $mftyp = 'nestedvm';
1361 $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
1362
1363 ##-- NestedVM makefile
1364 open OUT, ">$makefiles{'nestedvm'}"; select OUT;
1365 print
1366 "# Makefile for $project_name under NestedVM.\n".
1367 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1368 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1369 # gcc command line option is -D not /D
1370 ($_ = $help) =~ s/=\/D/=-D/gs;
1371 print $_;
1372 print
1373 "\n".
1374 "# This path points at the nestedvm root directory\n".
1375 "NESTEDVM = /opt/nestedvm\n".
1376 "# You can define this path to point at your tools if you need to\n".
1377 "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
1378 "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
1379 "\n".
1380 &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
1381 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1382 "\n";
1383 print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
1384 print "\n\n";
1385 foreach $p (&prognames("X")) {
1386 ($prog, $type) = split ",", $p;
1387 $objstr = &objects($p, "X.o", undef, undef);
1388 $objstr =~ s/gtk\.o/nestedvm\.o/g;
1389 print &splitline($prog . ".mips: " . $objstr), "\n";
1390 $libstr = &objects($p, undef, undef, "-lX");
1391 print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " .
1392 $objstr . " $libstr -lm", 69), "\n\n";
1393 }
1394 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1395 $oobjs = $d->{obj};
1396 $ddeps= join " ", @{$d->{deps}};
1397 $oobjs =~ s/gtk/nestedvm/g;
1398 $ddeps =~ s/gtk/nestedvm/g;
1399 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1400 "\n";
1401 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1402 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1403 " -c \$< -o \$\@\n";
1404 }
1405 print "\n";
1406 print $makefile_extra{'nestedvm'} || "";
1407 print "\nclean:\n".
1408 "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
1409 select STDOUT; close OUT;
1410 }
1411
1412 if (defined $makefiles{'osx'}) {
1413 $mftyp = 'osx';
1414 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1415 @osxarchs = ('i386');
1416
1417 ##-- Mac OS X makefile
1418 open OUT, ">$makefiles{'osx'}"; select OUT;
1419 print
1420 "# Makefile for $project_name under Mac OS X.\n".
1421 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1422 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1423 # gcc command line option is -D not /D
1424 ($_ = $help) =~ s/=\/D/=-D/gs;
1425 print $_;
1426 print
1427 "CC = \$(TOOLPATH)gcc\n".
1428 "LIPO = \$(TOOLPATH)lipo\n".
1429 "\n".
1430 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1431 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1432 "LDFLAGS = -framework Cocoa\n".
1433 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1434 "\n";
1435 print $makefile_extra{'osx'} || "";
1436 print "\n".
1437 ".SUFFIXES: .o .c .m\n".
1438 "\n";
1439 print "\n\n";
1440 foreach $p (&prognames("MX")) {
1441 ($prog, $type) = split ",", $p;
1442 $icon = &special($p, ".icns");
1443 $infoplist = &special($p, "info.plist");
1444 print "${prog}.app:\n\tmkdir -p \$\@\n";
1445 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1446 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1447 $targets = "${prog}.app/Contents/MacOS/$prog";
1448 if (defined $icon) {
1449 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1450 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1451 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1452 }
1453 if (defined $infoplist) {
1454 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1455 $targets .= " ${prog}.app/Contents/Info.plist";
1456 }
1457 $targets .= " \$(${prog}_extra)";
1458 print &splitline("${prog}: $targets", 69) . "\n\n";
1459 $libstr = &objects($p, undef, undef, "-lX");
1460 $archbins = "";
1461 foreach $arch (@osxarchs) {
1462 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1463 print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
1464 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(LDFLAGS) -o \$@ " .
1465 $objstr . " $libstr", 69), "\n\n";
1466 $archbins .= " ${prog}.${arch}.bin";
1467 }
1468 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1469 "${prog}.app/Contents/MacOS" . $archbins), "\n";
1470 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1471 }
1472 foreach $p (&prognames("U")) {
1473 ($prog, $type) = split ",", $p;
1474 $libstr = &objects($p, undef, undef, "-lX");
1475 $archbins = "";
1476 foreach $arch (@osxarchs) {
1477 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1478 print &splitline("${prog}.${arch}: " . $objstr), "\n";
1479 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(ULDFLAGS) -o \$@ " .
1480 $objstr . " $libstr", 69), "\n\n";
1481 $archbins .= " ${prog}.${arch}";
1482 }
1483 print &splitline("${prog}:" . $archbins), "\n";
1484 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1485 }
1486 foreach $arch (@osxarchs) {
1487 foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) {
1488 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1489 "\n";
1490 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1491 if ($d->{deps}->[0] =~ /\.m$/) {
1492 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1493 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1494 } else {
1495 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1496 " -c \$< -o \$\@\n";
1497 }
1498 }
1499 }
1500 print "\nclean:\n".
1501 "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
1502 "\trm -rf *.app\n";
1503 select STDOUT; close OUT;
1504 }
1505
1506 if (defined $makefiles{'gnustep'}) {
1507 $mftyp = 'gnustep';
1508 $dirpfx = &dirpfx($makefiles{'gnustep'}, "/");
1509
1510 ##-- GNUstep makefile (use with 'gs_make -f Makefile.gnustep')
1511
1512 # This is a pretty evil way to do things. In an ideal world, I'd
1513 # use the approved GNUstep makefile mechanism which just defines a
1514 # variable or two saying what source files go into what binary and
1515 # then includes application.make. Unfortunately, that has the
1516 # automake-ish limitation that it doesn't let you choose different
1517 # command lines for each object, so I can't arrange for all those
1518 # files with -DTHIS and -DTHAT to Just Work.
1519 #
1520 # A simple if ugly fix would be to have mkfiles.pl construct a
1521 # directory full of stub C files of the form '#define thing',
1522 # '#include "real_source_file"', and then reference those in this
1523 # makefile. That would also make it easy to build a proper
1524 # automake makefile.
1525 open OUT, ">$makefiles{'gnustep'}"; select OUT;
1526 print
1527 "# Makefile for $project_name under GNUstep.\n".
1528 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1529 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1530 # gcc command line option is -D not /D
1531 ($_ = $help) =~ s/=\/D/=-D/gs;
1532 print $_;
1533 print
1534 "NEEDS_GUI=yes\n".
1535 "include \$(GNUSTEP_MAKEFILES)/common.make\n".
1536 "include \$(GNUSTEP_MAKEFILES)/rules.make\n".
1537 "include \$(GNUSTEP_MAKEFILES)/Instance/rules.make\n".
1538 "\n".
1539 &splitline("all::" . join "", map { " $_" } &progrealnames("MX:U")) .
1540 "\n";
1541 print $makefile_extra{'gnustep'} || "";
1542 print "\n".
1543 ".SUFFIXES: .o .c .m\n".
1544 "\n";
1545 print "\n\n";
1546 foreach $p (&prognames("MX")) {
1547 ($prog, $type) = split ",", $p;
1548 $icon = &special($p, ".icns");
1549 $infoplist = &special($p, "info.plist");
1550 print "${prog}.app:\n\tmkdir -p \$\@\n";
1551 $targets = "${prog}.app ${prog}.app/$prog";
1552 if (defined $icon) {
1553 print "${prog}.app/Resources: ${prog}.app\n\tmkdir -p \$\@\n";
1554 print "${prog}.app/Resources/${prog}.icns: ${prog}.app/Resources $icon\n\tcp $icon \$\@\n";
1555 $targets .= " ${prog}.app/Resources/${prog}.icns";
1556 }
1557 if (defined $infoplist) {
1558 print "${prog}.app/Info.plist: ${prog}.app $infoplist\n\tcp $infoplist \$\@\n";
1559 $targets .= " ${prog}.app/Info.plist";
1560 }
1561 $targets .= " \$(${prog}_extra)";
1562 print &splitline("${prog}: $targets", 69) . "\n\n";
1563 $libstr = &objects($p, undef, undef, "-lX");
1564 $objstr = &objects($p, "X.o", undef, undef);
1565 print &splitline("${prog}.app/$prog: " . $objstr), "\n";
1566 print &splitline("\t\$(CC) \$(ALL_LDFLAGS) -o \$@ " . $objstr . " \$(ALL_LIB_DIRS) $libstr \$(ALL_LIBS)", 69), "\n\n";
1567 }
1568 foreach $p (&prognames("U")) {
1569 ($prog, $type) = split ",", $p;
1570 $libstr = &objects($p, undef, undef, "-lX");
1571 $objstr = &objects($p, "X.o", undef, undef);
1572 print &splitline("${prog}: " . $objstr), "\n";
1573 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n";
1574 }
1575 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1576 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1577 "\n";
1578 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1579 if ($d->{deps}->[0] =~ /\.m$/) {
1580 print "\t\$(CC) -DGNUSTEP \$(ALL_OBJCFLAGS) \$(COMPAT) \$(FWHACK) \$(OBJCFLAGS)".
1581 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1582 } else {
1583 print "\t\$(CC) \$(ALL_CFLAGS) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1584 " -c \$< -o \$\@\n";
1585 }
1586 }
1587 print "\nclean::\n".
1588 "\trm -f *.o ". (join " ", &progrealnames("U")) . "\n".
1589 "\trm -rf *.app\n";
1590 select STDOUT; close OUT;
1591 }