Refactoring, restructuring, import.

Well, this messy commit basically sets up a build process. Unfortunately, it's broken at the moment. Work-in-progress.