Add support for building files into modules

I tried to introduce this with as little modification to the original code as possible. Let me know if I should have taken a different approach to the feature.