[HN Gopher] Learn Makefiles with the Tastiest Examples
___________________________________________________________________
Learn Makefiles with the Tastiest Examples
Author : ingve
Score : 37 points
Date : 2023-05-14 09:34 UTC (1 days ago)
(HTM) web link (makefiletutorial.com)
(TXT) w3m dump (makefiletutorial.com)
| dijit wrote:
| Rant incoming;
|
| I really don't like Make for the common use-cases it is being
| used for in the modern day, such as the Golang ecosystem or in
| many cases: creating docker files.
|
| Make, at its core, is a tool that is meant to help you structure
| your dependencies for incrementally building things, but people
| use it as a glorified task runner simply due to the fact that
| it's such a common build tool that it is _nearly_ always
| installed if you have a development toolchain on your machine.
|
| Go and docker already have incremental compilation built in, and
| docker doesn't give definable artifacts so you can't make other
| things depend on them either
|
| It is a powerful tool, but the syntax is hideous and has more
| jagged edges than bash does, and we aren't even _using_ it in a
| way that justifies this. Makes me so frustrated for some reason.
|
| Like everyone deciding to use a supercar to do farmwork.
| tyingq wrote:
| Agree, though it can be handy for sort of non-standard
| dependency stuff. Like if you need to pull some thing with curl
| before a build, and you want "curl succeeded (exited zero)" to
| be a pre-requisite for that build. It's often less work to get
| a Makefile to do that than a script, or the make-like things
| that come with some other languages.
|
| Maybe not the best example, but if you have a project with
| several weird things like that, make is often easier.
| mongol wrote:
| But is there not a "minimal Makefile" type of subset that you
| can use that appears really clean and tidy? My Makefiles are
| super basic and are basically task runners. Perhaps there are
| traps I have not fallen into but I value that I can count on
| them working on whatever distro I run in 5 years time.
| LeBit wrote:
| go-task is a very good task runner. Better than "just" IMO. I
| am now using go-task with every project. Right after creating
| the gitignore, I create the Taskfile.
|
| https://github.com/go-task/task
| leetrout wrote:
| Second time that has been mentioned today. I wish it wasn't
| YAML.
| williamcotton wrote:
| Put this at the top of your Makefile for a node project:
| export PATH := node_modules/.bin:$(PATH)
| alhirzel wrote:
| I end up using Makefiles for many projects that have even trivial
| stages in their execution (e.g. manual/one-off ETL pipelines). I
| do feel like I bastardize it sometimes as a convenient command
| runner or brain augmentation: sure makes it easy to remember how
| to run something if you can just type "make" or look at the top
| of the file, a cool intersection between "can get it working in 5
| minutes" and "will be readable in 5 months".
|
| The Just command runner [1] is good, but is not as ubiquitous.
|
| [1]: https://github.com/casey/just
| roqi wrote:
| Nit picking.
|
| From the article:
|
| > Popular C/C++ alternative build systems are SCons, CMake,
| Bazel, and Ninja.
|
| CMake is not a build system. It's a build system generator. A
| higher level abstraction over the problem of specifying projects,
| which greatly simplifies the work of creating and maintaining
| them. Once a CMake project is created, it is then used to create
| the actually build system. Originally it was mainly Makefile, but
| nowadays it also supports Ninja, Xcode, and Visual Studio. I'm
| sure that if there is any interest cmake could also be updated to
| generate other build systems.
| aidenn0 wrote:
| Arguably CMake is a build system; as a user you can build your
| project only by running CMake commands. The fact that it will
| run e.g. ninja or make under-the-hood can be ignored for many
| use-cases.
| banku_brougham wrote:
| My favorite glorified taskrunner is https://just.systems/, using
| the `justfile` to formalize random task steps I do in local
| development.
| kstrauser wrote:
| I've started using justfiles (https://just.systems/man/en/) for
| everything I would've previously used Makefiles for that aren't
| directly related to compiling code.
|
| Make is a wonderful way to provide a standard set of entry points
| into working with repos. For instance, if you can standardize on
| `make setup`, `make test`, `make docker`, etc. on all of your
| organization's code, it's very easy for a new develop on a
| project to start contributing quickly. You _could_ do that with
| shell scripts, but then you have to re-implement all the command
| line parsing that make gives you for free. And with justfiles,
| you can have something that looks and feels like make, but with a
| more pleasant syntax for non-compiling jobs.
|
| IMO, Just is to make as zsh/fish are to bash. It's not
| ubiquitously available, and it's not 100% backward compatible,
| but if you can convince your coworkers to adopt it as your
| standard, it makes life that much easier for everyone.
| roqi wrote:
| > And with justfiles, you can have something that looks and
| feels like make, but with a more pleasant syntax for non-
| compiling jobs.
|
| Make is a part of UNIX, which ensures it is extremely stable
| and is available on all UNIX systems. You don't get that from
| justfiles. You get syntactic sugar, but all the best parts of
| Make are thrown out of the window.
| kstrauser wrote:
| OK, that's just not true. For starters, which make? GNU and
| BSD are common variants, and aren't 100% compatible. The
| overlap is large and useful, but does mean that you have to
| be aware of it if you're using multiple systems.
|
| _For my uses_ , make offers nothing of value over just. I
| don't need any of the clever build dependency resolution
| stuff when I'm working in Python, and cargo handles
| everything better when I'm using Rust. Which isn't to say
| that make isn't enormously powerful and useful _for other
| people_ , only that its extra power causes more work than
| reward for the ways I personally want to use it. For me, just
| is everything about make that I actually use, minus all the
| complicating features that get in my way.
| portiaKane wrote:
| [dead]
| boerseth wrote:
| I recently used my blog as a way to learn how to use Make and
| Makefiles. I write posts in Markdown, and my Makefile generates
| HTML for each using Pandoc, then stitches it all together into
| one `index.html` file. The webpage behaves like a single-page-
| app, with a table-of-contents and everything, with just some CSS
| trickery.
|
| I know there are probably frameworks and tools that do this for
| me already, in ways both more flexible and robust than how I've
| done it, but I've really enjoyed the process of getting to this
| point. I started writing dumb shell scripts and struggling with
| weird cases and messy code, then learned more about Make and
| improved on things by a lot. In the end, it didn't take a lot of
| code, yet I feel like I can be really pleased with the result.
|
| I have come to really like Make, I have to say. It is probably
| used more often than it should, judging by some of the comments
| here. I've seen a few Makefiles where a substantial percentage of
| recipes are `.PHONY`, and maybe those are the cases where you
| should think about looking for a different task-runner? Not sure,
| but I enjoy Make anyway.
___________________________________________________________________
(page generated 2023-05-15 23:00 UTC)