I have a makefile, with two variables like this
OS = foo.o bar.o baz.o
WS = -DWITH_FOO -DWITH_BAR -DWITH_BAZ
And so on. Instead of writing this out manually I want to generate these two when the makefile is executed based on an environment variable called WITH containing something like foo bar baz. If this environment variable is not set, or is empty, the makefile should use some hard-coded fallback instead.
How would I do that? I’m not too good at makefiles, all I can think is some kind of ‘foreach` call but the specifics elude me.
Well, I would write something like this:
This is the most straightforward solution I see, however, it is not 100% good because
WSwould be-DWITH_foo ...instead of-DWITH_FOO ....If such behavior does not fit your needs, you can use
trcommand to convertWSto uppercase:Or, as more portable option, use
trfunction from GMSL: