3 # Cross-platform Makefile generator.
5 # Reads the file `Recipe' to determine the list of generated
6 # executables and their component objects. Then reads the source
7 # files to compute #include dependencies. Finally, writes out the
8 # various target Makefiles.
10 # PuTTY specifics which could still do with removing:
11 # - Mac makefile is not portabilised at all. Include directories
12 # are hardwired, and also the libraries are fixed. This is
13 # mainly because I was too scared to go anywhere near it.
14 # - sbcsgen.pl is still run at startup.
16 # Other things undone:
17 # - special-define objects (foo.o[PREPROCSYMBOL]) are not
18 # supported in the mac or vcproj makefiles.
26 if ($ARGV[0] eq "-U") {
27 # Convenience for Unix users: -U means that after we finish what
28 # we're doing here, we also run mkauto.sh and then 'configure'. So
29 # it's a one-stop shop for regenerating the actual end-product
32 # Arguments supplied after -U go to configure.
38 die "unrecognised command-line argument '$ARGV[0]'\n";
44 open $in, "Recipe" or do {
45 # We want to deal correctly with being run from one of the
46 # subdirs in the source tree. So if we can't find Recipe here,
49 open $in, "Recipe" or die "unable to open Recipe file\n";
53 # HACK: One of the source files in `charset' is auto-generated by
54 # sbcsgen.pl. We need to generate that _now_, before attempting
55 # dependency analysis.
56 eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."';
60 $divert = undef; # ref to array of refs of scalars in which text is
62 $help = ""; # list of newline-free lines of help text
63 $project_name = "project"; # this is a good enough default
64 %makefiles = (); # maps makefile types to output makefile pathnames
65 %makefile_extra = (); # maps makefile types to extra Makefile text
66 %programs = (); # maps prog name + type letter to listref of objects/resources
67 %groups = (); # maps group name to listref of objects/resources
69 @allobjs = (); # all object file names
71 readinput: while (1) {
72 $in = $filestack[$#filestack];
73 while (not defined ($_ = <$in>)) {
74 close $filestack[$#filestack];
76 last readinput if 0 == scalar @filestack;
77 $in = $filestack[$#filestack];
82 # If we're gathering help text, keep doing so.
83 if (defined $divert) {
84 if ((defined $_[0]) && $_[0] eq "!end") {
87 for my $ref (@$divert) {
93 # Skip comments and blank lines.
94 next if /^\s*#/ or scalar @_ == 0;
96 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = [\$help]; next; }
97 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
98 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
99 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
100 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
101 if ($_[0] eq "!cflags" and &mfval($_[1])) {
102 ($rest = $_) =~ s/^\s*\S+\s+\S+\s+\S+\s*//; # find rest of input line
103 $rest = 1 if $rest eq "";
104 $cflags{$_[1]}->{$_[2]} = $rest;
107 if ($_[0] eq "!begin") {
111 for my $component (@args) {
112 if ($component =~ /^>(.*)/) {
113 push @$divert, \$auxfiles{$1};
114 } elsif ($component =~ /^([^_]*)(_.*)?$/ and &mfval($1)) {
115 push @$divert, \$makefile_extra{$component};
120 if ($_[0] eq "!include") {
122 for ($i = 1; $i <= $#_; $i++) {
123 push @newfiles, (sort glob $_[$i]);
125 for ($i = $#newfiles; $i >= 0; $i--) {
126 $file = $newfiles[$i];
128 open $f, "<$file" or die "unable to open include file '$file'\n";
134 # Now we have an ordinary line. See if it's an = line, a : line
139 $listref = $lastlistref;
141 die "$.: unexpected + line\n" if !defined $lastlistref;
142 } elsif ($_[1] eq "=") {
144 $listref = $groups{$_[0]};
146 shift @objs; # eat the group name
147 } elsif ($_[1] eq "+=") {
148 $groups{$_[0]} = [] if !defined $groups{$_[0]};
149 $listref = $groups{$_[0]};
151 shift @objs; # eat the group name
152 } elsif ($_[1] eq ":") {
155 shift @objs; # eat the program name
157 die "$.: unrecognised line type: '$_'\n";
159 shift @objs; # eat the +, the = or the :
161 while (scalar @objs > 0) {
164 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
165 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
166 $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
167 $type = substr($i,1,(length $i)-2);
170 # Object files with a trailing question mark are optional:
171 # the build can proceed fine without them, so we only use
172 # them if their primary source files are present.
174 $i = undef unless defined &finddep($i);
175 } elsif ($i =~ /\|/) {
176 # Object file descriptions containing a vertical bar are
177 # lists of choices: we use the _first_ one whose primary
178 # source file is present.
179 @options = split /\|/, $i;
181 foreach $k (@options) {
182 $j=$k, last if defined &finddep($k);
184 die "no alternative found for $i\n" unless defined $j;
193 if ($prog and $type) {
194 die "multiple program entries for $prog [$type]\n"
195 if defined $programs{$prog . "," . $type};
196 $programs{$prog . "," . $type} = $listref;
198 $lastlistref = $listref;
201 foreach $aux (sort keys %auxfiles) {
203 print AUX $auxfiles{$aux};
207 # Find object file names with predefines (in square brackets after
208 # the module name), and decide on actual object names for them.
209 foreach $i (@allobjs) {
213 $usedobjname{$i} = 1;
216 foreach $i (@allobjs) {
217 if ($i =~ /^(.*)\[([^\]]*)/) {
218 $defs{$i} = [ split ",",$2 ];
219 $srcname{$i} = $s = $1;
223 $maxlen = 8 if $maxlen < 8;
224 $chop = $maxlen - length $index;
225 $chop = length $s if $chop > length $s;
226 $chop = 0 if $chop < 0;
227 $name = substr($s, 0, $chop) . $index;
228 $index++, next if $usedobjname{$name};
229 $objname{$i} = $name;
230 $usedobjname{$name} = 1;
236 # Now retrieve the complete list of objects and resource files, and
237 # construct dependency data for them. While we're here, expand the
238 # object list for each program, and complain if its type isn't set.
239 @prognames = sort keys %programs;
242 foreach $i (@prognames) {
243 ($prog, $type) = split ",", $i;
244 # Strip duplicate object names.
246 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
247 sort @{$programs{$i}};
248 $programs{$i} = [@list];
249 foreach $jj (@list) {
251 $file = &finddep($j);
253 $depends{$jj} = [$file];
254 push @scanlist, $file;
259 # Scan each file on @scanlist and find further inclusions.
260 # Inclusions are given by lines of the form `#include "otherfile"'
261 # (system headers are automatically ignored by this because they'll
262 # be given in angle brackets). Files included by this method are
263 # added back on to @scanlist to be scanned in turn (if not already
266 # Resource scripts (.rc) can also include a file by means of a line
267 # ending `ICON "filename"'. Files included by this method are not
268 # added to @scanlist because they can never include further files.
270 # In this pass we write out a hash %further which maps a source
271 # file name into a listref containing further source file names.
274 while (scalar @scanlist > 0) {
275 $file = shift @scanlist;
276 next if defined $further{$file}; # skip if we've already done it
277 $further{$file} = [];
278 $dirfile = &findfile($file);
279 open IN, "$dirfile" or die "unable to open source file $file\n";
282 /^\s*#include\s+\"([^\"]+)\"/ and do {
283 push @{$further{$file}}, $1;
287 /ICON\s+\"([^\"]+)\"\s*$/ and do {
288 push @{$further{$file}}, $1;
295 # Now we're ready to generate the final dependencies section. For
296 # each key in %depends, we must expand the dependencies list by
297 # iteratively adding entries from %further.
298 foreach $i (keys %depends) {
300 @scanlist = @{$depends{$i}};
301 foreach $i (@scanlist) { $dep{$i} = 1; }
302 while (scalar @scanlist > 0) {
303 $file = shift @scanlist;
304 foreach $j (@{$further{$file}}) {
307 push @{$depends{$i}}, $j;
312 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
315 # Validation of input.
319 # Returns true if the argument is a known makefile type. Otherwise,
320 # prints a warning and returns false;
321 if (grep { $type eq $_ }
322 ("vc","vcproj","cygwin","borland","lcc","gtk","am","mpw","nestedvm","osx","wce","gnustep","emcc")) {
325 warn "$.:unknown makefile type '$type'\n";
329 # Utility routines while writing out the Makefiles.
332 my ($path) = shift @_;
333 my ($sep) = shift @_;
336 while (($i = index $path, $sep) >= 0) {
337 $path = substr $path, ($i + length $sep);
348 unless (defined $findfilecache{$name}) {
350 foreach $dir (@srcdirs) {
351 $outdir = $dir, $i++ if -f "$dir$name";
353 die "multiple instances of source file $name\n" if $i > 1;
354 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
356 return $findfilecache{$name};
362 # Find the first dependency of an object.
364 # Dependencies for "x" start with "x.c" or "x.m" (depending on
366 # Dependencies for "x.res" start with "x.rc".
367 # Dependencies for "x.rsrc" start with "x.r".
368 # Both types of file are pushed on the list of files to scan.
369 # Libraries (.lib) don't have dependencies at all.
370 if ($j =~ /^(.*)\.res$/) {
372 } elsif ($j =~ /^(.*)\.rsrc$/) {
374 } elsif ($j !~ /\./) {
376 $file = "$j.m" unless &findfile($file);
378 # For everything else, we assume it's its own dependency.
381 $file = undef unless &findfile($file);
386 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
389 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
391 foreach $ii (@{$programs{$prog}}) {
394 if ($i =~ /^(.*)\.(res|rsrc)/) {
396 ($x = $rtmpl) =~ s/X/$y/;
397 } elsif ($i =~ /^(.*)\.lib/) {
399 ($x = $ltmpl) =~ s/X/$y/;
400 } elsif ($i !~ /\./) {
401 ($x = $otmpl) =~ s/X/$i/;
403 push @ret, $x if $x ne "";
405 return join " ", @ret;
409 my ($prog, $suffix) = @_;
413 foreach $ii (@{$programs{$prog}}) {
415 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
419 return join " ", @ret;
423 my ($line, $width, $splitchar) = @_;
426 $len = (defined $width ? $width : 76);
427 $splitchar = (defined $splitchar ? $splitchar : '\\');
428 while (length $line > $len) {
429 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
431 $result .= " ${splitchar}\n\t\t" if $2 ne '';
435 return $result . $line;
439 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
445 foreach $ii (sort keys %depends) {
447 next if $specialobj{$mftyp}->{$i};
448 if ($i =~ /^(.*)\.(res|rsrc)/) {
449 next if !defined $rtmpl;
451 ($x = $rtmpl) =~ s/X/$y/;
453 ($x = $otmpl) =~ s/X/$i/;
455 @deps = @{$depends{$ii}};
456 # Skip things which are their own dependency.
457 next if grep { $_ eq $i } @deps;
463 push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}};
470 my ($n, $prog, $type);
473 foreach $n (@prognames) {
474 ($prog, $type) = split ",", $n;
475 push @ret, $n if index(":$types:", ":$type:") >= 0;
482 my ($n, $prog, $type);
485 foreach $n (@prognames) {
486 ($prog, $type) = split ",", $n;
487 push @ret, $prog if index(":$types:", ":$type:") >= 0;
493 my ($types,$suffix) = @_;
495 # assume that all UNIX programs have a man page
496 if($suffix eq "1" && $types =~ /:X:/) {
497 return map("$_.1", &progrealnames($types));
504 # Now we're ready to output the actual Makefiles.
506 if (defined $makefiles{'cygwin'}) {
508 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
511 open OUT, ">$makefiles{'cygwin'}"; select OUT;
513 "# Makefile for $project_name under cygwin.\n".
514 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
515 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
516 # gcc command line option is -D not /D
517 ($_ = $help) =~ s/=\/D/=-D/gs;
521 "# You can define this path to point at your tools if you need to\n".
522 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
523 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
524 "CC = \$(TOOLPATH)gcc\n".
525 "RC = \$(TOOLPATH)windres\n".
526 "# Uncomment the following two lines to compile under Winelib\n".
529 "# You may also need to tell windres where to find include files:\n".
530 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
532 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
533 " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
534 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
536 "LDFLAGS = -mno-cygwin -s\n".
537 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
538 " --define WINVER=0x0400 --define MINGW32_FIX=1 " .
539 (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n".
541 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
543 foreach $p (&prognames("G:C")) {
544 ($prog, $type) = split ",", $p;
545 $objstr = &objects($p, "X.o", "X.res.o", undef);
546 print &splitline($prog . ".exe: " . $objstr), "\n";
547 my $mw = $type eq "G" ? " -mwindows" : "";
548 $libstr = &objects($p, undef, undef, "-lX");
549 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
550 "-Wl,-Map,$prog.map " .
551 $objstr . " $libstr", 69), "\n\n";
553 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
554 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
556 if ($d->{obj} =~ /\.res\.o$/) {
557 print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
559 $deflist = join "", map { " -D$_" } @{$d->{defs}};
560 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" .
561 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
565 print $makefile_extra{'cygwin'} || "";
567 "\trm -f *.o *.exe *.res.o *.map\n".
569 select STDOUT; close OUT;
573 ##-- Borland makefile
574 if (defined $makefiles{'borland'}) {
576 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
578 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
590 open OUT, ">$makefiles{'borland'}"; select OUT;
592 "# Makefile for $project_name under Borland C.\n".
593 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
594 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
595 # bcc32 command line option is -D not /D
596 ($_ = $help) =~ s/=\/D/=-D/gs;
600 "# If you rename this file to `Makefile', you should change this line,\n".
601 "# so that the .rsp files still depend on the correct makefile.\n".
602 "MAKEFILE = Makefile.bor\n".
604 "# C compilation flags\n".
605 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
607 "# Get include directory for resource compiler\n".
609 "BCB = \$(MAKEDIR)\\..\n".
612 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
614 foreach $p (&prognames("G:C")) {
615 ($prog, $type) = split ",", $p;
616 $objstr = &objects($p, "X.obj", "X.res", undef);
617 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
618 my $ap = ($type eq "G") ? "-aa" : "-ap";
619 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
621 foreach $p (&prognames("G:C")) {
622 ($prog, $type) = split ",", $p;
623 print $prog, ".rsp: \$(MAKEFILE)\n";
624 $objstr = &objects($p, "X.obj", undef, undef);
625 @objlist = split " ", $objstr;
627 foreach $i (@objlist) {
628 if (length($objlines[$#objlines] . " $i") > 50) {
631 $objlines[$#objlines] .= " $i";
633 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
634 print "\techo $c0w + > $prog.rsp\n";
635 for ($i=0; $i<=$#objlines; $i++) {
636 $plus = ($i < $#objlines ? " +" : "");
637 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
639 print "\techo $prog.exe >> $prog.rsp\n";
640 $objstr = &objects($p, "X.obj", "X.res", undef);
641 @libs = split " ", &objects($p, undef, undef, "X");
642 @libs = grep { !$stdlibs{$_} } @libs;
643 unshift @libs, "cw32", "import32";
644 $libstr = join ' ', @libs;
645 print "\techo nul,$libstr, >> $prog.rsp\n";
646 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
649 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
650 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
652 if ($d->{obj} =~ /\.res$/) {
653 print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " .
654 "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32".
655 " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n";
657 $deflist = join "", map { " -D$_" } @{$d->{defs}};
658 print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
659 " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ".
660 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
661 " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
665 print $makefile_extra{'borland'} || "";
676 "\t-del *.\$\$\$\$\$\$\n";
677 select STDOUT; close OUT;
680 if (defined $makefiles{'vc'}) {
682 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
684 ##-- Visual C++ makefile
685 open OUT, ">$makefiles{'vc'}"; select OUT;
687 "# Makefile for $project_name under Visual C.\n".
688 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
689 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
693 "# If you rename this file to `Makefile', you should change this line,\n".
694 "# so that the .rsp files still depend on the correct makefile.\n".
695 "MAKEFILE = Makefile.vc\n".
697 "# C compilation flags\n".
698 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401 /I.\n".
699 "LFLAGS = /incremental:no /fixed\n".
701 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
703 foreach $p (&prognames("G:C")) {
704 ($prog, $type) = split ",", $p;
705 $objstr = &objects($p, "X.obj", "X.res", undef);
706 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
707 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
709 foreach $p (&prognames("G:C")) {
710 ($prog, $type) = split ",", $p;
711 print $prog, ".rsp: \$(MAKEFILE)\n";
712 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
713 @objlist = split " ", $objstr;
715 foreach $i (@objlist) {
716 if (length($objlines[$#objlines] . " $i") > 50) {
719 $objlines[$#objlines] .= " $i";
721 $subsys = ($type eq "G") ? "windows" : "console";
722 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
723 for ($i=0; $i<=$#objlines; $i++) {
724 print "\techo$objlines[$i] >> $prog.rsp\n";
728 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
729 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
731 if ($d->{obj} =~ /\.res$/) {
732 print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
733 "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
735 $deflist = join "", map { " /D$_" } @{$d->{defs}};
736 print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
737 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
741 print $makefile_extra{'vc'} || "";
742 print "\nclean: tidy\n".
759 "\t-del debug.log\n";
760 select STDOUT; close OUT;
763 if (defined $makefiles{'wce'}) {
765 $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
767 ##-- eMbedded Visual C PocketPC makefile
768 open OUT, ">$makefiles{'wce'}"; select OUT;
770 "# Makefile for $project_name on PocketPC using eMbedded Visual C.\n".
771 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
772 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
776 "# If you rename this file to `Makefile', you should change this line,\n".
777 "# so that the .rsp files still depend on the correct makefile.\n".
778 "MAKEFILE = Makefile.wce\n".
780 "# This makefile expects the environment to have been set up by one\n".
781 "# of the PocketPC batch files wcearmv4.bat and wceemulator.bat. No\n".
782 "# other build targets are currently supported, because they would\n".
783 "# need a section in this if statement.\n".
784 "!if \"\$(TARGETCPU)\" == \"emulator\"\n".
785 "PLATFORM_DEFS=/D \"_i386_\" /D \"i_386_\" /D \"_X86_\" /D \"x86\"\n".
787 "BASELIBS=commctrl.lib coredll.lib corelibc.lib aygshell.lib\n".
790 "PLATFORM_DEFS=/D \"ARM\" /D \"_ARM_\" /D \"ARMV4\"\n".
792 "BASELIBS=commctrl.lib coredll.lib aygshell.lib\n".
796 "# C compilation flags\n".
797 "CFLAGS = /nologo /W3 /O1 /MC /D _WIN32_WCE=420 /D \"WIN32_PLATFORM_PSPC=400\" /D UNDER_CE=420 \\\n".
798 " \$(PLATFORM_DEFS) \\\n".
799 " /D \"UNICODE\" /D \"_UNICODE\" /D \"NDEBUG\" /D \"NO_HTMLHELP\"\n".
801 "LFLAGS = /nologo /incremental:no \\\n".
802 " /base:0x00010000 /stack:0x10000,0x1000 /entry:WinMainCRTStartup \\\n".
803 " /nodefaultlib:libc.lib /nodefaultlib:libcmt.lib /nodefaultlib:msvcrt.lib /nodefaultlib:OLDNAMES.lib \\\n".
804 " /subsystem:windowsce,4.20 /align:4096 /MACHINE:\$(MACHINE)\n".
806 "RCFL = /d UNDER_CE=420 /d _WIN32_WCE=420 /d \"WIN32_PLATFORM_PSPC=400\" \\\n".
807 " \$(PLATFORM_DEFS) \\\n".
808 " /d \"NDEBUG\" /d \"UNICODE\" /d \"_UNICODE\"\n".
810 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G"));
812 foreach $p (&prognames("G")) {
813 ($prog, $type) = split ",", $p;
814 $objstr = &objects($p, "X.obj", "X.res", undef);
815 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
816 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
818 foreach $p (&prognames("G")) {
819 ($prog, $type) = split ",", $p;
820 print $prog, ".rsp: \$(MAKEFILE)\n";
821 $objstr = &objects($p, "X.obj", "X.res", undef);
822 @objlist = split " ", $objstr;
824 foreach $i (@objlist) {
825 if (length($objlines[$#objlines] . " $i") > 50) {
828 $objlines[$#objlines] .= " $i";
830 print "\techo \$(BASELIBS) > $prog.rsp\n";
831 for ($i=0; $i<=$#objlines; $i++) {
832 print "\techo$objlines[$i] >> $prog.rsp\n";
836 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
837 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
839 if ($d->{obj} =~ /\.res$/) {
840 print "\trc \$(FWHACK) \$(RCFL) -r -fo".
841 $d->{obj}." ".$d->{deps}->[0]."\n";
843 $deflist = join "", map { " /D$_" } @{$d->{defs}};
844 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
845 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
849 print $makefile_extra{'wce'} || "";
850 print "\nclean: tidy\n".
867 "\t-del debug.log\n";
868 select STDOUT; close OUT;
871 if (defined $makefiles{'vcproj'}) {
874 ##-- MSVC 6 Workspace and projects
876 # Note: All files created in this section are written in binary
877 # mode, because although MSVC's command-line make can deal with
878 # LF-only line endings, MSVC project files really _need_ to be
879 # CRLF. Hence, in order for mkfiles.pl to generate usable project
880 # files even when run from Unix, I make sure all files are binary
881 # and explicitly write the CRLFs.
883 # Create directories if necessary
884 mkdir $makefiles{'vcproj'}
885 if(! -d $makefiles{'vcproj'});
886 chdir $makefiles{'vcproj'};
887 @deps = &deps("X.obj", "X.res", "", "\\");
888 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
889 # Create the project files
890 # Get names of all Windows projects (GUI and console)
891 my @prognames = &prognames("G:C");
892 foreach $progname (@prognames) {
893 create_project(\%all_object_deps, $progname);
895 # Create the workspace file
896 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
898 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
899 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
901 "###############################################################################\r\n".
904 foreach $progname (@prognames) {
905 ($windows_project, $type) = split ",", $progname;
906 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
918 "###############################################################################\r\n".
930 "###############################################################################\r\n".
932 select STDOUT; close OUT;
936 my ($all_object_deps, $progname) = @_;
937 # Construct program's dependency info
942 %resource_files = ();
943 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
944 foreach $object_file (@object_files) {
945 next if defined $seen_objects{$object_file};
946 $seen_objects{$object_file} = 1;
947 if($object_file =~ /\.lib$/io) {
948 $lib_files{$object_file} = 1;
951 $object_deps = $all_object_deps{$object_file};
952 foreach $object_dep (@$object_deps) {
953 if($object_dep =~ /\.c$/io) {
954 $source_files{$object_dep} = 1;
957 if($object_dep =~ /\.h$/io) {
958 $header_files{$object_dep} = 1;
961 if($object_dep =~ /\.(rc|ico)$/io) {
962 $resource_files{$object_dep} = 1;
967 $libs = join " ", sort keys %lib_files;
968 @source_files = sort keys %source_files;
969 @header_files = sort keys %header_files;
970 @resources = sort keys %resource_files;
971 ($windows_project, $type) = split ",", $progname;
972 mkdir $windows_project
973 if(! -d $windows_project);
974 chdir $windows_project;
975 $subsys = ($type eq "G") ? "windows" : "console";
976 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
978 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
979 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
980 "# ** DO NOT EDIT **\r\n".
982 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
984 "CFG=$windows_project - Win32 Debug\r\n".
985 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
986 "!MESSAGE use the Export Makefile command and run\r\n".
988 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
990 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
991 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
993 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
995 "!MESSAGE Possible choices for configuration are:\r\n".
997 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
998 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
1001 "# Begin Project\r\n".
1002 "# PROP AllowPerConfigDependencies 0\r\n".
1003 "# PROP Scc_ProjName \"\"\r\n".
1004 "# PROP Scc_LocalPath \"\"\r\n".
1009 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1011 "# PROP BASE Use_MFC 0\r\n".
1012 "# PROP BASE Use_Debug_Libraries 0\r\n".
1013 "# PROP BASE Output_Dir \"Release\"\r\n".
1014 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
1015 "# PROP BASE Target_Dir \"\"\r\n".
1016 "# PROP Use_MFC 0\r\n".
1017 "# PROP Use_Debug_Libraries 0\r\n".
1018 "# PROP Output_Dir \"Release\"\r\n".
1019 "# PROP Intermediate_Dir \"Release\"\r\n".
1020 "# PROP Ignore_Export_Lib 0\r\n".
1021 "# PROP Target_Dir \"\"\r\n".
1022 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1023 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1024 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1025 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1026 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
1027 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
1028 "BSC32=bscmake.exe\r\n".
1029 "# ADD BASE BSC32 /nologo\r\n".
1030 "# ADD BSC32 /nologo\r\n".
1031 "LINK32=link.exe\r\n".
1032 "# 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".
1033 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
1034 "# SUBTRACT LINK32 /pdb:none\r\n".
1036 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1038 "# PROP BASE Use_MFC 0\r\n".
1039 "# PROP BASE Use_Debug_Libraries 1\r\n".
1040 "# PROP BASE Output_Dir \"Debug\"\r\n".
1041 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
1042 "# PROP BASE Target_Dir \"\"\r\n".
1043 "# PROP Use_MFC 0\r\n".
1044 "# PROP Use_Debug_Libraries 1\r\n".
1045 "# PROP Output_Dir \"Debug\"\r\n".
1046 "# PROP Intermediate_Dir \"Debug\"\r\n".
1047 "# PROP Ignore_Export_Lib 0\r\n".
1048 "# PROP Target_Dir \"\"\r\n".
1049 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1050 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1051 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1052 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1053 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
1054 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
1055 "BSC32=bscmake.exe\r\n".
1056 "# ADD BASE BSC32 /nologo\r\n".
1057 "# ADD BSC32 /nologo\r\n".
1058 "LINK32=link.exe\r\n".
1059 "# 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".
1060 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
1061 "# SUBTRACT LINK32 /pdb:none\r\n".
1065 "# Begin Target\r\n".
1067 "# Name \"$windows_project - Win32 Release\"\r\n".
1068 "# Name \"$windows_project - Win32 Debug\"\r\n".
1069 "# Begin Group \"Source Files\"\r\n".
1071 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
1072 foreach $source_file (@source_files) {
1074 "# Begin Source File\r\n".
1076 "SOURCE=..\\..\\$source_file\r\n";
1077 if($source_file =~ /ssh\.c/io) {
1078 # Disable 'Edit and continue' as Visual Studio can't handle the macros
1081 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1083 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1085 "# ADD CPP /Zi\r\n".
1090 print "# End Source File\r\n";
1094 "# Begin Group \"Header Files\"\r\n".
1096 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1097 foreach $header_file (@header_files) {
1099 "# Begin Source File\r\n".
1101 "SOURCE=..\\..\\$header_file\r\n".
1102 "# End Source File\r\n";
1106 "# Begin Group \"Resource Files\"\r\n".
1108 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1109 foreach $resource_file (@resources) {
1111 "# Begin Source File\r\n".
1113 "SOURCE=..\\..\\$resource_file\r\n".
1114 "# End Source File\r\n";
1119 "# End Project\r\n";
1120 select STDOUT; close OUT;
1125 if (defined $makefiles{'gtk'}) {
1127 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1129 ##-- X/GTK/Unix makefile
1130 open OUT, ">$makefiles{'gtk'}"; select OUT;
1132 "# Makefile for $project_name under X/GTK and Unix.\n".
1133 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1134 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1135 # gcc command line option is -D not /D
1136 ($_ = $help) =~ s/=\/D/=-D/gs;
1140 "# You can define this path to point at your tools if you need to\n".
1141 "# TOOLPATH = /opt/gcc/bin\n".
1142 "CC := \$(TOOLPATH)\$(CC)\n".
1143 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1144 "# (depending on what works on your system) if you want to enforce\n".
1145 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n".
1146 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1147 "# to 1.2 if it isn't found.\n".
1148 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1150 &splitline("CFLAGS := -O2 -Wall -Werror -ansi -pedantic -g " .
1151 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1152 " `\$(GTK_CONFIG) --cflags` \$(CFLAGS)")."\n".
1153 "XLIBS = `\$(GTK_CONFIG) --libs` -lm\n".
1155 "INSTALL=install\n",
1156 "INSTALL_PROGRAM=\$(INSTALL)\n",
1157 "INSTALL_DATA=\$(INSTALL)\n",
1158 "prefix=/usr/local\n",
1159 "exec_prefix=\$(prefix)\n",
1160 "bindir=\$(exec_prefix)/bin\n",
1161 "gamesdir=\$(exec_prefix)/games\n",
1162 "mandir=\$(prefix)/man\n",
1163 "man1dir=\$(mandir)/man1\n",
1165 print &splitline("all:" . join "", map { " \$(BINPREFIX)$_" }
1166 &progrealnames("X:U"));
1168 foreach $p (&prognames("X:U")) {
1169 ($prog, $type) = split ",", $p;
1170 $objstr = &objects($p, "X.o", undef, undef);
1171 print &splitline("\$(BINPREFIX)" . $prog . ": " . $objstr), "\n";
1172 $libstr = &objects($p, undef, undef, "-lX");
1173 print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(XLFLAGS) \$(${type}LIBS)", 69),
1176 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1177 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1179 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1180 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1181 " -c \$< -o \$\@\n";
1184 print $makefile_extra{'gtk'} || "";
1186 "\trm -f *.o". (join "", map { " \$(BINPREFIX)$_" } &progrealnames("X:U")) . "\n";
1187 select STDOUT; close OUT;
1190 if (defined $makefiles{'am'}) {
1192 die "Makefile.am in a subdirectory is not supported\n"
1193 if &dirpfx($makefiles{'am'}, "/") ne "";
1195 ##-- Unix/autoconf Makefile.am
1196 open OUT, ">$makefiles{'am'}"; select OUT;
1198 "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1199 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1200 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1202 print $makefile_extra{'am_begin'} || "";
1204 # All programs go in noinstprogs by default. If you want them
1205 # installed anywhere else, you have to also add them to
1206 # bin_PROGRAMS using '!begin am'. (Automake doesn't seem to mind
1207 # having a program name in _both_ of bin_PROGRAMS and
1210 foreach $p (&prognames("X:U")) {
1211 ($prog, $type) = split ",", $p;
1212 push @noinstprogs, $prog;
1214 print &splitline(join " ", "noinst_PROGRAMS", "=", @noinstprogs), "\n";
1217 %amspeciallibs = ();
1220 foreach $d (&deps("X", undef, "", "/", "am")) {
1221 my $obj = $d->{obj};
1222 my $use_archive = 0;
1224 if (defined $d->{defs}) {
1225 # This file needs to go in an archive, so that we can
1226 # change the preprocess flags to include some -Ds
1228 $archivecppflags{$obj} = [map { " -D$_" } @{$d->{defs}}];
1230 if (defined $cflags{'am'} && $cflags{'am'}->{$obj}) {
1231 # This file needs to go in an archive, so that we can
1232 # change the compile flags as specified in Recipe
1234 $archivecflags{$obj} = [$cflags{'am'}->{$obj}];
1237 $amspeciallibs{$obj} = "lib${obj}.a";
1238 $amlibobjname{$obj} = "lib${obj}_a-" .
1239 basename($d->{deps}->[0], ".c", ".m") .
1242 $objtosrc{$obj} = $d->{deps};
1243 map { $allsources{$_} = 1 } @{$d->{deps}};
1246 # 2014-02-22: as of automake-1.14 we begin to get complained at if
1247 # we don't use this option
1248 print "AUTOMAKE_OPTIONS = subdir-objects\n\n";
1250 # Complete list of source and header files. Not used by the
1251 # auto-generated parts of this makefile, but Recipe might like to
1252 # have it available as a variable so that mandatory-rebuild things
1253 # (version.o) can conveniently be made to depend on it.
1254 print &splitline(join " ", "allsources", "=",
1255 sort {$a cmp $b} keys %allsources), "\n\n";
1257 @amcppflags = map {"-I\$(srcdir)/$_"} @srcdirs;
1258 print &splitline(join " ", "AM_CPPFLAGS", "=", @amcppflags, "\n");
1260 @amcflags = ("\$(GTK_CFLAGS)", "\$(WARNINGOPTS)");
1261 print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1264 foreach $p (&prognames("X:U")) {
1265 ($prog, $type) = split ",", $p;
1266 @progsources = ("${prog}_SOURCES", "=");
1269 $objstr = &objects($p, "X", undef, undef);
1270 foreach $obj (split / /,$objstr) {
1271 if ($amspeciallibs{$obj}) {
1272 $amlibsused{$obj} = 1;
1273 push @ldadd, $amlibobjname{$obj};
1275 map { $sourcefiles{$_} = 1 } @{$objtosrc{$obj}};
1278 push @progsources, sort { $a cmp $b } keys %sourcefiles;
1279 print &splitline(join " ", @progsources), "\n";
1281 push @ldadd, "\$(GTK_LIBS)";
1284 print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1288 foreach $obj (sort { $a cmp $b } keys %amlibsused) {
1289 print &splitline(join " ", "lib${obj}_a_SOURCES", "=",
1290 @{$objtosrc{$obj}}), "\n";
1291 print &splitline(join " ", "lib${obj}_a_CPPFLAGS", "=",
1292 @amcflags, @{$archivecppflags{$obj}}), "\n"
1293 if $archivecppflags{$obj};
1294 print &splitline(join " ", "lib${obj}_a_CFLAGS", "=",
1295 @amcflags, @{$archivecflags{$obj}}), "\n"
1296 if $archivecflags{$obj};
1298 print &splitline(join " ", "noinst_LIBRARIES", "=",
1300 map { $amspeciallibs{$_} }
1304 print $makefile_extra{'am'} || "";
1305 select STDOUT; close OUT;
1308 if (defined $makefiles{'mpw'}) {
1311 open OUT, ">$makefiles{'mpw'}"; select OUT;
1313 "# Makefile for $project_name under MPW.\n#\n".
1314 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1315 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1316 # MPW command line option is -d not /D
1317 ($_ = $help) =~ s/=\/D/=-d /gs;
1320 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1325 "C_Carbon = {PPCC}\n".
1327 "# -w 35 disables \"unused parameter\" warnings\n".
1328 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1330 "COptions_68K = {COptions} -model far -opt time\n".
1331 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1332 "# _\$LDIVT and _\$LMODT.\n".
1333 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1334 "COptions_PPC = {COptions} -opt size -traceback\n".
1335 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1337 "Link_68K = ILink\n".
1338 "Link_CFM68K = ILink\n".
1339 "Link_PPC = PPCLink\n".
1340 "Link_Carbon = PPCLink\n".
1342 "LinkOptions = -c 'pTTY'\n".
1343 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1344 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1345 "LinkOptions_PPC = {LinkOptions}\n".
1346 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1348 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1349 " \"{Libraries}MacRuntime.o\" \xb6\n".
1350 " \"{Libraries}MathLib.far.o\" \xb6\n".
1351 " \"{Libraries}IntEnv.far.o\" \xb6\n".
1352 " \"{Libraries}Interface.o\" \xb6\n".
1353 " \"{Libraries}Navigation.far.o\" \xb6\n".
1354 " \"{Libraries}OpenTransport.o\" \xb6\n".
1355 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
1356 " \"{Libraries}OpenTptInet.o\" \xb6\n".
1357 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
1359 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1360 " \"{SharedLibraries}StdCLib\" \xb6\n".
1361 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
1362 " -weaklib AppearanceLib \xb6\n".
1363 " \"{SharedLibraries}NavigationLib\" \xb6\n".
1364 " -weaklib NavigationLib \xb6\n".
1365 " \"{SharedLibraries}TextCommon\" \xb6\n".
1366 " -weaklib TextCommon \xb6\n".
1367 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1368 " -weaklib UnicodeConverter\n".
1370 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1371 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1373 "Libs_PPC = {Libs_CFM} \xb6\n".
1374 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1375 " -weaklib ControlsLib \xb6\n".
1376 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1377 " -weaklib WindowsLib \xb6\n".
1378 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1379 " -weaklib OTClientLib \xb6\n".
1380 " -weaklib OTClientUtilLib \xb6\n".
1381 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1382 " -weaklib OTInetClientLib \xb6\n".
1383 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1384 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1385 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1386 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1387 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1389 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1390 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1391 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1392 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1393 " \"{SharedLibraries}StdCLib\"\n".
1395 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1397 foreach $p (&prognames("M")) {
1398 ($prog, $type) = split ",", $p;
1400 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1401 undef, "\xb6"), "\n\n";
1403 $rsrc = &objects($p, "", "X.rsrc", undef);
1405 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1406 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1407 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1409 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1410 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1411 "{LinkOptions_$arch} " .
1412 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1413 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1417 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1418 next unless $d->{obj};
1419 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1420 undef, "\xb6"), "\n";
1421 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1423 foreach $arch (qw(68K CFM68K)) {
1424 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1425 next unless $d->{obj};
1426 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1427 join " ", @{$d->{deps}}),
1428 undef, "\xb6"), "\n";
1429 print "\t{C_$arch} ", $d->{deps}->[0],
1430 " -o {Targ} {COptions_$arch}\n\n";
1433 foreach $arch (qw(PPC Carbon)) {
1434 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1435 next unless $d->{obj};
1436 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1437 join " ", @{$d->{deps}}),
1438 undef, "\xb6"), "\n";
1439 # The odd stuff here seems to stop afpd getting confused.
1440 print "\techo -n > {Targ}\n";
1441 print "\tsetfile -t XCOF {Targ}\n";
1442 print "\t{C_$arch} ", $d->{deps}->[0],
1443 " -o {Targ} {COptions_$arch}\n\n";
1446 select STDOUT; close OUT;
1449 if (defined $makefiles{'lcc'}) {
1451 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1454 open OUT, ">$makefiles{'lcc'}"; select OUT;
1456 "# Makefile for $project_name under lcc.\n".
1457 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1458 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1459 # lcc command line option is -D not /D
1460 ($_ = $help) =~ s/=\/D/=-D/gs;
1464 "# If you rename this file to `Makefile', you should change this line,\n".
1465 "# so that the .rsp files still depend on the correct makefile.\n".
1466 "MAKEFILE = Makefile.lcc\n".
1468 "# C compilation flags\n".
1469 "CFLAGS = -D_WINDOWS " .
1470 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1473 "# Get include directory for resource compiler\n".
1475 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1477 foreach $p (&prognames("G:C")) {
1478 ($prog, $type) = split ",", $p;
1479 $objstr = &objects($p, "X.obj", "X.res", undef);
1480 print &splitline("$prog.exe: " . $objstr ), "\n";
1481 $subsystemtype = undef;
1482 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1483 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1484 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1488 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1489 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1491 if ($d->{obj} =~ /\.res$/) {
1492 print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
1494 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1495 print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1496 " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
1500 print $makefile_extra{'lcc'} || "";
1506 select STDOUT; close OUT;
1509 if (defined $makefiles{'nestedvm'}) {
1510 $mftyp = 'nestedvm';
1511 $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
1513 ##-- NestedVM makefile
1514 open OUT, ">$makefiles{'nestedvm'}"; select OUT;
1516 "# Makefile for $project_name under NestedVM.\n".
1517 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1518 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1519 # gcc command line option is -D not /D
1520 ($_ = $help) =~ s/=\/D/=-D/gs;
1524 "# This path points at the nestedvm root directory\n".
1525 "NESTEDVM = /opt/nestedvm\n".
1526 "# You can define this path to point at your tools if you need to\n".
1527 "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
1528 "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
1530 &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
1531 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1533 print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
1535 foreach $p (&prognames("X")) {
1536 ($prog, $type) = split ",", $p;
1537 $objstr = &objects($p, "X.o", undef, undef);
1538 $objstr =~ s/gtk\.o/nestedvm\.o/g;
1539 print &splitline($prog . ".mips: " . $objstr), "\n";
1540 $libstr = &objects($p, undef, undef, "-lX");
1541 print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " .
1542 $objstr . " $libstr -lm", 69), "\n\n";
1544 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1546 $ddeps= join " ", @{$d->{deps}};
1547 $oobjs =~ s/gtk/nestedvm/g;
1548 $ddeps =~ s/gtk/nestedvm/g;
1549 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1551 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1552 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1553 " -c \$< -o \$\@\n";
1556 print $makefile_extra{'nestedvm'} || "";
1558 "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
1559 select STDOUT; close OUT;
1562 if (defined $makefiles{'osx'}) {
1564 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1565 @osxarchs = ('i386');
1567 ##-- Mac OS X makefile
1568 open OUT, ">$makefiles{'osx'}"; select OUT;
1570 "# Makefile for $project_name under Mac OS X.\n".
1571 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1572 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1573 # gcc command line option is -D not /D
1574 ($_ = $help) =~ s/=\/D/=-D/gs;
1577 "CC = \$(TOOLPATH)gcc\n".
1578 "LIPO = \$(TOOLPATH)lipo\n".
1580 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1581 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1582 "LDFLAGS = -framework Cocoa\n".
1583 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1585 print $makefile_extra{'osx'} || "";
1587 ".SUFFIXES: .o .c .m\n".
1590 foreach $p (&prognames("MX")) {
1591 ($prog, $type) = split ",", $p;
1592 $icon = &special($p, ".icns");
1593 $infoplist = &special($p, "info.plist");
1594 print "${prog}.app:\n\tmkdir -p \$\@\n";
1595 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1596 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1597 $targets = "${prog}.app/Contents/MacOS/$prog";
1598 if (defined $icon) {
1599 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1600 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1601 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1603 if (defined $infoplist) {
1604 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1605 $targets .= " ${prog}.app/Contents/Info.plist";
1607 $targets .= " \$(${prog}_extra)";
1608 print &splitline("${prog}: $targets", 69) . "\n\n";
1609 $libstr = &objects($p, undef, undef, "-lX");
1611 foreach $arch (@osxarchs) {
1612 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1613 print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
1614 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(LDFLAGS) -o \$@ " .
1615 $objstr . " $libstr", 69), "\n\n";
1616 $archbins .= " ${prog}.${arch}.bin";
1618 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1619 "${prog}.app/Contents/MacOS" . $archbins), "\n";
1620 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1622 foreach $p (&prognames("U")) {
1623 ($prog, $type) = split ",", $p;
1624 $libstr = &objects($p, undef, undef, "-lX");
1626 foreach $arch (@osxarchs) {
1627 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1628 print &splitline("${prog}.${arch}: " . $objstr), "\n";
1629 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(ULDFLAGS) -o \$@ " .
1630 $objstr . " $libstr", 69), "\n\n";
1631 $archbins .= " ${prog}.${arch}";
1633 print &splitline("${prog}:" . $archbins), "\n";
1634 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1636 foreach $arch (@osxarchs) {
1637 foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) {
1638 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1640 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1641 if ($d->{deps}->[0] =~ /\.m$/) {
1642 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1643 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1645 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1646 " -c \$< -o \$\@\n";
1651 "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
1653 select STDOUT; close OUT;
1656 if (defined $makefiles{'gnustep'}) {
1658 $dirpfx = &dirpfx($makefiles{'gnustep'}, "/");
1660 ##-- GNUstep makefile (use with 'gs_make -f Makefile.gnustep')
1662 # This is a pretty evil way to do things. In an ideal world, I'd
1663 # use the approved GNUstep makefile mechanism which just defines a
1664 # variable or two saying what source files go into what binary and
1665 # then includes application.make. Unfortunately, that has the
1666 # automake-ish limitation that it doesn't let you choose different
1667 # command lines for each object, so I can't arrange for all those
1668 # files with -DTHIS and -DTHAT to Just Work.
1670 # A simple if ugly fix would be to have mkfiles.pl construct a
1671 # directory full of stub C files of the form '#define thing',
1672 # '#include "real_source_file"', and then reference those in this
1673 # makefile. That would also make it easy to build a proper
1674 # automake makefile.
1675 open OUT, ">$makefiles{'gnustep'}"; select OUT;
1677 "# Makefile for $project_name under GNUstep.\n".
1678 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1679 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1680 # gcc command line option is -D not /D
1681 ($_ = $help) =~ s/=\/D/=-D/gs;
1685 "include \$(GNUSTEP_MAKEFILES)/common.make\n".
1686 "include \$(GNUSTEP_MAKEFILES)/rules.make\n".
1687 "include \$(GNUSTEP_MAKEFILES)/Instance/rules.make\n".
1689 &splitline("all::" . join "", map { " $_" } &progrealnames("MX:U")) .
1691 print $makefile_extra{'gnustep'} || "";
1693 ".SUFFIXES: .o .c .m\n".
1696 foreach $p (&prognames("MX")) {
1697 ($prog, $type) = split ",", $p;
1698 $icon = &special($p, ".icns");
1699 $infoplist = &special($p, "info.plist");
1700 print "${prog}.app:\n\tmkdir -p \$\@\n";
1701 $targets = "${prog}.app ${prog}.app/$prog";
1702 if (defined $icon) {
1703 print "${prog}.app/Resources: ${prog}.app\n\tmkdir -p \$\@\n";
1704 print "${prog}.app/Resources/${prog}.icns: ${prog}.app/Resources $icon\n\tcp $icon \$\@\n";
1705 $targets .= " ${prog}.app/Resources/${prog}.icns";
1707 if (defined $infoplist) {
1708 print "${prog}.app/Info.plist: ${prog}.app $infoplist\n\tcp $infoplist \$\@\n";
1709 $targets .= " ${prog}.app/Info.plist";
1711 $targets .= " \$(${prog}_extra)";
1712 print &splitline("${prog}: $targets", 69) . "\n\n";
1713 $libstr = &objects($p, undef, undef, "-lX");
1714 $objstr = &objects($p, "X.o", undef, undef);
1715 print &splitline("${prog}.app/$prog: " . $objstr), "\n";
1716 print &splitline("\t\$(CC) \$(ALL_LDFLAGS) -o \$@ " . $objstr . " \$(ALL_LIB_DIRS) $libstr \$(ALL_LIBS)", 69), "\n\n";
1718 foreach $p (&prognames("U")) {
1719 ($prog, $type) = split ",", $p;
1720 $libstr = &objects($p, undef, undef, "-lX");
1721 $objstr = &objects($p, "X.o", undef, undef);
1722 print &splitline("${prog}: " . $objstr), "\n";
1723 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n";
1725 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1726 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1728 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1729 if ($d->{deps}->[0] =~ /\.m$/) {
1730 print "\t\$(CC) -DGNUSTEP \$(ALL_OBJCFLAGS) \$(COMPAT) \$(FWHACK) \$(OBJCFLAGS)".
1731 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1733 print "\t\$(CC) \$(ALL_CFLAGS) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1734 " -c \$< -o \$\@\n";
1737 print "\nclean::\n".
1738 "\trm -f *.o ". (join " ", &progrealnames("U")) . "\n".
1740 select STDOUT; close OUT;
1743 if (defined $makefiles{'emcc'}) {
1745 $dirpfx = &dirpfx($makefiles{'emcc'}, "/");
1747 ##-- Makefile for building Javascript puzzles via Emscripten
1749 open OUT, ">$makefiles{'emcc'}"; select OUT;
1751 "# Makefile for $project_name using Emscripten. Requires GNU make.\n".
1752 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1753 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1754 # emcc command line option is -D not /D
1755 ($_ = $help) =~ s/=\/D/=-D/gs;
1759 "# This can be set on the command line to point at the emcc command,\n".
1760 "# if it is not on your PATH.\n".
1763 &splitline("CFLAGS = -DSLOW_SYSTEM " .
1764 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1766 $output_js_files = join "", map { " \$(OUTPREFIX)$_.js" } &progrealnames("X");
1767 print &splitline("all:" . $output_js_files);
1769 foreach $p (&prognames("X")) {
1770 ($prog, $type) = split ",", $p;
1771 $objstr = &objects($p, "X.o", undef, undef);
1772 $objstr =~ s/gtk\.o/emcc\.o/g;
1773 print &splitline("\$(OUTPREFIX)" . $prog . ".js: " . $objstr . " emccpre.js emcclib.js emccx.json"), "\n";
1774 print "\t\$(EMCC) -o \$(OUTPREFIX)".$prog.".js ".
1777 "--pre-js emccpre.js ".
1778 "--js-library emcclib.js ".
1779 "-s EXPORTED_FUNCTIONS=\"`sed 's://.*::' emccx.json | tr -d ' \\n'`\" " . $objstr . "\n\n";
1781 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1783 $ddeps= join " ", @{$d->{deps}};
1784 $oobjs =~ s/gtk/emcc/g;
1785 $ddeps =~ s/gtk/emcc/g;
1786 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1788 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1789 print "\t\$(EMCC) \$(CFLAGS) \$(XFLAGS)$deflist" .
1790 " -c \$< -o \$\@\n";
1793 print $makefile_extra{'emcc'} || "";
1795 "\trm -rf *.o $output_js_files\n";
1796 select STDOUT; close OUT;
1799 # All done, so do the Unix postprocessing if asked to.
1803 system "./mkauto.sh";
1804 die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
1805 system "./configure", @confargs;
1806 die "mkfiles.pl: configure returned $?\n" if $? > 0;