Add plumbing for building plugins
Tidy up and document