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/}" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 9 | MAJOR_VER="0" |
| 10 | MINOR_VER="0" |
| 11 | COREBOOT_VERSION_FILE=".coreboot-version" |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 12 | |
| 13 | export LANG=C |
Alexander Couzens | 946bf93 | 2015-06-07 02:10:57 +0200 | [diff] [blame] | 14 | export LC_ALL=C |
Paul Menzel | 38a906b | 2017-09-27 15:06:57 +0200 | [diff] [blame] | 15 | export TZ=UTC0 |
Alexander Couzens | 4dc1197 | 2015-06-07 02:07:34 +0200 | [diff] [blame] | 16 | |
Raul E Rangel | 4007d7f | 2019-07-09 09:52:16 -0600 | [diff] [blame] | 17 | XCOMPILE=$1 |
| 18 | |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 19 | if [ -z "${XCOMPILE}" ] || [ "$1" = "--help" ]; then |
Raul E Rangel | 4007d7f | 2019-07-09 09:52:16 -0600 | [diff] [blame] | 20 | echo "usage: $0 <xcompile>" >&2 |
| 21 | exit 1 |
| 22 | fi |
| 23 | |
Patrick Georgi | 237baa1 | 2019-04-12 11:08:17 +0200 | [diff] [blame] | 24 | # $1: format string |
| 25 | get_git_head_data() { |
Nico Huber | f9aec6e | 2023-07-16 00:59:55 +0200 | [diff] [blame] | 26 | LANG="" git log --no-show-signature --abbrev=12 -1 --format="format:$1" 2>/dev/null || \ |
| 27 | LANG="" git log --abbrev=12 -1 --format="format:$1" |
Patrick Georgi | 237baa1 | 2019-04-12 11:08:17 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Martin Roth | 8ba235e | 2016-03-12 20:15:18 -0700 | [diff] [blame] | 30 | if [ "${BUILD_TIMELESS}" = "1" ]; then |
Nico Huber | 566dd35 | 2016-01-24 16:00:50 +0100 | [diff] [blame] | 31 | GITREV=Timeless |
| 32 | TIMESOURCE="fixed" |
| 33 | DATE=0 |
Alex Thiessen | 1758fd2 | 2018-01-14 11:59:47 +0000 | [diff] [blame] | 34 | elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 35 | GITREV="$(get_git_head_data %h)" |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 36 | TIMESOURCE=git |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 37 | DATE="$(get_git_head_data %ct)" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 38 | VERSION="$(git describe)" |
Reka Norman | 5e78090 | 2022-12-15 15:04:11 +1100 | [diff] [blame] | 39 | # Only use the `git describe` output if the tag is in the expected <major>.<minor> |
| 40 | # format, e.g. 4.18. Forks of coreboot may have other tags in different formats. |
| 41 | if echo "${VERSION}" | grep -q "^[0-9]\.[0-9][0-9]*"; then |
| 42 | MAJOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/')" |
| 43 | MINOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/')" |
| 44 | fi |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 45 | else |
| 46 | GITREV=Unknown |
Patrick Georgi | f260f51 | 2015-08-09 20:53:16 +0200 | [diff] [blame] | 47 | TIMESOURCE="date" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 48 | DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s) |
| 49 | if [ -f "${COREBOOT_VERSION_FILE}" ]; then |
| 50 | MAJOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/' "${COREBOOT_VERSION_FILE}")" |
| 51 | MINOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/' "${COREBOOT_VERSION_FILE}")" |
| 52 | fi |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 53 | fi |
Alexander Couzens | 8448bd1 | 2015-03-07 01:34:55 +0100 | [diff] [blame] | 54 | |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 55 | our_date() { |
| 56 | case $(uname) in |
zbao | 5e1fb2d | 2015-09-09 05:16:40 -0400 | [diff] [blame] | 57 | NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin) |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 58 | date -r "$1" "$2" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 59 | ;; |
| 60 | *) |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 61 | date -d "@$1" "$2" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 62 | esac |
| 63 | } |
| 64 | |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 65 | # Look for IASL in XGCCPATH and xcompile. Unfortunately, |
| 66 | # xcompile isn't available on the first build. |
| 67 | # If neither of those gives a valid iasl, check the path. |
| 68 | IASL="${XGCCPATH}iasl" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 69 | eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)" |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 70 | if [ ! -x "${IASL}" ]; then |
| 71 | IASL=$(command -v iasl) |
| 72 | fi |
| 73 | IASLVERSION="$(${IASL} -v | grep version | sed 's/.*version //')" >/dev/null |
Patrick Georgi | e8367c0 | 2019-04-12 11:12:25 +0200 | [diff] [blame] | 74 | |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 75 | #Print out the information that goes into build.h |
| 76 | printf "/* build system definitions (autogenerated) */\n" |
| 77 | printf "#ifndef __BUILD_H\n" |
| 78 | printf "#define __BUILD_H\n\n" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 79 | printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\"" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 80 | |
| 81 | #See if the build is running in a git repo and the git command is available |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 82 | printf "/* timesource: %s */\n" "${TIMESOURCE}" |
| 83 | printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}" |
| 84 | printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 85 | |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 86 | printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}" |
Martin Roth | 0110e1a | 2022-12-08 19:04:02 -0700 | [diff] [blame] | 87 | printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER}" |
| 88 | printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER}" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 89 | printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")" |
Martin Roth | 0110e1a | 2022-12-08 19:04:02 -0700 | [diff] [blame] | 90 | printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")" |
| 91 | printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")" |
| 92 | printf "#define COREBOOT_BUILD_DAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%d")" |
| 93 | printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%w")" |
| 94 | printf "#define COREBOOT_BUILD_EPOCH \"%s\"\n" "$(our_date "${DATE}" "+%s")" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 95 | printf "#define COREBOOT_DMI_DATE \"%s\"\n" "$(our_date "${DATE}" "+%m/%d/%Y")" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 96 | printf "\n" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 97 | printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")" |
Martin Roth | 0110e1a | 2022-12-08 19:04:02 -0700 | [diff] [blame] | 98 | printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 99 | printf "#endif\n" |