Pre-pended "gen/" to "template/" to have DIR("")+"gen/template" as
default for the templates directory.

Replaced simple MKDIR for the traget directory with a small algorithm
that ensures any missing parent directories are created as well.