added background color option to Font.drawGlyph()
[org.ibex.core.git] / Makefile
index e8f2eb2..9ca6dea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,12 +18,12 @@ target := $(target_$(platform))
 
 all:         Java2 Linux Win32 Darwin Solaris
 
-clean:      ; rm -rf build; rm .preprocessor
+clean:      ; rm -rf build
 dist-clean:
        rm -rf .configure* .install* build .compile .build*
-       find upstream -name config.cache -exec rm {} \;
-       test -e upstream/nestedvm && make -C upstream/nestedvm clean
-       rm .install_nestedvm
+       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
@@ -33,23 +33,16 @@ 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
 
-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)"
+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
@@ -57,23 +50,35 @@ target_bin_extension_Java2       := jar
 target_bin_extension             := $(target_bin_extension_$(platform))
 target_bin                       := ibex.$(target_bin_extension)
 
-javac   := javac -classpath upstream/bcel-5.1/src/bcel-5.1.jar:build/class -d build/class/ -sourcepath build/java/:upstream/mips:upstream/mips/build:src
+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) -g
 gcc_flags          += -Iupstream/install/lib/gcc-lib/$(target)/3.3/include -Iupstream/install/$(target)/include
-gcc_flags          += -ffunction-sections -fdata-sections -fno-omit-frame-pointer
-gcj                := upstream/install/bin/$(target)-gcj $(gcc_flags) -fCLASSPATH=build/java
-gcj                += -fassume-compiled -fmerge-all-constants -finhibit-reflection
-gcj                += -foptimize-static-class-initialization -feliminate-dwarf2-dups -w
+#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 build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
+       @make build/$(platform)/$(target_bin) link_flags="$(link_flags)" platform=$(platform)
 
 include Makefile.upstream
 
@@ -84,93 +89,118 @@ include Makefile.upstream
 #      @grep -s extends src/$(subst .,/,$*).java | sed s_.\*extends\ __ | head -n 1 | sed s_\ .\*__ |\
 #              xargs --replace make -s superclass_org.ibex.plat.{}
 
-plat_classes_AWT     := org.ibex.plat.AWT
-plat_classes_Java2   := org.ibex.plat.Java2 org.ibex.plat.JVM $(plat_classes_AWT)
-plat_classes_GCJ     := org.ibex.plat.GCJ
-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_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 Preprocessor | grep -v /plat/)
+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))
 
-# FIXME ugly
-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
-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/UsermodeConstants.java
+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 ##############################################################################
 
