• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env sh
2#
3# SPDX-License-Identifier: GPL-2.0-only
4
5DATE=""
6GITREV=""
7TIMESOURCE=""
8XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}"
9MAJOR_VER=""
10MINOR_VER=""
11COREBOOT_VERSION_FILE=".coreboot-version"
12
13export LANG=C
14export LC_ALL=C
15export TZ=UTC0
16
17XCOMPILE=$1
18
19if [ -z "${XCOMPILE}" ] || [ "$1" = "--help" ]; then
20	echo "usage: $0 <xcompile>" >&2
21	exit 1
22fi
23
24# $1: format string
25get_git_head_data() {
26	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"
28}
29
30if [ "${BUILD_TIMELESS}" = "1" ]; then
31	GITREV=Timeless
32	TIMESOURCE="fixed"
33	DATE=0
34elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
35	GITREV="$(get_git_head_data %h)"
36	TIMESOURCE=git
37	DATE="$(get_git_head_data %ct)"
38	VERSION="$(git describe)"
39	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')"
41else
42	GITREV=Unknown
43	TIMESOURCE="date"
44	DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s)
45	if [ -f "${COREBOOT_VERSION_FILE}" ]; then
46		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}")"
48	fi
49fi
50
51our_date() {
52case $(uname) in
53NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
54	date -r "$1" "$2"
55	;;
56*)
57	date -d "@$1" "$2"
58esac
59}
60
61# 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"
65eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)"
66if [ ! -x "${IASL}" ]; then
67	IASL=$(command -v iasl)
68fi
69IASLVERSION="$("${IASL}" -v 2>/dev/null | grep version | sed 's/.*version //')"
70
71#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"
75printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\""
76
77#See if the build is running in a git repo and the git command is available
78printf "/* timesource: %s */\n" "${TIMESOURCE}"
79printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}"
80printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
81
82printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
83printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}"
84printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER:-0}"
85printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
86printf "#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")"
91printf "#define COREBOOT_DMI_DATE \"%s\"\n" "$(our_date "${DATE}" "+%m/%d/%Y")"
92printf "\n"
93printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")"
94printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}"
95printf "#endif\n"
96