Here is the relevant part of my Makefile.
...
LIBS = gc ft
vpath %.a $(LIBS:%=lib%)
all:
$(MAKE) $(NAME)
$(NAME): $(LIBS:%=lib%.a) $(OBJS) | libs
$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LDFLAGS)
-include $(DEPENDENCIES)
$(OBJS_DIR)/%.o: %.c $(OBJS_DIR)/debug$(DEBUG) | $(OBJS_DIR)
$(CC) $(CFLAGS) $(INCLUDES_DIR:%=-I %) -c $< -o $@
$(OBJS_DIR):
$(MKDIR) $@
libs: $(LIBS:%=lib%.a)
$(foreach LIB, ${LIBS}, ${MAKE} -C lib${LIB} ;)
lib%.a:
$(MAKE) -C $(@:%.a=%)
...
My problem is that, whenever I touch a file in one of my libs, make recompile that lib, but I have to run make a second time to make it relink the object files.
What am I doing wrong ?
Thanks in advance.
---EDIT---
So now my Makefile looks like this.
...
all: $(NAME)
$(NAME): $(OBJS) libft/libft.a libgc/libgc.a
$(CC) $(CFLAGS) $(OBJS) -o $(NAME) $(LDFLAGS)
-include $(DEPENDENCIES)
$(OBJS_DIR)/%.o: %.c $(OBJS_DIR)/debug$(DEBUG) | $(OBJS_DIR)
$(CC) $(CFLAGS) $(INCLUDES_DIR:%=-I %) -c $< -o $@
$(OBJS_DIR):
$(MKDIR) $@
libft/libft.a:
$(MAKE) -C libft
libgc/libgc.a:
$(MAKE) -C libgc
...
It does not relink anymore but if change some file in the sources of my libs, it does not recompile either.