The best solution I have found, disregarding of language, is to use the same language to write a program that generates the code you need.
Then you can compile, and debug them separately using the same workflow, and each program can be clear and simple to read. Its not sexy or clever, but it works and anyone can understand what is going on. Almost always that turns out to be the most important thing.