blob: b381ab27767b0dac6bfb1d32bafaaa378ca8bac1 [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/}"
Nico Huber3e4b5172024-03-16 01:00:46 +01009MAJOR_VER=""
10MINOR_VER=""
Martin Roth8a79a892022-11-27 18:18:10 -070011COREBOOT_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() {
Nico Huberf9aec6e2023-07-16 00:59:55 +020026 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 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)"
Nico Huber3e4b5172024-03-16 01:00:46 +010039 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 Couzensa74d5692015-03-07 01:50:22 +010041else
42 GITREV=Unknown
Patrick Georgif260f512015-08-09 20:53:16 +020043 TIMESOURCE="date"
Martin Roth8a79a892022-11-27 18:18:10 -070044 DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s)
45 if [ -f "${COREBOOT_VERSION_FILE}" ]; then
Nico Huber3e4b5172024-03-16 01:00:46 +010046 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 Roth8a79a892022-11-27 18:18:10 -070048 fi
Alexander Couzensa74d5692015-03-07 01:50:22 +010049fi
Alexander Couzens8448bd12015-03-07 01:34:55 +010050
Idwer Volleringb5589022015-03-27 00:15:20 +010051our_date() {
52case $(uname) in
zbao5e1fb2d2015-09-09 05:16:40 -040053NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
Martin Roth5161b2f2022-11-27 18:38:13 -070054 date -r "$1" "$2"
Idwer Volleringb5589022015-03-27 00:15:20 +010055 ;;
56*)
Martin Roth5161b2f2022-11-27 18:38:13 -070057 date -d "@$1" "$2"
Idwer Volleringb5589022015-03-27 00:15:20 +010058esac
59}
60
Martin Rothde0fd072021-05-09 11:44:15 -060061# 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.
64IASL="${XGCCPATH}iasl"
Martin Roth5161b2f2022-11-27 18:38:13 -070065eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)"
Martin Rothde0fd072021-05-09 11:44:15 -060066if [ ! -x "${IASL}" ]; then
67 IASL=$(command -v iasl)
68fi
Martin Rothfd634922023-07-31 09:59:07 -060069IASLVERSION="$("${IASL}" -v 2>/dev/null | grep version | sed 's/.*version //')"
Patrick Georgie8367c02019-04-12 11:12:25 +020070
Martin Rothe2362042015-02-12 19:32:41 -070071#Print out the information that goes into build.h
72printf "/* build system definitions (autogenerated) */\n"
73printf "#ifndef __BUILD_H\n"
74printf "#define __BUILD_H\n\n"
Martin Roth5161b2f2022-11-27 18:38:13 -070075printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\""
Martin Rothe2362042015-02-12 19:32:41 -070076
77#See if the build is running in a git repo and the git command is available
Martin Roth5161b2f2022-11-27 18:38:13 -070078printf "/* timesource: %s */\n" "${TIMESOURCE}"
79printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}"
80printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
Martin Rothe2362042015-02-12 19:32:41 -070081
Martin Roth5161b2f2022-11-27 18:38:13 -070082printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
Nico Huber3e4b5172024-03-16 01:00:46 +010083printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}"
84printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER:-0}"
Martin Roth5161b2f2022-11-27 18:38:13 -070085printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
Martin Roth0110e1a2022-12-08 19:04:02 -070086printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")"
87printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"
88printf "#define COREBOOT_BUILD_DAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%d")"
89printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%w")"
90printf "#define COREBOOT_BUILD_EPOCH \"%s\"\n" "$(our_date "${DATE}" "+%s")"
Martin Roth5161b2f2022-11-27 18:38:13 -070091printf "#define COREBOOT_DMI_DATE \"%s\"\n" "$(our_date "${DATE}" "+%m/%d/%Y")"
Martin Rothe2362042015-02-12 19:32:41 -070092printf "\n"
Martin Roth5161b2f2022-11-27 18:38:13 -070093printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")"
Martin Roth0110e1a2022-12-08 19:04:02 -070094printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}"
Martin Rothe2362042015-02-12 19:32:41 -070095printf "#endif\n"