Makefile recompiles after cleaning objects (but not the name target) -
when call clean rule make clean objects correctly deleted. if after call all rule make recompiles objects again, if target there.
as far know, should not recompile objects beacuse $(name) dependecy in all rule satisfied. indeed make clean erase object , not program target too.
somebody can explain me how avoid recompiling after make clean call? thank you.
here makefile:
name = myprogram cc = clang++ cflags = -werror -wextra -wall -o3 -std=c++11 dir_srcs = srcs/ dir_objs = objs/ dir_incs = incs/ files = main.cpp \ file1.cpp \ files2.cpp \ file3.cpp \ objs = $(addprefix $(dir_objs), $(notdir $(addprefix $(dir_srcs), $(files:.cpp=.o)))) all: $(name) $(name): $(objs) $(cc) $(objs) $(cflags) -i$(dir_incs) -o $(name) $(dir_objs)%.o: $(dir_srcs)%.cpp mkdir -p $(dir_objs) $(cc) $(cflags) -i$(dir_incs) -c $< -o $@ clean: rm -rf $(dir_objs) fclean: clean rm -f $(name) re: fclean .phony: clean fclean re
the $(name) dependecy in all rule not satisfied, because $(name) depends on $(objs) - , $(objs) not exist (after make clean). how make works. if dependencies don't exists or newer target - dependecies need regenerated (and in turn - target).
for example: program --> program.o --> (program.c, program.h)
if program.c or program.h newer program.o : program.o needs regenerated (updated). causes program.o newer program - program needs relinked (using program.o).
Comments
Post a Comment