News for hackers. Stuff that matters.
Re:Makefiles – Best Practices by DblPlusUngood on Friday February 01, 2019 @11:50AM (#19055757)
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.
Re:Makefiles – Best Practices by jgrahamc on Friday February 01, 2019 @12:24PM (#19056147)
Re:Makefiles – Best Practices by AceJohnny2 on Friday February 01, 2019 @12:44PM (#19056376)
Thanks John, your book is the most-referred to on my office shelf ;)

Edit: https://nostarch.com/gnumake (via https://blog.jgc.org/2015/04/the-gnu-make-book-probably-more...)

Re:Makefiles – Best Practices by nrclark on Friday February 01, 2019 @02:57PM (#19057871)
+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.

Re:Makefiles – Best Practices by mturmon on Saturday February 02, 2019 @02:05AM (#19061616)
I also recommend this book. The series on “meta programming make” is also quite good: http://make.mad-scientist.net/category/metaprogramming/
Re:Makefiles – Best Practices by jgrahamc on Saturday February 02, 2019 @05:15AM (#19062218)
Ooh. That's great. I had not seen that!
Re:Makefiles – Best Practices by jgrahamc on Friday February 01, 2019 @01:36PM (#19057011)
That'a great. Glad it was helpful. If you have any of your own GNU Make tips and tricks please do blog about them!
Re:Makefiles – Best Practices by Ace17 on Saturday February 02, 2019 @07:04AM (#19062565)
Here'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 "[email protected]" -MP -MM -MT "$@"
-include $(shell test -d $(BIN) && find $(BIN) -name "*.deps")
Re:Makefiles – Best Practices by sigjuice on Friday February 01, 2019 @12:56PM (#19056524)
This tiny Makefile should convey the idea.

    CFLAGS=-MD -MP

    prog: <list of .o files>
        $(CC) -o $@ $^
        
    -include *.d