-
-
-#############################################################################
-# Overview:
-#
-# The Makefile has been divided into phases; each phase depends on the
-# previous one. Subphases of the same phase (ie 1a, 1b) are not
-# interdependent. You can think of the build process as proceeding
-# through the phases in order, but processing subphases within a given
-# phase in any order.
-#
-
-
-# PHASE 1a: upstream code
-jpeg_c_sources := jdapimin.c jdapistd.c jcomapi.c jcparam.c jdmaster.c jdinput.c jdmainct.c jdcoefct.c jdpostct.c jdmarker.c
-jpeg_c_sources += jdhuff.c jdphuff.c jddctmgr.c jidctint.c jidctfst.c jidctflt.c jidctred.c jdsample.c jdcolor.c jdmerge.c
-jpeg_c_sources += jquant1.c jquant2.c jerror.c jutils.c jmemnobs.c jmemmgr.c
-jpeg_sources := $(jpeg_c_sources:%.c=upstream/jpeg-6b/src/%.c)
-$(jpeg_sources):
- make -sC upstream jpeg-6b/src
-
-freetype_sources := $(patsubst %,upstream/freetype-2.1.4/src/src/base/%,ftsystem.c ftmm.c ftbbox.c ftinit.c ftdebug.c ftbase.c ftglyph.c)
-freetype_sources += $(patsubst %,upstream/freetype-2.1.4/src/src/%,smooth/smooth.c autohint/autohint.c sfnt/sfnt.c truetype/truetype.c)
-$(freetype_sources):
- make -sC upstream freetype-2.1.4/.installed
-
-upstream/.jikes:
- make -sC upstream .jikes
-
-$(gcc_path)/bin/$(target)-gcj:
- make -sC upstream gcc-3.3-$(target)
-
-
-# PHASE 1b: human-written inputs
-handwritten_java_sources := $(shell find src -name \*.java)
-handwritten_java_pp_sources := $(shell find src -name \*.java.pp)
-handwritten_mips_sources := $(shell find src -name \*.mips.c)
-handwritten_cc_sources := src/org/xwt/plat/$(platform).cc
-handwritten_c_sources := $(jpeg_sources)
-handwritten_xwar_sources := $(shell ls src/org/xwt/builtin/*.png src/org/xwt/builtin/*.xwt src/org/xwt/builtin/*.xwf)
-
-
-# PHASE 2: ready-to-compile java files (either symlinked to phase 1a sources or else generated from them)
-java_sources := $(handwritten_java_sources:src/%.java=build/java/%.java)
-java_sources += $(handwritten_java_pp_sources:src/%.java.pp=build/java/%.java)
-java_sources += $(handwritten_mips_sources:src/%.mips.c=build/java/%.java)
-java_sources += build/java/org/xwt/Builtin.java
-#java_sources += build/java/org/xwt/imp/Freetype.java
-$(handwritten_java_sources:src/%.java=build/java/%.java): build/java/%.java: src/%.java
- @echo "symlinking: $@"
- @mkdir -p `dirname $@`; \
- cd `dirname $@`; \
- A=`echo $@ | sed 's_[^/]*/_../_g'`; \
- B=`dirname $$A`; \
- C=$$B/$<; \
- ln -s $$C
-
-
-# PHASE 3: class files
-class_files := $(java_sources:build/java/%.java=build/class/%.class)
-$(class_files): build/class/%.class: build/java/%.java upstream/.jikes
- @echo "compiling .java -> .class: $<"
- @mkdir -p build/class
- @upstream/.jikes $<
-
+include Makefile.upstream
+
+# figure out what stuff in org.xwt.plat.* this platform requires (its superclasses)
+java_sources := $(patsubst src/%.java, build/java/%.java, $(shell find src -name '*.java' \! -path 'src/org/xwt/util/Preprocessor.java'))
+all_java_sources := $(java_sources)
+
+nonplat_java_sources := $(filter-out build/java/org/xwt/plat/%, $(java_sources)) build/java/org/xwt/translators/Freetype.java build/java/org/xwt/translators/MSPack.java build/java/org/xwt/translators/MIPSApps.java
+plat_java_sources := $(filter build/java/org/xwt/plat/%, $(java_sources))
+
+build/java/org/xwt/translators/MIPSApps.java: build/mips/mipsapps.mips
+ make build/class/org/xwt/mips/Compiler.class
+ mkdir -p build/java/org/xwt/translators
+ @echo -e "\n\033[1mtranslating .mips -> .java: $<\033[0m"
+ (echo -e 'package org.xwt.translators;\nimport org.xwt.mips.*;\n'; \
+ java -Xint -cp build/class org.xwt.mips.Compiler MIPSApps build/mips/mipsapps.mips)\
+ | sed 's,//.*$$,,;'|tr -d '\n' > $@
+
+build/java/org/xwt/%.java: src/org/xwt/%.java
+ make build/class/org/xwt/util/Preprocessor.class
+ @echo -e "\n\033[1mpreprocessing .java -> .java: $<\033[0m"
+ mkdir -p `dirname $@`; java -cp build/class org.xwt.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/c/jpeg/%.c: upstream/jpeg-6b/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/xwt/translators/MIPSApps.class: build/java/org/xwt/translators/MIPSApps.java .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/xwt/translators
+ ./.jikes -g:none $<
+
+build/class/org/xwt/util/Preprocessor.class: src/org/xwt/util/Preprocessor.java .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/xwt/util/
+ ./.jikes $<
+
+build/class/org/xwt/mips/Compiler.class: src/org/xwt/mips/*.java
+ make .jikes
+ @echo -e "\n\033[1mcompiling .java -> .class: $<\033[0m"
+ mkdir -p build/class/org/xwt/mips/
+ ./.jikes $<
+
+# this forces a clean build every time because jikes is so damn buggy
+preprocess: $(java_sources)