soc/intel/cmn/cse: Deprecate CONFIG_SOC_INTEL_CSE_RW_VERSION
[coreboot2.git] / util / genbuild_h / genbuild_h.sh
blob2bfcc4c3b662c9c8e98f09b68b86ca9b51a8511f
1 #!/usr/bin/env sh
3 # SPDX-License-Identifier: GPL-2.0-only
5 DATE=""
6 GITREV=""
7 TIMESOURCE=""
8 XGCCPATH="${XGCCPATH:-util/crossgcc/xgcc/bin/}"
9 MAJOR_VER="0"
10 MINOR_VER="0"
11 COREBOOT_VERSION_FILE=".coreboot-version"
13 export LANG=C
14 export LC_ALL=C
15 export TZ=UTC0
17 XCOMPILE=$1
19 if [ -z "${XCOMPILE}" ] || [ "$1" = "--help" ]; then
20 echo "usage: $0 <xcompile>" >&2
21 exit 1
24 # $1: format string
25 get_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"
30 if [ "${BUILD_TIMELESS}" = "1" ]; then
31 GITREV=Timeless
32 TIMESOURCE="fixed"
33 DATE=0
34 elif [ "$(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 # Only use the `git describe` output if the tag is in the expected <major>.<minor>
40 # format, e.g. 4.18. Forks of coreboot may have other tags in different formats.
41 if echo "${VERSION}" | grep -q "^[0-9]\.[0-9][0-9]*"; then
42 MAJOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/')"
43 MINOR_VER="$(echo "${VERSION}" | sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/')"
45 else
46 GITREV=Unknown
47 TIMESOURCE="date"
48 DATE=$(LANG="" LC_ALL=C TZ=UTC0 date +%s)
49 if [ -f "${COREBOOT_VERSION_FILE}" ]; then
50 MAJOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\1/' "${COREBOOT_VERSION_FILE}")"
51 MINOR_VER="$(sed 's/\([0-9]\)\.\([0-9][0-9]*\).*/\2/' "${COREBOOT_VERSION_FILE}")"
55 our_date() {
56 case $(uname) in
57 NetBSD|OpenBSD|DragonFly|FreeBSD|Darwin)
58 date -r "$1" "$2"
61 date -d "@$1" "$2"
62 esac
65 # Look for IASL in XGCCPATH and xcompile. Unfortunately,
66 # xcompile isn't available on the first build.
67 # If neither of those gives a valid iasl, check the path.
68 IASL="${XGCCPATH}iasl"
69 eval "$(grep ^IASL:= "${XCOMPILE}" 2>/dev/null | sed s,:=,=,)"
70 if [ ! -x "${IASL}" ]; then
71 IASL=$(command -v iasl)
73 IASLVERSION="$("${IASL}" -v 2>/dev/null | grep version | sed 's/.*version //')"
75 #Print out the information that goes into build.h
76 printf "/* build system definitions (autogenerated) */\n"
77 printf "#ifndef __BUILD_H\n"
78 printf "#define __BUILD_H\n\n"
79 printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\""
81 #See if the build is running in a git repo and the git command is available
82 printf "/* timesource: %s */\n" "${TIMESOURCE}"
83 printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}"
84 printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}"
86 printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}"
87 printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER}"
88 printf "#define COREBOOT_MINOR_VERSION %s\n" "${MINOR_VER}"
89 printf "#define COREBOOT_BUILD \"%s\"\n" "$(our_date "${DATE}" "+%a %b %d %H:%M:%S %Z %Y")"
90 printf "#define COREBOOT_BUILD_YEAR_BCD 0x%s\n" "$(our_date "${DATE}" "+%y")"
91 printf "#define COREBOOT_BUILD_MONTH_BCD 0x%s\n" "$(our_date "${DATE}" "+%m")"
92 printf "#define COREBOOT_BUILD_DAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%d")"
93 printf "#define COREBOOT_BUILD_WEEKDAY_BCD 0x%s\n" "$(our_date "${DATE}" "+%w")"
94 printf "#define COREBOOT_BUILD_EPOCH \"%s\"\n" "$(our_date "${DATE}" "+%s")"
95 printf "#define COREBOOT_DMI_DATE \"%s\"\n" "$(our_date "${DATE}" "+%m/%d/%Y")"
96 printf "\n"
97 printf "#define COREBOOT_COMPILE_TIME \"%s\"\n" "$(our_date "${DATE}" "+%T")"
98 printf "#define ASL_VERSION 0x%s\n" "${IASLVERSION}"
99 printf "#endif\n"