-$(shell pwd)/gcc/bin/$(target)-gcj:
- cd gcc; make
-
-gcj: compile $(gcc_path)/bin/$(target)-gcj .headers link
-
-link: $(gcj_java_objects) $(cc_objects)
- echo "linking .o -> $(target_bin)"
- $(ar) r bin-$(platform)/org/xwt/plat/platform.ar bin-$(platform)/org/xwt/plat/*.o
- $(gcj) --main=org.xwt.Main -o bin-$(platform)/$(target_bin) $^ $(platform_link) bin-$(platform)/org/xwt/plat/platform.ar
-
-.headers: $(jikes_java_objects)
- cd bin; for A in `find * -name \*.class`; do \
- echo -ne "\033[K\\rextracting .class -> .h: $$A\\r"; \
- $(gcjh) --classpath . `echo $$A | sed s_/_._g | sed s/.class$$//`; \
- done
- echo -e "\033[K\\rextracting .class -> .h: done"
- touch .headers
-
-# turn off optimization of Trap.java due to a compiler bug
-bin-$(platform)/org/xwt/Trap.o: gcj_flags := -O0 -g
-
-$(gcj_java_objects): bin-$(platform)/%.o: src/%.java $(jikes_java_objects)
- echo -ne "\033[K\\rcompiling .java -> .o: $<\\r"
+$(shell pwd)/gcc/install/bin/$(target)-gcj: .upstream
+ make -C gcc
+
+gcc/src/.freetype:
+ mkdir -p gcc/src
+ curl http://umn.dl.sourceforge.net/sourceforge/freetype/freetype-2.1.4.tar.gz | tar xvzf - -C gcc/src
+ cd gcc/src; patch -p0 < freetype.patch
+ touch gcc/src/.freetype
+
+freetype.mips: gcc/src/.freetype
+ make -C gcc mips target=mips
+ $(gcc_path)/bin/mips-gcc \
+ --static \
+ -march=r3000 \
+ -o freetype.mips \
+ -I gcc/src/freetype-2.1.4/include \
+ $(freetype_sources) \
+ -Wl,--warn-once \
+ src/org/xwt/imp/Freetype.c \
+ $(gcc_path)/mips/lib/libc.a \
+ -Wl,-T,$(gcc_path)/mips/lib/nullmon.ld
+
+# compile is here to force compilation of the .class files (they get used via -Ibin/) without
+# having the individual .o's depend on the .java's (otherwise every .o gets recompiled when one .java changes)
+gcj: $(gcc_path)/bin/$(target)-gcj compile $(target_bin)
+
+$(target_bin): $(java_objects) $(cc_objects) $(c_objects) bin-$(platform)/org/xwt/builtin.o
+ @echo "linking .o -> $(target_bin)"
+ $(gcj) --main=org.xwt.Main -o bin-$(platform)/$(target_bin) $^ $(platform_link)
+
+bin-$(platform)/org/xwt/builtin.o: bin/org/xwt/builtin.xwar
+ @echo "wrapping .xwar -> .o: bin/org/xwt/builtin.o"
+ @(echo "unsigned int builtin_xwar_length = ";\
+ (wc -c bin/org/xwt/builtin.xwar | sed "s_bin.*__");\
+ echo \;;\
+ echo "unsigned char builtin_xwar[] = {";\
+ hexdump -ve '"0x" 1/1 "%x,\n"' bin/org/xwt/builtin.xwar;\
+ echo "};") > .builtin.c
+ $(gcc) -c .builtin.c -o bin-$(platform)/org/xwt/builtin.o
+
+$(java_headers): bin/%.h: bin/%.class
+ @echo "extracting .class -> .h: $<"
+ cd bin; find `echo $< | sed s/.class$$// | sed s_^bin/__ `*.class |\
+ sed s_/_._g | sed s/.class$$// | sed s/.java$$// |\
+ xargs $(gcjh) --classpath .
+
+$(java_objects): bin-$(platform)/%.java.o: src/%.java
+ @echo "compiling .java -> .o: $<"