Is it possible to configure a file at build time?

This function I wrote years ago can do what you want. You do need to list all variables you want to be able to use as they’re not otherwise available.