2

Possible Duplicate:
Target-specific Variables as Prerequisites in a Makefile

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?

Community
  • 1
  • 1
Nate
  • 12,499
  • 5
  • 45
  • 60

1 Answers1

2

The Make manual says this about target-specific variables

"these values are only available within the context of a target's command script (and in other target-specific assignments). " 1

and I guess this is what you are seeing, the target-specific variable is not expanded in targets themselves.

What is it you're trying to accomplish?

Per Knytt
  • 1,931
  • 1
  • 11
  • 14
  • I would like $(OBJECTS) to expand to "Release/main.o" instead of "Foo/main.o"; I had thought that variables were lazily evaluated, so that this is how it would be expanded. – Nate Mar 04 '10 at 16:14
  • I understand that, but what I mean to ask is why Release must be target specific. What is the scenario when it has some other value? Do you have a "debug" target and want to put the debug object files in a Debug directory? – Per Knytt Mar 04 '10 at 16:22
  • yes - as I said, the posted makefile was very much over-simplified. – Nate Mar 04 '10 at 16:37