Detect missing output directories and rebuild dependencies as necessary, fixes #165