I have a project where you can build for multiple platforms, architectures, etc. I need to be able to set various variables based on the target before compiling any source files. But what's happening is the non-platform specific files are getting compiled immediately and then the platform specific ones didn't get compiled at all.
Below calling "make foobar_mac", foo.o gets created but bar.mac.o does not and therefore during the final link bar.mac.o is missing.
OBJS = foo.c bar.$(PLATFORM).c
%.o : %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<
foobar_mac: PLATFORM := mac
foobar_mac: $(OBJS)
foobar_win: PLATFORM := win
foobar_win: $(OBJS)