A make recipe is not makefile syntax, it's a shell script. It's passed to the shell, which is a subprocess and (in UNIX/POSIX) there's no way for a subprocess to modify its parent.
There's a lot wrong here. First, you should never use make
to run make recursively, always use $(MAKE)
.
Second, you have a useless recursion here. debug
depends on $(EXEC)
, so before the debug recipe is run make will build $(EXEC)
. Then in the debug recipe you will recursively invoke make to build $(EXEC)
again, but this will do nothing because $(EXEC)
is already built.
You don't need the recursion, and you can use target-specific variables to do what you want:
debug: CFLAGS += -g -DDEBUG
debug: $(EXEC)
$(EXEC): example.c
$(CC) $(CFLAGS) -o $@ $<