Fixes (incomplete) for out-of-source builds

There still seems to be an issue with parallel out-of-source builds,
but this at least fixes the issues I saw in serial.