Refactor makefile so that it can be used piecewise.

This is motivated by my efforts to build a debian package.