Fixes BUILDINSOURCE detection

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