Build process improvements

These changes

* Introduce a configure script
* Remove all the hard-coded hacks in Makefile