Fixes BUILDINSOURCE detection

Fixes #713

Amends #736; paths are not regexps.

Re-applies #791 wrongly merged and reverted by #797; please test BEFORE merging.

(low priority)