Skip to content

Commit

Permalink
build: man: improve usage of date command
Browse files Browse the repository at this point in the history
Changes:

* Use the exact same source date string for all `date` invocations
* Use `date -d` instead of `date --date=`
* Only use `-d` if supported

The `date` command on ChromeOS does not support the `-d` / `--date=`
option[1] [2]:

    # using `date --date=`
    ./mkman.sh 0.9.72 src/man/firejail.man firejail.1
    date: invalid option -- '-'
    date: usage: date [-u] [-c] [-r seconds] [+format]
    make: *** [Makefile:42: firejail.1] Error 1

    # using `date -d`
    ./mkman.sh 0.9.72 src/man/firejail.man firejail.1
    date: invalid option -- 'd'
    date: usage: date [-u] [-c] [-r seconds] [+format]
    make: *** [Makefile:42: firejail.1] Error 1

Environment: zoneinfo 2024a on ChromeOS M125.

Relates to netblue30#193.

Fixes netblue30#6403.

[1] netblue30#6403 (comment)
[2] netblue30#6403 (comment)

Reported-by: @Zopolis4
  • Loading branch information
kmk3 committed Jul 11, 2024
1 parent 6c8b104 commit e9ba1f9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/man/mkman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@

set -e

MONTH="$(LC_ALL=C date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%b)"
YEAR="$(LC_ALL=C date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y)"
test -z "$SOURCE_DATE_EPOCH" && SOURCE_DATE_EPOCH="$(date +%s)"

if LC_ALL=C date -d "@$SOURCE_DATE_EPOCH" >/dev/null 2>/dev/null; then
MONTH="$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" +%b)"
YEAR="$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" +%Y)"
else
MONTH="$(LC_ALL=C date -u +%b)"
YEAR="$(LC_ALL=C date -u +%Y)"
fi

sed \
-e "s/VERSION/$1/g" \
Expand Down

0 comments on commit e9ba1f9

Please sign in to comment.