║│ • cksum │║
║│ • cp │║
║│ • date │║
+║│ • diff │║
║│ • file │║
║│ • find │║
║│ • grep │║
║│ • git (optional) │║
║│ • ln │║
-║│ • ls │║
║│ • mkdir │║
║│ • mv │║
║│ • od │║
CKSUM := cksum
CP := cp
DATE := date
+DIFF := diff
FILE := file
FIND := find
GIT := git
GREP := grep
LN := ln
-LS := ls
MKDIR := mkdir
MV := mv
OD := od
# (callable) Get the modified time of the provided file.
#
-# Only the date·time information available via `ls -l´ is supported; that is, only minute precision for files newer than six months, and only day precision for files which are older.
-# This is, unfortunately, the best that can be done in pure Posix as of now.
+# This touches a file containing only a newline and then diffs it with `/dev/null´ and extracts the timestamp from the diff.
+# Interestingly, on Macintosh, the format of `diff -u´ is only Posixy (including a fractional component and timezone) when `COMMAND_MODE=legacy´; however, the timezone will always be zero and the fractional component is ignorable, so it’s not necessary to worry about that here.
#
-# There is an easier implementation which provides the full date·time by archiving an empty file and then reading it back out of the archive :—
-#
-# $(shell LC_TIME=POSIX TZ=UTC0 $(TOUCH) -m -r $(callquote,$1) $(BUILDDIR)/.mtime && $(PAX) -w -x ustar $(BUILDDIR)/.mtime | $(PAX) -v -o 'listopt=%(mtime=%Y-%m-%dT%H:%M:%SZ)T')
-#
-# However, it depends on the `listopt´ option in `pax´, which (despite being specified in Posix) no implementations actually support.
+# The diff will always have an exit status of 1, but this is ignored by piping into Sed.
#
# ☡ This variable creates a subshell every time it is computed.
-override modtime = $(shell { $(DATE) -u '+%Y-%m'; LC_TIME=POSIX TZ=UTC0 ls -q -A -l $(call quote,$1) | $(SED) 's/\([^ ]* \{1,\}\)\{5\}\(\([^ ]* \{1,\}\)\{3\}\).*/\2/;s/ \([0123456789]\) / 0\1 /;s/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/;s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/;s/\([0123456789]\{2\}\) *\([0123456789]\{2\}\) *\([0123456789]\{4\}\)/\3-\1-\2T00:00:00Z/;s/\([0123456789]\{2\}\) *\([0123456789]\{2\}\) *\([0123456789:]\{5\}\)/XXXX-\1-\2T\3:00Z/'; } | $(TR) -d ' ' | $(AWK) -F '-' 'NR==1{year=$$1;month=$$2}$$1=="XXXX"&&$$2<=month{print year"-"$$2"-"$$3}$$1=="XXXX"&&$$2>month{print year-1"-"$$2"-"$$3}NR>1&&$$1!="XXXX"')
+override modtime = $(shell if $(TEST) ! -f $(call quote,$(BUILDDIR)/.mtime); then $(PRINTF) '%b' '\n' > $(call quote,$(BUILDDIR)/.mtime); fi; $(TOUCH) -r $(call quote,$1) $(call quote,$(BUILDDIR)/.mtime); TZ=UTC0 $(DIFF) -u $(call quote,$(BUILDDIR)/.mtime) /dev/null | $(SED) '1!d;s/.* \([^ ]*\) \([^ ]*\).*$$/\1T\2Z/')
# ─ ¶ Recipe Variable Definitions ─────────────────────────────────────
- `cksum`
- `cp`
- `date`
+- `diff`
- `file`
- `find`
- `git` (optional; set `GIT=` to disable)
- `grep`
- `ln`
-- `ls`
- `mkdir`
- `mv`
- `od`
- **`SRCTIME`:**
The time at which the source file was last modified.
- Due to limitations in Posix, this time will only have minute
- precision if the file was modified in the last six months, and will
- only have day precision if the file is older.
- Users should not expect this value to be particularly stable.
- **`THISREV`:**
The value of the `THISREV` variable (if present).