let’s say I’ve got:
target.o: target.h target.c
gcc $(CFLAGS) -c target.c
But I’d like to get rid of the redundant ‘target.c’.
I know that $< will give target.h, is there an internal macro that will give target.c or should I just rearrange it:
target.o: target.c target.h
gcc $(CFLAGS) -c $<
However… I seem to recall that $< won’t always return target.c in this case, for example if a change in target.h triggered this rule, then $< would return target.h. So is there any way to do this consistently?
You should just use your second example:
$<always evaluates to the first prerequisite; it doesn’t matter which one caused the recipe to be run. For more info, see http://www.gnu.org/software/make/manual/make.html#Automatic-Variables.If you’re really paranoid, you could always do this (but it’s unnecessary):