X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/fa2cb13d4940a616f7d35151d0c9c341a52e5e98..4d6d127734e9debf3eb909b3a5817110fcc67bf5:/mkfiles.pl diff --git a/mkfiles.pl b/mkfiles.pl index c81d64d..7f36f8f 100755 --- a/mkfiles.pl +++ b/mkfiles.pl @@ -131,11 +131,22 @@ readinput: while (1) { $type = substr($i,1,(length $i)-2); } else { if ($i =~ /\?$/) { - # Source files with a trailing question mark are optional: + # Object files with a trailing question mark are optional: # the build can proceed fine without them, so we only use - # them if they're present. + # 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; @@ -273,7 +284,7 @@ sub mfval($) { # 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","nestedvm","osx","wce")) { return 1; } warn "$.:unknown makefile type '$type'\n"; @@ -403,6 +414,8 @@ sub deps { ($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; @@ -476,12 +489,13 @@ if (defined $makefiles{'cygwin'}) { "# 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". + " --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"; @@ -640,7 +654,7 @@ if (defined $makefiles{'vc'}) { "MAKEFILE = Makefile.vc\n". "\n". "# C compilation flags\n". - "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n". + "CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401 /I.\n". "LFLAGS = /incremental:no /fixed\n". "\n"; print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); @@ -705,6 +719,114 @@ if (defined $makefiles{'vc'}) { 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'; @@ -978,7 +1100,7 @@ if (defined $makefiles{'gtk'}) { "\n". "# You can define this path to point at your tools if you need to\n". "# TOOLPATH = /opt/gcc/bin\n". - "CC = \$(TOOLPATH)cc\n". + "CC := \$(TOOLPATH)\$(CC)\n". "# You can manually set this to `gtk-config' or `pkg-config gtk+-1.2'\n". "# (depending on what works on your system) if you want to enforce\n". "# building with GTK 1.2, or you can set it to `pkg-config gtk+-2.0'\n". @@ -986,11 +1108,11 @@ if (defined $makefiles{'gtk'}) { "# to 1.2 if it isn't found.\n". "GTK_CONFIG = sh -c 'pkg-config gtk+-2.0 \$\$0 2>/dev/null || gtk-config \$\$0'\n". "\n". - &splitline("CFLAGS = -O2 -Wall -Werror -g " . + &splitline("CFLAGS := -O2 -Wall -Werror -ansi -pedantic -g " . (join " ", map {"-I$dirpfx$_"} @srcdirs) . - " `\$(GTK_CONFIG) --cflags`")."\n". - "XLDFLAGS = `\$(GTK_CONFIG) --libs`\n". - "ULDFLAGS =#\n". + " `\$(GTK_CONFIG) --cflags` \$(CFLAGS)")."\n". + "XLIBS = `\$(GTK_CONFIG) --libs`\n". + "ULIBS =#\n". "INSTALL=install\n", "INSTALL_PROGRAM=\$(INSTALL)\n", "INSTALL_DATA=\$(INSTALL)\n", @@ -1008,8 +1130,8 @@ if (defined $makefiles{'gtk'}) { $objstr = &objects($p, "X.o", undef, undef); print &splitline($prog . ": " . $objstr), "\n"; $libstr = &objects($p, undef, undef, "-lX"); - print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " . - $objstr . " $libstr", 69), "\n\n"; + print &splitline("\t\$(CC) -o \$@ $objstr $libstr \$(${type}LIBS)", 69), + "\n\n"; } foreach $d (&deps("X.o", undef, $dirpfx, "/")) { print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), @@ -1226,9 +1348,63 @@ if (defined $makefiles{'lcc'}) { select STDOUT; close OUT; } +if (defined $makefiles{'nestedvm'}) { + $mftyp = 'nestedvm'; + $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/"); + + ##-- NestedVM makefile + open OUT, ">$makefiles{'nestedvm'}"; select OUT; + print + "# Makefile for $project_name under NestedVM.\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"; + # gcc command line option is -D not /D + ($_ = $help) =~ s/=\/D/=-D/gs; + print $_; + print + "\n". + "# This path points at the nestedvm root directory\n". + "NESTEDVM = /opt/nestedvm\n". + "# You can define this path to point at your tools if you need to\n". + "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n". + "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n". + "\n". + &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " . + (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n". + "\n"; + print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X")); + print "\n\n"; + foreach $p (&prognames("X")) { + ($prog, $type) = split ",", $p; + $objstr = &objects($p, "X.o", undef, undef); + $objstr =~ s/gtk\.o/nestedvm\.o/g; + print &splitline($prog . ".mips: " . $objstr), "\n"; + $libstr = &objects($p, undef, undef, "-lX"); + print &splitline("\t\$(CC) \$(${type}LDFLAGS) -o \$@ " . + $objstr . " $libstr -lm", 69), "\n\n"; + } + foreach $d (&deps("X.o", undef, $dirpfx, "/")) { + $oobjs = $d->{obj}; + $ddeps= join " ", @{$d->{deps}}; + $oobjs =~ s/gtk/nestedvm/g; + $ddeps =~ s/gtk/nestedvm/g; + print &splitline(sprintf("%s: %s", $oobjs, $ddeps)), + "\n"; + $deflist = join "", map { " -D$_" } @{$d->{defs}}; + print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" . + " -c \$< -o \$\@\n"; + } + print "\n"; + print $makefile_extra{'nestedvm'}; + print "\nclean:\n". + "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n"; + select STDOUT; close OUT; +} + if (defined $makefiles{'osx'}) { $mftyp = 'osx'; $dirpfx = &dirpfx($makefiles{'osx'}, "/"); + @osxarchs = ('ppc', 'i386'); ##-- Mac OS X makefile open OUT, ">$makefiles{'osx'}"; select OUT; @@ -1241,6 +1417,7 @@ if (defined $makefiles{'osx'}) { print $_; print "CC = \$(TOOLPATH)gcc\n". + "LIPO = \$(TOOLPATH)lipo\n". "\n". &splitline("CFLAGS = -O2 -Wall -Werror -g " . (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n". @@ -1254,7 +1431,6 @@ if (defined $makefiles{'osx'}) { print "\n\n"; foreach $p (&prognames("MX")) { ($prog, $type) = split ",", $p; - $objstr = &objects($p, "X.o", undef, undef); $icon = &special($p, ".icns"); $infoplist = &special($p, "info.plist"); print "${prog}.app:\n\tmkdir -p \$\@\n"; @@ -1272,34 +1448,49 @@ if (defined $makefiles{'osx'}) { } $targets .= " \$(${prog}_extra)"; print &splitline("${prog}: $targets", 69) . "\n\n"; - print &splitline("${prog}.app/Contents/MacOS/$prog: ". - "${prog}.app/Contents/MacOS " . $objstr), "\n"; $libstr = &objects($p, undef, undef, "-lX"); - print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " . + $archbins = ""; + foreach $arch (@osxarchs) { + $objstr = &objects($p, "X.${arch}.o", undef, undef); + print &splitline("${prog}.${arch}.bin: " . $objstr), "\n"; + print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(LDFLAGS) -o \$@ " . $objstr . " $libstr", 69), "\n\n"; + $archbins .= " ${prog}.${arch}.bin"; + } + print &splitline("${prog}.app/Contents/MacOS/$prog: ". + "${prog}.app/Contents/MacOS" . $archbins), "\n"; + print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n"; } foreach $p (&prognames("U")) { ($prog, $type) = split ",", $p; - $objstr = &objects($p, "X.o", undef, undef); - print &splitline($prog . ": " . $objstr), "\n"; $libstr = &objects($p, undef, undef, "-lX"); - print &splitline("\t\$(CC)" . $mw . " \$(ULDFLAGS) -o \$@ " . - $objstr . " $libstr", 69), "\n\n"; + $archbins = ""; + foreach $arch (@osxarchs) { + $objstr = &objects($p, "X.${arch}.o", undef, undef); + print &splitline("${prog}.${arch}: " . $objstr), "\n"; + print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(ULDFLAGS) -o \$@ " . + $objstr . " $libstr", 69), "\n\n"; + $archbins .= " ${prog}.${arch}"; + } + print &splitline("${prog}:" . $archbins), "\n"; + print &splitline("\t\$(LIPO) -create $archbins -output \$@", 69), "\n\n"; } - foreach $d (&deps("X.o", undef, $dirpfx, "/")) { - print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), - "\n"; - $deflist = join "", map { " -D$_" } @{$d->{defs}}; - if ($d->{deps}->[0] =~ /\.m$/) { - print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)". - " \$(XFLAGS)$deflist -c \$< -o \$\@\n"; - } else { - print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" . - " -c \$< -o \$\@\n"; + foreach $arch (@osxarchs) { + foreach $d (&deps("X.${arch}.o", undef, $dirpfx, "/")) { + print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})), + "\n"; + $deflist = join "", map { " -D$_" } @{$d->{defs}}; + if ($d->{deps}->[0] =~ /\.m$/) { + print "\t\$(CC) -arch $arch -mmacosx-version-min=10.3 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)". + " \$(XFLAGS)$deflist -c \$< -o \$\@\n"; + } else { + print "\t\$(CC) -arch $arch -mmacosx-version-min=10.3 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" . + " -c \$< -o \$\@\n"; + } } } print "\nclean:\n". - "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n". + "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n". "\trm -rf *.app\n"; select STDOUT; close OUT; }