Refactor setting directory patterns into j2 templates.

Modulo small remaining bugs this should build GCC on Debian.