blob: b4878c64076d05ae9358810661f77b7c34eb6bae [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env sh
Martin Rothe2362042015-02-12 19:32:41 -07002#
Patrick Georgi7333a112020-05-08 20:48:04 +02003# SPDX-License-Identifier: GPL-2.0-only
Martin Rothe2362042015-02-12 19:32:41 -07004
Alexander Couzensa74d5692015-03-07 01:50:22 +01005DATE=""
6GITREV=""
7TIMESOURCE=""
Martin Rothde0fd072021-05-09 11:44:15 -06008XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}"
Martin Roth8a79a892022-11-27 18:18:10 -07009MAJOR_VER="0"
10MINOR_VER="0"
11COREBOOT_VERSION_FILE=".coreboot-version"
Alexander Couzens4dc11972015-06-07 02:07:34 +020012
13export LANG=C
Alexander Couzens946bf932015-06-07 02:10:57 +020014export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020015export TZ=UTC0
Alexander Couzens4dc11972015-06-07 02:07:34 +020016
Raul E Rangel4007d7f2019-07-09 09:52:16 -060017XCOMPILE=$1
18
Martin Roth5161b2f2022-11-27 18:38:13 -070019if [ -z "${XCOMPILE}" ] || [ "$1" = "--help" ]; then
Raul E Rangel4007d7f2019-07-09 09:52:16 -060020 echo "usage: $0 <xcompile>" >&2
21 exit 1
22fi
23
Patrick Georgi237baa12019-04-12 11:08:17 +020024# $1: format string
25get_git_head_data() {
Martin Roth5161b2f2022-11-27 18:38:13 -070026 LANG="" git log --no-show-signature -1 --format="format:$1" 2>/dev/null || \
27 LANG="" git log -1 --format="format:$1"
Patrick Georgi237baa12019-04-12 11:08:17 +020028}
29
Martin Roth8ba235e2016-03-12 20:15:18 -070030if [ "${BUILD_TIMELESS}" = "1" ]; then
Nico Huber566dd352016-01-24 16:00:50 +010031 GITREV=Timeless
32 TIMESOURCE="fixed"
33 DATE=0
Alex Thiessen1758fd22018-01-14 11:59:47 +000034elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
Martin Roth5161b2f2022-11-27 18:38:13 -070035 GITREV="$(get_git_head_data %h)"
Alexander Couzensa74d5692015-03-07 01:50:22 +010036 TIMESOURCE=git
Martin Roth5161b2f2022-11-27 18:38:13 -070037 DATE="$(get_git_head_data %ct)"
Martin Roth8a79a892022-11-27 18:18:10 -070038 VERSION="$(git describe)"
Reka Norman5e780902022-12-15 15:04:11 +110039 # 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 Couzensa74d5692015-03-07 01:50:22 +010045else
46 GITREV=Unknown
Patrick Georgif260f512015-08-09 20:53:16 +020047 TIMESOURCE="date"
Martin Roth8a79a892022-11-27 18:18:10 -070048 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 Couzensa74d5692015-03-07 01:50:22 +010053fi
Alexander Couzens8448bd12015-03-07 01:34:55 +010054
Idwer Volleringb5589022015-03-27 00:15:20 +010055our_date() {
56case $(uname) in
zbao5e1fb2d2015-09-09 05:16:40 -040057NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
Martin Roth5161b2f2022-11-27 18:38:13 -070058 date -r "$1" "$2"
Idwer Volleringb5589022015-03-27 00:15:20 +010059 ;;
60*)
Martin Roth5161b2f2022-11-27 18:38:13 -070061 date -d "@$1" "$2"
Idwer Volleringb5589022015-03-27 00:15:20 +010062esac
63}
64
Martin Rothde0fd072021-05-09 11:44:15 -060065# 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.
68IASL="${XGCCPATH}iasl"
Martin Roth5161b2f2022-11-27 18:38:13 -070069eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)"
Martin Rothde0fd072021-05-09 11:44:15 -060070if [ ! -x "${IASL}" ]; then
71 IASL=$(command -v iasl)
72fi
73IASLVERSION="$(${IASL} -v | grep version | sed 's/.*version //')" >/dev/null
Patrick Georgie8367c02019-04-12 11:12:25 +020074
Martin Rothe2362042015-02-12 19:32:41 -070075#Print out the information that goes into build.h
76printf "/* build system definitions (autogenerated) */\n"
77printf "#ifndef __BUILD_H\n"
78printf "#define __BUILD_H\n\n"
Martin Roth5161b2f2022-11-27 18:38:13 -070079printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\""
Martin Rothe2362042015-02-12 19:32:41 -070080
81#See if the build is running in a git repo and the git command is available
Martin Roth5161b2f2022-11-27 18:38:13 -070082printf "/* timesource: %s */\n" "${TIMESOURCE}"
83printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}"
84printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
Martin Rothe2362042015-02-12 19:32:41 -070085
Martin Roth5161b2f2022-11-27 18:38:13 -070086printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
Martin Roth0110e1a2022-12-08 19:04:02 -070087printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER}"
88printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER}"
Martin Roth5161b2f2022-11-27 18:38:13 -070089printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
Martin Roth0110e1a2022-12-08 19:04:02 -070090printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")"
91printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"
92printf "#define COREBOOT_BUILD_DAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%d")"
93printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%w")"
94printf "#define COREBOOT_BUILD_EPOCH \"%s\"\n" "$(our_date "${DATE}" "+%s")"
Martin Roth5161b2f2022-11-27 18:38:13 -070095printf "#define COREBOOT_DMI_DATE \"%s\"\n" "$(our_date "${DATE}" "+%m/%d/%Y")"
Martin Rothe2362042015-02-12 19:32:41 -070096printf "\n"
Martin Roth5161b2f2022-11-27 18:38:13 -070097printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")"
Martin Roth0110e1a2022-12-08 19:04:02 -070098printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}"
Martin Rothe2362042015-02-12 19:32:41 -070099printf "#endif\n"