+#############################################################################
+# Configurables:
+#
+target_bin := xwt.$(shell echo $(platform) | tr A-Z a-z)
+jikes_flags := -nowarn -sourcepath src/
+gcc_optimizations := -O2
+#gcc_optimizations := -O9 -ffast-math -fomit-frame-pointer -foptimize-sibling-calls
+#gcc_optimizations += -finline-functions -funroll-loops -ffunction-sections -fdata-sections
+gcc_flags := -nostdinc $(gcc_optimizations) -Ibuild/h -Iupstream/jpeg-6b/src/ -Iupstream/jpeg-6b/build-$(target)/
+gcj_flags := -fCLASSPATH=build/java
+gcj := upstream/install/bin/$(target)-gcj $(gcc_flags) $(gcj_flags)
+gcjh := $(shell test -e `pwd`/upstream/install/bin/$(target)-gcjh && echo `pwd`/upstream/install/bin/$(target)-gcjh || echo `pwd`/upstream/install/bin/gcjh)
+g++ := upstream/install/bin/$(target)-gcj $(gcc_flags)
+gcc := upstream/install/bin/$(target)-gcc $(gcc_flags)
+jar := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
+
+include Makefile.upstream
+
+# figure out what stuff in org.xwt.plat.* this platform requires (its superclasses)
+all_java_sources := $(patsubst src/%.java, build/java/%.java, $(shell find src -name '*.java'))
+all_java_sources += $(patsubst src/%.java.pp, build/java/%.java, $(shell find src -name '*.java.pp'))
+
+java_sources := $(all_java_sources)
+nonplat_java_sources := $(filter-out build/java/org/xwt/plat/%, $(all_java_sources))
+plat_java_sources := $(filter build/java/org/xwt/plat/%, $(all_java_sources))
+
+# FIXME: must have a relitavely new GNU sed... Apple sed fails silently (why?)
+build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+build/cc/%.cc: src/%.c ; @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+build/c/jpeg/%.c: upstream/jpeg-6b/src/%.c
+ @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+build/res/%: src/% ; @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+
+build/java/%.java: src/%.java.pp
+ make build/class/org/xwt/util/Preprocessor.class
+ @echo -e "\n\033[1mpreprocessing .java.pp -> .java: $<\033[0m"
+ mkdir -p `dirname $@`
+ rm -f $@
+ java -cp build/class org.xwt.util.Preprocessor < $< > $@
+
+build/class/%.class: build/java/%.java .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class
+ ./.jikes $<
+
+# this forces a clean build every time because jikes is so damn buggy
+compile: .compile
+.compile: $(all_java_sources) .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m"
+ rm -rf build/class
+ mkdir -p build/class
+ @./.jikes $(all_java_sources)
+ touch .compile
+
+# PHASE 4: gcj-generated headers
+java_headers := $(all_java_sources:build/java/%.java=build/h/%.h)
+build/h/edu/stanford/ejalbert/BrowserLauncher.h:; mkdir -p $(@D); touch $@
+build/h/%.h: build/class/%.class
+ @echo -e "\n\033[1mextracting .class -> .h: $<\033[0m"
+ mkdir -p `dirname $@`
+ ls `echo $< | sed s/.class\$$//`*.class |\
+ sed s_build/class/__ | sed s/.class\$$//g | sed s_/_._g | (cd build/class; xargs $(gcjh) -d ../h --classpath .)