-build/java/gnu/regexp: .download_gnu.regexp-1.1.4
-       mkdir -p $(@D); cd $(@D); ln -sf ../../../upstream/gnu.regexp-1.1.4/src/src/gnu/regexp
-build/java/org/xwt/mips: .download_nestedvm
-       mkdir -p $(@D); cd $(@D); ln -sf ../../../../upstream/nestedvm/src/org/xwt/mips
-build/java/org/ibex/crypto: .download_org.ibex.crypto
-       mkdir -p $(@D); cd $(@D); ln -sf ../../../../upstream/org.ibex.crypto/src/org/ibex/crypto
-       mkdir -p build/java/org/ibex/net;
-       cd build/java/org/ibex/net; ln -sf ../../../../../upstream/org.ibex.crypto/src/org/ibex/net/SSL.java
-       cd build/java/org/ibex/net; ln -sf ../../../../../upstream/org.ibex.crypto/src/org/ibex/net/ssl
-
-ifeq ($(platform),Java2)
-.preprocessor: build/java/gnu/regexp src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java build/java/org/xwt/mips build/java/org/ibex/crypto
-
-       @mkdir -p build/class/org/ibex/util build/class/gnu/regexp
-       $(javac) src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java build/java/gnu/regexp/*.java  -d build/class
-       @touch $@
-else
-.preprocessor: build/java/gnu/regexp src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java build/java/org/xwt/mips build/java/org/ibex/crypto
-       @mkdir -p build/class/org/ibex/util build/class/gnu/regexp
-       $(gcj) -Isrc -C src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java build/java/gnu/regexp/*.java  -d build/class
-       @touch $@
-endif
+$(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'`/$< $@
-build/java/org/ibex/%.java: src/org/ibex/%.java .preprocessor
-       @echo -e "\n\033[1mpreprocessing      .java -> .java:  $<\033[0m"
-       mkdir -p `dirname $@`; java -cp build/class:build/java org.ibex.util.Preprocessor < $^ > $@
-build/java/%.java: src/%.java ; @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)
 
 
 ### Java Class Files ##############################################################################
 
-build/class/org/ibex/util/MIPSApps.class: build/mips/mipsapps.mips .install_nestedvm 
-       mkdir -p build/java/org/ibex/util
-       @echo -e "\n\033[1mtranslating        .mips -> .class:  $<\033[0m"
-       java -cp upstream/nestedvm/build:upstream/nestedvm/upstream/build/bcel-5.1/bcel-5.1.jar \
-               org.xwt.mips.Compiler org.ibex.util.MIPSApps $< -outfile $@
-#-o onepage,pagesize=8m
+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: .download_nestedvm .download_bcel-5.1 $(java_sources) $(java_classes); touch $@
-
-ifeq ($(platform),Java2)
-build/class/%.class: build/java/%.java .preprocessor
-       @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
-       mkdir -p build/class
-       @$(javac) $< -d build/class
-else
-build/class/%.class: build/java/%.java
-       @echo -e "\n\033[1mcompiling          .java -> .class: $<\033[0m"
-       mkdir -p $(@D)
-       $(gcj) -I$(bcel_jar) -C -O0 $< -d build/class
-endif
+.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
+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.Main\n" > build/Java2/.manifest
+       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 ../Java2/ibex.jar ../Java2/.manifest `find . -name \*.class -or -name \*.jar`
 
@@ -178,7 +208,6 @@ build/Java2/ibex.jar: .compile build/res/builtin.jar build/class/org/ibex/util/M
 ### 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 $@`
@@ -192,7 +221,6 @@ build/h/%.h: build/class/%.class .compile
 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) 
 
-libjava_dir := $(shell pwd)/upstream/gcc-3.3/build-$(target)/$(target)/libjava
 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
@@ -212,13 +240,20 @@ build/$(platform)/org/ibex/plat/$(platform).cc.o: src/org/ibex/plat/$(platform).
 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) |\
+       ($(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/xwt/mips/* org/xwt/mips/; 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
+       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
@@ -228,10 +263,61 @@ 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  \
@@ -240,40 +326,11 @@ build/$(platform)/$(target_bin): build/$(platform)/ibex.pruned.jar src/org/ibex/
                -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              \
-               -Wl,-O2,--relax,--gc-sections,--noinhibit-exec,--no-whole-archive        \
-               --main=org.ibex.plat.$(platform)                                         \
-               -Dfile.encoding=UTF8                                                     \
-               -DPREFIX=\"\"                                                            \
-               -Lupstream/install/$(target)/lib -Lupstream/install/lib                  \
-               -finhibit-reflection                                                     \
-               -fno-store-check                                                         \
-               -w -g                                                                    \
-               -Iupstream/jpeg-6b/build-$(target)/                                      \
-               -Iupstream/jpeg-6b/src                                                   \
-               -Ibuild/h                                                                \
-               -Iupstream/gcc-3.3/src/gcc \
-               -Iupstream/gcc-3.3/build-i686-pc-linux-gnu/i686-pc-linux-gnu/boehm-gc/    \
-               -Iupstream/gcc-3.3/build-i686-pc-linux-gnu/i686-pc-linux-gnu/boehm-gc/include    \
-               -Iupstream/gcc-3.3/src/boehm-gc                                           \
-               -Iupstream/gcc-3.3/src/boehm-gc/include                                       \
-               -Iupstream/gcc-3.3/build-i686-pc-linux-gnu/i686-pc-linux-gnu/libjava/    \
-               -Iupstream/gcc-3.3/build-i686-pc-linux-gnu/i686-pc-linux-gnu/libjava/include    \
-               -Iupstream/gcc-3.3/src/libjava                                           \
-               -Iupstream/gcc-3.3/src/libjava/include                                       \
-               -Ufile \
-               build/$(platform)/ibex.pruned.jar                                        \
-               src/org/ibex/plat/$(platform).cc                                         \
-               $(nat_libjava_files_:%.o=$(shell pwd)/upstream/gcc-3.3/src/libjava/%.c*) \
-               $(filedes) \
-               build/$(platform)/builtin.o                                              \
-               upstream/jpeg-6b/build-$(target)/libjpeg.a                               \
-               $(link_flags)                                                            \
-               $(libjava_dir)/../boehm-gc/.libs/libgcjgc.a                              \
-               build/$(platform)/Class.o                                                \
-               $(libjava_dir)/gnu/gcj/runtime/FirstThread.o \
-               -lz -o $@.phat
+       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"
@@ -283,6 +340,9 @@ build/$(platform)/$(target_bin): build/$(platform)/ibex.pruned.jar src/org/ibex/
        @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 ##############################################################################
@@ -307,7 +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 .install_nestedvm
+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)
@@ -325,8 +385,8 @@ build/mips/mipsapps.mips: build/mips/org/ibex/graphics/Freetype.c.o build/mips/o
        upstream/install/bin/mips-unknown-elf-gcc \
                --static \
                -march=mips1 \
-               -T upstream/nestedvm/src/org/xwt/mips/linker.ld \
-               -L upstream/nestedvm/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 $@ \
@@ -355,7 +415,7 @@ dist: compile
        echo -e "\n\n\n*** DONE ******************************************"
 
 propose-patch:
-       @darcs push --and-apply --edit-description -o .darcspatch -T patches@xwt.org http://core.ibex.org/
+       @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";\
@@ -364,11 +424,14 @@ propose-patch:
        @rm .darcspatch 
 
 commit: propose-patch
-       darcs push --and-apply xwt@xwt.org:/var/www/org/ibex/core/
-
-doc/%.pdf: build/class/org/ibex/util/XML.class build/class/org/ibex/util/Doc.class doc/%.xml
-       cd $(@D); java -cp ../../build/class org.ibex.util.Doc slides < `basename $*`.xml > `basename $*`.tex
-       cd $(@D); pdflatex `basename $*`.tex
-       open doc/$*.pdf
-
-
+       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