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 scalar in which text is currently being put
61 $help = ""; # list of newline-free lines of help text
62 $project_name = "project"; # this is a good enough default
63 %makefiles = (); # maps makefile types to output makefile pathnames
64 %makefile_extra = (); # maps makefile types to extra Makefile text
65 %programs = (); # maps prog name + type letter to listref of objects/resources
66 %groups = (); # maps group name to listref of objects/resources
68 @allobjs = (); # all object file names
70 readinput: while (1) {
71 $in = $filestack[$#filestack];
72 while (not defined ($_ = <$in>)) {
73 close $filestack[$#filestack];
75 last readinput if 0 == scalar @filestack;
76 $in = $filestack[$#filestack];
81 # If we're gathering help text, keep doing so.
82 if (defined $divert) {
83 if ((defined $_[0]) && $_[0] eq "!end") {
90 # Skip comments and blank lines.
91 next if /^\s*#/ or scalar @_ == 0;
93 if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
94 if ($_[0] eq "!name") { $project_name = $_[1]; next; }
95 if ($_[0] eq "!srcdir") { push @srcdirs, $_[1]; next; }
96 if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
97 if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
98 if ($_[0] eq "!cflags" and &mfval($_[1])) {
99 ($rest = $_) =~ s/^\s*\S+\s+\S+\s+\S+\s*//; # find rest of input line
100 $rest = 1 if $rest eq "";
101 $cflags{$_[1]}->{$_[2]} = $rest;
104 if ($_[0] eq "!begin") {
105 if ($_[1] =~ /^>(.*)/) {
106 $divert = \$auxfiles{$1};
107 } elsif (&mfval($_[1])) {
108 $divert = \$makefile_extra{$_[1]};
112 if ($_[0] eq "!include") {
114 for ($i = 1; $i <= $#_; $i++) {
115 push @newfiles, (sort glob $_[$i]);
117 for ($i = $#newfiles; $i >= 0; $i--) {
118 $file = $newfiles[$i];
120 open $f, "<$file" or die "unable to open include file '$file'\n";
126 # Now we have an ordinary line. See if it's an = line, a : line
131 $listref = $lastlistref;
133 die "$.: unexpected + line\n" if !defined $lastlistref;
134 } elsif ($_[1] eq "=") {
136 $listref = $groups{$_[0]};
138 shift @objs; # eat the group name
139 } elsif ($_[1] eq "+=") {
140 $groups{$_[0]} = [] if !defined $groups{$_[0]};
141 $listref = $groups{$_[0]};
143 shift @objs; # eat the group name
144 } elsif ($_[1] eq ":") {
147 shift @objs; # eat the program name
149 die "$.: unrecognised line type: '$_'\n";
151 shift @objs; # eat the +, the = or the :
153 while (scalar @objs > 0) {
156 foreach $j (@{$groups{$i}}) { unshift @objs, $j; }
157 } elsif (($i eq "[G]" or $i eq "[C]" or $i eq "[M]" or
158 $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
159 $type = substr($i,1,(length $i)-2);
162 # Object files with a trailing question mark are optional:
163 # the build can proceed fine without them, so we only use
164 # them if their primary source files are present.
166 $i = undef unless defined &finddep($i);
167 } elsif ($i =~ /\|/) {
168 # Object file descriptions containing a vertical bar are
169 # lists of choices: we use the _first_ one whose primary
170 # source file is present.
171 @options = split /\|/, $i;
173 foreach $k (@options) {
174 $j=$k, last if defined &finddep($k);
176 die "no alternative found for $i\n" unless defined $j;
185 if ($prog and $type) {
186 die "multiple program entries for $prog [$type]\n"
187 if defined $programs{$prog . "," . $type};
188 $programs{$prog . "," . $type} = $listref;
190 $lastlistref = $listref;
193 foreach $aux (sort keys %auxfiles) {
195 print AUX $auxfiles{$aux};
199 # Find object file names with predefines (in square brackets after
200 # the module name), and decide on actual object names for them.
201 foreach $i (@allobjs) {
205 $usedobjname{$i} = 1;
208 foreach $i (@allobjs) {
209 if ($i =~ /^(.*)\[([^\]]*)/) {
210 $defs{$i} = [ split ",",$2 ];
211 $srcname{$i} = $s = $1;
215 $maxlen = 8 if $maxlen < 8;
216 $chop = $maxlen - length $index;
217 $chop = length $s if $chop > length $s;
218 $chop = 0 if $chop < 0;
219 $name = substr($s, 0, $chop) . $index;
220 $index++, next if $usedobjname{$name};
221 $objname{$i} = $name;
222 $usedobjname{$name} = 1;
228 # Now retrieve the complete list of objects and resource files, and
229 # construct dependency data for them. While we're here, expand the
230 # object list for each program, and complain if its type isn't set.
231 @prognames = sort keys %programs;
234 foreach $i (@prognames) {
235 ($prog, $type) = split ",", $i;
236 # Strip duplicate object names.
238 @list = grep { $status = ($prev ne $_); $prev=$_; $status }
239 sort @{$programs{$i}};
240 $programs{$i} = [@list];
241 foreach $jj (@list) {
243 $file = &finddep($j);
245 $depends{$jj} = [$file];
246 push @scanlist, $file;
251 # Scan each file on @scanlist and find further inclusions.
252 # Inclusions are given by lines of the form `#include "otherfile"'
253 # (system headers are automatically ignored by this because they'll
254 # be given in angle brackets). Files included by this method are
255 # added back on to @scanlist to be scanned in turn (if not already
258 # Resource scripts (.rc) can also include a file by means of a line
259 # ending `ICON "filename"'. Files included by this method are not
260 # added to @scanlist because they can never include further files.
262 # In this pass we write out a hash %further which maps a source
263 # file name into a listref containing further source file names.
266 while (scalar @scanlist > 0) {
267 $file = shift @scanlist;
268 next if defined $further{$file}; # skip if we've already done it
269 $further{$file} = [];
270 $dirfile = &findfile($file);
271 open IN, "$dirfile" or die "unable to open source file $file\n";
274 /^\s*#include\s+\"([^\"]+)\"/ and do {
275 push @{$further{$file}}, $1;
279 /ICON\s+\"([^\"]+)\"\s*$/ and do {
280 push @{$further{$file}}, $1;
287 # Now we're ready to generate the final dependencies section. For
288 # each key in %depends, we must expand the dependencies list by
289 # iteratively adding entries from %further.
290 foreach $i (keys %depends) {
292 @scanlist = @{$depends{$i}};
293 foreach $i (@scanlist) { $dep{$i} = 1; }
294 while (scalar @scanlist > 0) {
295 $file = shift @scanlist;
296 foreach $j (@{$further{$file}}) {
299 push @{$depends{$i}}, $j;
304 # printf "%s: %s\n", $i, join ' ',@{$depends{$i}};
307 # Validation of input.
311 # Returns true if the argument is a known makefile type. Otherwise,
312 # prints a warning and returns false;
313 if (grep { $type eq $_ }
314 ("vc","vcproj","cygwin","borland","lcc","gtk","am","mpw","nestedvm","osx","wce","gnustep","emcc")) {
317 warn "$.:unknown makefile type '$type'\n";
321 # Utility routines while writing out the Makefiles.
324 my ($path) = shift @_;
325 my ($sep) = shift @_;
328 while (($i = index $path, $sep) >= 0) {
329 $path = substr $path, ($i + length $sep);
340 unless (defined $findfilecache{$name}) {
342 foreach $dir (@srcdirs) {
343 $outdir = $dir, $i++ if -f "$dir$name";
345 die "multiple instances of source file $name\n" if $i > 1;
346 $findfilecache{$name} = (defined $outdir ? $outdir . $name : undef);
348 return $findfilecache{$name};
354 # Find the first dependency of an object.
356 # Dependencies for "x" start with "x.c" or "x.m" (depending on
358 # Dependencies for "x.res" start with "x.rc".
359 # Dependencies for "x.rsrc" start with "x.r".
360 # Both types of file are pushed on the list of files to scan.
361 # Libraries (.lib) don't have dependencies at all.
362 if ($j =~ /^(.*)\.res$/) {
364 } elsif ($j =~ /^(.*)\.rsrc$/) {
366 } elsif ($j !~ /\./) {
368 $file = "$j.m" unless &findfile($file);
370 # For everything else, we assume it's its own dependency.
373 $file = undef unless &findfile($file);
378 my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
381 ($otmpl, $rtmpl, $ltmpl) = map { defined $_ ? $_ : "" } ($otmpl, $rtmpl, $ltmpl);
383 foreach $ii (@{$programs{$prog}}) {
386 if ($i =~ /^(.*)\.(res|rsrc)/) {
388 ($x = $rtmpl) =~ s/X/$y/;
389 } elsif ($i =~ /^(.*)\.lib/) {
391 ($x = $ltmpl) =~ s/X/$y/;
392 } elsif ($i !~ /\./) {
393 ($x = $otmpl) =~ s/X/$i/;
395 push @ret, $x if $x ne "";
397 return join " ", @ret;
401 my ($prog, $suffix) = @_;
405 foreach $ii (@{$programs{$prog}}) {
407 if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
411 return join " ", @ret;
415 my ($line, $width, $splitchar) = @_;
418 $len = (defined $width ? $width : 76);
419 $splitchar = (defined $splitchar ? $splitchar : '\\');
420 while (length $line > $len) {
421 $line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
423 $result .= " ${splitchar}\n\t\t" if $2 ne '';
427 return $result . $line;
431 my ($otmpl, $rtmpl, $prefix, $dirsep, $depchar, $splitchar) = @_;
437 foreach $ii (sort keys %depends) {
439 next if $specialobj{$mftyp}->{$i};
440 if ($i =~ /^(.*)\.(res|rsrc)/) {
441 next if !defined $rtmpl;
443 ($x = $rtmpl) =~ s/X/$y/;
445 ($x = $otmpl) =~ s/X/$i/;
447 @deps = @{$depends{$ii}};
448 # Skip things which are their own dependency.
449 next if grep { $_ eq $i } @deps;
455 push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}};
462 my ($n, $prog, $type);
465 foreach $n (@prognames) {
466 ($prog, $type) = split ",", $n;
467 push @ret, $n if index(":$types:", ":$type:") >= 0;
474 my ($n, $prog, $type);
477 foreach $n (@prognames) {
478 ($prog, $type) = split ",", $n;
479 push @ret, $prog if index(":$types:", ":$type:") >= 0;
485 my ($types,$suffix) = @_;
487 # assume that all UNIX programs have a man page
488 if($suffix eq "1" && $types =~ /:X:/) {
489 return map("$_.1", &progrealnames($types));
496 # Now we're ready to output the actual Makefiles.
498 if (defined $makefiles{'cygwin'}) {
500 $dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
503 open OUT, ">$makefiles{'cygwin'}"; select OUT;
505 "# Makefile for $project_name under cygwin.\n".
506 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
507 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
508 # gcc command line option is -D not /D
509 ($_ = $help) =~ s/=\/D/=-D/gs;
513 "# You can define this path to point at your tools if you need to\n".
514 "# TOOLPATH = c:\\cygwin\\bin\\ # or similar, if you're running Windows\n".
515 "# TOOLPATH = /pkg/mingw32msvc/i386-mingw32msvc/bin/\n".
516 "CC = \$(TOOLPATH)gcc\n".
517 "RC = \$(TOOLPATH)windres\n".
518 "# Uncomment the following two lines to compile under Winelib\n".
521 "# You may also need to tell windres where to find include files:\n".
522 "# RCINC = --include-dir c:\\cygwin\\include\\\n".
524 &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
525 " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
526 (join " ", map {"-I$dirpfx$_"} @srcdirs)) .
528 "LDFLAGS = -mno-cygwin -s\n".
529 &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
530 " --define WINVER=0x0400 --define MINGW32_FIX=1 " .
531 (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n".
533 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
535 foreach $p (&prognames("G:C")) {
536 ($prog, $type) = split ",", $p;
537 $objstr = &objects($p, "X.o", "X.res.o", undef);
538 print &splitline($prog . ".exe: " . $objstr), "\n";
539 my $mw = $type eq "G" ? " -mwindows" : "";
540 $libstr = &objects($p, undef, undef, "-lX");
541 print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
542 "-Wl,-Map,$prog.map " .
543 $objstr . " $libstr", 69), "\n\n";
545 foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
546 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
548 if ($d->{obj} =~ /\.res\.o$/) {
549 print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
551 $deflist = join "", map { " -D$_" } @{$d->{defs}};
552 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" .
553 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
557 print $makefile_extra{'cygwin'} || "";
559 "\trm -f *.o *.exe *.res.o *.map\n".
561 select STDOUT; close OUT;
565 ##-- Borland makefile
566 if (defined $makefiles{'borland'}) {
568 $dirpfx = &dirpfx($makefiles{'borland'}, "\\");
570 %stdlibs = ( # Borland provides many Win32 API libraries intrinsically
582 open OUT, ">$makefiles{'borland'}"; select OUT;
584 "# Makefile for $project_name under Borland C.\n".
585 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
586 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
587 # bcc32 command line option is -D not /D
588 ($_ = $help) =~ s/=\/D/=-D/gs;
592 "# If you rename this file to `Makefile', you should change this line,\n".
593 "# so that the .rsp files still depend on the correct makefile.\n".
594 "MAKEFILE = Makefile.bor\n".
596 "# C compilation flags\n".
597 "CFLAGS = -D_WINDOWS -DWINVER=0x0401\n".
599 "# Get include directory for resource compiler\n".
601 "BCB = \$(MAKEDIR)\\..\n".
604 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
606 foreach $p (&prognames("G:C")) {
607 ($prog, $type) = split ",", $p;
608 $objstr = &objects($p, "X.obj", "X.res", undef);
609 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
610 my $ap = ($type eq "G") ? "-aa" : "-ap";
611 print "\tilink32 $ap -Gn -L\$(BCB)\\lib \@$prog.rsp\n\n";
613 foreach $p (&prognames("G:C")) {
614 ($prog, $type) = split ",", $p;
615 print $prog, ".rsp: \$(MAKEFILE)\n";
616 $objstr = &objects($p, "X.obj", undef, undef);
617 @objlist = split " ", $objstr;
619 foreach $i (@objlist) {
620 if (length($objlines[$#objlines] . " $i") > 50) {
623 $objlines[$#objlines] .= " $i";
625 $c0w = ($type eq "G") ? "c0w32" : "c0x32";
626 print "\techo $c0w + > $prog.rsp\n";
627 for ($i=0; $i<=$#objlines; $i++) {
628 $plus = ($i < $#objlines ? " +" : "");
629 print "\techo$objlines[$i]$plus >> $prog.rsp\n";
631 print "\techo $prog.exe >> $prog.rsp\n";
632 $objstr = &objects($p, "X.obj", "X.res", undef);
633 @libs = split " ", &objects($p, undef, undef, "X");
634 @libs = grep { !$stdlibs{$_} } @libs;
635 unshift @libs, "cw32", "import32";
636 $libstr = join ' ', @libs;
637 print "\techo nul,$libstr, >> $prog.rsp\n";
638 print "\techo " . &objects($p, undef, "X.res", undef) . " >> $prog.rsp\n";
641 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
642 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
644 if ($d->{obj} =~ /\.res$/) {
645 print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " .
646 "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32".
647 " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n";
649 $deflist = join "", map { " -D$_" } @{$d->{defs}};
650 print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
651 " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ".
652 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
653 " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
657 print $makefile_extra{'borland'} || "";
668 "\t-del *.\$\$\$\$\$\$\n";
669 select STDOUT; close OUT;
672 if (defined $makefiles{'vc'}) {
674 $dirpfx = &dirpfx($makefiles{'vc'}, "\\");
676 ##-- Visual C++ makefile
677 open OUT, ">$makefiles{'vc'}"; select OUT;
679 "# Makefile for $project_name under Visual C.\n".
680 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
681 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
685 "# If you rename this file to `Makefile', you should change this line,\n".
686 "# so that the .rsp files still depend on the correct makefile.\n".
687 "MAKEFILE = Makefile.vc\n".
689 "# C compilation flags\n".
690 "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401 /I.\n".
691 "LFLAGS = /incremental:no /fixed\n".
693 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
695 foreach $p (&prognames("G:C")) {
696 ($prog, $type) = split ",", $p;
697 $objstr = &objects($p, "X.obj", "X.res", undef);
698 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
699 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
701 foreach $p (&prognames("G:C")) {
702 ($prog, $type) = split ",", $p;
703 print $prog, ".rsp: \$(MAKEFILE)\n";
704 $objstr = &objects($p, "X.obj", "X.res", "X.lib");
705 @objlist = split " ", $objstr;
707 foreach $i (@objlist) {
708 if (length($objlines[$#objlines] . " $i") > 50) {
711 $objlines[$#objlines] .= " $i";
713 $subsys = ($type eq "G") ? "windows" : "console";
714 print "\techo /nologo /subsystem:$subsys > $prog.rsp\n";
715 for ($i=0; $i<=$#objlines; $i++) {
716 print "\techo$objlines[$i] >> $prog.rsp\n";
720 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
721 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
723 if ($d->{obj} =~ /\.res$/) {
724 print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
725 "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
727 $deflist = join "", map { " /D$_" } @{$d->{defs}};
728 print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
729 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
733 print $makefile_extra{'vc'} || "";
734 print "\nclean: tidy\n".
751 "\t-del debug.log\n";
752 select STDOUT; close OUT;
755 if (defined $makefiles{'wce'}) {
757 $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
759 ##-- eMbedded Visual C PocketPC makefile
760 open OUT, ">$makefiles{'wce'}"; select OUT;
762 "# Makefile for $project_name on PocketPC using eMbedded Visual C.\n".
763 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
764 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
768 "# If you rename this file to `Makefile', you should change this line,\n".
769 "# so that the .rsp files still depend on the correct makefile.\n".
770 "MAKEFILE = Makefile.wce\n".
772 "# This makefile expects the environment to have been set up by one\n".
773 "# of the PocketPC batch files wcearmv4.bat and wceemulator.bat. No\n".
774 "# other build targets are currently supported, because they would\n".
775 "# need a section in this if statement.\n".
776 "!if \"\$(TARGETCPU)\" == \"emulator\"\n".
777 "PLATFORM_DEFS=/D \"_i386_\" /D \"i_386_\" /D \"_X86_\" /D \"x86\"\n".
779 "BASELIBS=commctrl.lib coredll.lib corelibc.lib aygshell.lib\n".
782 "PLATFORM_DEFS=/D \"ARM\" /D \"_ARM_\" /D \"ARMV4\"\n".
784 "BASELIBS=commctrl.lib coredll.lib aygshell.lib\n".
788 "# C compilation flags\n".
789 "CFLAGS = /nologo /W3 /O1 /MC /D _WIN32_WCE=420 /D \"WIN32_PLATFORM_PSPC=400\" /D UNDER_CE=420 \\\n".
790 " \$(PLATFORM_DEFS) \\\n".
791 " /D \"UNICODE\" /D \"_UNICODE\" /D \"NDEBUG\" /D \"NO_HTMLHELP\"\n".
793 "LFLAGS = /nologo /incremental:no \\\n".
794 " /base:0x00010000 /stack:0x10000,0x1000 /entry:WinMainCRTStartup \\\n".
795 " /nodefaultlib:libc.lib /nodefaultlib:libcmt.lib /nodefaultlib:msvcrt.lib /nodefaultlib:OLDNAMES.lib \\\n".
796 " /subsystem:windowsce,4.20 /align:4096 /MACHINE:\$(MACHINE)\n".
798 "RCFL = /d UNDER_CE=420 /d _WIN32_WCE=420 /d \"WIN32_PLATFORM_PSPC=400\" \\\n".
799 " \$(PLATFORM_DEFS) \\\n".
800 " /d \"NDEBUG\" /d \"UNICODE\" /d \"_UNICODE\"\n".
802 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G"));
804 foreach $p (&prognames("G")) {
805 ($prog, $type) = split ",", $p;
806 $objstr = &objects($p, "X.obj", "X.res", undef);
807 print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
808 print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
810 foreach $p (&prognames("G")) {
811 ($prog, $type) = split ",", $p;
812 print $prog, ".rsp: \$(MAKEFILE)\n";
813 $objstr = &objects($p, "X.obj", "X.res", undef);
814 @objlist = split " ", $objstr;
816 foreach $i (@objlist) {
817 if (length($objlines[$#objlines] . " $i") > 50) {
820 $objlines[$#objlines] .= " $i";
822 print "\techo \$(BASELIBS) > $prog.rsp\n";
823 for ($i=0; $i<=$#objlines; $i++) {
824 print "\techo$objlines[$i] >> $prog.rsp\n";
828 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
829 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
831 if ($d->{obj} =~ /\.res$/) {
832 print "\trc \$(FWHACK) \$(RCFL) -r -fo".
833 $d->{obj}." ".$d->{deps}->[0]."\n";
835 $deflist = join "", map { " /D$_" } @{$d->{defs}};
836 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
837 " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
841 print $makefile_extra{'wce'} || "";
842 print "\nclean: tidy\n".
859 "\t-del debug.log\n";
860 select STDOUT; close OUT;
863 if (defined $makefiles{'vcproj'}) {
866 ##-- MSVC 6 Workspace and projects
868 # Note: All files created in this section are written in binary
869 # mode, because although MSVC's command-line make can deal with
870 # LF-only line endings, MSVC project files really _need_ to be
871 # CRLF. Hence, in order for mkfiles.pl to generate usable project
872 # files even when run from Unix, I make sure all files are binary
873 # and explicitly write the CRLFs.
875 # Create directories if necessary
876 mkdir $makefiles{'vcproj'}
877 if(! -d $makefiles{'vcproj'});
878 chdir $makefiles{'vcproj'};
879 @deps = &deps("X.obj", "X.res", "", "\\");
880 %all_object_deps = map {$_->{obj} => $_->{deps}} @deps;
881 # Create the project files
882 # Get names of all Windows projects (GUI and console)
883 my @prognames = &prognames("G:C");
884 foreach $progname (@prognames) {
885 create_project(\%all_object_deps, $progname);
887 # Create the workspace file
888 open OUT, ">$project_name.dsw"; binmode OUT; select OUT;
890 "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n".
891 "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n".
893 "###############################################################################\r\n".
896 foreach $progname (@prognames) {
897 ($windows_project, $type) = split ",", $progname;
898 print "Project: \"$windows_project\"=\".\\$windows_project\\$windows_project.dsp\" - Package Owner=<4>\r\n";
910 "###############################################################################\r\n".
922 "###############################################################################\r\n".
924 select STDOUT; close OUT;
928 my ($all_object_deps, $progname) = @_;
929 # Construct program's dependency info
934 %resource_files = ();
935 @object_files = split " ", &objects($progname, "X.obj", "X.res", "X.lib");
936 foreach $object_file (@object_files) {
937 next if defined $seen_objects{$object_file};
938 $seen_objects{$object_file} = 1;
939 if($object_file =~ /\.lib$/io) {
940 $lib_files{$object_file} = 1;
943 $object_deps = $all_object_deps{$object_file};
944 foreach $object_dep (@$object_deps) {
945 if($object_dep =~ /\.c$/io) {
946 $source_files{$object_dep} = 1;
949 if($object_dep =~ /\.h$/io) {
950 $header_files{$object_dep} = 1;
953 if($object_dep =~ /\.(rc|ico)$/io) {
954 $resource_files{$object_dep} = 1;
959 $libs = join " ", sort keys %lib_files;
960 @source_files = sort keys %source_files;
961 @header_files = sort keys %header_files;
962 @resources = sort keys %resource_files;
963 ($windows_project, $type) = split ",", $progname;
964 mkdir $windows_project
965 if(! -d $windows_project);
966 chdir $windows_project;
967 $subsys = ($type eq "G") ? "windows" : "console";
968 open OUT, ">$windows_project.dsp"; binmode OUT; select OUT;
970 "# Microsoft Developer Studio Project File - Name=\"$windows_project\" - Package Owner=<4>\r\n".
971 "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n".
972 "# ** DO NOT EDIT **\r\n".
974 "# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n".
976 "CFG=$windows_project - Win32 Debug\r\n".
977 "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n".
978 "!MESSAGE use the Export Makefile command and run\r\n".
980 "!MESSAGE NMAKE /f \"$windows_project.mak\".\r\n".
982 "!MESSAGE You can specify a configuration when running NMAKE\r\n".
983 "!MESSAGE by defining the macro CFG on the command line. For example:\r\n".
985 "!MESSAGE NMAKE /f \"$windows_project.mak\" CFG=\"$windows_project - Win32 Debug\"\r\n".
987 "!MESSAGE Possible choices for configuration are:\r\n".
989 "!MESSAGE \"$windows_project - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n".
990 "!MESSAGE \"$windows_project - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n".
993 "# Begin Project\r\n".
994 "# PROP AllowPerConfigDependencies 0\r\n".
995 "# PROP Scc_ProjName \"\"\r\n".
996 "# PROP Scc_LocalPath \"\"\r\n".
1001 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1003 "# PROP BASE Use_MFC 0\r\n".
1004 "# PROP BASE Use_Debug_Libraries 0\r\n".
1005 "# PROP BASE Output_Dir \"Release\"\r\n".
1006 "# PROP BASE Intermediate_Dir \"Release\"\r\n".
1007 "# PROP BASE Target_Dir \"\"\r\n".
1008 "# PROP Use_MFC 0\r\n".
1009 "# PROP Use_Debug_Libraries 0\r\n".
1010 "# PROP Output_Dir \"Release\"\r\n".
1011 "# PROP Intermediate_Dir \"Release\"\r\n".
1012 "# PROP Ignore_Export_Lib 0\r\n".
1013 "# PROP Target_Dir \"\"\r\n".
1014 "# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1015 "# ADD CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /c\r\n".
1016 "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1017 "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n".
1018 "# ADD BASE RSC /l 0x809 /d \"NDEBUG\"\r\n".
1019 "# ADD RSC /l 0x809 /d \"NDEBUG\"\r\n".
1020 "BSC32=bscmake.exe\r\n".
1021 "# ADD BASE BSC32 /nologo\r\n".
1022 "# ADD BSC32 /nologo\r\n".
1023 "LINK32=link.exe\r\n".
1024 "# 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".
1025 "# ADD LINK32 $libs /nologo /subsystem:$subsys /machine:I386\r\n".
1026 "# SUBTRACT LINK32 /pdb:none\r\n".
1028 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1030 "# PROP BASE Use_MFC 0\r\n".
1031 "# PROP BASE Use_Debug_Libraries 1\r\n".
1032 "# PROP BASE Output_Dir \"Debug\"\r\n".
1033 "# PROP BASE Intermediate_Dir \"Debug\"\r\n".
1034 "# PROP BASE Target_Dir \"\"\r\n".
1035 "# PROP Use_MFC 0\r\n".
1036 "# PROP Use_Debug_Libraries 1\r\n".
1037 "# PROP Output_Dir \"Debug\"\r\n".
1038 "# PROP Intermediate_Dir \"Debug\"\r\n".
1039 "# PROP Ignore_Export_Lib 0\r\n".
1040 "# PROP Target_Dir \"\"\r\n".
1041 "# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1042 "# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D \"WIN32\" /D \"_DEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" /YX /FD /GZ /c\r\n".
1043 "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1044 "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n".
1045 "# ADD BASE RSC /l 0x809 /d \"_DEBUG\"\r\n".
1046 "# ADD RSC /l 0x809 /d \"_DEBUG\"\r\n".
1047 "BSC32=bscmake.exe\r\n".
1048 "# ADD BASE BSC32 /nologo\r\n".
1049 "# ADD BSC32 /nologo\r\n".
1050 "LINK32=link.exe\r\n".
1051 "# 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".
1052 "# ADD LINK32 $libs /nologo /subsystem:$subsys /debug /machine:I386 /pdbtype:sept\r\n".
1053 "# SUBTRACT LINK32 /pdb:none\r\n".
1057 "# Begin Target\r\n".
1059 "# Name \"$windows_project - Win32 Release\"\r\n".
1060 "# Name \"$windows_project - Win32 Debug\"\r\n".
1061 "# Begin Group \"Source Files\"\r\n".
1063 "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n";
1064 foreach $source_file (@source_files) {
1066 "# Begin Source File\r\n".
1068 "SOURCE=..\\..\\$source_file\r\n";
1069 if($source_file =~ /ssh\.c/io) {
1070 # Disable 'Edit and continue' as Visual Studio can't handle the macros
1073 "!IF \"\$(CFG)\" == \"$windows_project - Win32 Release\"\r\n".
1075 "!ELSEIF \"\$(CFG)\" == \"$windows_project - Win32 Debug\"\r\n".
1077 "# ADD CPP /Zi\r\n".
1082 print "# End Source File\r\n";
1086 "# Begin Group \"Header Files\"\r\n".
1088 "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n";
1089 foreach $header_file (@header_files) {
1091 "# Begin Source File\r\n".
1093 "SOURCE=..\\..\\$header_file\r\n".
1094 "# End Source File\r\n";
1098 "# Begin Group \"Resource Files\"\r\n".
1100 "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n";
1101 foreach $resource_file (@resources) {
1103 "# Begin Source File\r\n".
1105 "SOURCE=..\\..\\$resource_file\r\n".
1106 "# End Source File\r\n";
1111 "# End Project\r\n";
1112 select STDOUT; close OUT;
1117 if (defined $makefiles{'gtk'}) {
1119 $dirpfx = &dirpfx($makefiles{'gtk'}, "/");
1121 ##-- X/GTK/Unix makefile
1122 open OUT, ">$makefiles{'gtk'}"; select OUT;
1124 "# Makefile for $project_name under X/GTK and Unix.\n".
1125 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1126 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1127 # gcc command line option is -D not /D
1128 ($_ = $help) =~ s/=\/D/=-D/gs;
1132 "# You can define this path to point at your tools if you need to\n".
1133 "# TOOLPATH = /opt/gcc/bin\n".
1134 "CC := \$(TOOLPATH)\$(CC)\n".
1135 "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n".
1136 "# (depending on what works on your system) if you want to enforce\n".
1137 "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n".
1138 "# if you want to enforce 2.0. The default is to try 2.0 and fall back\n".
1139 "# to 1.2 if it isn't found.\n".
1140 "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n".
1142 &splitline("CFLAGS := -O2 -Wall -Werror -ansi -pedantic -g " .
1143 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1144 " `\$(GTK_CONFIG) --cflags` \$(CFLAGS)")."\n".
1145 "XLIBS = `\$(GTK_CONFIG) --libs` -lm\n".
1147 "INSTALL=install\n",
1148 "INSTALL_PROGRAM=\$(INSTALL)\n",
1149 "INSTALL_DATA=\$(INSTALL)\n",
1150 "prefix=/usr/local\n",
1151 "exec_prefix=\$(prefix)\n",
1152 "bindir=\$(exec_prefix)/bin\n",
1153 "gamesdir=\$(exec_prefix)/games\n",
1154 "mandir=\$(prefix)/man\n",
1155 "man1dir=\$(mandir)/man1\n",
1157 print &splitline("all:" . join "", map { " \$(BINPREFIX)$_" }
1158 &progrealnames("X:U"));
1160 foreach $p (&prognames("X:U")) {
1161 ($prog, $type) = split ",", $p;
1162 $objstr = &objects($p, "X.o", undef, undef);
1163 print &splitline("\$(BINPREFIX)" . $prog . ": " . $objstr), "\n";
1164 $libstr = &objects($p, undef, undef, "-lX");
1165 print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(XLFLAGS) \$(${type}LIBS)", 69),
1168 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1169 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1171 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1172 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1173 " -c \$< -o \$\@\n";
1176 print $makefile_extra{'gtk'} || "";
1178 "\trm -f *.o". (join "", map { " \$(BINPREFIX)$_" } &progrealnames("X:U")) . "\n";
1179 select STDOUT; close OUT;
1182 if (defined $makefiles{'am'}) {
1184 $dirpfx = "\$(srcdir)/" . &dirpfx($makefiles{'am'}, "/");
1186 ##-- Unix/autoconf Makefile.am
1187 open OUT, ">$makefiles{'am'}"; select OUT;
1189 "# Makefile.am for $project_name under Unix with Autoconf/Automake.\n".
1190 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1191 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n\n";
1195 foreach $p (&prognames("X:U")) {
1196 ($prog, $type) = split ",", $p;
1197 if ("FIXME") { # decide which programs go where
1198 push @binprogs, # FIXME "\$(BINPREFIX)" .
1201 push @noinstprogs, # FIXME "\$(BINPREFIX)" .
1205 print &splitline(join " ", "bin_PROGRAMS", "=", @binprogs), "\n";
1206 print &splitline(join " ", "noinst_PROGRAMS", "=", @noinstprogs), "\n";
1209 %amspeciallibs = ();
1212 foreach $d (&deps("X", undef, $dirpfx, "/", "am")) {
1213 my $obj = $d->{obj};
1214 my $use_archive = 0;
1216 if (defined $d->{defs}) {
1217 # This file needs to go in an archive, so that we can
1218 # change the preprocess flags to include some -Ds
1220 $archivecppflags{$obj} = [map { " -D$_" } @{$d->{defs}}];
1222 if (defined $cflags{'am'} && $cflags{'am'}->{$obj}) {
1223 # This file needs to go in an archive, so that we can
1224 # change the compile flags as specified in Recipe
1225 $archivecflags{$obj} = [$cflags{'am'}->{$obj}];
1228 $amspeciallibs{$obj} = "lib${obj}.a";
1229 $amlibobjname{$obj} = "lib${obj}_a-" .
1230 basename($d->{deps}->[0], ".c", ".m") .
1233 $objtosrc{$obj} = $d->{deps};
1234 map { $allsources{$_} = 1 } @{$d->{deps}};
1237 # Complete list of source and header files. Not used by the
1238 # auto-generated parts of this makefile, but Recipe might like to
1239 # have it available as a variable so that mandatory-rebuild things
1240 # (version.o) can conveniently be made to depend on it.
1241 print &splitline(join " ", "allsources", "=",
1242 sort {$a cmp $b} keys %allsources), "\n\n";
1244 @amcppflags = map {"-I$dirpfx$_"} @srcdirs;
1245 print &splitline(join " ", "AM_CPPFLAGS", "=", @amcppflags, "\n");
1247 @amcflags = ("\$(GTK_CFLAGS)", "\$(WARNINGOPTS)");
1248 print &splitline(join " ", "AM_CFLAGS", "=", @amcflags), "\n";
1251 foreach $p (&prognames("X:U")) {
1252 ($prog, $type) = split ",", $p;
1253 @progsources = ("${prog}_SOURCES", "=");
1256 $objstr = &objects($p, "X", undef, undef);
1257 foreach $obj (split / /,$objstr) {
1258 if ($amspeciallibs{$obj}) {
1259 $amlibsused{$obj} = 1;
1260 push @ldadd, $amlibobjname{$obj};
1262 map { $sourcefiles{$_} = 1 } @{$objtosrc{$obj}};
1265 push @progsources, sort { $a cmp $b } keys %sourcefiles;
1266 print &splitline(join " ", @progsources), "\n";
1268 push @ldadd, "\$(GTK_LIBS)";
1271 print &splitline(join " ", "${prog}_LDADD", "=", @ldadd), "\n";
1275 foreach $obj (sort { $a cmp $b } keys %amlibsused) {
1276 print &splitline(join " ", "lib${obj}_a_SOURCES", "=",
1277 @{$objtosrc{$obj}}), "\n";
1278 print &splitline(join " ", "lib${obj}_a_CPPFLAGS", "=",
1279 @amcflags, @{$archivecppflags{$obj}}), "\n"
1280 if $archivecppflags{$obj};
1281 print &splitline(join " ", "lib${obj}_a_CFLAGS", "=",
1282 @amcflags, @{$archivecflags{$obj}}), "\n"
1283 if $archivecflags{$obj};
1285 print &splitline(join " ", "noinst_LIBRARIES", "=",
1287 map { $amspeciallibs{$_} }
1291 print $makefile_extra{'am'} || "";
1292 select STDOUT; close OUT;
1295 if (defined $makefiles{'mpw'}) {
1298 open OUT, ">$makefiles{'mpw'}"; select OUT;
1300 "# Makefile for $project_name under MPW.\n#\n".
1301 "# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1302 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1303 # MPW command line option is -d not /D
1304 ($_ = $help) =~ s/=\/D/=-d /gs;
1307 "ROptions = `Echo \"{VER}\" | StreamEdit -e \"1,\$ replace /=(\xc5)\xa81\xb0/ 'STR=\xb6\xb6\xb6\xb6\xb6\"' \xa81 '\xb6\xb6\xb6\xb6\xb6\"'\"`".
1312 "C_Carbon = {PPCC}\n".
1314 "# -w 35 disables \"unused parameter\" warnings\n".
1315 "COptions = -i : -i :: -i ::charset -w 35 -w err -proto strict -ansi on \xb6\n".
1317 "COptions_68K = {COptions} -model far -opt time\n".
1318 "# Enabling \"-opt space\" for CFM-68K gives me undefined references to\n".
1319 "# _\$LDIVT and _\$LMODT.\n".
1320 "COptions_CFM68K = {COptions} -model cfmSeg -opt time\n".
1321 "COptions_PPC = {COptions} -opt size -traceback\n".
1322 "COptions_Carbon = {COptions} -opt size -traceback -d TARGET_API_MAC_CARBON\n".
1324 "Link_68K = ILink\n".
1325 "Link_CFM68K = ILink\n".
1326 "Link_PPC = PPCLink\n".
1327 "Link_Carbon = PPCLink\n".
1329 "LinkOptions = -c 'pTTY'\n".
1330 "LinkOptions_68K = {LinkOptions} -br 68k -model far -compact\n".
1331 "LinkOptions_CFM68K = {LinkOptions} -br 020 -model cfmseg -compact\n".
1332 "LinkOptions_PPC = {LinkOptions}\n".
1333 "LinkOptions_Carbon = -m __appstart -w {LinkOptions}\n".
1335 "Libs_68K = \"{CLibraries}StdCLib.far.o\" \xb6\n".
1336 " \"{Libraries}MacRuntime.o\" \xb6\n".
1337 " \"{Libraries}MathLib.far.o\" \xb6\n".
1338 " \"{Libraries}IntEnv.far.o\" \xb6\n".
1339 " \"{Libraries}Interface.o\" \xb6\n".
1340 " \"{Libraries}Navigation.far.o\" \xb6\n".
1341 " \"{Libraries}OpenTransport.o\" \xb6\n".
1342 " \"{Libraries}OpenTransportApp.o\" \xb6\n".
1343 " \"{Libraries}OpenTptInet.o\" \xb6\n".
1344 " \"{Libraries}UnicodeConverterLib.far.o\"\n".
1346 "Libs_CFM = \"{SharedLibraries}InterfaceLib\" \xb6\n".
1347 " \"{SharedLibraries}StdCLib\" \xb6\n".
1348 " \"{SharedLibraries}AppearanceLib\" \xb6\n".
1349 " -weaklib AppearanceLib \xb6\n".
1350 " \"{SharedLibraries}NavigationLib\" \xb6\n".
1351 " -weaklib NavigationLib \xb6\n".
1352 " \"{SharedLibraries}TextCommon\" \xb6\n".
1353 " -weaklib TextCommon \xb6\n".
1354 " \"{SharedLibraries}UnicodeConverter\" \xb6\n".
1355 " -weaklib UnicodeConverter\n".
1357 "Libs_CFM68K = {Libs_CFM} \xb6\n".
1358 " \"{CFM68KLibraries}NuMacRuntime.o\"\n".
1360 "Libs_PPC = {Libs_CFM} \xb6\n".
1361 " \"{SharedLibraries}ControlsLib\" \xb6\n".
1362 " -weaklib ControlsLib \xb6\n".
1363 " \"{SharedLibraries}WindowsLib\" \xb6\n".
1364 " -weaklib WindowsLib \xb6\n".
1365 " \"{SharedLibraries}OpenTransportLib\" \xb6\n".
1366 " -weaklib OTClientLib \xb6\n".
1367 " -weaklib OTClientUtilLib \xb6\n".
1368 " \"{SharedLibraries}OpenTptInternetLib\" \xb6\n".
1369 " -weaklib OTInetClientLib \xb6\n".
1370 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1371 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1372 " \"{PPCLibraries}CarbonAccessors.o\" \xb6\n".
1373 " \"{PPCLibraries}OpenTransportAppPPC.o\" \xb6\n".
1374 " \"{PPCLibraries}OpenTptInetPPC.o\"\n".
1376 "Libs_Carbon = \"{PPCLibraries}CarbonStdCLib.o\" \xb6\n".
1377 " \"{PPCLibraries}StdCRuntime.o\" \xb6\n".
1378 " \"{PPCLibraries}PPCCRuntime.o\" \xb6\n".
1379 " \"{SharedLibraries}CarbonLib\" \xb6\n".
1380 " \"{SharedLibraries}StdCLib\"\n".
1382 print &splitline("all \xc4 " . join(" ", &progrealnames("M")), undef, "\xb6");
1384 foreach $p (&prognames("M")) {
1385 ($prog, $type) = split ",", $p;
1387 print &splitline("$prog \xc4 $prog.68k $prog.ppc $prog.carbon",
1388 undef, "\xb6"), "\n\n";
1390 $rsrc = &objects($p, "", "X.rsrc", undef);
1392 foreach $arch (qw(68K CFM68K PPC Carbon)) {
1393 $objstr = &objects($p, "X.\L$arch\E.o", "", undef);
1394 print &splitline("$prog.\L$arch\E \xc4 $objstr $rsrc", undef, "\xb6");
1396 print &splitline("\tDuplicate -y $rsrc {Targ}", 69, "\xb6"), "\n";
1397 print &splitline("\t{Link_$arch} -o {Targ} -fragname $prog " .
1398 "{LinkOptions_$arch} " .
1399 $objstr . " {Libs_$arch}", 69, "\xb6"), "\n";
1400 print &splitline("\tSetFile -a BMi {Targ}", 69, "\xb6"), "\n\n";
1404 foreach $d (&deps("", "X.rsrc", "::", ":")) {
1405 next unless $d->{obj};
1406 print &splitline(sprintf("%s \xc4 %s", $d->{obj}, join " ", @{$d->{deps}}),
1407 undef, "\xb6"), "\n";
1408 print "\tRez ", $d->{deps}->[0], " -o {Targ} {ROptions}\n\n";
1410 foreach $arch (qw(68K CFM68K)) {
1411 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1412 next unless $d->{obj};
1413 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1414 join " ", @{$d->{deps}}),
1415 undef, "\xb6"), "\n";
1416 print "\t{C_$arch} ", $d->{deps}->[0],
1417 " -o {Targ} {COptions_$arch}\n\n";
1420 foreach $arch (qw(PPC Carbon)) {
1421 foreach $d (&deps("X.\L$arch\E.o", "", "::", ":")) {
1422 next unless $d->{obj};
1423 print &splitline(sprintf("%s \xc4 %s", $d->{obj},
1424 join " ", @{$d->{deps}}),
1425 undef, "\xb6"), "\n";
1426 # The odd stuff here seems to stop afpd getting confused.
1427 print "\techo -n > {Targ}\n";
1428 print "\tsetfile -t XCOF {Targ}\n";
1429 print "\t{C_$arch} ", $d->{deps}->[0],
1430 " -o {Targ} {COptions_$arch}\n\n";
1433 select STDOUT; close OUT;
1436 if (defined $makefiles{'lcc'}) {
1438 $dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
1441 open OUT, ">$makefiles{'lcc'}"; select OUT;
1443 "# Makefile for $project_name under lcc.\n".
1444 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1445 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1446 # lcc command line option is -D not /D
1447 ($_ = $help) =~ s/=\/D/=-D/gs;
1451 "# If you rename this file to `Makefile', you should change this line,\n".
1452 "# so that the .rsp files still depend on the correct makefile.\n".
1453 "MAKEFILE = Makefile.lcc\n".
1455 "# C compilation flags\n".
1456 "CFLAGS = -D_WINDOWS " .
1457 (join " ", map {"-I$dirpfx$_"} @srcdirs) .
1460 "# Get include directory for resource compiler\n".
1462 print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
1464 foreach $p (&prognames("G:C")) {
1465 ($prog, $type) = split ",", $p;
1466 $objstr = &objects($p, "X.obj", "X.res", undef);
1467 print &splitline("$prog.exe: " . $objstr ), "\n";
1468 $subsystemtype = undef;
1469 if ($type eq "G") { $subsystemtype = "-subsystem windows"; }
1470 my $libss = "shell32.lib wsock32.lib ws2_32.lib winspool.lib winmm.lib imm32.lib";
1471 print &splitline("\tlcclnk $subsystemtype -o $prog.exe $objstr $libss");
1475 foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
1476 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1478 if ($d->{obj} =~ /\.res$/) {
1479 print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
1481 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1482 print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1483 " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
1487 print $makefile_extra{'lcc'} || "";
1493 select STDOUT; close OUT;
1496 if (defined $makefiles{'nestedvm'}) {
1497 $mftyp = 'nestedvm';
1498 $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
1500 ##-- NestedVM makefile
1501 open OUT, ">$makefiles{'nestedvm'}"; select OUT;
1503 "# Makefile for $project_name under NestedVM.\n".
1504 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1505 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1506 # gcc command line option is -D not /D
1507 ($_ = $help) =~ s/=\/D/=-D/gs;
1511 "# This path points at the nestedvm root directory\n".
1512 "NESTEDVM = /opt/nestedvm\n".
1513 "# You can define this path to point at your tools if you need to\n".
1514 "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
1515 "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
1517 &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
1518 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1520 print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
1522 foreach $p (&prognames("X")) {
1523 ($prog, $type) = split ",", $p;
1524 $objstr = &objects($p, "X.o", undef, undef);
1525 $objstr =~ s/gtk\.o/nestedvm\.o/g;
1526 print &splitline($prog . ".mips: " . $objstr), "\n";
1527 $libstr = &objects($p, undef, undef, "-lX");
1528 print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " .
1529 $objstr . " $libstr -lm", 69), "\n\n";
1531 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1533 $ddeps= join " ", @{$d->{deps}};
1534 $oobjs =~ s/gtk/nestedvm/g;
1535 $ddeps =~ s/gtk/nestedvm/g;
1536 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1538 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1539 print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1540 " -c \$< -o \$\@\n";
1543 print $makefile_extra{'nestedvm'} || "";
1545 "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
1546 select STDOUT; close OUT;
1549 if (defined $makefiles{'osx'}) {
1551 $dirpfx = &dirpfx($makefiles{'osx'}, "/");
1552 @osxarchs = ('i386');
1554 ##-- Mac OS X makefile
1555 open OUT, ">$makefiles{'osx'}"; select OUT;
1557 "# Makefile for $project_name under Mac OS X.\n".
1558 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1559 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1560 # gcc command line option is -D not /D
1561 ($_ = $help) =~ s/=\/D/=-D/gs;
1564 "CC = \$(TOOLPATH)gcc\n".
1565 "LIPO = \$(TOOLPATH)lipo\n".
1567 &splitline("CFLAGS = -O2 -Wall -Werror -g " .
1568 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1569 "LDFLAGS = -framework Cocoa\n".
1570 &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
1572 print $makefile_extra{'osx'} || "";
1574 ".SUFFIXES: .o .c .m\n".
1577 foreach $p (&prognames("MX")) {
1578 ($prog, $type) = split ",", $p;
1579 $icon = &special($p, ".icns");
1580 $infoplist = &special($p, "info.plist");
1581 print "${prog}.app:\n\tmkdir -p \$\@\n";
1582 print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
1583 print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1584 $targets = "${prog}.app/Contents/MacOS/$prog";
1585 if (defined $icon) {
1586 print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
1587 print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
1588 $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
1590 if (defined $infoplist) {
1591 print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
1592 $targets .= " ${prog}.app/Contents/Info.plist";
1594 $targets .= " \$(${prog}_extra)";
1595 print &splitline("${prog}: $targets", 69) . "\n\n";
1596 $libstr = &objects($p, undef, undef, "-lX");
1598 foreach $arch (@osxarchs) {
1599 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1600 print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
1601 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(LDFLAGS) -o \$@ " .
1602 $objstr . " $libstr", 69), "\n\n";
1603 $archbins .= " ${prog}.${arch}.bin";
1605 print &splitline("${prog}.app/Contents/MacOS/$prog: ".
1606 "${prog}.app/Contents/MacOS" . $archbins), "\n";
1607 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1609 foreach $p (&prognames("U")) {
1610 ($prog, $type) = split ",", $p;
1611 $libstr = &objects($p, undef, undef, "-lX");
1613 foreach $arch (@osxarchs) {
1614 $objstr = &objects($p, "X.${arch}.o", undef, undef);
1615 print &splitline("${prog}.${arch}: " . $objstr), "\n";
1616 print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.4 \$(ULDFLAGS) -o \$@ " .
1617 $objstr . " $libstr", 69), "\n\n";
1618 $archbins .= " ${prog}.${arch}";
1620 print &splitline("${prog}:" . $archbins), "\n";
1621 print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n";
1623 foreach $arch (@osxarchs) {
1624 foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) {
1625 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1627 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1628 if ($d->{deps}->[0] =~ /\.m$/) {
1629 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
1630 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1632 print "\t\$(CC) -arch $arch -mmacosx-version-min=10.4 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1633 " -c \$< -o \$\@\n";
1638 "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
1640 select STDOUT; close OUT;
1643 if (defined $makefiles{'gnustep'}) {
1645 $dirpfx = &dirpfx($makefiles{'gnustep'}, "/");
1647 ##-- GNUstep makefile (use with 'gs_make -f Makefile.gnustep')
1649 # This is a pretty evil way to do things. In an ideal world, I'd
1650 # use the approved GNUstep makefile mechanism which just defines a
1651 # variable or two saying what source files go into what binary and
1652 # then includes application.make. Unfortunately, that has the
1653 # automake-ish limitation that it doesn't let you choose different
1654 # command lines for each object, so I can't arrange for all those
1655 # files with -DTHIS and -DTHAT to Just Work.
1657 # A simple if ugly fix would be to have mkfiles.pl construct a
1658 # directory full of stub C files of the form '#define thing',
1659 # '#include "real_source_file"', and then reference those in this
1660 # makefile. That would also make it easy to build a proper
1661 # automake makefile.
1662 open OUT, ">$makefiles{'gnustep'}"; select OUT;
1664 "# Makefile for $project_name under GNUstep.\n".
1665 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1666 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1667 # gcc command line option is -D not /D
1668 ($_ = $help) =~ s/=\/D/=-D/gs;
1672 "include \$(GNUSTEP_MAKEFILES)/common.make\n".
1673 "include \$(GNUSTEP_MAKEFILES)/rules.make\n".
1674 "include \$(GNUSTEP_MAKEFILES)/Instance/rules.make\n".
1676 &splitline("all::" . join "", map { " $_" } &progrealnames("MX:U")) .
1678 print $makefile_extra{'gnustep'} || "";
1680 ".SUFFIXES: .o .c .m\n".
1683 foreach $p (&prognames("MX")) {
1684 ($prog, $type) = split ",", $p;
1685 $icon = &special($p, ".icns");
1686 $infoplist = &special($p, "info.plist");
1687 print "${prog}.app:\n\tmkdir -p \$\@\n";
1688 $targets = "${prog}.app ${prog}.app/$prog";
1689 if (defined $icon) {
1690 print "${prog}.app/Resources: ${prog}.app\n\tmkdir -p \$\@\n";
1691 print "${prog}.app/Resources/${prog}.icns: ${prog}.app/Resources $icon\n\tcp $icon \$\@\n";
1692 $targets .= " ${prog}.app/Resources/${prog}.icns";
1694 if (defined $infoplist) {
1695 print "${prog}.app/Info.plist: ${prog}.app $infoplist\n\tcp $infoplist \$\@\n";
1696 $targets .= " ${prog}.app/Info.plist";
1698 $targets .= " \$(${prog}_extra)";
1699 print &splitline("${prog}: $targets", 69) . "\n\n";
1700 $libstr = &objects($p, undef, undef, "-lX");
1701 $objstr = &objects($p, "X.o", undef, undef);
1702 print &splitline("${prog}.app/$prog: " . $objstr), "\n";
1703 print &splitline("\t\$(CC) \$(ALL_LDFLAGS) -o \$@ " . $objstr . " \$(ALL_LIB_DIRS) $libstr \$(ALL_LIBS)", 69), "\n\n";
1705 foreach $p (&prognames("U")) {
1706 ($prog, $type) = split ",", $p;
1707 $libstr = &objects($p, undef, undef, "-lX");
1708 $objstr = &objects($p, "X.o", undef, undef);
1709 print &splitline("${prog}: " . $objstr), "\n";
1710 print &splitline("\t\$(CC) \$(ULDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n";
1712 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1713 print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
1715 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1716 if ($d->{deps}->[0] =~ /\.m$/) {
1717 print "\t\$(CC) -DGNUSTEP \$(ALL_OBJCFLAGS) \$(COMPAT) \$(FWHACK) \$(OBJCFLAGS)".
1718 " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
1720 print "\t\$(CC) \$(ALL_CFLAGS) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
1721 " -c \$< -o \$\@\n";
1724 print "\nclean::\n".
1725 "\trm -f *.o ". (join " ", &progrealnames("U")) . "\n".
1727 select STDOUT; close OUT;
1730 if (defined $makefiles{'emcc'}) {
1732 $dirpfx = &dirpfx($makefiles{'emcc'}, "/");
1734 ##-- Makefile for building Javascript puzzles via Emscripten
1736 open OUT, ">$makefiles{'emcc'}"; select OUT;
1738 "# Makefile for $project_name using Emscripten. Requires GNU make.\n".
1739 "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
1740 "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
1741 # emcc command line option is -D not /D
1742 ($_ = $help) =~ s/=\/D/=-D/gs;
1746 "# This can be set on the command line to point at the emcc command,\n".
1747 "# if it is not on your PATH.\n".
1750 &splitline("CFLAGS = -DSLOW_SYSTEM " .
1751 (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
1753 $output_js_files = join "", map { " \$(OUTPREFIX)$_.js" } &progrealnames("X");
1754 print &splitline("all:" . $output_js_files);
1756 foreach $p (&prognames("X")) {
1757 ($prog, $type) = split ",", $p;
1758 $objstr = &objects($p, "X.o", undef, undef);
1759 $objstr =~ s/gtk\.o/emcc\.o/g;
1760 print &splitline("\$(OUTPREFIX)" . $prog . ".js: " . $objstr . " emccpre.js emcclib.js emccx.json"), "\n";
1761 print "\t\$(EMCC) -o \$(OUTPREFIX)".$prog.".js ".
1764 "--pre-js emccpre.js ".
1765 "--js-library emcclib.js ".
1766 "-s EXPORTED_FUNCTIONS=\"`sed 's://.*::' emccx.json | tr -d ' \\n'`\" " . $objstr . "\n\n";
1768 foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
1770 $ddeps= join " ", @{$d->{deps}};
1771 $oobjs =~ s/gtk/emcc/g;
1772 $ddeps =~ s/gtk/emcc/g;
1773 print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
1775 $deflist = join "", map { " -D$_" } @{$d->{defs}};
1776 print "\t\$(EMCC) \$(CFLAGS) \$(XFLAGS)$deflist" .
1777 " -c \$< -o \$\@\n";
1780 print $makefile_extra{'emcc'} || "";
1782 "\trm -rf *.o $output_js_files\n";
1783 select STDOUT; close OUT;
1786 # All done, so do the Unix postprocessing if asked to.
1790 system "./mkauto.sh";
1791 die "mkfiles.pl: mkauto.sh returned $?\n" if $? > 0;
1792 system "./configure", @confargs;
1793 die "mkfiles.pl: configure returned $?\n" if $? > 0;