6 ms·
A particularly tricky task with GNU make is automatically adding target dependencies on header files and handling updates to them (gcc's -M and -MMD switches).
by DblPlusUngood 8y ago
A particularly tricky task with GNU make is automatically adding target dependencies on header files and handling updates to them (gcc's -M and -MMD switches). It would be great if the article explained those best practices, too.
- jgrahamc 8y agohttps://www.cmcrossroads.com/article/tips-and-tricks-automatic-dependency-generation-masters https://www.cmcrossroads.com/article/tips-and-tricks-automat...
- AceJohnny2 8y agoThanks John, your book is the most-referred to on my office shelf ;) Edit: https://nostarch.com/gnumake https://nostarch.com/gnumake (via https://blog.jgc.org/2015/04/the-gnu-make-book-probably-more-than.html https://blog.jgc.org/2015/04/the-gnu-make-book-probably-more...)
- jgrahamc 8y agoThat'a great. Glad it was helpful. If you have any of your own GNU Make tips and tricks please do blog about them!
- nrclark 8y ago+1 for a great book, I bought that book too! I use the patterns in @jgrahamc's article "Escaping: A Walk on the Wild Side" pretty often. Especially the \n definition, which works great to put on the end of a $(foreach) loop inside of a recipe. @jgrahamc: Thanks for all you've written on Make over the years.
- mturmon 8y agoI also recommend this book. The series on “meta programming make” is also quite good: http://make.mad-scientist.net/category/metaprogramming/ http://make.mad-scientist.net/category/metaprogramming/
- jgrahamc 8y agoOoh. That's great. I had not seen that!
- sigjuice 8y agoThis tiny Makefile should convey the idea. CFLAGS=-MD -MP prog: <list of .o files> $(CC) -o $@ $^ -include *.d
- Ace17 8y agoHere's all you need to track header file dependencies. Basically, when compiling a .cpp file to generate a .o file, a corresponding .deps file is also generated. And at make startup, we include all the .deps files we find in the bin (output) directory, if there's one. $(BIN)/%.cpp.o: %.cpp $(CXX) -c $(CXXFLAGS) "$<" -o "$@" @$(CXX) -c $(CXXFLAGS) "$<" -o "$@.deps" -MP -MM -MT "$@" -include $(shell test -d $(BIN) && find $(BIN) -name "*.deps")