Implement -generate (fixes #459)