Anytime you see a recipe which creates a target file which is not exactly $@
, you know it's wrong and you're going to have this problem.
Here, you tell make you're going to create a target that matches the pattern %.a
. make matches that pattern to libInterface.a
and sets $@
to libInterface.a
and invokes your recipe.
But your recipe doesn't build $@
, it builds $(LIBDIR)/$@
which is a totally different file. So the next time you run make
, it will look for libInterface.a
as the prerequisite to all
, see that it doesn't exist, and re-run the rule you provided... which again will not create the target you told make it would, $@
, but instead create some other file make doesn't know anything about.
You need to use:
LIB_TARGET = $(LIB_DIR)/libInterface.a
....
### Archive into a library file (.a)
$(LIB_DIR)/%.a: $(OBJS)
@echo $(MSG_L)
@echo 'Adding $< to library $@'
$(AR) $(ARFLAGS) $@ $^
@echo $(MSG_L)