Martin Roth | 0ad5fbd | 2020-12-24 12:06:38 -0700 | [diff] [blame] | 1 | #!/usr/bin/env sh |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 2 | # |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0-only |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 4 | |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 5 | DATE="" |
| 6 | GITREV="" |
| 7 | TIMESOURCE="" |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 8 | XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}" |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 9 | |
| 10 | export LANG=C |
Alexander Couzens | 946bf93 | 2015-06-07 02:10:57 +0200 | [diff] [blame] | 11 | export LC_ALL=C |
Paul Menzel | 38a906b | 2017-09-27 15:06:57 +0200 | [diff] [blame] | 12 | export TZ=UTC0 |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 13 | |
Raul E Rangel | 4007d7f | 2019-07-09 09:52:16 -0600 | [diff] [blame] | 14 | XCOMPILE=$1 |
| 15 | |
| 16 | if [ -z "$XCOMPILE" ] || [ "$1" = "--help" ]; then |
| 17 | echo "usage: $0 <xcompile>" >&2 |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
Patrick Georgi | 237baa1 | 2019-04-12 11:08:17 +0200 | [diff] [blame] | 21 | # $1: format string |
| 22 | get_git_head_data() { |
| 23 | LANG= git log --no-show-signature -1 --format="format:$1" 2>/dev/null || \ |
| 24 | LANG= git log -1 --format="format:$1" |
| 25 | } |
| 26 | |
Martin Roth | 8ba235e | 2016-03-12 20:15:18 -0700 | [diff] [blame] | 27 | if [ "${BUILD_TIMELESS}" = "1" ]; then |
Nico Huber | 566dd35 | 2016-01-24 16:00:50 +0100 | [diff] [blame] | 28 | GITREV=Timeless |
| 29 | TIMESOURCE="fixed" |
| 30 | DATE=0 |
Alex Thiessen | 1758fd2 | 2018-01-14 11:59:47 +0000 | [diff] [blame] | 31 | elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then |
Patrick Georgi | 237baa1 | 2019-04-12 11:08:17 +0200 | [diff] [blame] | 32 | GITREV=$(get_git_head_data %h) |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 33 | TIMESOURCE=git |
Patrick Georgi | 237baa1 | 2019-04-12 11:08:17 +0200 | [diff] [blame] | 34 | DATE=$(get_git_head_data %ct) |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 35 | else |
| 36 | GITREV=Unknown |
Patrick Georgi | f260f51 | 2015-08-09 20:53:16 +0200 | [diff] [blame] | 37 | TIMESOURCE="date" |
Paul Menzel | 38a906b | 2017-09-27 15:06:57 +0200 | [diff] [blame] | 38 | DATE=$(LANG= LC_ALL=C TZ=UTC0 date +%s) |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 39 | fi |
Alexander Couzens | 8448bd1 | 2015-03-07 01:34:55 +0100 | [diff] [blame] | 40 | |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 41 | our_date() { |
| 42 | case $(uname) in |
zbao | 5e1fb2d | 2015-09-09 05:16:40 -0400 | [diff] [blame] | 43 | NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin) |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 44 | date -r $1 $2 |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 45 | ;; |
| 46 | *) |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 47 | date -d @$1 $2 |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 48 | esac |
| 49 | } |
| 50 | |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 51 | # Look for IASL in XGCCPATH and xcompile. Unfortunately, |
| 52 | # xcompile isn't available on the first build. |
| 53 | # If neither of those gives a valid iasl, check the path. |
| 54 | IASL="${XGCCPATH}iasl" |
Raul E Rangel | 4007d7f | 2019-07-09 09:52:16 -0600 | [diff] [blame] | 55 | eval $(grep ^IASL:= "$XCOMPILE" 2>/dev/null | sed s,:=,=,) |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 56 | if [ ! -x "${IASL}" ]; then |
| 57 | IASL=$(command -v iasl) |
| 58 | fi |
| 59 | IASLVERSION="$(${IASL} -v | grep version | sed 's/.*version //')" >/dev/null |
Patrick Georgi | e8367c0 | 2019-04-12 11:12:25 +0200 | [diff] [blame] | 60 | |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 61 | #Print out the information that goes into build.h |
| 62 | printf "/* build system definitions (autogenerated) */\n" |
| 63 | printf "#ifndef __BUILD_H\n" |
| 64 | printf "#define __BUILD_H\n\n" |
| 65 | printf "#define COREBOOT_VERSION %s\n" "\"$KERNELVERSION\"" |
| 66 | |
| 67 | #See if the build is running in a git repo and the git command is available |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 68 | printf "/* timesource: $TIMESOURCE */\n" |
| 69 | printf "#define COREBOOT_VERSION_TIMESTAMP $DATE\n" |
| 70 | printf "#define COREBOOT_ORIGIN_GIT_REVISION \"$GITREV\"\n" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 71 | |
| 72 | printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "$COREBOOT_EXTRA_VERSION" |
Idwer Vollering | 70f3d43 | 2021-08-04 12:56:11 +0200 | [diff] [blame] | 73 | printf "#define COREBOOT_MAJOR_VERSION %d\n#define COREBOOT_MINOR_VERSION %d\n" `git describe --match [0-9].[0-9]* | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1 \2/'` |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 74 | printf "#define COREBOOT_BUILD \"$(our_date "$DATE")\"\n" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 75 | printf "#define COREBOOT_BUILD_YEAR_BCD 0x$(our_date "$DATE" +%y)\n" |
| 76 | printf "#define COREBOOT_BUILD_MONTH_BCD 0x$(our_date "$DATE" +%m)\n" |
| 77 | printf "#define COREBOOT_BUILD_DAY_BCD 0x$(our_date "$DATE" +%d)\n" |
| 78 | printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x$(our_date "$DATE" +%w)\n" |
Alexander Couzens | cf68f34 | 2021-04-07 23:17:50 +0200 | [diff] [blame] | 79 | printf "#define COREBOOT_BUILD_EPOCH \"$(our_date "$DATE" +%s)\"\n" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 80 | printf "#define COREBOOT_DMI_DATE \"$(our_date "$DATE" +%m/%d/%Y)\"\n" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 81 | printf "\n" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 82 | printf "#define COREBOOT_COMPILE_TIME \"$(our_date "$DATE" +%T)\"\n" |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 83 | printf "#define ASL_VERSION 0x%d\n" "${IASLVERSION}" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 84 | printf "#endif\n" |