+java_sources := $(patsubst src/%.java, build/java/%.java, $(shell find src -name '*.java' | grep -v Preprocessor | grep -v plat/AWT | grep -v plat/Java2))
+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/%:
+ @test -e .install_mips2java || make .install_mips2java
+ @echo linking $@
+ @mkdir -p $(@D)
+ @cd $(@D); ln -sf ../../../../../../upstream/mips/org/xwt/mips/util/$*
+
+build/java/org/xwt/mips/%:
+ @test -e .install_mips2java || make .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/ibex/translators/MIPSApps.class: build/mips/mipsapps.mips .jikes
+ mkdir -p build/java/org/ibex/translators
+ @echo -e "\n\033[1mtranslating .mips -> .java: $<\033[0m"
+ (echo -e 'package org.ibex.translators;\n'; \
+ java -Xint -cp upstream/mips/build org.xwt.mips.Compiler MIPSApps build/mips/mipsapps.mips) \
+ | sed 's,//.*$$,,;'| tr -d '\n' > build/java/org/ibex/translators/MIPSApps.java
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ ./.jikes -g:none build/java/org/ibex/translators/MIPSApps.java
+
+build/java/org/ibex/%.java: src/org/ibex/%.java
+ make build/class/org/ibex/util/Preprocessor.class
+ @echo -e "\n\033[1mpreprocessing .java -> .java: $<\033[0m"
+ mkdir -p `dirname $@`; java -cp build/class org.ibex.util.Preprocessor < $< > $@
+
+build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
+build/cc/%.cc: src/%.c ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
+build/res/%: src/% ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
+
+gnu_regexp_jfiles := $(patsubst src/%.java, build/java/%.java, $(shell find src/gnu/regexp -name \*.java))
+gnu_regexp := $(patsubst src/%.java, build/class/%.class, $(shell find src/gnu/regexp -name \*.java))
+
+build/class/gnu/regexp/%.class: build/java/gnu/regexp/%.java $(gnu_regexp_jfiles) .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/ibex/util/
+ ./.jikes $<
+
+build/class/org/ibex/util/Preprocessor.class: src/org/ibex/util/Preprocessor.java $(gnu_regexp) .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/ibex/util/
+ ./.jikes src/org/ibex/util/Vec.java
+ ./.jikes $<
+
+build/class/%.class: build/java/%.java $(java_sources) .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p $(@D)
+ ./.jikes $<
+
+oldcompile:; CLASSPATH=$$CLASSPATH:lib/libgcj-minimal.jar:upstream/mips/build javac -target 1.1 -source 1.2 -d build/class `find build/java/ -name \*.java`
+
+compile: .jikes .install_mips2java
+ @make -s $(java_sources:build/java/%.java=build/class/%.class)
+.compile: compile
+
+.compile: $(java_sources) .jikes .install_mips2java
+ @echo -e "\n\033[1mcompiling .java -> .class: src/**/*.java\033[0m"
+ @rm -f $(java_sources:build/java/%.java=build/class/%.class)
+ mkdir -p build/class
+ cd build/java; for A in `find . -name \*.java`; do mkdir -p ../class/`dirname $$A`; done
+ @./.jikes $(java_sources)
+ touch .compile
+
+build/JVM/ibex.jar: .compile build/res/builtin.jar build/class/org/ibex/translators/MIPSApps.class
+ @echo -e "\n\033[1marchiving .class -> .jar: build/JVM/ibex.jar\033[0m"
+ mkdir -p build/JVM
+ echo -e "Manifest-Version: 1.0\nMain-Class: org.ibex.Main\n" > build/JVM/.manifest
+ cd build/class/org/ibex; ln -sf ../../../res/builtin.jar
+ cd build/class; $(jar) cfm ../JVM/ibex.jar ../JVM/.manifest \
+ `find . \! -type d` \
+ $(patsubst %,../../upstream/mips/build/org/xwt/mips/%*.class, Runtime Registers Syscalls Errno)
+
+
+### GCJH Headers ##############################################################################
+
+java_headers := $(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 .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 $(gcjh) -d ../h --classpath .)
+
+
+### Native Code ##############################################################################
+
+# a hack since we've disabled gcj's awt implementation
+build/$(platform)/org/ibex/plat/Java2.java.o: ; touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
+build/$(platform)/org/ibex/plat/AWT.java.o: ; touch .empty.c; mkdir -p $(@D); $(gcc) -c .empty.c -o $@;
+
+build/$(platform)/%.java.o: build/class/%.class
+ @echo -e "\n\033[1mcompiling .java -> .o: $<\033[0m"
+ mkdir -p `dirname $@`
+ $(gcj) -fCLASSPATH=build/pruned -c $< -o $@
+
+# FIXME detect subclasses of X11
+build/$(platform)/org/ibex/plat/Linux.cc.o: .install_WindowMaker-0.80.2_$(target)
+build/$(platform)/org/ibex/plat/Solaris.cc.o: .install_WindowMaker-0.80.2_$(target)
+
+build/$(platform)/org/ibex/plat/$(platform).cc.o: src/org/ibex/plat/$(platform).cc src/org/ibex/plat/*.cc .configure_jpeg-6b_$(target)
+ @make $(java_headers)
+ @echo -e "\n\033[1mcompiling .cc -> .o: $<\033[0m"
+ mkdir -p `dirname $@`
+ $(g++) -c $< -o $@
+
+nonplat_java_sources := $(filter-out build/java/org/ibex/plat/$(platform).java,$(java_sources))
+build/$(platform)/$(platform).ar: $(nonplat_java_sources:build/java/%.java=build/$(platform)/%.java.o)
+ @echo -e "\n\033[1marchiving .o -> .a\033[0m"
+ mkdir -p build/$(platform)
+ rm -f $@
+ upstream/install/$(target)/bin/ar rc $@ $^
+ upstream/install/$(target)/bin/ranlib $@
+
+upstream/jpeg-6b/build-$(target)/libjpeg.a: .install_jpeg-6b_$(target)
+
+# note: binaries appear in a different order in the dependency line vs the link line
+build/$(platform)/$(target_bin): upstream/jpeg-6b/build-$(target)/libjpeg.a
+ @echo -e "\n\033[1mlinking .o -> $(target_bin)\033[0m"
+
+ rm -rf build/$(platform)/*
+ make build/$(platform)/org/ibex/plat/$(platform).cc.o
+ make build/$(platform)/builtin.o
+
+ cd upstream/gcc-3.3/build-$(target)/$(target)/libjava; \
+ (find . -name nat\*.o | grep -v JIS; \
+ echo boehm.o;\
+ echo defineclass.o;\
+ echo exception.o;\
+ echo posix-threads.o;\
+ echo posix.o;\
+ echo prims.o;\
+ echo jni.o;\
+ echo resolve.o;\
+ echo libltdl/ltdl.o;\
+ find java gnu -name \*.o -not -name '*[A-Z]*'; \
+ ) > $(shell pwd)/.natbins
+
+
+ cd upstream/gcc-3.3/build-$(target)/$(target)/libjava;\
+ (cat $(shell pwd)/.natbins; echo $(shell pwd)/build/$(platform)/org/ibex/plat/$(platform).cc.o) |\
+ grep -v shs | grep -v SHS |xargs nm |\
+ grep _ZN | c++filt --format java | grep " U " | sed 's_\.class\$$_.class_' | sed 's_ * U __' | sed 's_(.*__' \
+ > $(shell pwd)/.natcalls
+
+ rm -rf build/pruned; mkdir -p build/pruned
+ javac -classpath lib/bcel-5.1.jar:build/class -d build/class src/org/ibex/util/BytecodePruner.java
+ rm -f build/$(platform)/ibex.jar
+ cd build/class; \
+ fastjar cf ../$(platform)/ibex.jar \
+ `find . -name \*.class | grep -v ibex/plat/` \
+ org/ibex/plat/$(platform)*.class \
+ org/ibex/plat/X11*.class \
+ org/ibex/plat/GCJ*.class \
+ org/ibex/plat/POSIX*.class
+ java -cp lib/bcel-5.1.jar:build/class org.ibex.util.BytecodePruner \
+ build/$(platform)/ibex.jar:upstream/install/share/java/libgcj-3.3.jar \
+ -o build/pruned \
+ `cat .natcalls`
+
+ rm build/pruned/org/ibex/plat/GCJ*.class
+ cp build/java/org/ibex/plat/GCJ.java build/pruned/org/ibex/plat/
+
+ rm -rf build/Linux/java
+ rm -rf build/Linux/gnu/gcj
+ rm -rf build/Linux/gnu/java
+ rm -rf build/Linux/gnu/classpath
+
+ cp upstream/gcc-3.3/build-$(target)/$(target)/libjava/java/lang/Object.class build/pruned/java/lang/
+
+# -fnew-ra \
+# -ffunction-sections \
+# -fdata-sections \
+# -fomit-frame-pointer \
+# -fno-force-mem \
+# -fno-force-addr \
+# -fbranch-probabilities \
+# -fno-schedule-insns \
+# -fno-optimize-sibling-calls \
+# -fno-if-conversion \
+# -fno-thread-jumps \
+# -foptimize-static-class-initialization \
+# -fno-store-check \
+# -fno-bounds-check \
+# -fmerge-all-constants \
+# -fno-inline-functions \
+# -finline-limit=1 \
+
+ cd build/pruned; \
+ for A in `find . -name \*.class -or -name \*.java`; do \
+ echo compiling $$A....; \
+ ../../upstream/install/bin/$(target)-gcj \
+ -w -c -Os \
+ -fCLASSPATH=../../build/$(platform)/ibex.jar \
+ $$A && \
+ (mkdir -p ../../build/$(platform)/`dirname $$A`; mv *.o ../../build/$(platform)/`dirname $$A`); \
+ done
+
+# rm -rf build/Linux/java/security build/Linux/gnu/java/security build/Linux/java/util/jar build/Linux/java/io/Object*
+# rm -rf build/pruned/java/security build/pruned/gnu/java/security build/pruned/java/util/jar build/pruned/java/io/Object*
+
+ rm -f build/$(platform)/ibex.a
+
+ cd upstream/gcc-3.3/build-$(target)/$(target)/libjava; \
+ $(shell pwd)/upstream/install/$(target)/bin/ar cq \
+ $(shell pwd)/build/$(platform)/ibex.a \
+ `find $(shell pwd)/build/$(platform) -name \*.o` \
+ `cat $(shell pwd)/.natbins`
+# --relax,-O2,--no-whole-archive,
+ PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj \
+ -Wl,--no-gc-sections,--noinhibit-exec,-rpath,upstream/install/$(target)/lib \
+ -Wl,-nostdlib,--eh-frame-hdr,-m,elf_i386,-dynamic-linker,/lib/ld-linux.so.2 \
+ --main=org.ibex.plat.$(platform) \
+ -Lupstream/install/$(target)/lib \
+ -Lupstream/install/lib \
+ -Os -w \
+ build/$(platform)/ibex.a \
+ upstream/jpeg-6b/build-$(target)/libjpeg.a \
+ $(link_flags) \
+ upstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/.libs/libgcjgc.a \
+ -lz -ldl -lgcc -lm -lpthread -ldl -lgcc -lc -lgcc \
+ upstream/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.3/crtend.o \
+ upstream/install/bin/../lib/gcc-lib/i686-pc-linux-gnu/3.3/../../../../i686-pc-linux-gnu/lib/crtn.o \
+ -o $@
+# strip build/Linux/ibex.linux
+# ls -l build/Linux/ibex.linux
+# upx-ucl-beta --best build/Linux/ibex.linux
+# ls -l build/Linux/ibex.linux
+
+
+### Builtin Resources ##############################################################################
+
+builtin_src := $(shell find src/org/ibex/builtin -name '*.*' \! -name '*.xcf')
+build/res/fonts/vera: .download_vera-1.10
+ mkdir -p build/res/fonts/vera
+ cd build/res/fonts/vera; ln -fs ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/Vera.ttf
+ cd build/res/fonts/vera; ln -fs ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraMono.ttf
+ cd build/res/fonts/vera; ln -fs ../../../../upstream/vera-1.10/ttf-bitstream-vera-1.10/VeraSe.ttf
+build/res/builtin.jar: $(builtin_src:src/%=build/res/%) build/res/fonts/vera
+ @echo -e "\n\033[1mzipping res/* -> .jar: builtin.jar\033[0m"
+ cd build/res; $(jar) cf builtin.jar org/ibex/builtin/scar.png
+# cd build/res; $(jar) cf builtin.jar $(^:build/res/%=%)
+build/$(platform)/builtin.o: build/res/builtin.jar
+ @echo -e "\n\033[1mwrapping .jar -> .o: resources.o\033[0m"
+ @(echo "unsigned int builtin_length = "; \
+ (wc -c build/res/builtin.jar | sed "s_build.*__"); \
+ echo \;; \
+ echo "unsigned char builtin_bytes[] = {"; \
+ hexdump -ve '"0x" 1/1 "%x,\n"' build/res/builtin.jar; \
+ echo "};") > .builtin.c
+ $(gcc) -c .builtin.c -o build/$(platform)/builtin.o
+
+
+build/mips/%.c.o: src/%.c .download_libmspack-20030726
+ make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
+ make .install_libmspack-20030726_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 \
+ -Iupstream/freetype-2.1.4/src/include \
+ -Iupstream/libmspack-20030726/src/mspack \