You can't do that. You have to remember that the recipe is running in a shell that make has invoked. That's a separate process, not in the make process.
There's no way that anything that happens in the shell (a child process) can change any aspect of make (the parent process) such as set a make variable. Once the shell exits, all the information it had is lost. The only thing that make gets back from the shell is the ultimate exit code; that's how make decides whether the command succeeded or failed.
The only way to do this is to write the value to a file and then have make read the file and put the resulting value into a make variable.
ETA:
But if all you want to do is preserve the exit code within the shell (as your edits say), then you don't need a make
variable at all. You need a shell variable, and that's very easy. Also, note that make
always invokes /bin/sh
which is a POSIX shell, and pushd
and popd
are bash shell features, so this makefile is not portable. Luckily, there's no point in doing the pushd
or popd
anyway, because the working directory (in a POSIX system) is a feature of an individual process (the shell in this case) so any directory changes you make inside the shell only impact that shell and are gone when the shell exits.
So, try something like this:
RUNNER = \
RETURN=0; \
for asm in $${TEST_ASSEMBLIES}; do \
echo -e "Running tests on $${asm}..."; \
$(ENV_OPTIONS) $(NUNIT_CONSOLE) -nologo -noshadow $$asm \
|| RETURN=$$?; \
done
test:
@export TEST_ASSEMBLIES="$(TEST_ASSEMBLIES)"; \
$(RUNNER); \
exit $$RETURN
I don't really understand why you're setting the shell variable TEST_ASSEMBLIES
to the value of the make variable $(TEST_ASSEMBLIES)
. It's not necessary, but it will work.