Replace the configure templating system with something better.

A large amount of this code can be removed when buildtool is done
as we will not need to worry about the differences between BSD and
GNU Make.