What is the difference between the two options below? Wouldn’t $< expand to only one requisite (by definition “the first one”) in both cases?
Option 1:
libcounter.a(lexer.o): lexer.o
$(AR) $(ARFLAGS) $@ $<
libcounter.a(counter.o): counter.o
$(AR) $(ARFLAGS) $@ $<
Option 2:
libcounter.a: lexer.o
$(AR) $(ARFLAGS) $@ $<
libcounter.a: counter.o
$(AR) $(ARFLAGS) $@ $<
ARFLAGS holds rv in both cases.
As a reference, the examples are taken from the book Managing Projects with GNU Make.
In the first option,
makeknows enough to look insidelibcounter.aat thelexer.oobject to see if it needs to update the library with the new object. In the second option, the timestamp on the library itself is compared with the object, which may lead to missed updates of the library – e.g. imagine 1)lexer.ogets built, then 2)counter.ogets built, then 3)libcounter.agets newlexer.oadded; now at this point, the timestamp onlibcounter.ais newer thancounter.o, somakewrongly concludes it does not need to add the newcounter.oto the library.