--- /dev/null
+OCAMLC=ocamlc -I cparser
+OCAMLOPT=ocamlopt -I cparser
+
+CMOS=extracted.cmo clightFromC.cmo clightParser.cmo IntelHex.cmo clightPrinter.cmo rTLabsPrinter.cmo ASMPrinter.cmo printer.cmo error.cmo optionsParsing.cmo options.cmo acc.cmo
+
+CMXS=$(CMOS:.cmo=.cmx)
+
+byte:
+       make -C cparser cparser.cma
+       make -C extracted byte
+       cp extracted/_build/extracted.cm[io] .
+       ${OCAMLC} -c -g *.mli
+       ${OCAMLC} -c -g error.ml
+       ${OCAMLC} -c -g optionsParsing.ml
+       ${OCAMLC} -c -g options.ml
+       ${OCAMLC} -c -g *.ml
+       ${OCAMLC} -custom -g cparser/cparser.cma ${CMOS} -o acc
+
+opt:
+       make -C cparser cparser.cmxa
+       make -C extracted opt
+       cp extracted/_build/extracted.cm[ix] extracted/_build/extracted.o .
+       ${OCAMLOPT} -c -g *.mli
+       ${OCAMLOPT} -c -g error.ml
+       ${OCAMLOPT} -c -g optionsParsing.ml
+       ${OCAMLOPT} -c -g options.ml
+       ${OCAMLOPT} -c -g *.ml
+       ${OCAMLOPT} -g cparser/cparser.cmxa ${CMXS} -o acc.opt
+
+clean:
+       make -C cparser clean
+       make -C extracted clean
+       rm -f *.cmi *.cmo *.cmx acc
 
+++ /dev/null
-#!/bin/sh
-
-# A crappy build script that needs to be replaced by some proper structure.
-
-OCAMLC="ocamlc -I cparser"
-
-make -C cparser
-(cd extracted; ./build)
-cp extracted/_build/extracted.cm[io] .
-$OCAMLC -c -g *.mli
-$OCAMLC -c -g error.ml
-$OCAMLC -c -g optionsParsing.ml
-$OCAMLC -c -g options.ml
-$OCAMLC -c -g *.ml
-$OCAMLC -custom -g extracted.cmo cparser/cparser.cma clightFromC.cmo clightParser.cmo IntelHex.cmo clightPrinter.cmo rTLabsPrinter.cmo ASMPrinter.cmo printer.cmo error.cmo optionsParsing.cmo options.cmo acc.cmo -o acc
 
--- /dev/null
+byte: pre
+       ocamlbuild -Is untrusted -tag debug extracted.cmo
+
+opt: pre
+       ocamlbuild -Is untrusted -tag debug extracted.cmx
+pre:
+       # The untrusted ones replace the extracted ones
+       rm -f set_adt.ml set_adt.mli
+       # Uses a GNU sed extension
+       for i in `ls *.ml untrusted/*.ml`; do basename $$i | sed -e 's/\(.\)\(.*\)\.ml/\U\1\E\2/'; done > extracted.mlpack
+       for i in `ls *.ml untrusted/*.ml`; do echo "<"$${i%%.ml}".cmx>: for-pack(Extracted)"; done > _tags
+
+
+clean:
+       ocamlbuild -clean
 
+++ /dev/null
-#!/bin/sh
-
-# The untrusted ones replace the extracted ones
-rm -f set_adt.ml set_adt.mli
-# Uses a GNU sed extension
-for i in `ls *.ml untrusted/*.ml`; do basename $i | sed -e 's/\(.\)\(.*\)\.ml/\U\1\E\2/'; done > extracted.mlpack
-for i in `ls *.ml untrusted/*.ml`; do echo "<"${i%%.ml}".cmx>: for-pack(Extracted)"; done > _tags
-ocamlbuild -Is untrusted -tag debug extracted.cmo extracted.cmx