blob: 3df3730ef2b29e54cd2942c5ae98caf2069b3a42 [file] [log] [blame]
Martin Rothe2362042015-02-12 19:32:41 -07001#!/bin/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=""
Alexander Couzens4dc11972015-06-07 02:07:34 +02008
9export LANG=C
Alexander Couzens946bf932015-06-07 02:10:57 +020010export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020011export TZ=UTC0
Alexander Couzens4dc11972015-06-07 02:07:34 +020012
Raul E Rangel4007d7f2019-07-09 09:52:16 -060013XCOMPILE=$1
14
15if [ -z "$XCOMPILE" ] || [ "$1" = "--help" ]; then
16 echo "usage: $0 <xcompile>" >&2
17 exit 1
18fi
19
Patrick Georgi237baa12019-04-12 11:08:17 +020020# $1: format string
21get_git_head_data() {
22 LANG= git log --no-show-signature -1 --format="format:$1" 2>/dev/null || \
23 LANG= git log -1 --format="format:$1"
24}
25
Martin Roth8ba235e2016-03-12 20:15:18 -070026if [ "${BUILD_TIMELESS}" = "1" ]; then
Nico Huber566dd352016-01-24 16:00:50 +010027 GITREV=Timeless
28 TIMESOURCE="fixed"
29 DATE=0
Alex Thiessen1758fd22018-01-14 11:59:47 +000030elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
Patrick Georgi237baa12019-04-12 11:08:17 +020031 GITREV=$(get_git_head_data %h)
Alexander Couzensa74d5692015-03-07 01:50:22 +010032 TIMESOURCE=git
Patrick Georgi237baa12019-04-12 11:08:17 +020033 DATE=$(get_git_head_data %ct)
Alexander Couzensa74d5692015-03-07 01:50:22 +010034else
35 GITREV=Unknown
Patrick Georgif260f512015-08-09 20:53:16 +020036 TIMESOURCE="date"
Paul Menzel38a906b2017-09-27 15:06:57 +020037 DATE=$(LANG= LC_ALL=C TZ=UTC0 date +%s)
Alexander Couzensa74d5692015-03-07 01:50:22 +010038fi
Alexander Couzens8448bd12015-03-07 01:34:55 +010039
Idwer Volleringb5589022015-03-27 00:15:20 +010040our_date() {
41case $(uname) in
zbao5e1fb2d2015-09-09 05:16:40 -040042NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
Alexander Couzens4dc11972015-06-07 02:07:34 +020043 date -r $1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010044 ;;
45*)
Alexander Couzens4dc11972015-06-07 02:07:34 +020046 date -d @$1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010047esac
48}
49
Patrick Georgie8367c02019-04-12 11:12:25 +020050IASL=util/crossgcc/xgcc/bin/iasl
Raul E Rangel4007d7f2019-07-09 09:52:16 -060051eval $(grep ^IASL:= "$XCOMPILE" 2>/dev/null | sed s,:=,=,)
Patrick Georgie8367c02019-04-12 11:12:25 +020052
Martin Rothe2362042015-02-12 19:32:41 -070053#Print out the information that goes into build.h
54printf "/* build system definitions (autogenerated) */\n"
55printf "#ifndef __BUILD_H\n"
56printf "#define __BUILD_H\n\n"
57printf "#define COREBOOT_VERSION %s\n" "\"$KERNELVERSION\""
58
59#See if the build is running in a git repo and the git command is available
Alexander Couzensa74d5692015-03-07 01:50:22 +010060printf "/* timesource: $TIMESOURCE */\n"
61printf "#define COREBOOT_VERSION_TIMESTAMP $DATE\n"
62printf "#define COREBOOT_ORIGIN_GIT_REVISION \"$GITREV\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070063
64printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "$COREBOOT_EXTRA_VERSION"
Elyes HAOUAS94ad3762019-02-15 17:39:56 +010065printf "#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 +020066printf "#define COREBOOT_BUILD \"$(our_date "$DATE")\"\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010067printf "#define COREBOOT_BUILD_YEAR_BCD 0x$(our_date "$DATE" +%y)\n"
68printf "#define COREBOOT_BUILD_MONTH_BCD 0x$(our_date "$DATE" +%m)\n"
69printf "#define COREBOOT_BUILD_DAY_BCD 0x$(our_date "$DATE" +%d)\n"
70printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x$(our_date "$DATE" +%w)\n"
71printf "#define COREBOOT_DMI_DATE \"$(our_date "$DATE" +%m/%d/%Y)\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070072printf "\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010073printf "#define COREBOOT_COMPILE_TIME \"$(our_date "$DATE" +%T)\"\n"
Patrick Georgie8367c02019-04-12 11:12:25 +020074printf "#define ASL_VERSION 0x%d\n" `$IASL -v | grep version | sed 's/.*version //'`
Martin Rothe2362042015-02-12 19:32:41 -070075printf "#endif\n"