blob: 6a2a04d92f42fd8e5dd3d10f900ccb971214ccd0 [file] [log] [blame]
Felipe Contreras17c5ca92009-09-17 00:38:40 +03001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Felipe Contreras17c5ca92009-09-17 00:38:40 +03003
Linus Torvalds1da177e2005-04-16 15:20:36 -07004TARGET=$1
5ARCH=$2
6SMP=$3
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +00007PREEMPT=$4
Thomas Gleixner4b950bb2019-07-28 20:27:41 +02008PREEMPT_RT=$5
Masahiro Yamada9a950152020-04-23 23:23:54 +09009CC_VERSION="$6"
Kees Cook4dcc9a82020-04-02 01:18:37 -070010LD=$7
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012# Do not expand names
13set -f
14
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020015# Fix the language to get consistent output
16LC_ALL=C
17export LC_ALL
18
19if [ -z "$KBUILD_BUILD_VERSION" ]; then
Masahiro Yamada37131ec2017-09-22 14:31:14 +090020 VERSION=$(cat .version 2>/dev/null || echo 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021else
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020022 VERSION=$KBUILD_BUILD_VERSION
Linus Torvalds1da177e2005-04-16 15:20:36 -070023fi
24
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020025if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
26 TIMESTAMP=`date`
27else
28 TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
29fi
Michal Marek53e68922011-04-05 14:32:30 +020030if test -z "$KBUILD_BUILD_USER"; then
Marcin Nowakowskif0772602011-04-25 13:35:21 +010031 LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
Michal Marek53e68922011-04-05 14:32:30 +020032else
33 LINUX_COMPILE_BY=$KBUILD_BUILD_USER
34fi
35if test -z "$KBUILD_BUILD_HOST"; then
Chris Down1e66d502020-10-20 10:34:59 +010036 LINUX_COMPILE_HOST=`uname -n`
Michal Marek53e68922011-04-05 14:32:30 +020037else
38 LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
39fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41UTS_VERSION="#$VERSION"
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000042CONFIG_FLAGS=""
43if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
44if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
Thomas Gleixner4b950bb2019-07-28 20:27:41 +020045if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47# Truncate to maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -070048UTS_LEN=64
Masahiro Yamadae8193652019-12-06 22:03:01 +090049UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51# Generate a temporary compile.h
52
Masahiro Yamadab79c6aa2019-01-17 19:02:44 +090053{ echo /\* This file is auto generated, version $VERSION \*/
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000054 if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
Masahiro Yamada38385f82014-04-28 16:26:18 +090055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 echo \#define UTS_MACHINE \"$ARCH\"
57
Masahiro Yamadae8193652019-12-06 22:03:01 +090058 echo \#define UTS_VERSION \"$UTS_VERSION\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Masahiro Yamadac8f3dea2019-12-06 22:03:02 +090060 printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
Masahiro Yamadae8193652019-12-06 22:03:01 +090061 echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Kees Cook4dcc9a82020-04-02 01:18:37 -070063 LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
64 | sed 's/[[:space:]]*$//')
65 printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
Masahiro Yamadab79c6aa2019-01-17 19:02:44 +090066} > .tmpcompile
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68# Only replace the real compile.h if the new one is different,
69# in order to preserve the timestamp and avoid unnecessary
70# recompilations.
Matthias Maennicha9795222021-06-12 15:18:38 +010071# We don't consider the file changed if only the date/time changed,
72# unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for
73# reproducible builds with that value referring to a commit timestamp).
Linus Torvalds1da177e2005-04-16 15:20:36 -070074# A kernel config change will increase the generation number, thus
Masahiro Yamada38385f82014-04-28 16:26:18 +090075# causing compile.h to be updated (including date/time) due to the
Linus Torvalds1da177e2005-04-16 15:20:36 -070076# changed comment in the
77# first line.
78
Matthias Maennicha9795222021-06-12 15:18:38 +010079if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
80 IGNORE_PATTERN="UTS_VERSION"
81else
82 IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED"
83fi
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085if [ -r $TARGET ] && \
Matthias Maennicha9795222021-06-12 15:18:38 +010086 grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \
87 grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 cmp -s .tmpver.1 .tmpver.2; then
89 rm -f .tmpcompile
90else
Masahiro Yamadac39013e2021-05-17 16:03:14 +090091 echo " UPD $TARGET"
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 mv -f .tmpcompile $TARGET
93fi
94rm -f .tmpver.1 .tmpver.2