make sure finalpath is always set for sources, add gen_builddir function

built on top of #769, so for @JensTimmerman to review