The intent is to do it all for you with a suitably-smart include file,
using nothing but GNU make language and portable shell within it (perhaps
with some extensions on the make front).
I've done similar things in the past (replacing horrible proprietary build
systems). It's doable.