blob: c898fb6e3fb8c8521bd08503c6f7e222bd7400e7 [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/}"
Alexander Couzens4dc11972015-06-07 02:07:34 +02009
10export LANG=C
Alexander Couzens946bf932015-06-07 02:10:57 +020011export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020012export TZ=UTC0
Alexander Couzens4dc11972015-06-07 02:07:34 +020013
Raul E Rangel4007d7f2019-07-09 09:52:16 -060014XCOMPILE=$1
15
16if [ -z "$XCOMPILE" ] || [ "$1" = "--help" ]; then
17 echo "usage: $0 <xcompile>" >&2
18 exit 1
19fi
20
Patrick Georgi237baa12019-04-12 11:08:17 +020021# $1: format string
22get_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 Roth8ba235e2016-03-12 20:15:18 -070027if [ "${BUILD_TIMELESS}" = "1" ]; then
Nico Huber566dd352016-01-24 16:00:50 +010028 GITREV=Timeless
29 TIMESOURCE="fixed"
30 DATE=0
Alex Thiessen1758fd22018-01-14 11:59:47 +000031elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
Patrick Georgi237baa12019-04-12 11:08:17 +020032 GITREV=$(get_git_head_data %h)
Alexander Couzensa74d5692015-03-07 01:50:22 +010033 TIMESOURCE=git
Patrick Georgi237baa12019-04-12 11:08:17 +020034 DATE=$(get_git_head_data %ct)
Alexander Couzensa74d5692015-03-07 01:50:22 +010035else
36 GITREV=Unknown
Patrick Georgif260f512015-08-09 20:53:16 +020037 TIMESOURCE="date"
Paul Menzel38a906b2017-09-27 15:06:57 +020038 DATE=$(LANG= LC_ALL=C TZ=UTC0 date +%s)
Alexander Couzensa74d5692015-03-07 01:50:22 +010039fi
Alexander Couzens8448bd12015-03-07 01:34:55 +010040
Idwer Volleringb5589022015-03-27 00:15:20 +010041our_date() {
42case $(uname) in
zbao5e1fb2d2015-09-09 05:16:40 -040043NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
Alexander Couzens4dc11972015-06-07 02:07:34 +020044 date -r $1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010045 ;;
46*)
Alexander Couzens4dc11972015-06-07 02:07:34 +020047 date -d @$1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010048esac
49}
50
Martin Rothde0fd072021-05-09 11:44:15 -060051# 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.
54IASL="${XGCCPATH}iasl"
Raul E Rangel4007d7f2019-07-09 09:52:16 -060055eval $(grep ^IASL:= "$XCOMPILE" 2>/dev/null | sed s,:=,=,)
Martin Rothde0fd072021-05-09 11:44:15 -060056if [ ! -x "${IASL}" ]; then
57 IASL=$(command -v iasl)
58fi
59IASLVERSION="$(${IASL} -v | grep version | sed 's/.*version //')" >/dev/null
Patrick Georgie8367c02019-04-12 11:12:25 +020060
Martin Rothe2362042015-02-12 19:32:41 -070061#Print out the information that goes into build.h
62printf "/* build system definitions (autogenerated) */\n"
63printf "#ifndef __BUILD_H\n"
64printf "#define __BUILD_H\n\n"
65printf "#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 Couzensa74d5692015-03-07 01:50:22 +010068printf "/* timesource: $TIMESOURCE */\n"
69printf "#define COREBOOT_VERSION_TIMESTAMP $DATE\n"
70printf "#define COREBOOT_ORIGIN_GIT_REVISION \"$GITREV\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070071
72printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "$COREBOOT_EXTRA_VERSION"
Elyes HAOUAS94ad3762019-02-15 17:39:56 +010073printf "#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]\+\).*/\1 \2/'`
Alexander Couzens4dc11972015-06-07 02:07:34 +020074printf "#define COREBOOT_BUILD \"$(our_date "$DATE")\"\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010075printf "#define COREBOOT_BUILD_YEAR_BCD 0x$(our_date "$DATE" +%y)\n"
76printf "#define COREBOOT_BUILD_MONTH_BCD 0x$(our_date "$DATE" +%m)\n"
77printf "#define COREBOOT_BUILD_DAY_BCD 0x$(our_date "$DATE" +%d)\n"
78printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x$(our_date "$DATE" +%w)\n"
Alexander Couzenscf68f342021-04-07 23:17:50 +020079printf "#define COREBOOT_BUILD_EPOCH \"$(our_date "$DATE" +%s)\"\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010080printf "#define COREBOOT_DMI_DATE \"$(our_date "$DATE" +%m/%d/%Y)\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070081printf "\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010082printf "#define COREBOOT_COMPILE_TIME \"$(our_date "$DATE" +%T)\"\n"
Martin Rothde0fd072021-05-09 11:44:15 -060083printf "#define ASL_VERSION 0x%d\n" "${IASLVERSION}"
Martin Rothe2362042015-02-12 19:32:41 -070084printf "#endif\n"