I need automatic dependency generation to be done in my
makefile. So, I have tried to write one, after googling for similar ones. I have found some ways to do that, but the problem is that they are usually too complicated for me (because of usage of
sed command etc. and I want a way for me to create a
makefile without the need of refering to some other
Below is a
makefile I hope should do the same job i.e. automatically find out all the dependencies of the object files and build them. Could you please review this
makefile and point out cases where the build may fail when it should not have?
Gpp=g++ srcs=$(wildcard *.cpp) objs=$(srcs:.cpp=.o) deps=$(srcs:.cpp=.d) default:test %.o:%.d $(Gpp) -c $*.cpp %.d:%.cpp echo -n "$*.d ">$*.d $(Gpp) -MM $*.cpp>>$*.d test: $(objs) $(Gpp) $^ -o $@ -include $(deps) .PHONY:clean default clean: -rm -rf *.o test *.d
One place where the
makefile fails is when for example
a.cpp initially included
a1.h but it has been updated to exclude
a1.h file has been deleted from file-system. So, except that is there any place that this makefile fails?