+#############################################################################
+# 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/
+gcj_flags := -fCLASSPATH=build/java
+gcj := upstream/install/bin/$(target)-gcj $(gcc_flags) $(gcj_flags)
+g++ := upstream/install/bin/$(target)-g++ $(gcc_flags)
+gcc := upstream/install/bin/$(target)-gcc $(gcc_flags)
+jar := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
+
+
+
+include Makefile.upstream
+jpeg_c_sources := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
+jpeg_c_sources += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
+jpeg_c_sources += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
+
+upstream/jpeg-6b/src/%.c: download_jpeg-6b
+
+freetype_sources := ftsystem.c ftmm.c ftbbox.c ftinit.c ftdebug.c ftbase.c ftglyph.c smooth.c sfnt.c truetype.c
+upstream/freetype-2.1.4/%.c: download_freetype-2.1.4
+
+java_sources := $(patsubst src/%.java, build/java/%.java, $(shell find src -name \*.java))
+java_sources += $(patsubst src/%.java.pp, build/java/%.java, $(shell find src -name \*.java.pp))
+java_sources += build/java/org/xwt/Builtin.java
+
+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/c/freetype/%.c: upstream/freetype-2.1.4/src/base/%.c
+ @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+build/c/freetype/%.c: upstream/freetype-2.1.4/src/%/%.c
+ @echo linking $@; mkdir -p $(@D); ln -s `echo $(@D) | sed 's_[^/]*\(/\|$$\)_../_g'`/$< $@
+
+build/java/%.java: src/%.java.pp
+ @make -s 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 $<
+
+compile: .compile
+.compile: $(java_sources:build/java/%.c=build/class/%.class)
+ @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m"
+ mkdir -p build/class
+ @./.jikes $(java_sources)
+ touch .compile
+
+# PHASE 4: gcj-generated headers
+java_headers := $(java_sources:build/java/%.java=build/h/%.h)
+build/h/%.h: build/class/%.class .compile
+ @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 ../../upstream/install/bin/$(target)-gcjh -d ../h --classpath .)