News for hackers. Stuff that matters.
Re:Using Make – writing less Makefile by hathawsh on Tuesday December 26, 2023 @05:23PM (#38776748)
With all due respect, I don't understand the first part of your comment. Make's core purpose is to execute commands, isn't it? How was it not designed to execute commands?
Re:Using Make – writing less Makefile by nine_k on Tuesday December 26, 2023 @05:40PM (#38776884)
No, no. Make's principal purpose is to put a set of files into a desired state. It can "make" a particular file by invoking a dependent graph of commands that produce that file from other files. It checks timestamps and only run steps where the resulting files are older than some of the (transitive) source files.

You can invoke it by naming a named rule, not a file, but the logic will remain.

If this is not what you want to be doing, and if your Makefile is full of .PHONY targets, you likely need a Justfile instead, or (worse) plain shell scripts.

Re:Using Make – writing less Makefile by KajMagnus on Tuesday December 26, 2023 @06:11PM (#38777090)
I also don't like Make for running commands.

I was using Make for running commands, but it interprets all command line parameters as build targets, which was annoying. And Bash scripts in Makefiles aren't type safe, became messy.

Nowadays I use Make only for building. And Deno + Typescript instead, for running commands & scripts.

(Hadn't heard about Just — the scrips aren't type safe though?)

Re:Using Make – writing less Makefile by maleldil on Tuesday December 26, 2023 @07:14PM (#38777538)
> Hadn't heard about Just — the scrips aren't type safe though?

Just runs code written in other languages. It's `sh` by default, but you can define anything (e.g. `python3 -c` to run Python scripts).

Re:Using Make – writing less Makefile by gregwebs on Wednesday December 27, 2023 @10:33AM (#38782940)
depends on how you define type-safe. Even in TypeScript you are still executing strings when running commands. You can turn those strings into variables and share them as a form of type safety- the type check will fail if you mis-type the variable name. Just supports that- you will get an error if a variable that is being inserted doesn't actually exist. The error will occur at startup before usage or can be checked ahead of time with just --check --fmt. So for quick usage there's not much benefit to TS, but over time in TS you could build up type safe interfaces to commands and obviously if you want to run TS scripts instead of shell scripts that's going to have more opportunities for strong typing then invoking TS from just.
Re:Using Make – writing less Makefile by BeetleB on Tuesday December 26, 2023 @09:11PM (#38778324)
I tell people not to use make if there's no need for a dependency graph.

Just don't.

And do just :-)

Re:Using Make – writing less Makefile by twaw on Wednesday December 27, 2023 @01:14AM (#38779545)
Yeah, use make -j8 instead.
Re:Using Make – writing less Makefile by alwillis on Tuesday December 26, 2023 @05:54PM (#38776988)
> Make's core purpose is to execute commands, isn't it? How was it not designed to execute commands?

Some people on HN believe that if you use make primarily as a task runner that you're doing it wrong and should use something else. I don't agree.

Most users are using multiple aspects of make: as a task runner and as something that handles the dependency graph when building something digital.

As a web developer, I used npm scripts, grunt, gulp, etc. to manage web builds but now I only use make and have gotten off the merry-go-round of web build tools.

Re:Using Make – writing less Makefile by TheSoftwareGuy on Tuesday December 26, 2023 @09:03PM (#38778286)
What’s the point of using another tool to manage your shell scripts though? Why not just use shell scripts
Re:Using Make – writing less Makefile by alwillis on Wednesday December 27, 2023 @01:11AM (#38779535)
> What’s the point of using another tool to manage your shell scripts though? Why not just use shell scripts.

When you create a Makefile, you're describing a dependency graph of what depends on what and the order tasks need to take to produce a particular set of digital artifacts--you're not writing shell scripts.

Turns out there are all kinds of edge cases and foot guns that make handles for you that you'd otherwise have to deal with if you wrote a bespoke shell script.

Plus make is battle tested and has been around since the dawn of Unix--there's literally no build scenario it can't handle.

I hadn't used make until a few years ago but it's been one of the best investments I've made in my workflow.

Re:Using Make – writing less Makefile by jcelerier on Wednesday December 27, 2023 @07:04AM (#38781180)
> there's literally no build scenario it can't handle.

Well except this little case where some files or folders in your paths have spaces in them...

Re:Using Make – writing less Makefile by Izkata on Wednesday December 27, 2023 @03:57AM (#38780261)
Makefiles coordinate your shell scripts, using a dependency tree you'd have to reimplement if you did it purely with shell scripts.

For example:

A) You have a recipe that installs dependencies if they're not up-to-date (such as "pip install").

B) You have a recipe that compiles stuff if it's not up-to-date; it's made to depend on A.

C) "make" can be an interface recipe that depends on B and does nothing else.

D) "make test" can be an interface recipe that depends on B, then runs tests.

E) "make run" can be an interface recipe that depends on B, then actually runs the code / a webserver to interact with.

Nowadays whenever I put one of these together there's 2 versions of A (one for python, one for node), 1+ versions of B (webpack build without watch, maybe others depending on the project), 3 versions of D ("test-js", "test-python", and "test" that does both, and each of them only requires the relevant parts of A and B).

Makes it trivial to ensure you're up-to-date after a "git pull" without having to waste time waiting on things that don't need updating.

Re:Using Make – writing less Makefile by alwillis on Tuesday December 26, 2023 @06:34PM (#38777252)
Out of the box with no configuration, Fish shell provides target completions for a Makefile in the current directory [1].

[1]: https://fishshell.com/docs/current/interactive.html