4 ms·
> Whenever I see comments about people trying to reinvent make, my conclusion is that make "as a tool" is inevitably far superior, but people are mostly familia
by frankjr 2y ago
> Whenever I see comments about people trying to reinvent make, my conclusion is that make "as a tool" is inevitably far superior, but people are mostly familiar with a small subset of its functionality, which makes it appear clunky.
If you're looking for a task runner, not a build tool, then make is not "far superior" in any sense and there are much better alternatives, the most prominent probably being "just". Even something as basic as accepting parameters to a task (make fetch <arg1> <arg2>) is awkward because make doesn't understand this syntax and interprets the arguments as targets. The only way to make it work is either through named arguments or empty target hacks and in both cases you need to write the validation logic yourself. In just it's simply:
fetch PACKAGE VER:
@echo fetching {{PACKAGE}} at version {{VER}}
$ just fetch foo
error: Recipe `fetch` got 1 argument but takes 2
usage:
just fetch PACKAGE VER
$ just fetch foo 1.2.3
fetching foo at version 1.2.3
https://just.systems/man/en/chapter_1.html https://just.systems/man/en/chapter_1.html
- nrclark 2y agoJust is fine, don't get me wrong. But Make targets can take arguements too. They just have to be named, or (if you stretch the definition a bit) wildcard targets. AFAIK, Just doesn't have any way to mark "this task is complete, so don't re-run it". It also doesn't have file-based dependendicies, which are pretty common for any kind of programming. Why would I want to lose all of Make's flexibility and power in exchange for slightly prettier UI syntax?
- frankjr 2y ago> AFAIK, Just doesn't have any way to mark "this task is complete, so don't re-run it". It also doesn't have file-based dependendicies, which are pretty common for any kind of programming. That's fair but also not what I'm looking for in a task runner, that's why I explicitly said "not a build tool", which to me this falls under (although I realize everybody has a different definition of these terms and where they draw the line if at all).
- maccard 2y agoI think this post is well intentioned but misses the point entirely. GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'main.Version=v1.2.3'" Executing this with variables for os/arch/version is not straightforward in a makefile. You might argue that it's a flaw with the `go build` command, but replace go with cargo/dotnet/maven and you have the same problem. > AFAIK, Just doesn't have any way to mark "this task is complete, so don't re-run it" What does a makefile look like for "install this list of dependencies with pip/homebrew/apt, and don't run it twice?" > It also doesn't have file-based dependendicies, which are pretty common for any kind of programming C and C++ compilers at this stage are the only places that I work with file based dependencies. Unless you explicitly declare all the headers as dependencies in a makefile, make won't rebuild a cpp file if you change a header. IME ninja (plus cmake to generate it) has entirely superseded make in this space. Tools and languages comes with it's own build tool (see above - go/cargo/dotnet/etc) or state tracking (docker) that break make's assumption of file based dependencies. > Why would I want to lose all of Make's flexibility and power in exchange for slightly prettier UI syntax? Because every make file I've ever used in recent memory has been 30% workarounds to avoid file based dependencies, and work around subtle footguns that make has, rather than actually doing what I want it to do - execute a build command.
- jgrahamc 2y agoI think this post is well intentioned but misses the point entirely. GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'main.Version=v1.2.3'" Executing this with variables for os/arch/version is not straightforward in a makefile. You might argue that it's a flaw with the `go build` command, but replace go with cargo/dotnet/maven and you have the same problem. What makes that hard? I think the following works correctly: $ cat Makefile goos := FOO goarch := BAR mainversion := BAZ .PHONY: build build: ; @GOOS=$(goos) GOARCH=$(goarch) go build -ldflags="-X 'main.Version=v$(mainversion)'"* $ make -n GOOS=FOO GOARCH=BAR go build -ldflags="-X 'main.Version=vBAZ'"
- nrclark 2y ago> What does a makefile look like for "install this list of dependencies with pip/homebrew/apt, and don't run it twice?" It looks like this: default: your_task VENV_DIR := venv $(VENV_DIR)/bin/python: requirements.txt python -m venv $(VENV_DIR) . $(VENV_DIR)/bin/activate && pip install -r requirements.txt your_task: $(VENV_DIR)/bin/python do_your_thing clean: rm -rf $(VENV_DIR) > C and C++ compilers at this stage are the only places that I work with file based dependencies. Unless you explicitly declare all the headers as dependencies in a makefile, make won't rebuild a cpp file if you change a header. IME ninja (plus cmake to generate it) has entirely superseded make in this space. Tools and languages comes with it's own build tool (see above - go/cargo/dotnet/etc) or state tracking (docker) that break make's assumption of file based dependencies. In our Python example above, you have a file-based dependency between requirements.txt and your virtual environment. And then you have a file-based dependency on your virtual-environment's Python for whatever task you're trying to run. > Because every make file I've ever used in recent memory has been 30% workarounds to avoid file based dependencies, and work around subtle footguns that make has, rather than actually doing what I want it to do - execute a build command. Why would you want to avoid expressing your dependencies? File dependencies exist, and are the simplest / most correct model for 75% of all build automation. When somebody has to sit down and read your Makefile, isn't it nice to have a way to express "these are the files that actually matter for task X"?
- kstrauser 2y agoBecause it makes the common things easier. We make these tradeoffs all the time in software engineering. Raw machine code is the most flexible and powerful programming language, and yet most of us here aren't using it today. Make isn't machine code and Just isn't Python, but there's an analogy: you give up something by using the latter in exchange for making it easier to do everyday things. Just doesn't replace Make. For the thousand everyday tasks where Make's power isn't needed, it's likely a better choice for most people.
- bityard 2y agoI like the idea of Just (and the many tools like it), I only wish it had come along a few decades earlier. Make has the advantage of being a ubiquitous de facto standard. It is probably already installed anywhere you want to deploy your repo, or can be very easily installed with one command. As a personal preference, I actually do tend to avoid Make as a task runner because a quick shell script is almost as easy to write and far more flexible. I am pretty familiar with Make but have still painted myself into a corner with it more times than I'd like to admit.
- mitjafelicijan 2y agoYou are not alone in this. I have found myself stubbornly writing a complex Makefile when I should have just written a simple shell script and be done with it.
- throwaway984393 2y ago[dead]
- nrclark 2y ago---- fetch PACKAGE VER: @echo fetching {{PACKAGE}} at version {{VER}} ---- $ just fetch foo 1.2.3 Here is the Make equivalent, with equivalent error-checking ---- fetch: $(if $(PACKAGE),,$(error PACKAGE was not set)) $(if $(VERSION),,$(error VERSION was not set)) @echo fetching $(PACKAGE) at $(VERSION) ---- $ make fetch PACKAGE=foo VERSION=1.2.3 I agree that the `just` version is a little neater / tidier. But it's not like Make can't do the same thing. And Make is a much more powerful tool.