You can't do this. The documentation for GNU make is very clear: target-specific variables are available ONLY inside the recipe. They are not available in the target or prerequisite lists. In the prerequisite list make will expand $(OBJS)
the value of the global variable OBJS
, or the empty string if that doesn't exist; NOT to the target-specific variable value.
However, I don't understand why you write this:
file.o: OBJS := libs/lib1/lib1.o libs/lib2/lib2.o
when you could just write this:
file.o: libs/lib1/lib1.o libs/lib2/lib2.o
and have it work fine?