-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'`/$< $@
+java_sources := $(patsubst src/%.java, build/java/%.java, $(shell find src -name '*.java' | grep -v Preprocessor))
+java_sources += build/java/org/xwt/mips/Errno.java
+java_sources += build/java/org/xwt/mips/Unistd.java
+java_sources += build/java/org/xwt/mips/Syscalls.java
+java_sources += build/java/org/xwt/mips/Registers.java
+java_sources += build/java/org/xwt/mips/Runtime.java
+java_sources += build/java/org/xwt/mips/UnixRuntime.java
+java_sources += build/java/org/xwt/mips/util/SeekableByteArray.java
+java_sources += build/java/org/xwt/mips/util/SeekableData.java
+java_sources += build/java/org/xwt/mips/util/SeekableFile.java
+java_sources += build/java/org/xwt/mips/util/SeekableInputStream.java
+
+build/java/org/xwt/mips/util/%: .install_mips2java
+ @echo linking $@
+ @mkdir -p $(@D)
+ @cd $(@D); ln -sf ../../../../../../upstream/mips/org/xwt/mips/util/$*
+build/java/org/xwt/mips/%: .install_mips2java
+ @echo linking $@
+ @mkdir -p $(@D)
+ @test -e upstream/mips/build/org/xwt/mips/$* && (cd $(@D); \
+ ln -sf ../../../../../upstream/mips/build/org/xwt/mips/$*); true
+ @test -e upstream/mips/org/xwt/mips/$* && (cd $(@D); \
+ ln -sf ../../../../../upstream/mips/org/xwt/mips/$*); true
+
+
+### Java Class Files ##############################################################################
+
+build/class/org/xwt/translators/MIPSApps.class: build/mips/mipsapps.mips .jikes
+ mkdir -p build/java/org/xwt/translators
+ @echo -e "\n\033[1mtranslating .mips -> .java: $<\033[0m"
+ (echo -e 'package org.xwt.translators;\nimport org.xwt.mips.*;\n'; \
+ java -Xint -cp upstream/mips/build org.xwt.mips.Compiler MIPSApps build/mips/mipsapps.mips) \
+ | sed 's,//.*$$,,;'| tr -d '\n') > build/java/org/xwt/translators/MIPSApps.java
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ ./.jikes -g:none build/java/org/xwt/translators/MIPSApps.java