Make is not generating dependency files

I'm trying to use make to build dependency makefiles by following this:

http://www.gnu.org/software/make/manual/make.html#Automatic-Prerequisites

here is my makefile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  BIN=bin
SRC=src
INC=include
sources=$(wildcard $(SRC)/*.cpp)
# objects are the sources but with .o
objects=$(sources:.cpp=.o)
deps=$(sources:.cpp=.d)
GPP=g++
CPPFLAGS=-std=c++11
LINKARGS=-L/usr/lib/x86_64-linux-gnu

$(BIN)/app.exe : $(objects) $(deps)
	$(GPP) $(CPPFLAGS) $(LINKARGS) $(objects) -lcurl -o $(BIN)/app.exe

$(SRC)/%.d : $(SRC)/%.cpp
	@set -e; rm -f $@; \
	$(GPP) -I$(INC) -MM $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

include $(deps)

.PHONY:clean
clean:
	rm -f $(SRC)/*.o
	rm -f $(SRC)/*.d
	rm -f $(BIN)/* */


when I run it I get this:

1
2
3
4
5
6
7
8
9
10
11
mike@ubuntu:~/NetBeansProjects/CppApplication_1$ make -f mk.mk
mk.mk:25: src/DownloadBuffer.d: No such file or directory
mk.mk:25: src/Downloader.d: No such file or directory
mk.mk:25: src/main.d: No such file or directory
g++  -std=c++11  -c -o src/DownloadBuffer.o src/DownloadBuffer.cpp
src/DownloadBuffer.cpp:3:30: fatal error: DownloadBuffer.hpp: No such file or directory
 #include "DownloadBuffer.hpp"
                              ^
compilation terminated.
make: *** [src/DownloadBuffer.o] Error 1


so make is trying to execute my include before it actually builds those dependency makefiles. Would somebody please tell me how to have make build those dependency files before it tries to include them?

What's funny is that it does eventually build the .d files, but it's after it failed building other things. However, I opened up one of them:

 
DownloadBuffer.o src/DownloadBuffer.d : src/DownloadBuffer.cpp include/DownloadBuffer.hpp


and you can see that it has the wrong path, I want the .o files to go in src, not in the root directory. Should I use sed? or something else?
Last edited on
This is the instructions that I have followed and it has worked great for me.

http://scottmcpeak.com/autodepend/autodepend.html
Topic archived. No new replies allowed.