Hacker News new | ask | show | jobs
by gregwebs 2232 days ago
Make was designed for building dependencies. I think it is always problematic to use it as a command runner (for example there is no standard way to list out the available commands).

[just](https://github.com/casey/just) is a tool that feels similar to make but is designed explicitly for the purpose of running commands.

I think of this as a simple CLI for your project workflow. You still really want to avoid putting code into a Justfile and put it into scripts. But the Justfile helps provide a slightly nicer UX and automatically invoke dependencies.

4 comments

Yes I agree with this. I use shell instead of make, because make wrapps shell and its syntax collides very poorly with it. For example, the PID is now $$$$ and not $$.

Most people forget to mark their targets .PHONY, so they have a subtle bug in their build (touch build; touch test).

----

But shell also suffers from the problem where it doesn't list the commands. I filed a bug for Oil shell here:

https://github.com/oilshell/oil/issues/751

I mentioned a couple other "frameworks" there like just, go, Taskfile, etc.

But it should really just be built into the shell, since it's so common. And there should be command completion too, which I think bash-completion has for Makefiles on many distros.

Apparently there is no standard name for this kind of "task runner". But I think shell makes a lot more sense than a custom format, because there are many instances where you need a simple loop or conditional. It scales better. (And Oil also fixes bad shell syntax while remaining compatible: http://www.oilshell.org/blog/2020/01/simplest-explanation.ht...)

If anyone wants to help let me know :) The code is plain Python and pretty hackable. However it generates fast C++, so you get the best of both worlds (in progress)

The tool you want is remake: http://bashdb.sourceforge.net/remake/

This is GNU Make + a few patches. So it's 100% compatible. And you get an interactive debugger, and lots more stuff. For instance, to list out the commands:

  remake --targets
No idea why this hasn't been merged upstream.

Your larger point really stands, though: if you're just running commands, you shouldn't be using Make. But it is abused in that way often, so...

How does it deal with wildcard rules? I would bet it gets complicated when you start having chained wildcard rules that have also side effects.
There's --targets and --tasks to handle such things, but it really depends on the Makefile in question. If you really want to know how it behaves, apt install remake.
> remake --targets; No idea why this hasn't been merged upstream

I would think because it's useless. The targets in a Makefile are very often just internal and aren't always meant to be run by the user.

Many shell autocompleters would read the makefile to complete target names though, suggesting it is not useless.

Anyway, one could always have a 'help' target that prints a short documentation. This also avoid listing internal targets.

Yes, I remember using zsh and in my experience this was barely useful since most Makefiles are auto-generated with hundreds or thousands of targets.

> one could always have a 'help' target that prints a short documentation

Sure, that's fine. But the point is that if you have an unknown Makefile you can't (or shouldn't) just execute it without knowing what it will do. Makefiles should be treated as individual programs just like any other executable and there's no guaranteed standard way to get help from it.

It has an interactive debugger, which is not useless. Clearly.
I was just referring to the --targets option which I thought was meant as an answer to the missing standard help.
When you say, "there is no standard way to list out the available commands", do you mean like a `make help`?

https://gist.github.com/prwhite/8168133#gistcomment-3114855

While you you could argue that this is a convention -- I'd say this isn't even a common one -- it's still a long way from being "standard".
"make help" is definitely not a standard. For all I know "make help" builds help.exe. But there is a standard way to get available commands: Just look at the README or open the Makefile with a text-editor!

The lack of a standard argument for getting help doesn't make it problematic for use as a command runner. You can't get atomatically all available commands from a Makefile just like you can't get all command-line flags from an executable. The program/Makefile has to provide it by itself.

I didn't generate any files in the examples for simplicity. But you could imagine a workflow where Python generates some data and then you use R to plot it + run some statistical tool.