Reputation: 700
My makefile always rebuild, don't understand why..
Here it is :
SRC = $(DIR)/my_getnbr.c \
$(DIR)/my_isneg.c \
$(DIR)/my_putchar.c \
OBJ = $(SRC:.c=.o)
DIR = lib/my
LIB_DIR = lib
NAME = libmy.a
MYH = include/my.h
BUILD = ar rcs $(NAME) $(DIR)/*.o
MV = mv $(NAME) $(LIB_DIR)
CP = cp $(MYH) $(DIR)
all: $(NAME)
$(NAME): $(OBJ)
$(BUILD)
$(MV)
$(CP)
clean:
rm -f $(OBJ)
fclean:clean
rm -f $(LIB_DIR)/$(NAME)
re: fclean all
.PHONY: fclean all re clean
I added the .PHONY
but it changes anything :(
He always do the BUILD, MV and CP
calls.
If i delete them from the Makefile, it will not rebuild if he is up to date (only with the .OBJ).
Thanks again.
Upvotes: 2
Views: 397
Reputation: 27053
you are moving libmy.a
to the directory lib
. the next time you run make it will look for libmy.a
and since it doesn't exists it will be build.
make will always look for the targets (libmy.a
in your case) in the current directory. so if you are moving the file to another place make will think the file has not been created.
rule of thumb is: the recipe for a target should always create the file named by the target.
possible solutions:
NAME = lib/libmy.a
) (perhaps easiest in your case)Upvotes: 5