Refactor so that analysis is separate from writing dependency file (and more).

The more is that the path manipulation is now more explicit.