Makefile improvements and fixes

Please take a look at the commit messages as they should explain the rationale behind the changes quite well ;)