-gpc := $(usr)/bin/mips-unknown-elf-gpc
-gpc_flags := --big-endian -w -lgpc -lc $(usr)/mips-unknown-elf/lib/support*.o
-gpc_flags += -Wl,-T,$(usr)/mips-unknown-elf/lib/linker.ld
-
-# FIXME ugly path hacks evil bad
-nestedvm := java -cp $(usr)/../build/bcel/bcel-5.1.jar:$(usr)/../../nestedvm.jar org.ibex.nestedvm.Compiler -outformat class
-
-tasks/build_tex: tasks/full_toolchain tasks/extract_tex
- cd build/tex; $(gpc) tangle.p $(gpc_flags) -o tangle.mips
- cd build/tex; $(nestedvm) -o unixruntime -outfile Tangle.class Tangle tangle.mips
- cd build/tex; java -cp .:$(usr)/../../nestedvm.jar Tangle \
- --gpc-rts=-nPascalfile:tex.unpatched.p \
- --gpc-rts=-npool:tex.pool \
- --gpc-rts=-nwebfile:tex.web \
- --gpc-rts=-nchangefile:tex.ch
- cd build/tex; cat tex.unpatched.p | sed s_STANDARDTEXT_TEXT_ | sed 's_\\^DIV_\\^ DIV_g' > tex.p
- cd build/tex; PATH=$$PATH:../../install/bin; $(gpc) tex.p $(gpc_flags) -o tex.mips
- cd build/tex; $(nestedvm) -o unixruntime -outfile TeX.class TeX tex.mips
- #ln -s tex.pool 'TeXformats:TEX.POOL '
- #ln -s trip.tfm 'TeXfonts:trip.tfm '
- #ln -s trip.tex 'trip.tex '
+tasks/build_extraheaders: $(upstream)/misc/extraheaders.sh tasks/build_newlib
+ # Add extra nestedvm specific headers to include
+ cd $(cross_root)/include && sh $<
+ touch $@
+
+tasks/build_libc: tasks/build_newlib tasks/build_extraheaders tasks/build_regex tasks/build_openbsdglob misc/extraheaders.sh $(patsubst %,$(root)/build/org/ibex/nestedvm/%.o, crt0 support support_aux)
+ # HACK: Get the top level makefile to build the support stuff
+ $(MAKE) -s -C $(root) $(patsubst %,build/org/ibex/nestedvm/%.o, crt0 support support_aux)
+
+ # Add our support stuff to libc
+ mips-unknown-elf-ar sr $(libc_a) $(patsubst %,$(root)/build/org/ibex/nestedvm/%.o, support support_aux)
+ rm -f $(cross_root)/lib/crt0.o
+ cp $(root)/build/org/ibex/nestedvm/crt0.o $(cross_root)/lib/crt0.o