added background color option to Font.drawGlyph()
[org.ibex.core.git] / Makefile
index 3acc98c..9ca6dea 100644 (file)
--- a/Makefile
+++ b/Makefile
-#############################################################################
+############################################################################# 
 #
 # The Ibex Makefile
 #
 
 #  auto directory creation with %/%: %?
 
+ifeq ($(platform),)
+# default
+platform := Java2
+endif
+
 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
+all:         Java2 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
+       rm -rf .configure* .install* build .compile .build*
+       find upstream -name config.cache -exec rm -f {} \;
+       test -e upstream/org.ibex.nestedvm && make -C upstream/org.ibex.nestedvm clean
+       rm -f .install_org.ibex.nestedvm
 
-#libwing_Linux := -Lupstream/install/i686-pc-linux-gnu/lib/
-#libwing_Linux +=   upstream/install/i686-pc-linux-gnu/lib/libWINGs.a
-#libwing_Linux +=   upstream/install/i686-pc-linux-gnu/lib/libwraster.a
+libwing_Linux := -Lupstream/install/i686-pc-linux-gnu/lib/
+libwing_Linux +=   upstream/install/i686-pc-linux-gnu/lib/libWINGs.a
+libwing_Linux +=   upstream/install/i686-pc-linux-gnu/lib/libwraster.a
 
 libwing_Solaris := -Lupstream/install/sparc-sun-solaris2.7/lib/
 libwing_Solaris +=   upstream/install/sparc-sun-solaris2.7/lib/libWINGs.a
 libwing_Solaris +=   upstream/install/sparc-sun-solaris2.7/lib/libwraster.a
 
-JVM:        build/JVM/ibex.jar
-Linux:    ; make gcj platform=Linux   link_flags="$(libwing_Linux) -lXpm -lX11 -lXext"
-Solaris:  ; make gcj platform=Solaris link_flags="$(libwing_Solaris) -lXpm -lX11 -lXext -lpthread"
-Win32:    ; make gcj platform=Win32   link_flags="-Wl,--subsystem,windows -lcomdlg32"
-Darwin:   ; make gcj platform=Darwin  link_flags="$(darwin_linker_flags)"
+Java2:      build/Java2/ibex.jar
+JVM:;       @make Java2
+Linux:    ; @make gcj platform=Linux   link_flags="$(libwing_Linux) -lXpm -lX11 -lXext"
+Solaris:  ; @make gcj platform=Solaris link_flags="$(libwing_Solaris) -lXpm -lX11 -lXext -lpthread"
+Win32:    ; @make gcj platform=Win32   link_flags="-Wl,--subsystem,windows -lcomdlg32"
+Darwin:   ; @make gcj platform=Darwin  link_flags="$(darwin_linker_flags)"
 
+libjava_dir         := $(shell pwd)/upstream/gcc-3.3/build-$(target)/$(target)/libjava
 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_Java2       := jar
 target_bin_extension             := $(target_bin_extension_$(platform))
 target_bin                       := ibex.$(target_bin_extension)
 
-jikes_flags        := -nowarn
-gcc_optimizations  := -O2
+ifeq ($(platform),Darwin)
+gcc_optimizations  := -O0
+else
+gcc_optimizations  := -Os
+endif
 #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          := -nostdinc $(gcc_optimizations) -Ibuild/h -Iupstream/jpeg-6b/src -Iupstream/jpeg-6b/build-$(target) -g
 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
+#gcc_flags          += -ffunction-sections -fdata-sections -fno-omit-frame-pointer
+gcj                := CLASSPATH=build/java upstream/install/bin/$(target)-gcj $(gcc_flags)
+ifneq ($(platform),Darwin)
+gcj                += -finhibit-reflection
+endif
+#gcj                += -fassume-compiled -fmerge-all-constants
+#gcj                += -foptimize-static-class-initialization -feliminate-dwarf2-dups -w
 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)
+nm                 := upstream/install/$(target)/bin/nm
 jar                := $(shell ((type fastjar &>/dev/null) && echo fastjar) || echo jar)
