-# platforms
-all_platforms := Win32 Linux Java2
-
-# path
-PATH := jikes-1.18/bin:$(PATH)
-
-
-## Platform-Neutral ###########################################################################
-
-ifneq ($(verbose),true)
-.SILENT: $(javac_java_objects) .headers $(gcj_java_objects) $(all_platforms) bin/org/xwt/builtin.xwar .bootclasspath .javac
-silent := --silent
-endif
-
-compile: $(javac_java_objects) bin/org/xwt/builtin.xwar
-
-all: $(all_platforms)
-
-.javac:
- if \
- type jikes && (jikes --version | grep "Version 1.18"); \
- then \
- echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java; \
- echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }" >> GetBootClassPath.java; \
- javac GetBootClassPath.java; \
- java -cp . GetBootClassPath > .bootclasspath; \
- rm GetBootClassPath.*; \
- echo -n "jikes -nowarn -sourcepath src/ -bootclasspath " > .javac; \
- cat .bootclasspath >> .javac; \
- else \
- echo "WARNING: You do not have jikes; falling back to javac. Compiles will be very slow."; \
- echo javac > .javac; \
- fi \
-
-jikes:
- curl ftp://www-126.ibm.com/pub/jikes/1.18/jikes-1.18.tar.bz2 | tar xj
- cd jikes-1.18; ./configure --prefix=`pwd` && make && make install
- ln -sf jikes-1.18/bin/jikes .jikes
-
-$(javac_java_objects): $(javac_java_sources) .javac
- test "$(JAVA_HOME)"x != x || (echo "you forgot to set your JAVA_HOME environment variable"; false)
- echo "compiling .java -> .class:"
- mkdir -p bin
- $(shell cat .javac) -classpath lib/libgcj-minimal.jar $(javac_java_sources) -d bin/
- echo "compiling .java -> .class: done"
-
-bin/org/xwt/builtin.xwar: $(xwar_sources)
- mkdir -p bin/org/xwt
- cd src; $(jar) cf ../bin/org/xwt/builtin.xwar $(xwar_sources:src/%=%)
-
-clean:
- rm -rf bin-* bin
- find . -name \*~ | xargs rm -f
- find . -name \#\*\# | xargs rm -f
+include Makefile.upstream
+
+# FIXME this should be done with -ljpeg
+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
+
+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/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 .)
+
+# a hack since we've disabled gcj's awt implementation
+build/$(platform)/org/xwt/plat/Java2.java.o:
+ touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
+build/$(platform)/org/xwt/plat/AWT.java.o:
+ touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
+
+build/$(platform)/%.java.o: build/java/%.java
+ @echo -e "\n\033[1mcompiling .java -> .o: $<\033[0m"
+ mkdir -p `dirname $@`
+ $(gcj) -c $< -o $@
+
+build/$(platform)/org/xwt/plat/$(platform).cc.o: src/org/xwt/plat/$(platform).cc src/org/xwt/plat/*.cc $(java_headers) .configure_jpeg-6b_$(target)
+ @echo -e "\n\033[1mcompiling .cc -> .o: $<\033[0m"
+ mkdir -p `dirname $@`
+ $(g++) -Iupstream/install/lib/gcc-lib/$(target)/3.3/include/ -Iupstream/install/$(target)/include -I/usr/X11R6/include/ -Ibuild/h -Wno-multichar -Iupstream/install/include -c $< -o $@
+
+build/$(platform)/jpeg-6b/%.c.o: upstream/jpeg-6b/src/%.c
+ @echo -e "\n\033[1mcompiling .c -> .o: $<\033[0m"
+ mkdir -p `dirname $@`
+ $(gcc) -Ibuild/h -c $< -o $@
+
+# PHASE 5: linking
+build/$(target)/$(target_bin).ar: $(java_sources:build/java/%.java=build/$(platform)/%.java.o) build/$(platform)/org/xwt/plat/$(platform).cc.o $(jpeg_object_files)
+ @echo -e "\n\033[1marchiving .o -> $(target_bin).ar\033[0m"
+ rm -f build/$(target)/$(target_bin).ar
+ upstream/install/$(target)/bin/ar -cq build/$(target)/$(target_bin).ar $^
+ upstream/install/$(target)/bin/ranlib build/$(target)/$(target_bin).ar
+
+$(target_bin): build/$(target)/$(target_bin).ar
+ @echo -e "\n\033[1mlinking .o -> $(target_bin)\033[0m"
+ mkdir -p build/$(platform)
+ PATH=upstream/install/bin:$$PATH $(gcj) --main=org.xwt.Main -o build/$(platform)/$(target_bin) build/$(target)/$(target_bin).ar -Lupstream/install/$(target)/lib $(link_flags)
+
+
+##############################################################################
+# Special treatment:
+#
+
+build/java/org/xwt/Builtin.java: $(shell ls src/org/xwt/builtin/*.png src/org/xwt/builtin/*.xwt src/org/xwt/builtin/*.xwf)
+ @mkdir -p `dirname $@` build build/java build/class build/h build
+ echo -e "\n\033[1mzipping/uuencoding .xwt -> .java: build/java/org/xwt/Builtin.java\033[0m"
+ echo "package org.xwt;" > build/java/org/xwt/Builtin.java
+ echo "class Builtin {" >> build/java/org/xwt/Builtin.java
+ echo "public static String encoded = " >> build/java/org/xwt/Builtin.java
+ cd src; $(jar) cf - $(<:src/%=%) | \
+ uuencode foo | tail -n +2 | grep -v '^end$$' | grep -v '^`$$' | \
+ sed 's_\(.+\)_"\1" +_' >> ../build/java/org/xwt/Builtin.java
+ echo "\"\"; }" >> build/java/org/xwt/Builtin.java
+
+
+# compile is here to force compilation of the .class files (they get used via -Ibuild) without
+# having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
+gcj: .vendor .install_gcc-3.3_$(target) .compile $(target_bin)
+build/JVM/xwt.jar: .compile
+ @echo -e "\n\033[1marchiving .class -> .jar: build/JVM/xwt.jar\033[0m"
+ mkdir -p build/JVM
+ echo -e "Manifest-Version: 1.0\nMain-Class: org.xwt.Main\n" > build/JVM/.manifest
+ cd build/class; $(jar) cfm ../JVM/xwt.jar ../JVM/.manifest `find . -name \*.class`;
+
+
+
+##############################################################################
+# Freetype
+#
+
+build/mips/%.c.o: src/%.c
+ make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
+ mkdir -p $(@D)
+ echo -e "\n\033[1mcompiling $< -> $@ (mips)\033[0m"
+ upstream/install/bin/mips-unknown-elf-gcc -march=r3000 -I upstream/freetype-2.1.4/src/include -c -o $@ $<
+
+build/mips/freetype.mips: build/mips/org/xwt/imp/Freetype.c.o build/mips/org/xwt/imp/crt0.c.o build/mips/org/xwt/imp/syscalls.c.o
+ make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
+ @echo -e "\n\033[1mlinking .o -> .mips: $@\033[0m"
+ mkdir -p build/mips
+ upstream/install/bin/mips-unknown-elf-gcc \
+ -nostdlib \
+ --static \
+ -march=mips1 \
+ -T src/org/xwt/imp/linker.ld \
+ -Lbuild/mips \
+ -Lupstream/freetype-2.1.4/src/objs \
+ -o $@ \
+ build/mips/org/xwt/imp/Freetype.c.o \
+ --strip \
+ -lfreetype
+
+build/java/org/xwt/imp/Freetype.java: build/mips/freetype.mips build/class/org/xwt/imp/MIPS.class
+ @echo -e "\n\033[1mtranslating .mips -> .java: $@\033[0m"
+ mkdir -p build/java/org/xwt/imp/
+ rm -f $@
+ java -cp build/class org.xwt.imp.MIPS org.xwt.imp.Freetype build/mips/freetype.mips > build/java/org/xwt/imp/Freetype.java
+
+
+
+##############################################################################
+# Maintainer stuff: generating numbered builds, proposing patches
+#