blob: 8da68ba44523582c4e297fea5b84d2fd8e55cfdd [file] [log] [blame]
Martin Rothe2362042015-02-12 19:32:41 -07001#!/bin/sh
2
3# This file is part of the coreboot project.
4#
5# Copyright (C) 2014 Sage Electronic Engineering, LLC.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
Martin Rothe2362042015-02-12 19:32:41 -070016
Alexander Couzensa74d5692015-03-07 01:50:22 +010017DATE=""
18GITREV=""
19TIMESOURCE=""
Alexander Couzens4dc11972015-06-07 02:07:34 +020020
21export LANG=C
Alexander Couzens946bf932015-06-07 02:10:57 +020022export LC_ALL=C
Paul Menzel38a906b2017-09-27 15:06:57 +020023export TZ=UTC0
Alexander Couzens4dc11972015-06-07 02:07:34 +020024
Raul E Rangel4007d7f2019-07-09 09:52:16 -060025XCOMPILE=$1
26
27if [ -z "$XCOMPILE" ] || [ "$1" = "--help" ]; then
28 echo "usage: $0 <xcompile>" >&2
29 exit 1
30fi
31
Patrick Georgi237baa12019-04-12 11:08:17 +020032# $1: format string
33get_git_head_data() {
34 LANG= git log --no-show-signature -1 --format="format:$1" 2>/dev/null || \
35 LANG= git log -1 --format="format:$1"
36}
37
Martin Roth8ba235e2016-03-12 20:15:18 -070038if [ "${BUILD_TIMELESS}" = "1" ]; then
Nico Huber566dd352016-01-24 16:00:50 +010039 GITREV=Timeless
40 TIMESOURCE="fixed"
41 DATE=0
Alex Thiessen1758fd22018-01-14 11:59:47 +000042elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
Patrick Georgi237baa12019-04-12 11:08:17 +020043 GITREV=$(get_git_head_data %h)
Alexander Couzensa74d5692015-03-07 01:50:22 +010044 TIMESOURCE=git
Patrick Georgi237baa12019-04-12 11:08:17 +020045 DATE=$(get_git_head_data %ct)
Alexander Couzensa74d5692015-03-07 01:50:22 +010046else
47 GITREV=Unknown
Patrick Georgif260f512015-08-09 20:53:16 +020048 TIMESOURCE="date"
Paul Menzel38a906b2017-09-27 15:06:57 +020049 DATE=$(LANG= LC_ALL=C TZ=UTC0 date +%s)
Alexander Couzensa74d5692015-03-07 01:50:22 +010050fi
Alexander Couzens8448bd12015-03-07 01:34:55 +010051
Idwer Volleringb5589022015-03-27 00:15:20 +010052our_date() {
53case $(uname) in
zbao5e1fb2d2015-09-09 05:16:40 -040054NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
Alexander Couzens4dc11972015-06-07 02:07:34 +020055 date -r $1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010056 ;;
57*)
Alexander Couzens4dc11972015-06-07 02:07:34 +020058 date -d @$1 $2
Idwer Volleringb5589022015-03-27 00:15:20 +010059esac
60}
61
Patrick Georgie8367c02019-04-12 11:12:25 +020062IASL=util/crossgcc/xgcc/bin/iasl
Raul E Rangel4007d7f2019-07-09 09:52:16 -060063eval $(grep ^IASL:= "$XCOMPILE" 2>/dev/null | sed s,:=,=,)
Patrick Georgie8367c02019-04-12 11:12:25 +020064
Martin Rothe2362042015-02-12 19:32:41 -070065#Print out the information that goes into build.h
66printf "/* build system definitions (autogenerated) */\n"
67printf "#ifndef __BUILD_H\n"
68printf "#define __BUILD_H\n\n"
69printf "#define COREBOOT_VERSION %s\n" "\"$KERNELVERSION\""
70
71#See if the build is running in a git repo and the git command is available
Alexander Couzensa74d5692015-03-07 01:50:22 +010072printf "/* timesource: $TIMESOURCE */\n"
73printf "#define COREBOOT_VERSION_TIMESTAMP $DATE\n"
74printf "#define COREBOOT_ORIGIN_GIT_REVISION \"$GITREV\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070075
76printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "$COREBOOT_EXTRA_VERSION"
Elyes HAOUAS94ad3762019-02-15 17:39:56 +010077printf "#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 +020078printf "#define COREBOOT_BUILD \"$(our_date "$DATE")\"\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010079printf "#define COREBOOT_BUILD_YEAR_BCD 0x$(our_date "$DATE" +%y)\n"
80printf "#define COREBOOT_BUILD_MONTH_BCD 0x$(our_date "$DATE" +%m)\n"
81printf "#define COREBOOT_BUILD_DAY_BCD 0x$(our_date "$DATE" +%d)\n"
82printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x$(our_date "$DATE" +%w)\n"
83printf "#define COREBOOT_DMI_DATE \"$(our_date "$DATE" +%m/%d/%Y)\"\n"
Martin Rothe2362042015-02-12 19:32:41 -070084printf "\n"
Idwer Volleringb5589022015-03-27 00:15:20 +010085printf "#define COREBOOT_COMPILE_TIME \"$(our_date "$DATE" +%T)\"\n"
Patrick Georgie8367c02019-04-12 11:12:25 +020086printf "#define ASL_VERSION 0x%d\n" `$IASL -v | grep version | sed 's/.*version //'`
Martin Rothe2362042015-02-12 19:32:41 -070087printf "#endif\n"