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