+ifeq ($(platform),Java2)
+javac   := javac -classpath upstream/bcel-5.1/src/bcel-5.1.jar   -d build/class/ -sourcepath build/java/
+else
+javac   := $(gcj) -fCLASSPATH=upstream/bcel-5.1/src/bcel-5.1.jar -d build/class/          -Ibuild/java -Iupstream/gnu.regexp-1.1.4/src/src -C
+endif
 
 gcj: .install_gcc-3.3_$(target)
-#      make compile
-       make build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
+       @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 | 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'`/$< $@
+# find the superclasses of a platform class
+#superclass_%:
+#      @if [ "$*" = "org.ibex.plat.Darwin" ]; then echo org.ibex.plat.OpenGL; fi
+#      @echo $*
+#      @grep -s extends src/$(subst .,/,$*).java | sed s_.\*extends\ __ | head -n 1 | sed s_\ .\*__ |\
+#              xargs --replace make -s superclass_org.ibex.plat.{}
+
+plat_classes_Platform := org.ibex.plat.Platform
+plat_classes_AWT      := org.ibex.plat.AWT $(plat_classes_Platform)
+plat_classes_Java2    := org.ibex.plat.Java2 org.ibex.plat.JVM $(plat_classes_AWT)
+plat_classes_GCJ      := org.ibex.plat.GCJ $(plat_classes_Platform)
+plat_classes_Win32    := org.ibex.plat.Win32 $(plat_classes_GCJ)
+plat_classes_POSIX    := org.ibex.plat.POSIX $(plat_classes_GCJ)
+plat_classes_X11      := org.ibex.plat.X11 $(plat_classes_POSIX)
+plat_classes_Linux    := org.ibex.plat.Linux $(plat_classes_X11)
+plat_classes_Solaris  := org.ibex.plat.Solaris $(plat_classes_X11)
+plat_classes_Darwin   := org.ibex.plat.Darwin org.ibex.plat.OpenGL $(plat_classes_POSIX)
+
+plat_java_src_sources     := $(patsubst %,build/java/%.java,$(subst .,/,$(plat_classes_$(platform))))
+java_src_sources          := $(shell find src -name '*.java' | grep -v NanoGoat | grep -v Preprocessor | grep -v /plat/)
+java_src_sources          += $(plat_java_src_sources)
+java_sources              := $(patsubst src/%.java,     build/java/%.java, $(java_src_sources))
+
+java_sources              += build/java/org/ibex/nestedvm/util/Seekable.java
+java_sources              += build/java/org/ibex/nestedvm/util/Platform.java
+java_sources              += build/java/org/ibex/nestedvm/Registers.java
+java_sources              += build/java/org/ibex/nestedvm/Runtime.java
+java_sources              += build/java/org/ibex/nestedvm/UsermodeConstants.java
+
+java_sources              += build/java/org/ibex/crypto/DER.java
+java_sources              += build/java/org/ibex/crypto/Digest.java
+java_sources              += build/java/org/ibex/crypto/HMAC.java
+java_sources              += build/java/org/ibex/crypto/MD2.java
+java_sources              += build/java/org/ibex/crypto/MD5.java
+java_sources              += build/java/org/ibex/crypto/PKCS1.java
+java_sources              += build/java/org/ibex/crypto/RC4.java
+java_sources              += build/java/org/ibex/crypto/RSA.java
+java_sources              += build/java/org/ibex/crypto/SHA1.java
+java_sources              += build/java/org/ibex/crypto/X509.java
+java_sources              += build/java/org/ibex/crypto/Base64.java
+java_sources              += build/java/org/ibex/net/ssl/RootCerts.java
+java_sources              += build/java/org/ibex/net/SSL.java
+
+java_sources              += build/java/gnu/regexp/CharIndexed.java
+java_sources              += build/java/gnu/regexp/CharIndexedCharArray.java
+java_sources              += build/java/gnu/regexp/CharIndexedInputStream.java
+java_sources              += build/java/gnu/regexp/CharIndexedString.java
+java_sources              += build/java/gnu/regexp/CharIndexedStringBuffer.java
+java_sources              += build/java/gnu/regexp/RE.java
+java_sources              += build/java/gnu/regexp/REException.java
+java_sources              += build/java/gnu/regexp/REFilterInputStream.java
+java_sources              += build/java/gnu/regexp/REMatch.java
+java_sources              += build/java/gnu/regexp/REMatchEnumeration.java
+java_sources              += build/java/gnu/regexp/RESyntax.java
+java_sources              += build/java/gnu/regexp/REToken.java
+java_sources              += build/java/gnu/regexp/RETokenAny.java
+java_sources              += build/java/gnu/regexp/RETokenBackRef.java
+java_sources              += build/java/gnu/regexp/RETokenChar.java
+java_sources              += build/java/gnu/regexp/RETokenEnd.java
+java_sources              += build/java/gnu/regexp/RETokenEndSub.java
+java_sources              += build/java/gnu/regexp/RETokenLookAhead.java
+java_sources              += build/java/gnu/regexp/RETokenWordBoundary.java
+java_sources              += build/java/gnu/regexp/RETokenOneOf.java
+java_sources              += build/java/gnu/regexp/RETokenPOSIX.java
+java_sources              += build/java/gnu/regexp/RETokenRange.java
+java_sources              += build/java/gnu/regexp/RETokenRepeated.java
+java_sources              += build/java/gnu/regexp/RETokenStart.java
+java_sources              += build/java/gnu/regexp/UncheckedRE.java
+java_sources              += build/java/gnu/regexp/CharIndexedReader.java
+java_sources              += build/java/gnu/regexp/REFilterReader.java
+
+java_classes              := $(java_sources:build/java/%.java=build/class/%.class)
+java_classes              += build/class/gnu/regexp/CharUnit.class build/class/gnu/regexp/IntPair.class
+java_classes              += build/class/org/ibex/util/MIPSApps.class
+
+### Java Source Files ##############################################################################
+
+$(java_sources):: .download_org.ibex.crypto .download_org.ibex.nestedvm .download_gnu.regexp-1.1.4
+link_upstream  = build/java/$(1):: $(2)/$(1) $(3); \
+                 @echo -e "\033[1mlinking            .java -> .java:  $$@\033[0m"; \
+                 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'`/$< $@
+$(call link_upstream,org/ibex/nestedvm/%.java,upstream/org.ibex.nestedvm/src,.download_org.ibex.nestedvm)
+$(call link_upstream,org/ibex/crypto/%.java,upstream/org.ibex.crypto/src,.download_org.ibex.crypto)
+$(call link_upstream,org/ibex/net/ssl/%.java,upstream/org.ibex.crypto/src,.download_org.ibex.crypto)
+$(call link_upstream,org/ibex/net/SSL.java,upstream/org.ibex.crypto/src,.download_org.ibex.crypto)
+$(call link_upstream,gnu/regexp/%.java,upstream/gnu.regexp-1.1.4/src/src)
+build/java/org/ibex/%.java: src/org/ibex/%.java .download_gnu.regexp-1.1.4 build/class/org/ibex/util/Preprocessor.class
+       @echo -e "\033[1mpreprocessing      .java -> .java:  $<\033[0m"
+       mkdir -p `dirname $@`; java -cp build/class:upstream/gnu.regexp-1.1.4/src/src org.ibex.util.Preprocessor < $< > $@
+$(call link_upstream,%.java,src)
+$(call link_upstream,%.cc,src)
 
