Build system tidyup
Disclosure: I'm working on a meson branch and in the process I found a few quirks that are slightly incompatible with how meson works. That's the main motivation here for the first 5 patches, the rest is just other stuff I've stumbled across.
I ran a diff of the installed directory trees before/after the changes and the installed files are the same, so there shouldn't be any breakage here.