Hook the templates to the build system.
Assorted runtime fixes (still not working right in the test program).