Refactor the Makefile and add a configure script
More build system refactoring.