by skore · 5y ago · 0 comments
I use it heavily and think it's extremely underappreciated, so instead of reinventing it, I would like to build on it. But - trying to extend the old C codebase is daunting. I'd even be happy with a reduced featureset that avoids the exotic stuff that is either outdated or no longer useful. The core syntax of a Makefile is just so close to perfect.
(I wrote about some of this in the remake repo: https://github.com/rocky/remake/issues/114 )
> 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.
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.
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.
Gnu Make is almost pathetic.
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
GNU Make is hurt by its minimalism. Doing anything interesting in pure GNU Make is a herculean effort. Even something simple like recursing into directories in order to build up a list of source files is extremely hard. Most people don't even try, they would rather keep their source code tree flat than deal with GNU Make. I wanted to support any directory structure so I implemented a simple version of find as a pure GNU Make function!
At the same time, a reduced feature set would be nice. GNU Make ships with a ton of old rules enabled by default. The no-builtin-rules and no-builtin-variables options let you disable this stuff. Makes it a lot easier to understand the print-data-base output.
> The core syntax of a Makefile is just so close to perfect.
It's very simple syntax but it has its pain points. Significant spaces effectively rules out spaces in file names. It also makes it much harder to format custom functions.
Speaking of functions, why can't we call user-defined functions directly? We're forced to use the call function with the custom function's name as parameter. Things quickly get out of hand when you're building new functions on top of existing ones. I actually looked up the GNU Make source code, I remember comments and a discussion about this... It was possible to do it but they didn't want to because then they'd have to think about users when introducing new built-in functions. Oh well...
What's wrong with shelling out to find?
Okay, I just wanted to see if I could do it in pure GNU Make.
true := T
not = $(if $(1),,$(true))
directory? = $(if $(1),$(wildcard $(addsuffix /.,$(1))))
file? = $(and $(wildcard $(1)),$(call not,$(call directory?,$(1))))
glob = $(sort $(wildcard $(or $(1),*)))
glob.directory = $(call glob,$(addsuffix /$(or $(2),*),$(or $(1),.)))
recurse = $(foreach x,$(3),$(if $(call $(2),$(x)),$(x),$(x) $(call recurse,$(1),$(2),$(call $(1),$(x)))))
file_system.traverse = $(call recurse,glob.directory,file?,$(or $(1),.))
find = $(strip $(foreach entry,$(call file_system.traverse,$(1)),$(if $(call $(or $(2),true),$(entry)),$(entry))))
sources := $(call find,src,file?)
Yes.Then I discovered GNU Make supports C extensions. It will even automatically build them due to the way the include keyword works. It might actually be easier to just make a plugin with all the functionality I want...
It's make-like but supposedly improves on some of the arcane aspects of make (I can't judge how successful it is at that as I've never used make in anger).
That makes make a great entry point for any project. Does anyone have a general suggestion about how to work around this? The goal being, sync a project and not need to install anything to get going. One thing I do sometimes is to use make as the entry point, and it has an init target to install the necessary tools to get going (depends on who I know to be the target audience).
E.g. in one project it will install rbenv, bundle, npm, yarn etc. Call Rake, npx, that odd docker wrapper, etc. Or deploy with git in one project and through capistrano or ansible in another.
As a dev, in daily mode, all you need is 'make lint && make test && make deploy'. All the underlying tools and their intricacies are only needed when it fails or when you want to change stuff.
So while it's replaced one use of Make for me, I can't rightly call it a Make replacement.
if it was opt-in to him monitoring i might be more open. maybe i should fork and change the filename to keep this from happening
edit: Yeah, I can't see how I can make it work for a file-based approach.
https://github.com/google/kati/blob/master/INTERNALS.md
This takes your existing Makefile(s) and produces a ninja build file. Not sure if Android still uses it or it is all soong now.
That's about the last thing I would call it.
The one thing that I'm currently struggling to find information on is dynamic dependency handling (dyndep in ninja terms).
Is that something that build2 covers as well? Any resource you could point me to?
Would it be appropriate to open a github issue for discussing this further? I would like to share some example for how my current setup is working and having the github syntax available would be helpful.
edit: Yeah, doesn't seem like it.
I would love to see this completed to the point of passing the GNU make testsuite. Having make as a modular library would be wildly useful.