about summary refs log tree commit diff
path: root/buildtools/stamp-date
blob: baeec3fd8e8f70da9dfc9c532d55422ee8f38b03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#
# Copyright (C) 1993 by Oliver Trepte.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  This software is provided "as is" without express or
# implied warranty.

# SOURCE_DATE_EPOCH is an environment variable as described here:
# https://reproducible-builds.org/specs/source-date-epoch/ on 2017.03.16.

# COMPILED_BY is a similar environment variable whose value is some
# description of who is doing the build.  If it is not set, we use the
# value of LOGNAME; if that is not set, we use the value of User; if that
# is not set, we use the output of program 'whoami'.

SOURCE_DATE_OR_NONE=${SOURCE_DATE_EPOCH:-NONE}

NOW_FROM_DATE_PGM=$(date +%s)
if [ "$NOW_FROM_DATE_PGM" = "%s" ]; then
    # This system's 'date' doesn't know %s.  (Solaris 10 for example).
    # Try Perl
    BUILD_DATETIME=$(perl -e 'print time()')
else
    BUILD_DATETIME=$NOW_FROM_DATE_PGM
fi

LOGNAME_OR_UNKNOWN=${LOGNAME:-UNKNOWN}
USER_OR_UNKNOWN=${USER:-$LOGNAME_OR_UNKNOWN}
COMPILED_BY_OR_UNKNOWN=${COMPILED_BY:-$USER_OR_UNKNOWN}
if [ "$COMPILED_BY_OR_UNKNOWN" = "UNKNOWN" ]; then
    COMPILED_BY=$(whoami)
else
    COMPILED_BY=$COMPILED_BY_OR_UNKNOWN
fi

echo "/* This file tells some facts about the building of the package */"
echo "/* DO NOT EDIT - THIS FILE IS MAINTAINED AUTOMATICALLY */"
echo "/* Created by the program 'stamp-date'  */"
if [ "$SOURCE_DATE_OR_NONE" != "NONE" ]; then
  echo "#define SOURCE_DATETIME $SOURCE_DATE_OR_NONE"
fi
echo "#define BUILD_DATETIME $BUILD_DATETIME"
echo "#define COMPILED_BY \"$COMPILED_BY\""