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/}" |
Nico Huber | 3e4b517 | 2024-03-16 01:00:46 +0100 | [diff] [blame] | 9 | MAJOR_VER="" |
| 10 | MINOR_VER="" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 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)" |
Nico Huber | 3e4b517 | 2024-03-16 01:00:46 +0100 | [diff] [blame] | 39 | MAJOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p')" |
| 40 | MINOR_VER="$(echo "${VERSION}" | sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p')" |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 41 | else |
| 42 | GITREV=Unknown |
Patrick Georgi | f260f51 | 2015-08-09 20:53:16 +0200 | [diff] [blame] | 43 | TIMESOURCE="date" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 44 | DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s) |
| 45 | if [ -f "${COREBOOT_VERSION_FILE}" ]; then |
Nico Huber | 3e4b517 | 2024-03-16 01:00:46 +0100 | [diff] [blame] | 46 | MAJOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p' "${COREBOOT_VERSION_FILE}")" |
| 47 | MINOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p' "${COREBOOT_VERSION_FILE}")" |
Martin Roth | 8a79a89 | 2022-11-27 18:18:10 -0700 | [diff] [blame] | 48 | fi |
Alexander Couzens | a74d569 | 2015-03-07 01:50:22 +0100 | [diff] [blame] | 49 | fi |
Alexander Couzens | 8448bd1 | 2015-03-07 01:34:55 +0100 | [diff] [blame] | 50 | |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 51 | our_date() { |
| 52 | case $(uname) in |
zbao | 5e1fb2d | 2015-09-09 05:16:40 -0400 | [diff] [blame] | 53 | NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin) |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 54 | date -r "$1" "$2" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 55 | ;; |
| 56 | *) |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 57 | date -d "@$1" "$2" |
Idwer Vollering | b558902 | 2015-03-27 00:15:20 +0100 | [diff] [blame] | 58 | esac |
| 59 | } |
| 60 | |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 61 | # Look for IASL in XGCCPATH and xcompile. Unfortunately, |
| 62 | # xcompile isn't available on the first build. |
| 63 | # If neither of those gives a valid iasl, check the path. |
| 64 | IASL="${XGCCPATH}iasl" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 65 | eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)" |
Martin Roth | de0fd07 | 2021-05-09 11:44:15 -0600 | [diff] [blame] | 66 | if [ ! -x "${IASL}" ]; then |
| 67 | IASL=$(command -v iasl) |
| 68 | fi |
Martin Roth | fd63492 | 2023-07-31 09:59:07 -0600 | [diff] [blame] | 69 | IASLVERSION="$("${IASL}" -v 2>/dev/null | grep version | sed 's/.*version //')" |
Patrick Georgi | e8367c0 | 2019-04-12 11:12:25 +0200 | [diff] [blame] | 70 | |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 71 | #Print out the information that goes into build.h |
| 72 | printf "/* build system definitions (autogenerated) */\n" |
| 73 | printf "#ifndef __BUILD_H\n" |
| 74 | printf "#define __BUILD_H\n\n" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 75 | printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\"" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 76 | |
| 77 | #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] | 78 | printf "/* timesource: %s */\n" "${TIMESOURCE}" |
| 79 | printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}" |
| 80 | printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 81 | |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 82 | printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}" |
Nico Huber | 3e4b517 | 2024-03-16 01:00:46 +0100 | [diff] [blame] | 83 | printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}" |
| 84 | printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER:-0}" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 85 | 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] | 86 | printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")" |
| 87 | printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")" |
| 88 | printf "#define COREBOOT_BUILD_DAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%d")" |
| 89 | printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%w")" |
| 90 | printf "#define COREBOOT_BUILD_EPOCH \"%s\"\n" "$(our_date "${DATE}" "+%s")" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 91 | 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] | 92 | printf "\n" |
Martin Roth | 5161b2f | 2022-11-27 18:38:13 -0700 | [diff] [blame] | 93 | printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")" |
Martin Roth | 0110e1a | 2022-12-08 19:04:02 -0700 | [diff] [blame] | 94 | printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}" |
Martin Roth | e236204 | 2015-02-12 19:32:41 -0700 | [diff] [blame] | 95 | printf "#endif\n" |