-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 $<
+### Java Class Files ##############################################################################
 
-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
+build/class/org/ibex/util/Preprocessor.class: src/org/ibex/util/Preprocessor.java
+       @mkdir -p build/class/gnu/regexp build/class/org/ibex/util
+       $(javac) $< src/org/ibex/util/Vec.java upstream/gnu.regexp-1.1.4/src/src/gnu/regexp/*.java
+
+compile: .compile
+.compile: $(java_sources)
+       @echo -e "\n\033[1mcompiling          .java -> .class\033[0m"
+       @echo $(java_sources) | tr ' ' '\n' | sed 's_build/java/_    _' | sed 's_/_._g' | sed 's_.java$$__g'
+       @make -s $(java_sources)
+       $(javac) $(java_sources)
+       touch $@
+
+build/class/org/ibex/util/MIPSApps.class: build/mips/mipsapps.mips .install_org.ibex.nestedvm 
+       @mkdir -p build/java/org/ibex/util
+       @echo -e "\n\033[1mtranslating        .mips -> .class:  $<\033[0m"
+       java -cp upstream/org.ibex.nestedvm/build:upstream/org.ibex.nestedvm/upstream/build/classgen/build \
+               org.ibex.nestedvm.Compiler org.ibex.util.MIPSApps $< -outfile $@
+
+build/Java2/ibex.jar: compile build/res/builtin.jar build/class/org/ibex/util/MIPSApps.class
+       @echo -e "\n\033[1marchiving         .class -> .jar:   build/Java2/ibex.jar\033[0m"
+       mkdir -p build/Java2
+       echo -e "Manifest-Version: 1.0\nMain-Class: org.ibex.core.Main\n" > build/Java2/.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)
+       cd build/class; $(jar) cfm ../Java2/ibex.jar ../Java2/.manifest `find . -name \*.class -or -name \*.jar`
 
 
-### GCJH Headers ##############################################################################
+### 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 $@`
@@ -174,140 +218,136 @@ build/h/%.h: build/class/%.class .compile
 ### 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) 
 
+nat_libjava_files_ := boehm.o exception.o posix-threads.o posix.o prims.o resolve.o java/net/natInetAddress.o
+nat_libjava_files_ += java/net/natPlainSocketImpl.o java/util/zip/nat*.o gnu/gcj/runtime/natFirstThread.o
+nat_libjava_files_ += gnu/gcj/runtime/natNameFinder.o gnu/gcj/runtime/natStackTrace.o gnu/gcj/runtime/natSharedLibLoader.o
+nat_libjava_files_ += gnu/gcj/runtime/natStringBuffer.o gnu/gcj/runtime/natVMClassLoader.o gnu/gcj/runtime/natFinalizerThread.o
+nat_libjava_files_ += $(shell cd $(libjava_dir) 2>/dev/null; find java/lang -name \*.o -not -name '*[A-Z]*' 2>/dev/null)
+nat_libjava_files_ += $(shell cd $(libjava_dir) 2>/dev/null; find java/lang -name nat\*.o 2>/dev/null)
+nat_libjava_files := $(nat_libjava_files_:%=$(libjava_dir)/%)
+nat_libjava_files += $(libjava_dir)/java/io/natFile.o $(libjava_dir)/java/io/natFileDescriptor.o
+
 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/
-       cp upstream/gcc-3.3/build-$(target)/$(target)/libjava/java/lang/Object.class build/pruned/java/lang/
-
-       rm -f build/pruned/java/lang/System*.*
-       cp upstream/gcc-3.3/src/libjava/java/lang/System.java build/pruned/java/lang/
-
-#                              -fnew-ra \
-#                              -ffunction-sections \
-#                              -fdata-sections \
-#                              -fomit-frame-pointer \
-#                              -fno-force-mem \
-#                              -fno-force-addr \
-#                              -fmerge-all-constants \
-
-       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 -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`
-
-       rm -f build/$(platform)/natibex.a
-       cd upstream/gcc-3.3/build-$(target)/$(target)/libjava;           \
-               $(shell pwd)/upstream/install/$(target)/bin/ar cq        \
-                       $(shell pwd)/build/$(platform)/natibex.a         \
-                       `cat $(shell pwd)/.natbins`
-# -O2,--relax,
-       PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj          \
-               -Wl,--no-gc-sections,--noinhibit-exec                                \
-               --main=org.ibex.plat.$(platform)                                     \
-               -Lupstream/install/$(target)/lib                                     \
-               -Lupstream/install/lib                                               \
-               -Os -w                                                               \
-               -Wl,--whole-archive                                                  \
-               build/$(platform)/ibex.a                                             \
-               -Wl,--no-whole-archive                                               \
-               build/$(platform)/natibex.a                                          \
-               upstream/jpeg-6b/build-$(target)/libjpeg.a                           \
-               $(link_flags)                                                        \
-               upstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/.libs/libgcjgc.a \
-               -lz -ldl                                                             \
-               -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
-
+       $(g++) -Iupstream/gcc-3.3/build-$(target)/$(target)/libjava -c $< -o $@
+
+
+bcel_jar := upstream/bcel-5.1/src/bcel-5.1.jar
+build/$(platform)/ibex.pruned.jar: .compile $(java_classes) .install_jpeg-6b_$(target) build/$(platform)/builtin.o build/$(platform)/org/ibex/plat/$(platform).cc.o
+       @echo -e "\n\033[1mpruning              .jar -> .jar\033[0m"
+ifneq ($(platform),Darwin)
+       cp upstream/install/share/java/libgcj-3.3.jar build/$(platform)/ibex.jar
+       cd build/class; jar uf ../$(platform)/ibex.jar $(java_classes:build/class/%.class=%*.class)
+       ($(nm) $(nat_libjava_files) build/$(platform)/org/ibex/plat/$(platform).cc.o; echo org.ibex.plat.$(platform).main) |\
+               grep _ZN | c++filt --format java | grep " U " | sed 's_ * U __' | sed 's_(.*__' \
+               | java -cp $(bcel_jar):build/class org.ibex.util.NanoGoat build/$(platform)/ibex.jar | tee nanogoat.log
+       mkdir tmp; cd tmp; fastjar xvf ../build/$(platform)/ibex.jar.pruned; rm gnu/gcj/runtime/FirstThread*; cp ../build/class/org/ibex/plat/GCJ* org/ibex/plat/; cp -r ../build/class/org/ibex/nestedvm/* org/ibex/nestedvm/; mkdir -p $(shell pwd)/build/$(platform)/java/lang; mv java/lang/Class.class $(shell pwd)/build/$(platform)/java/lang; fastjar cvf ../build/$(platform)/ibex.jar.pruned .; cd ..; rm -rf tmp
+       mv build/$(platform)/ibex.jar.pruned $@
+endif
+ifeq ($(platform),Darwin)
+       cd build/class; jar cf ../$(platform)/ibex.pruned.jar \
+                                       org/ibex/plat/Platform*.class \
+                                       $(filter-out org/ibex/util/NanoGoat%,$(java_classes:build/class/%.class=%*.class))
+endif
+
+ifeq ($(platform),Win32)
+filedes := $(shell pwd)/upstream/gcc-3.3/src/libjava/java/io/natFileWin32.cc
+filedes += $(shell pwd)/upstream/gcc-3.3/src/libjava/java/io/natFileDescriptorWin32.cc
+else
+filedes := $(shell pwd)/upstream/gcc-3.3/src/libjava/java/io/natFilePosix.cc
+filedes += $(shell pwd)/upstream/gcc-3.3/src/libjava/java/io/natFileDescriptorPosix.cc
+endif
+
+final_compile := --main=org.ibex.plat.$(platform)
+final_compile += -Dfile.encoding=UTF8                                                     
+final_compile += -DPREFIX=\"\"                                                            
+final_compile += -Lupstream/install/$(target)/lib -Lupstream/install/lib                  
+final_compile += -g -save-temps -w -v
+final_compile += -Iupstream/jpeg-6b/build-$(target)/                                      
+final_compile += -Iupstream/jpeg-6b/src                                                   
+final_compile += -Ibuild/h                                                                
+final_compile += -Iupstream/gcc-3.3/src/gcc 
+final_compile += -Iupstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/    
+final_compile += -Iupstream/gcc-3.3/build-$(target)/$(target)/boehm-gc/include    
+final_compile += -Iupstream/gcc-3.3/src/boehm-gc                                           
+final_compile += -Iupstream/gcc-3.3/src/boehm-gc/include                                       
+final_compile += -Iupstream/gcc-3.3/src/libjava                                           
+final_compile += -Iupstream/gcc-3.3/src/libjava/include                                       
+final_compile += -Iupstream/gcc-3.3/build-$(target)/$(target)/libjava/    
+final_compile += -Iupstream/gcc-3.3/build-$(target)/$(target)/libjava/include    
+final_compile += -Ufile 
+final_compile += src/org/ibex/plat/$(platform).cc                                         
+final_compile += upstream/jpeg-6b/build-$(target)/libjpeg.a                               
+final_compile += build/$(platform)/builtin.o                                              
+final_compile += build/$(platform)/ibex.pruned.jar                                        
+ifneq ($(platform),Darwin)
+final_compile += $(libjava_dir)/../boehm-gc/.libs/libgcjgc.a                              
+final_compile += -fno-store-check                                                         
+final_compile += -finhibit-reflection
+final_compile += $(nat_libjava_files_:%.o=$(shell pwd)/upstream/gcc-3.3/src/libjava/%.c*) 
+final_compile += $(filedes)                                                               
+final_compile += build/$(platform)/Class.o                                                
+final_compile += $(libjava_dir)/gnu/gcj/runtime/FirstThread.o                             
+final_compile += -Wl,-O2,--relax,--gc-sections,--noinhibit-exec,--no-whole-archive        
+final_compile += -lz
+else
+final_compile += -Wl,-dylib_file,/usr/lib/libSystem.B.dylib:$(darwin_libdir)/libSystem.B.dylib
+final_compile += -Wl,-dylib_file,/usr/lib/system/libmathCommon.A.dylib:$(darwin_libdir)/libmathCommon.A.dylib
+final_compile += -Wl,-dylib_file,$(darwin_ogl_libdir)/libGL.dylib:$(darwin_libdir)/libGL.dylib
+final_compile += -Wl,-dylib_file,$(darwin_ogl_libdir):$(darwin_libdir)/libGLU.dylib
+final_compile += -lSystem.B -lmathCommon.A -lGL -lGLU
+#final_compile += $(libjava_dir)/.libs/libgcj.a
+#final_compile += $(libjava_dir)/../boehm-gc/.libs/libgcjgc.a
+#final_compile += -lgcc
+#final_compile += -lm
+#final_compile += -lpthread
+#final_compile += -lgcc
+#final_compile += -lcrt1.o
+#final_compile += -lcrt2.o
+#final_compile += -lSystem
+endif
+
+
+ifneq ($(target_bin_extension),jar)
+build/$(platform)/$(target_bin): build/$(platform)/ibex.pruned.jar src/org/ibex/plat/*.cc build/$(platform)/builtin.o $(java_headers)
+
+       @echo -e "\n\033[1mlinking              .jar -> $(target_bin).phat\033[0m"
+ifneq ($(platform),Darwin)
+# -Os
+       cd build/$(platform); $(shell pwd)/upstream/install/bin/$(target)-gcj        \
+               -fCLASSPATH=$(shell pwd)/upstream/install/share/java/libgcj-3.3.jar  \
+               -finhibit-reflection                                                 \
+               -fno-store-check                                                     \
+               -c java/lang/Class.class
+       cd upstream/gcc-3.3/src/libjava/java/lang;\
+               ln -sf ../../../../build-$(target)/$(target)/libjava/java/lang/natConcreteProcess.cc
+endif
+# we need -fno-store-check since we can't dynamically resolve references to array classes
+       PATH=upstream/install/bin:$$PATH upstream/install/bin/$(target)-gcj $(final_compile) -o $@.phat
+
+ifneq ($(platform),Darwin)
+       @echo; ls -l $@.phat
+
+       @echo -e "\n\033[1mstripping              $(target_bin).phat -> $(target_bin)\033[0m"
+       strip $@.phat -o $@
+       @echo; ls -l $@.phat
+
+       @echo -e "\n\033[1mcompressing              $(target_bin) -> $(target_bin)\033[0m"
+       upx-ucl-beta $@
+       @echo; ls -l $@.phat
+else
+       mv $@.phat $@
+endif
+endif
 
 ### Builtin Resources ##############################################################################
 
-builtin_src := $(shell find src/org/ibex/builtin -name '*.*' \! -name '*.xcf')
+builtin_src := $(shell find src/org/ibex/core/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
@@ -315,10 +355,10 @@ build/res/fonts/vera: .download_vera-1.10
        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/%=%)
+       cd build/res; $(jar) cf builtin.jar org/ibex/core/builtin/scar.png fonts
 build/$(platform)/builtin.o: build/res/builtin.jar
        @echo -e "\n\033[1mwrapping            .jar -> .o: resources.o\033[0m"
+       @mkdir -p $(@D)
        @(echo "unsigned int builtin_length = ";                                \
                (wc -c build/res/builtin.jar | sed "s_build.*__");              \
                echo \;;                                                        \
@@ -327,8 +367,7 @@ build/$(platform)/builtin.o: 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
+build/mips/%.c.o: src/%.c .download_libmspack-20030726 .install_org.ibex.nestedvm
        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)
@@ -338,7 +377,7 @@ build/mips/%.c.o: src/%.c .download_libmspack-20030726
                -Iupstream/libmspack-20030726/src/mspack \
                -c -o $@ $<
 
-build/mips/mipsapps.mips: build/mips/org/ibex/translators/Freetype.c.o build/mips/org/ibex/translators/MSPack.c.o build/mips/org/ibex/translators/main.c.o 
+build/mips/mipsapps.mips: build/mips/org/ibex/graphics/Freetype.c.o build/mips/org/ibex/util/MSPack.c.o
        make .install_freetype-2.1.4_mips-unknown-elf target=mips-unknown-elf
        make .install_libmspack-20030726_mips-unknown-elf target=mips-unknown-elf
        @echo -e "\n\033[1mlinking               .o -> .mips:  $@\033[0m"
@@ -346,8 +385,8 @@ build/mips/mipsapps.mips: build/mips/org/ibex/translators/Freetype.c.o build/mip
        upstream/install/bin/mips-unknown-elf-gcc \
                --static \
                -march=mips1 \
-               -T upstream/mips/org/xwt/mips/linker.ld \
-               -L upstream/mips/build/org/xwt/mips/ \
+               -T upstream/org.ibex.nestedvm/src/org/ibex/nestedvm/linker.ld \
+               -L upstream/org.ibex.nestedvm/build/org/ibex/nestedvm/ \
                -L upstream/freetype-2.1.4/src/objs \
                -L upstream/libmspack-20030726/build-mips-unknown-elf/ \
                -o $@ \
@@ -360,8 +399,8 @@ build/mips/mipsapps.mips: build/mips/org/ibex/translators/Freetype.c.o build/mip
 ### Maintainer ######################################################################################
 
 current_build         := $(shell cat next.build)
-strip_$(platform) := upstream/install/$(target)/bin/strip build/$(platform)/$(target_bin) -o 
-strip_JVM       := cp build/$(platform)/$(target_bin)
+strip_$(platform)     := upstream/install/$(target)/bin/strip build/$(platform)/$(target_bin) -o 
+strip_Java2             := cp build/$(platform)/$(target_bin)
 install-dist:;     $(strip_$(platform)) /var/www/org/xwt/dist/master/ibex-$(current_build).$(target_bin_extension).unsigned
 dist: compile
        (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
@@ -372,11 +411,11 @@ dist: compile
        make install-dist platform=Linux
        make install-dist platform=Solaris
        make install-dist platform=Darwin
-       make install-dist platform=JVM
+       make install-dist platform=Java2
        echo -e "\n\n\n*** DONE ******************************************"
 
 propose-patch:
-       @darcs push --and-apply --edit-description -o .darcspatch -T patches@xwt.org http://darcs.ibex.org/ibex/
+       @darcs send --edit-description -o .darcspatch -T patches@xwt.org http://core.ibex.org/
        @(echo "To: patches@xwt.org";\
         SUB=`grep -A10000 New.patches .darcspatch | grep '^\\[' | cut -b 2- | tr \\\n , | sed s_,_,\ _g | sed "s_, *\\$$__"`;\
         echo "Subject: $$SUB";\
@@ -384,3 +423,15 @@ propose-patch:
         cat .darcspatch) | /usr/sbin/sendmail -bm -f $(USER)@xwt.org patches@xwt.org;
        @rm .darcspatch 
 
+commit: propose-patch
+       darcs push xwt@xwt.org:/var/www/org/ibex/core/
+
+upstream/org.ibex.doc/src/org/ibex/doc/Doc.java: .download_org.ibex.doc
+build/class/org/ibex/doc/Doc.class: upstream/org.ibex.doc/src/org/ibex/doc/Doc.java
+       $(javac) upstream/org.ibex.doc/src/org/ibex/doc/Doc.java
+doc/%.pdf: build/class/org/ibex/util/XML.class build/class/org/ibex/doc/Doc.class
+       cd doc/$*; java -cp ../../build/class org.ibex.doc.Doc < $*.xml > $*.tex
+       cd doc/$*; pdflatex $*.tex
+       mv doc/$*/$*.pdf doc/$*.pdf
+       test `uname` == Darwin && open doc/$*.pdf
+reference: ; rm -f doc/reference.pdf; make doc/reference.pdf
\ No newline at end of file