Skip to content

Instantly share code, notes, and snippets.

@rrbutani
Last active July 9, 2025 08:36
Show Gist options
  • Save rrbutani/2132f1cae871e7b33d20e93b4978fa5f to your computer and use it in GitHub Desktop.
Save rrbutani/2132f1cae871e7b33d20e93b4978fa5f to your computer and use it in GitHub Desktop.
use nix -p gnumake
.PHONY: clean
clean:
rm -rf *.out
top.out: c.out b.out
touch top.out
c.out:
touch c.out
b.out: a.out
@if [[ ! -f b.out ]]; then echo "touch b.out"; touch b.out; elif [[ $${FORCE_REBUILD+x} ]]; then echo "touch b.out (forced)"; touch b.out; else echo "No rebuild b."; fi
a.out:
touch a.out
.DEFAULT_GOAL := top.out
# you can update `a` and `b` will not be rebuilt. thus, changes to `a` do not trigger rebuilds of `top.out`.
#
# however note that until `b` is rebuilt, it will always be built because `a` is newer than `b`
# compare with ninja's `restat`: https://ninja-build.org/manual.html
#
# we get the "ECO"-esque functionality (i.e. build actions can say that dependents do not need to be rebuilt)
#
# however the "re stat" part is missing: we cannot tell Make that the changes in deps (i.e. the changes in A)
# have been "accounted for" already and thus don't need to trigger a rebuild of the target (b)
#
# this makes sense. `ninja` has it's `.ninja_log` file in which it records modification times; Make has no
# such machinery. it just checks the filesystem. in other words: there's no where for make to even _record_
# this information (i.e. that changes of A not newer than <some time> needn't retrigger B (for the artifact
# built at <some older time>))
#
# also see: https://fuchsia.dev/fuchsia-src/development/build/ninja_how#restat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment