Skip to content

Instantly share code, notes, and snippets.

@pete
Created August 15, 2025 15:13
Show Gist options
  • Save pete/8bf73d3b7c37fd9938495c58bfc4240a to your computer and use it in GitHub Desktop.
Save pete/8bf73d3b7c37fd9938495c58bfc4240a to your computer and use it in GitHub Desktop.
Make in a few lines of awk
#!/usr/bin/awk
# Friend on fedi just showed me https://github.com/xonixx/makesure , I speculated that you could do make in ~10 lines of awk.
# You basically can: 9 lines, not counting comments.
# File format is a subset of make, "targ1: dep1 ... depN\n\tline1\n\tline2\ntarg2: ..."
# Invocation is different: `make.awk 'targ=whatever' Makefileish`
# To run it on Plan 9, change /usr/bin/awk to /bin/awk and "stat -c %Y" to just "mtime"
# I have not executed this code; it is a stunt-hack. I just thought it would be funny.
BEGIN{if(!length(targ))targ="all"}
/^\t/{if(length(cur) < 1) { print "no targ"; exit }; ts[cur] = ts[cur] "&&" $0; next }
!NF{cur=""; next}
$1 ~ /:$/ {cur = $1; sub(/:$/, "", cur); $1=""; dep[cur] = $0; dep["all"] = dep["all"] " " cur; next}
{print "syntaks";exit}
END{if(targ == "clean")system("rm -f " dep["all"]);else ensure(targ)}
function ensure(ct) { any=edeps(dep[ct]); if(system(ts[ct])){print "bild fail:", ct; exit} }
function edeps(t, deps){ split(deps, ds); for(i in ds){if(ts(t) < ts(ds[i]))ensure(ds[i])} }
function ts(fn){c = "stat -c %Y " fn;if((c|getline tts)>0)return tts;return 0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment