wordgrinder
wordgrinder copied to clipboard
Setting SOURCE_DATE_EPOCH doesn't work on non-GNU systems
If I set SOURCE_DATE_EPOCH to something when running make, the DATE gets set to the empty string.
If I build with hide set to nothing, then I see that the reason for this is:
/bin/sh: LC_ALL: command not found
If I fix that by replacing LC_ALL with LC_ALL=C in your Makefile, then it still fails with:
date: illegal option -- -
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
I am on macOS, which uses a BSD-derived date command that does not understand the GNU-specific options you are passing to it.
Here are links to the various manuals:
- https://www.unix.com/man-page/mojave/1/date/
- https://man.openbsd.org/date.1
- https://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html
There doesn't seem to be a cross-POSIX way of doing what @davidgiven wants
to do, which is convert a Unix timestamp into a day month year in UTC. The BSDs
and macOS would need something like date -r "$SOURCE_DATE_EPOCH". Meanwhile,
GNU and Busybox systems need to use -d or --date. Maybe the Makefile (or
build.lua) could check for which system the user is on and choose a date
command that way.
This can be done entirely in Lua with
os.date('!%d %B %Y', tonumber(os.getenv('SOURCE_DATE_EPOCH')))
~~Interesting note, I'm pretty sure this is undocumented.~~ It also doesn't support the leading dash that removes zero padding.
I'll admit, I think that patch was actually an NMA from Debian, so I never actually thought about this at all.
The easiest thing is probably to do it in Lua.