in my opinion we should have something external that generates this part of the makefile for us, maybe in a "apps.mk" file that we'd include here.

An external shell script would do the trick; I'm even sure we can try to have a make target that would do that and then possibly restart the make process if the file changed. Everything would be better than using so much unmaintainable makefile magic.