Live data from Hacker News

How I stopped worrying and loved Makefiles

gagor.pro

21–30 of 144 posts

Re: How I stopped worrying and loved Makefiles

#21

If you're going to use Makefiles as a top-level build wrapper you might be interested in self-documenting targets. https://marmelab.com/blog/2016/02/29/auto-documented-makefil...

I've been using this for a while now - it's fantastic, highly recommended for non-core-Unix-build-stuff. Just make `help` your default recipe and voila, a massive drop in people asking "how do I run tests in make" -> they probably tried to `make` already and it told them how.

Re: How I stopped worrying and loved Makefiles

#22
Makefiles fill that great need for a high-level 'scripting DSL', where you have a lot of different programs (or scripts), with a loose set of dependencies or order of operation, and you want a very simple way to call them, with some very simple logic determining the order, arguments to pass, parallelization, etc. Their ubiquity on all platforms makes it even easier to use them.

I much prefer Make to alternatives like Just or Taskfile. Besides the fact that more people know Make, Make actually has incredibly useful functionality that alternatives remove 'for simplicity', but then later you realize you want that functionality and go back to Make. Sometimes old tricks are the best tricks.

Re: How I stopped worrying and loved Makefiles

#23
post #9

I use makefiles a lot as make-do but I must admit the syntax does my head in at times. If anyone has a good resource that teaches makefile progressively, I'd be interested. The main issue I have is that it goes from dead simple to pit of what the hell is happening with various things interacting with each others.

> If anyone has a good resource that teaches makefile progressively

https://www.gnu.org/software/make/manual/make.html

Re: How I stopped worrying and loved Makefiles

#25

Earlier quoted context omitted.

> I feel that there is a niche between make and ninja for the task runner. I think that's called CMake.

No, CMake is a compatibility layer on top of existing task runners like make and ninja. I don't want a compatibility layer, and also CMake has even more features than make.

CMake is a (not the) correct answer according to the Ninja manual[1]. "Some explicit non-goals: convenient syntax for writing build files by hand. You should generate your ninja files using another program. This is how we can sidestep many policy decisions."

The other options are here: https://github.com/ninja-build/ninja/wiki/List-of-generators...

[1] https://ninja-build.org/manual.html#_design_goals

Re: How I stopped worrying and loved Makefiles

#26

Ninja is simple and fast, but intentionally limited in order to not be programmable. Make is powerful and versatile (especially the GNU variant) but has an arcane syntax and lots of pitfalls. I feel that there is a niche between make and ninja for the task runner.

> I feel that there is a niche between make and ninja for the task runner. I think that's called CMake.

CMake is a very cool buildsystem that can do a lot, you can use it to run tests, fetch sources, and everything else. The documentation is the only thing that I find quite suboptimal, they could really add examples in there and better explain things. Or at least have list of projects that they believe are using CMake correctly so one can have some guidance. It took me five years before I was comfortable writing CMake from scratch.

Re: How I stopped worrying and loved Makefiles

#28
post #25

Earlier quoted context omitted.

No, CMake is a compatibility layer on top of existing task runners like make and ninja. I don't want a compatibility layer, and also CMake has even more features than make.

CMake is a (not the ) correct answer according to the Ninja manual[1]. "Some explicit non-goals: convenient syntax for writing build files by hand. You should generate your ninja files using another program. This is how we can sidestep many policy decisions." The other options are here: https://github.com/ninja-build/ninja/wiki/List-of-generators... [1] https://ninja-build.org/manual.html#_design_goals

It is entirely correct that Ninja is technically designed for a related but different problem. But you can write Ninja by hand with some restrictions (I have done so for example), so bring back some of those sidestepped decisions may still be worthwhile.

Re: How I stopped worrying and loved Makefiles

#29
post #26

Earlier quoted context omitted.

> I feel that there is a niche between make and ninja for the task runner. I think that's called CMake.

CMake is a very cool buildsystem that can do a lot, you can use it to run tests, fetch sources, and everything else. The documentation is the only thing that I find quite suboptimal, they could really add examples in there and better explain things. Or at least have list of projects that they believe are using CMake correctly so one can have some guidance. It took me five years before I was comfortable writing CMake…

I had a boss who once quipped that CMake became much easier for him to understand and write once he realized it was just a really shitty version of BASIC with only global variables. (He later added "but two separate namespaces for them" because of the prevalent use of environmental variables as well as CMake-specific variables)

Re: How I stopped worrying and loved Makefiles

#30
post #9

I use makefiles a lot as make-do but I must admit the syntax does my head in at times. If anyone has a good resource that teaches makefile progressively, I'd be interested. The main issue I have is that it goes from dead simple to pit of what the hell is happening with various things interacting with each others.

https://makefiletutorial.com/
Post reply on HN