myexec myexec_v2: $(prerequisites)
@echo compile $@
observe:
$ make myexec
compile myexec
$ make myexec_v2
compile myexec_v2
if nothing else is needed to compile myexec_v2
then you are done.
see here for more information: https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html
here is a slightly more advanced version
myexec myexec_v2: myexec%: $(prerequisites)
@echo compile $@ $*
this is called a static pattern rule. the myexec%
in the middle is called the target pattern. in this example we only use it to get the so called stem. the stem would be _v2
and the variable $*
expands to the stem.
for more information: https://www.gnu.org/software/make/manual/html_node/Static-Usage.html
observe:
$ make myexec
compile myexec
$ make myexec_v2
compile myexec_v2 _v2
now you can use either $@
or $*
in the recipe to modify the behaviour to compile on or the other.
but if you want to do if branches in the recipe read this first: Basic if else statement in Makefile