Refactors much of the build system. Finishes the compile-time templating logic.