Live data from Hacker News

How I stopped worrying and loved Makefiles

gagor.pro

51–60 of 144 posts

Re: How I stopped worrying and loved Makefiles

#52
post #33

Earlier quoted context omitted.

Yeah. Which is why I wouldn't implement that in the first place - I come down hard on the idea that you should ship your dependencies, have them in a standard place or use a third-party resolution system (like every vaugely modern setup does. C#, Python, Ruby, Node, Rust even Java all understand that this is not optional anymore). Its a code smell to me when your build system starts to become too complicated and not…

You do know that there is software that runs on more than one version of Linux (or even on a *BSD, MacOS or Windows), works with more than a single version of a compiler,...?

Thats only really a problem for C/C++, which I have had the misfortune to make build systems for.

The solution is not to ship complicated and bug infested build systems, it is to fix the dependency problem in the same way any other language has done so far and until we do this, ship the dependencies with the program.

And if you aren't making a GUI and don't need to target Windows, just wrap it in Docker, which enforces a functional dependency system and means you can ship your dependencies.

Re: How I stopped worrying and loved Makefiles

#53

If you're going to use Makefiles as a top-level build wrapper you might be interested in self-documenting targets. https://marmelab.com/blog/2016/02/29/auto-documented-makefil...

The punchline here is a help target that digs through your makefiles looking for comments:

  help:
 @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
I stumbled over .*? since ? usually means optional, but turns out it means lazy in this context. The $$ would be makefile escaping. Dropping the grep and changing the regex slightly, I just appended this to an overengineered makefile:

  # Help idea derived from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
  # Prints the help-text from `target: ## help-text`, slightly reformatted and sorted
  .PHONY: help
  help: ## Write this help
   awk 'BEGIN {FS = ":.*#+"}; /^[a-zA-Z_*.-]+:.*## .*$$/ {printf "%-30s %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

Very nice idea, thanks for sharing it!

Re: How I stopped worrying and loved Makefiles

#54

What's the rationale for using makefiles as script runners over just having a directory with scripts inside? Not for compiling, just as script runner. I see this practice often and I haven't found a good reason

If scripts need particular arguments the make is a good place to record them.

I use it quite a lot for automating deployments - if you want to Terraform up a VM:

  make colo1-fooserver01.vm
Then if you want to run Ansible against it:

  make colo1-fooserver01
You don’t have remember or type all of the flags or arguments - just type make and hit tab for a list of the targets that you can build

Re: How I stopped worrying and loved Makefiles

#55
post #50

This pattern of usage always seems like abuse. When `make` is used as a glorified front-end to `bash` scriptlets, why not use `bash` directly instead of having two-level of scripting? See: https://blog.aloni.org/posts/bash-functional-command-relay/

Because PHONY targets can do that, too, and without the needless manual work. Because a Makefile can still do Makefile things: PHONY targets depending on other PHONY targets, which so happens to depend on that one openapi json export you also create, which in turn depends on ...

You can do that in Bash. And now you've reinvented Makefile, but poorly.

Re: How I stopped worrying and loved Makefiles

#56
post #52

Earlier quoted context omitted.

You do know that there is software that runs on more than one version of Linux (or even on a *BSD, MacOS or Windows), works with more than a single version of a compiler,...?

Thats only really a problem for C/C++, which I have had the misfortune to make build systems for. The solution is not to ship complicated and bug infested build systems, it is to fix the dependency problem in the same way any other language has done so far and until we do this, ship the dependencies with the program. And if you aren't making a GUI and don't need to target Windows, just wrap it in Docker, which enforc…

> Thats only really a problem for C/C++

Even if that would be true, still every language that isn't C (or JS in the browser) needs to link or build against some C (or Fortran), which results in more or less working solutions on how to integrate with or build C sources. Of course you may not see that (as long as it works), because somebody else has wrapped that up in a package (or whatever) for your language of choice, but somebody has to do that.

> ship the dependencies with the program.

My post should have been the answer to this argument: this is not possible for example when "shipping" the source for a cross-platform library. Or a cross-platform end-user program/app. Or just about anything which isn't "just" some web-backend or a server of some kind.

Does that mean _you_ need a complicated (I'd call that "working for anything but the most basic stuff") build-system? No.

I am a bit puzzled by this phrase:

> The solution is not to ship complicated and bug infested build systems, it is to fix the dependency problem in the same way any other language has done so far

But any other language than C or C++ (sadly, _way_ less than "any other") solves that by using a complicated and bug infested build system(s) and package manager(s) or a combination of both.

Re: How I stopped worrying and loved Makefiles

#57

If you’re really looking for a tool to collect small steps/script I highly recommend you check out the ‘just’ cli tool. It’s completely replaced our use of Make and the syntax is much easier.

I've been using this on almost all of my projects, and am really pleased with it. Shell autocompletion is a nice bonus. If you also Nix, checkout `just-flake`:

https://github.com/juspay/just-flake

Re: How I stopped worrying and loved Makefiles

#59
post #50

This pattern of usage always seems like abuse. When `make` is used as a glorified front-end to `bash` scriptlets, why not use `bash` directly instead of having two-level of scripting? See: https://blog.aloni.org/posts/bash-functional-command-relay/

It is abuse, but people love ergonomics more than they love reducing dependencies

Re: How I stopped worrying and loved Makefiles

#60

If you’re really looking for a tool to collect small steps/script I highly recommend you check out the ‘just’ cli tool. It’s completely replaced our use of Make and the syntax is much easier.

Seconded. For all the million things we used Makefiles for besides compiling software, Just is much more ergonomic.

Looks interesting.
Post reply on HN