The commands in a makefile recipe are executed by the shell, not by Make, and each line is executed in a new shell subprocess, so variables defined on previous lines are no longer defined after that line (unless you use .ONESHELL
as shown in this answer).
So you cannot set Make variables there, and then use them like $(arg1)
later. You need to set shell variables (with no space around the =
) and refer to them using shell variable syntax, i.e. $arg1
or ${arg1}
, but you need to escape the $
signs so that Make doesn't try to interpret them itself, i.e. use $$arg1
or $${arg1}
.
With your attempt you are trying to refer to Make variables called $(arg1)
and $(arg2)
but those were never defined in the Makefile, so they expand to nothing, and no arguments are passed.
Furthermore, each line of the make recipe is executed in a separate shell process, so the way you wrote it, make
creates a new shell subprocess, sets arg1="somevalue"
and then that shell process exits (so the variable definition is lost). Then it starts a new shell, sets another variable, then exits that shell etc.
Setting the variables and using them needs to happen in a single shell process, which can be done using .ONESHELL
if you are using GNU Make version 3.82 or later. For other versions of Make, another way to ensure that the variable definitions and the uses are all in the same shell process is to put them all on one line:
run-exe:
arg1="somevalue" ; arg2="somevalue" ; arg3="somevalue" ; arg4="somevalue" ; arg5="somevalue" ; $(ExeFolderPath)/Task $$arg1 $$arg2 $$arg3 $$arg4 $$arg5
But this is hard to read, so you can keep them on separate lines but use backslashes so that make
still treats them as a single line and runs them in the same shell process:
run-exe:
arg1="somevalue" ; \
arg2="somevalue" ; \
arg3="somevalue" ; \
arg4="somevalue" ; \
arg5="somevalue" ; \
$(ExeFolderPath)/Task $$arg1 $$arg2 $$arg3 $$arg4 $$arg5