Good Makefiles (2018)

  • You shouldn't hard-code gcc. make has an implicit CC variable for this: https://www.gnu.org/software/make/manual/html_node/Implicit-...

    Your makefile will then work on systems without gcc, and it is also easier to override it, ie:

        make CC=clang

  • Make is a great tool. I mostly use it to remember repetitive tasks, like running python tests, not as a build system. Works even better for this. What annoys me deeply is that gnu make isn’t available on windows, e.g git bash.

  • I really don't know the first thing about C or makefiles o anything related, but I was browsing the code out of general curiosity and I have a question.

    Would this code benefit from better variable names or is it just that I don't know the domain and this is good understandable code? I'm honestly curious.

    This happens a lot with C code examples here.

  • There's a larger discussion on this topic at https://news.ycombinator.com/item?id=19052830.

  • For lots of things, and especially if you stick to the Unix Philosophy or Suckless Philosophy, this Makefile is all you need. I personally add ‘install’, ‘uninstall’, ‘clean’, and ‘superclean’ targets to my projects but this is a really great start.

  • I understand there's lots of build systems out there with better scripting languages, but is there anything else that can challenge make for simplicity and portability (although I guess you could export Makefiles)?

  • Unfortunately, the reality is never as simple as that. Your makefile will grow like a tumour once your project grows: Specific dependencies, OS and compiler related flags and switches, special folder structures, etc etc.

  • It's a terrible Makefile