In my makefile (rather simplified below) I have a target-specific variable that needs to influence a recursively expanded variable, but it's not doing so - leaving me sitting here scratching my head:
NAME = MyProg
OBJECTS = $(OD)/main.o
RD = Release
OD = Foo
all: OD = $(RD)
all: $(OD) $(OD)/$(NAME).elf
$(OD):
mkdir $(OD)
$(OD)/$(NAME).elf: $(OBJECTS)
$(CC) $(LDFLAGS) -o "$@" $^
$(OD)/%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -Wa,-a="$(OD)/$*.lst" -o "$@" "$<"
The command that actually gets executed is as follows:
gcc -O2 -Wall -Wstrict-prototypes -c -Wa,-a="Release/main.lst" -o "Foo/main.o" "main.c"
$(OD) is correctly evaluated in the ".lst" expression, but incorrectly by $(OBJECTS). It must be that $(OBJECTS) is evaluating $(OD) outside my rule... so is it possible to correct this behavior? Where am I making the mistake?