-compile: .javac $(java_pp_postproc) bin/org/xwt/builtin.xwar
- echo "compiling .java -> .class:"
- mkdir -p bin
- $(shell cat .javac) -classpath lib/libgcj-minimal.jar $(java_sources) $(java_pp_postproc) -d bin/ 2>&1 | \
- grep -v ^\\[read | sed s_^\\[write\ bin/__ | sed s_.class\\]_.java_ | sed "s_^_compiling .java -> .class: src/_"
-
-bin/org/xwt/util/Preprocessor.class: .javac
- echo "compiling preprocessor"
- mkdir -p bin
- $(shell cat .javac) -classpath lib/libgcj-minimal.jar src/org/xwt/util/Preprocessor.java -d bin/ 2>&1 | \
- grep -v ^\\[read | sed s_^\\[write\ bin/__ | sed s_.class\\]_.java_ | sed "s_^_compiling .java -> .class: src/_"
-
-$(java_pp_postproc): bin/%.java: src/%.java.pp bin/org/xwt/util/Preprocessor.class
- @echo "preprocessing .java.pp -> .java: $<"
- @mkdir -p `dirname $@`
- @java -cp bin org.xwt.util.Preprocessor < $< > $@
-
-# platforms
-all: Win32 Linux Java2 #Solaris
-
-.javac:
- @if \
- type jikes && (jikes --version | grep "Version 1.18"); \
- then \
- echo "public class GetBootClassPath { public static void main(String[] s) { " > GetBootClassPath.java; \
- echo "System.out.println(System.getProperty(\"sun.boot.class.path\")); } }" >> GetBootClassPath.java; \
- javac GetBootClassPath.java; \
- java -cp . GetBootClassPath > .bootclasspath; \
- rm GetBootClassPath.*; \
- echo -n "jikes -nowarn -sourcepath src/ -bootclasspath " > .javac; \
- cat .bootclasspath >> .javac; \
- else \
- echo "WARNING: You do not have jikes; falling back to javac. Compiles will be very slow."; \
- echo javac > .javac; \
- fi
-
-jikes:
- curl ftp://www-126.ibm.com/pub/jikes/1.18/jikes-1.18.tar.bz2 | tar xjvf -
- cd jikes-1.18; ./configure --prefix=`pwd` && make && make install
- ln -sf jikes-1.18/bin/jikes .jikes
-
-bin/org/xwt/builtin.xwar: $(xwar_sources)
- mkdir -p bin/org/xwt
- cd src; $(jar) cf ../bin/org/xwt/builtin.xwar $(xwar_sources:src/%=%)
-
-clean:
- rm -rf bin-* bin
- find . -name \*~ | xargs rm -f
- find . -name \#\*\# | xargs rm -f
-
-update-build:
- cvs tag -F xwt-$(current_build)
- (echo -n 0000; (echo "10k16o16i"; cat next.build | tr a-z A-Z; echo "1+f") | dc) | tail --bytes=5 > next.build-
- mv next.build- next.build
- echo -n "Next build will be "
- cat next.build
- cvs update CHANGES
- echo "" >> CHANGES
- echo `date +%d-%b`" =========== build $(current_build) ================================================" >> CHANGES
- echo committing...
- cvs commit -m 'this comment should not appear in CHANGES' next.build CHANGES
- echo committed.
+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: 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
+
+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
+
+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)"
+
+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_Java2 := jar
+target_bin_extension := $(target_bin_extension_$(platform))
+target_bin := ibex.$(target_bin_extension)
+
+jikes_flags := -nowarn
+gcc_optimizations := -Os
+#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
+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
+
+# 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_AWT := org.ibex.plat.AWT
+plat_classes_Java2 := org.ibex.plat.Java2 $(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_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 += $(plat_java_src_sources)
+java_sources := $(patsubst src/%.java, build/java/%.java, $(java_src_sources))
+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/Compiler.java
+java_sources += build/java/org/xwt/mips/ELF.java
+java_sources += build/java/org/xwt/mips/Interpreter.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/Errno.java
+java_sources += build/java/org/xwt/mips/Syscalls.java
+java_sources += build/java/org/xwt/mips/Unistd.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
+
+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 Source Files ##############################################################################
+
+ifeq ($(platform),Java2)
+.preprocessor: src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java src/gnu/regexp/*.java
+ @make .jikes
+ @mkdir -p build/class/org/ibex/util build/class/gnu/regexp
+ ./.jikes $^ -d build/class
+ @touch $@
+else
+.preprocessor: src/org/ibex/util/Preprocessor.java src/org/ibex/util/Vec.java src/gnu/regexp/*.java
+ @mkdir -p build/class/org/ibex/util build/class/gnu/regexp
+ $(gcj) -Isrc -C $^ -d build/class
+ @touch $@
+endif
+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 org.ibex.util.Preprocessor < $^ > $@
+build/java/%.java: src/%.java ; @echo linking $@; mkdir -p $(@D); ln -fs `echo $(@D)/ | sed 's_[^/]*//*_../_g'`/$< $@
+
+
+### 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
+
+compile: .compile
+.compile: .install_mips2java .download_bcel-5.1 $(java_sources) $(java_classes); touch $@
+
+ifeq ($(platform),Java2)
+build/class/%.class: build/java/%.java .preprocessor .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class
+ @./.jikes $< -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