by dataflow · 5y ago · 0 comments
> The core syntax of a Makefile is just so close to perfect.
I'd argue what is close to perfect is much of the underlying model/semantics, and what is terrible is very much the syntax. I've long wanted to make something similar to Make but simply with better syntax...
target: prereq | ooprereq
recipe
In my eyes, the most important thing when building something that is complex is the dependency graph and it makes sense to make the syntax for defining the graph as simple as possible. I think the make syntax just nails it and most of the other approaches I have seen so far add complexity without any benefit. In fact, most of the complexity they introduce seems to stem from confusion on the side of the developer being unable to simplify what they're trying to express.At the level of variable handling and so forth, make is slightly annoying but manageable.
Anything beyond that - yeah, I'm with you, a lot of that is terrible.
Yes, there are workarounds for some situations, but none of them work in all cases and no-one ever applies them consistently.
Spaces in filenames is a perfectly reasonable thing to want to do. They are supported on all three major platforms, but make just throws up it's hands and doesn't care. Yes, it is workable around, but it would be nice if it wasn't.
It's an annoyance with make overall, but if we're talking about the syntax specifically then yes I would call that a "major insurmountable problem".
It caused so many issues. But mostly with developer tooling, like Make, that assumes these sorts of things. Most programs worked just fine.
It's a build-system in Rust with some really cool features (and an even simpler syntax).
Other than that, I think Ninja is perfect.
Small enough to even checkin into git. Your compiler, cmake and all the other tools you use is going to be a much bigger problem.
While ninja is great for many uses i would not recommend to use it for hand written rules. In fact any simple dependency-resolver like make or ninja will be lacking a lot of language context about includes and other transitive dependencies so you always want some higher level abstraction closer to the language as your porcelain.
Anyway, not having any other automagical behavior and hidden rules and the fact that it can do incremental and correct job re-runs even when the rules change is exactly why I like to use ninja.
Here's one such use case, maybe not the cleanest:
https://megous.com/git/p-boot/tree/configure.php
I especially love it in projects involving many different compilers/architectures/sdks at once (like when doing low level embedded programming), where things like meson or autotools or arcane Makefile hacks become harder to stomach.
Gnu Make is almost pathetic.
I had trouble with the one class in uni that used Haskell and I've been working in a Python shop for some years now, so I kept expecting to encounter some impenetrable section that would make my eyes glaze over and my hand close the tab. I was probably closest around page 9!
But the writing was excellent, and clear, and satisfying, and little concepts I was so close grokking kept catching my eye and pulling me back in until I understood them, then their neighbors, then the section, then I was done.
Guess I've picked up some things since college. Wish I could go back and take that class again. I think learning to use Rust's Option type in anger on a personal project helped me understand monads more than anything in that class.
Also, I'm happy to see the method described by the paper does seem to have become the official GHC build system [0].
0. https://gitlab.haskell.org/ghc/ghc/-/wikis/building/hadrian
1 module Main(main) where
2 import Development.Shake
3 import System.FilePath
4
5 main :: IO ()
6 main = shake shakeOptions $ do
7 want ["foo.o"]
8
9 "∗.o" %> \out → do
10 let src = out -<.> "c"
11 need [src]
12 cmd "gcc -c" src "-o" out
Maybe there is a need for super sophisticated graph handling, but for most use cases the way more complicated syntax of Shake is not a worthy tradeof.
If you haven't, I'd suggest having a look at pmake (sometimes packaged as 'bmake' since it is the base 'make' implementation on BSDs) - the core 'make' portions are still the same (like gmake extends core 'make' as well), but the more script-like 'dynamic' parts are much nicer than gnumake in my opinion. It also supports the notion of 'makefile libraries' which are directories containing make snippets which can be #include's into other client projects.
freebsd examples:
manual: https://www.freebsd.org/cgi/man.cgi?query=make&apropos=0&sek...
makefile library used by the system to build itself (good examples): https://cgit.freebsd.org/src/tree/share/mk