# - special-define objects (foo.o[PREPROCSYMBOL]) are not
# supported in the mac or vcproj makefiles.
-use FileHandle;
+use IO::Handle;
use Cwd;
-open IN, "Recipe" or do {
+@filestack = ();
+$in = new IO::Handle;
+open $in, "Recipe" or do {
# We want to deal correctly with being run from one of the
# subdirs in the source tree. So if we can't find Recipe here,
# try one level up.
chdir "..";
- open IN, "Recipe" or die "unable to open Recipe file\n";
+ open $in, "Recipe" or die "unable to open Recipe file\n";
};
+push @filestack, $in;
# HACK: One of the source files in `charset' is auto-generated by
# sbcsgen.pl. We need to generate that _now_, before attempting
@allobjs = (); # all object file names
-while (<IN>) {
+readinput: while (1) {
+ while (not defined ($_ = <$in>)) {
+ close $in;
+ last readinput if 0 == scalar @filestack;
+ $in = pop @filestack;
+ }
+
+ chomp;
+ split;
+
# Skip comments (unless the comments belong, for example because
# they're part of a diversion).
next if /^\s*#/ and !defined $divert;
- chomp;
- split;
if ($_[0] eq "!begin" and $_[1] eq "help") { $divert = \$help; next; }
if ($_[0] eq "!end") { $divert = undef; next; }
if ($_[0] eq "!name") { $project_name = $_[1]; next; }
if ($_[0] eq "!makefile" and &mfval($_[1])) { $makefiles{$_[1]}=$_[2]; next;}
if ($_[0] eq "!specialobj" and &mfval($_[1])) { $specialobj{$_[1]}->{$_[2]} = 1; next;}
if ($_[0] eq "!begin") {
- if (&mfval($_[1])) {
+ if ($_[1] =~ /^>(.*)/) {
+ $divert = \$auxfiles{$1};
+ } elsif (&mfval($_[1])) {
$divert = \$makefile_extra{$_[1]};
- } else {
- $divert = \$dummy;
}
next;
}
+ if ($_[0] eq "!include") {
+ @newfiles = ();
+ for ($i = 1; $i <= $#_; $i++) {
+ push @newfiles, (sort glob $_[$i]);
+ }
+ for ($i = $#newfiles; $i >= 0; $i--) {
+ $file = $newfiles[$i];
+ $f = new IO::Handle;
+ open $f, "<$file" or die "unable to open include file '$file'\n";
+ push @filestack, $f;
+ }
+ $in = $filestack[$#filestack];
+ next;
+ }
# If we're gathering help text, keep doing so.
if (defined $divert) { ${$divert} .= "$_\n"; next; }
# Ignore blank lines.
$prog = undef;
die "$.: unexpected + line\n" if !defined $lastlistref;
} elsif ($_[1] eq "=") {
+ $groups{$_[0]} = [];
+ $listref = $groups{$_[0]};
+ $prog = undef;
+ shift @objs; # eat the group name
+ } elsif ($_[1] eq "+=") {
$groups{$_[0]} = [] if !defined $groups{$_[0]};
$listref = $groups{$_[0]};
$prog = undef;
$prog = $_[0];
shift @objs; # eat the program name
} else {
- die "$.: unrecognised line type\n";
+ die "$.: unrecognised line type: '$_'\n";
}
shift @objs; # eat the +, the = or the :
$i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
$type = substr($i,1,(length $i)-2);
} else {
- push @$listref, $i;
- push @allobjs, $i;
+ if ($i =~ /\?$/) {
+ # Object files with a trailing question mark are optional:
+ # the build can proceed fine without them, so we only use
+ # them if their primary source files are present.
+ $i =~ s/\?$//;
+ $i = undef unless defined &finddep($i);
+ } elsif ($i =~ /\|/) {
+ # Object file descriptions containing a vertical bar are
+ # lists of choices: we use the _first_ one whose primary
+ # source file is present.
+ @options = split /\|/, $i;
+ $j = undef;
+ foreach $k (@options) {
+ $j=$k, last if defined &finddep($k);
+ }
+ die "no alternative found for $i\n" unless defined $j;
+ $i = $j;
+ }
+ if (defined $i) {
+ push @$listref, $i;
+ push @allobjs, $i;
+ }
}
}
if ($prog and $type) {
$lastlistref = $listref;
}
-close IN;
+foreach $aux (sort keys %auxfiles) {
+ open AUX, ">$aux";
+ print AUX $auxfiles{$aux};
+ close AUX;
+}
# Find object file names with predefines (in square brackets after
# the module name), and decide on actual object names for them.
$programs{$i} = [@list];
foreach $jj (@list) {
$j = $srcname{$jj};
- # Dependencies for "x" start with "x.c" or "x.m" (depending on
- # which one exists).
- # Dependencies for "x.res" start with "x.rc".
- # Dependencies for "x.rsrc" start with "x.r".
- # Both types of file are pushed on the list of files to scan.
- # Libraries (.lib) don't have dependencies at all.
- if ($j =~ /^(.*)\.res$/) {
- $file = "$1.rc";
- $depends{$jj} = [$file];
- push @scanlist, $file;
- } elsif ($j =~ /^(.*)\.rsrc$/) {
- $file = "$1.r";
- $depends{$jj} = [$file];
- push @scanlist, $file;
- } elsif ($j !~ /\./) {
- $file = "$j.c";
- $file = "$j.m" unless &findfile($file);
+ $file = &finddep($j);
+ if (defined $file) {
$depends{$jj} = [$file];
push @scanlist, $file;
}
# Returns true if the argument is a known makefile type. Otherwise,
# prints a warning and returns false;
if (grep { $type eq $_ }
- ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx")) {
+ ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx","wce")) {
return 1;
}
warn "$.:unknown makefile type '$type'\n";
return $findfilecache{$name};
}
+sub finddep {
+ my $j = shift @_;
+ my $file;
+ # Find the first dependency of an object.
+
+ # Dependencies for "x" start with "x.c" or "x.m" (depending on
+ # which one exists).
+ # Dependencies for "x.res" start with "x.rc".
+ # Dependencies for "x.rsrc" start with "x.r".
+ # Both types of file are pushed on the list of files to scan.
+ # Libraries (.lib) don't have dependencies at all.
+ if ($j =~ /^(.*)\.res$/) {
+ $file = "$1.rc";
+ } elsif ($j =~ /^(.*)\.rsrc$/) {
+ $file = "$1.r";
+ } elsif ($j !~ /\./) {
+ $file = "$j.c";
+ $file = "$j.m" unless &findfile($file);
+ } else {
+ # For everything else, we assume it's its own dependency.
+ $file = $j;
+ }
+ $file = undef unless &findfile($file);
+ return $file;
+}
+
sub objects {
my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
my @ret;
$splitchar = (defined $splitchar ? $splitchar : '\\');
while (length $line > $len) {
$line =~ /^(.{0,$len})\s(.*)$/ or $line =~ /^(.{$len,}?\s(.*)$/;
- $result .= $1 . " ${splitchar}\n\t\t";
+ $result .= $1;
+ $result .= " ${splitchar}\n\t\t" if $2 ne '';
$line = $2;
$len = 60;
}
($x = $otmpl) =~ s/X/$i/;
}
@deps = @{$depends{$ii}};
+ # Skip things which are their own dependency.
+ next if grep { $_ eq $i } @deps;
@deps = map {
$_ = &findfile($_);
s/\//$dirsep/g;
"# RCINC = --include-dir c:\\cygwin\\include\\\n".
"\n".
&splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT".
- " -D_NO_OLDNAMES -DNO_MULTIMON " .
+ " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " .
(join " ", map {"-I$dirpfx$_"} @srcdirs)) .
"\n".
"LDFLAGS = -mno-cygwin -s\n".
&splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1".
- " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n".
- "\n".
- ".SUFFIXES:\n".
- "\n".
- "%.o: %.c\n".
- "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
- "\n".
- "%.res.o: %.rc\n".
- "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n".
+ " --define WINVER=0x0400 --define MINGW32_FIX=1 " .
+ (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n".
"\n";
print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
print "\n\n";
print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
} else {
$deflist = join "", map { " -D$_" } @{$d->{defs}};
- print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS)" .
- " \$(CFLAGS)$deflist -c \$< -o \$\@\n";
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS)" .
+ " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
}
}
print "\n";
} else {
$deflist = join "", map { " -D$_" } @{$d->{defs}};
print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
- " \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist ".
+ " \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist ".
(join " ", map {"-I$dirpfx$_"} @srcdirs) .
" /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
}
"\n";
if ($d->{obj} =~ /\.res$/) {
print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
- "-DWINVER=0x0400 ".$d->{deps}->[0]."\n";
+ "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
} else {
$deflist = join "", map { " /D$_" } @{$d->{defs}};
- print "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist".
+ print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
" /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
}
}
select STDOUT; close OUT;
}
+if (defined $makefiles{'wce'}) {
+ $mftyp = 'wce';
+ $dirpfx = &dirpfx($makefiles{'wce'}, "\\");
+
+ ##-- eMbedded Visual C PocketPC makefile
+ open OUT, ">$makefiles{'wce'}"; select OUT;
+ print
+ "# Makefile for $project_name on PocketPC using eMbedded Visual C.\n".
+ "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
+ "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
+ print $help;
+ print
+ "\n".
+ "# If you rename this file to `Makefile', you should change this line,\n".
+ "# so that the .rsp files still depend on the correct makefile.\n".
+ "MAKEFILE = Makefile.wce\n".
+ "\n".
+ "# This makefile expects the environment to have been set up by one\n".
+ "# of the PocketPC batch files wcearmv4.bat and wceemulator.bat. No\n".
+ "# other build targets are currently supported, because they would\n".
+ "# need a section in this if statement.\n".
+ "!if \"\$(TARGETCPU)\" == \"emulator\"\n".
+ "PLATFORM_DEFS=/D \"_i386_\" /D \"i_386_\" /D \"_X86_\" /D \"x86\"\n".
+ "CC=cl\n".
+ "BASELIBS=commctrl.lib coredll.lib corelibc.lib aygshell.lib\n".
+ "MACHINE=IX86\n".
+ "!else\n".
+ "PLATFORM_DEFS=/D \"ARM\" /D \"_ARM_\" /D \"ARMV4\"\n".
+ "CC=clarm\n".
+ "BASELIBS=commctrl.lib coredll.lib aygshell.lib\n".
+ "MACHINE=ARM\n".
+ "!endif\n".
+ "\n".
+ "# C compilation flags\n".
+ "CFLAGS = /nologo /W3 /O1 /MC /D _WIN32_WCE=420 /D \"WIN32_PLATFORM_PSPC=400\" /D UNDER_CE=420 \\\n".
+ " \$(PLATFORM_DEFS) \\\n".
+ " /D \"UNICODE\" /D \"_UNICODE\" /D \"NDEBUG\" /D \"NO_HTMLHELP\"\n".
+ "\n".
+ "LFLAGS = /nologo /incremental:no \\\n".
+ " /base:0x00010000 /stack:0x10000,0x1000 /entry:WinMainCRTStartup \\\n".
+ " /nodefaultlib:libc.lib /nodefaultlib:libcmt.lib /nodefaultlib:msvcrt.lib /nodefaultlib:OLDNAMES.lib \\\n".
+ " /subsystem:windowsce,4.20 /align:4096 /MACHINE:\$(MACHINE)\n".
+ "\n".
+ "RCFL = /d UNDER_CE=420 /d _WIN32_WCE=420 /d \"WIN32_PLATFORM_PSPC=400\" \\\n".
+ " \$(PLATFORM_DEFS) \\\n".
+ " /d \"NDEBUG\" /d \"UNICODE\" /d \"_UNICODE\"\n".
+ "\n";
+ print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G"));
+ print "\n\n";
+ foreach $p (&prognames("G")) {
+ ($prog, $type) = split ",", $p;
+ $objstr = &objects($p, "X.obj", "X.res", undef);
+ print &splitline("$prog.exe: " . $objstr . " $prog.rsp"), "\n";
+ print "\tlink \$(LFLAGS) -out:$prog.exe -map:$prog.map \@$prog.rsp\n\n";
+ }
+ foreach $p (&prognames("G")) {
+ ($prog, $type) = split ",", $p;
+ print $prog, ".rsp: \$(MAKEFILE)\n";
+ $objstr = &objects($p, "X.obj", "X.res", undef);
+ @objlist = split " ", $objstr;
+ @objlines = ("");
+ foreach $i (@objlist) {
+ if (length($objlines[$#objlines] . " $i") > 50) {
+ push @objlines, "";
+ }
+ $objlines[$#objlines] .= " $i";
+ }
+ print "\techo \$(BASELIBS) > $prog.rsp\n";
+ for ($i=0; $i<=$#objlines; $i++) {
+ print "\techo$objlines[$i] >> $prog.rsp\n";
+ }
+ print "\n";
+ }
+ foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
+ print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
+ "\n";
+ if ($d->{obj} =~ /\.res$/) {
+ print "\trc \$(FWHACK) \$(RCFL) -r -fo".
+ $d->{obj}." ".$d->{deps}->[0]."\n";
+ } else {
+ $deflist = join "", map { " /D$_" } @{$d->{defs}};
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".
+ " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
+ }
+ }
+ print "\n";
+ print $makefile_extra{'wce'};
+ print "\nclean: tidy\n".
+ "\t-del *.exe\n\n".
+ "tidy:\n".
+ "\t-del *.obj\n".
+ "\t-del *.res\n".
+ "\t-del *.pch\n".
+ "\t-del *.aps\n".
+ "\t-del *.ilk\n".
+ "\t-del *.pdb\n".
+ "\t-del *.rsp\n".
+ "\t-del *.dsp\n".
+ "\t-del *.dsw\n".
+ "\t-del *.ncb\n".
+ "\t-del *.opt\n".
+ "\t-del *.plg\n".
+ "\t-del *.map\n".
+ "\t-del *.idb\n".
+ "\t-del debug.log\n";
+ select STDOUT; close OUT;
+}
+
if (defined $makefiles{'vcproj'}) {
$mftyp = 'vcproj';
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
$deflist = join "", map { " -D$_" } @{$d->{defs}};
- print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist" .
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
" -c \$< -o \$\@\n";
}
print "\n";
print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
} else {
$deflist = join "", map { " -D$_" } @{$d->{defs}};
- print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(XFLAGS)".
- " \$(CFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
+ print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
+ " \$(XFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
}
}
print "\n";
"\n";
$deflist = join "", map { " -D$_" } @{$d->{defs}};
if ($d->{deps}->[0] =~ /\.m$/) {
- print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS)".
- " \$(CFLAGS)$deflist -c \$< -o \$\@\n";
+ print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
+ " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
} else {
- print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist" .
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
" -c \$< -o \$\@\n";
}
}