Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For one-line recipes you can use semicolon

    foo.o: foo.c ; $(CC) $<
If you find $(@D) hard to remember then do $(dir $@) instead.

I wrote a book about GNU Make stuff (https://nostarch.com/gnumake). If (and only if) you've read the GNU Make Manual from the FSF my book may help you. It's not for newbies. Don't want the book? All the articles are here: https://blog.jgc.org/2013/02/updated-list-of-my-gnu-make-art...



I can attest that it's a great book. It took my Make savvy from "pretty average" to "can build Makefiles that conform pretty decently to DRY". Not all of the book is useful to me, but it's a pleasant read and also a good well-indexed reference manual and I consult it at least monthly for fun.


With backslashes before newlines you can do “multiline oneliners” too.


Yep. One of the reasons I recommend the FSF manual is that it's a great introduction: https://www.gnu.org/software/make/manual/make.html#Splitting...


You can also do "multiline multiliners" by adding a target .ONESHELL. By overriding the variable SHELL, this allows you to put arbitrary multi-line scripts of your preferred programming language into makefile recipes.

https://www.gnu.org/software/make/manual/html_node/One-Shell...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: