Improve out-of-tree builds

Several make rules don't work when building out-of-tree. There are also some files that aren't cleaned up on make clean or make distclean. Lastly, some file generation blobs don't work properly by leaving temporary files behind. These are just some of the things i have ran into so far and i am currently patching these issues.

Also creating this ticket to discuss certain parts of the build configuration that are unfamiliar and for which the reasons of implementation can't be traced back.