For beginners, you do exotic things. You should start simple and use only the code in the Makefile, which you 100% understand and trust. Even with a large project with hundreds of files, you won’t spend much time saving the Makefile.
Variables assigned with: = are expanded immediately - all $ (VAR) values are substituted into the variable value at the time of assignment. Variables assigned with = expand when they are used, so they can do things like references to variables that are not yet defined.
The -MM flag for g ++ will generate a Makefile dependency line, for example. foo.o: foo.cc foo.hh, but I never found this useful. I had a false “dependency” target that generated one dependency file. Your idea of creating a bunch of * .d files with these single line dependencies might work, but you end up with a lot of these files.
The error you get is from g ++, not from make. This is because you use $ (DEPS), as if it were the only file when it has the entire list of * .d files. What happens is this line:
@$(CC) -c -MM $< > $(DEPS)
expands to:
g++ -c -MM MyFile.cpp > MyFile.d stdAfx.d Main.cpp
mcdave just posted the code that I used to create the dependency file. You can either switch to one dependency file style, or change the -MM command to this:
@$(CC) -MM $< > $@
You may also need to fix the -include statement because I don't think it maintains a list of files to include.
Ken fox
source share