+target_Darwin := powerpc-apple-darwin
+target_Win32 := i686-pc-mingw32
+target_Solaris := sparc-sun-solaris2.7
+target_Linux := i686-pc-linux-gnu
+target := $(target_$(platform))
+
+all: JVM Linux Win32 Darwin Solaris
+
+clean: ; rm -rf build
+dist-clean:
+ rm -rf .jikes .configure* .install* build .compile .build*
+ find upstream -name config.cache -exec rm {} \;
+ test -e upstream/mips && make -C upstream/mips clean
+
+JVM: build/JVM/ibex.jar
+Linux: ; make gcj platform=Linux link_flags="-lX11 -lXext"
+Solaris: ; make gcj platform=Solaris link_flags="-lX11 -lXext -lpthread"
+Win32: ; make gcj platform=Win32 link_flags="-Wl,--subsystem,windows -lcomdlg32"
+Darwin: ; make gcj platform=Darwin link_flags="$(darwin_linker_flags)"
+
+foo: .compile
+ rm -rf build/class/*
+ make oldcompile
+ make .install_jode-1.1.1_java target=java
+ cd build; jar xvf ../upstream/install/share/java/libgcj-3.3.jar java/lang/Object.class
+ java -cp upstream/java-getopt-1.0.9:upstream/jode-1.1.1/build-java jode.obfuscator.Main jode.conf
+ cd out; jar xvf ../upstream/install/share/java/libgcj-3.3.jar java/lang/
+ cd build/class; tar cf - org/ | tar -C ../../out -xvf -
+ cd out ; rm -rf gnu/java/awt gnu/java/beans gnu/java/rmi java/rmi java/beans java/awt java/sql
+ for A in `find out -name \*.class`; do cd `dirname $$A`; $(shell pwd)/$(gcj) -c `basename $$A` -fCLASSPATH=$(shell pwd)/out; cd $(shell pwd); done
+
+darwin_libdir := upstream/install/powerpc-apple-darwin/lib
+darwin_linker_flags := -Wl,-dylib_file,/usr/lib/libSystem.B.dylib:$(darwin_libdir)/libSystem.B.dylib
+darwin_linker_flags += -Wl,-dylib_file,/usr/lib/system/libmathCommon.A.dylib:$(darwin_libdir)/libmathCommon.A.dylib
+darwin_ogl_libdir := /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries
+darwin_linker_flags += -Wl,-dylib_file,$(darwin_ogl_libdir)/libGL.dylib:$(darwin_libdir)/libGL.dylib
+darwin_linker_flags += -Wl,-dylib_file,$(darwin_ogl_libdir):$(darwin_libdir)/libGLU.dylib
+darwin_linker_flags += -lSystem.B -lmathCommon.A -lGL -lGLU
+
+# stupid broke-ass darwin linker...
+darwin_linker_flags += build/Darwin/org/ibex/plat/OpenGL.java.o build/Darwin/org/ibex/plat/POSIX.java.o
+
+target_bin_extension_$(platform) := $(shell echo $(platform) | tr A-Z a-z)
+target_bin_extension_Win32 := exe
+target_bin_extension_JVM := jar
+target_bin_extension := $(target_bin_extension_$(platform))
+target_bin := ibex.$(target_bin_extension)
+
+jikes_flags := -nowarn
+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)
+gcc_flags += -Iupstream/install/lib/gcc-lib/$(target)/3.3/include -Iupstream/install/$(target)/include
+gcj := upstream/install/bin/$(target)-gcj $(gcc_flags) -fCLASSPATH=build/java
+gcjh := $(shell pwd)/upstream/install/bin/$(shell test -e upstream/install/bin/$(target)-gcjh && echo $(target)-)gcjh
+g++ := upstream/install/bin/$(target)-gcj $(gcc_flags) -Iupstream/install/include -Wno-multichar
+gcc := upstream/install/bin/$(target)-gcc $(gcc_flags)
+jar := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
+
+gcj: .install_gcc-3.3_$(target); make build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
+
+include Makefile.upstream
+
+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/%:
+ @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/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;\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
+
+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'`/$< $@
+
+build/class/org/ibex/util/Preprocessor.class: src/org/ibex/util/Preprocessor.java .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/ibex/util/
+ ./.jikes $<
+
+oldcompile:; CLASSPATH=$$CLASSPATH:lib/libgcj-minimal.jar:upstream/mips/build javac -target 1.1 -d build/class `find build/java/ -name \*.java`
+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
+ echo @./.jikes $(java_sources)
+ @./.jikes $(java_sources)
+ touch .compile
+
+build/JVM/ibex.jar: .compile build/res/builtin.jar build/class/org/xwt/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)