blob: baf3ab8d9d49ce40036d9e788ac5ecd5197aac53 [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
Mike Frysingerd03fab42008-11-06 03:31:22 -050012vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014# Do not expand names
15set -f
16
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020017# Fix the language to get consistent output
18LC_ALL=C
19export LC_ALL
20
21if [ -z "$KBUILD_BUILD_VERSION" ]; then
Masahiro Yamada37131ec2017-09-22 14:31:14 +090022 VERSION=$(cat .version 2>/dev/null || echo 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023else
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020024 VERSION=$KBUILD_BUILD_VERSION
Linus Torvalds1da177e2005-04-16 15:20:36 -070025fi
26
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020027if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
28 TIMESTAMP=`date`
29else
30 TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
31fi
Michal Marek53e68922011-04-05 14:32:30 +020032if test -z "$KBUILD_BUILD_USER"; then
Marcin Nowakowskif0772602011-04-25 13:35:21 +010033 LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
Michal Marek53e68922011-04-05 14:32:30 +020034else
35 LINUX_COMPILE_BY=$KBUILD_BUILD_USER
36fi
37if test -z "$KBUILD_BUILD_HOST"; then
38 LINUX_COMPILE_HOST=`hostname`
39else
40 LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
41fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43UTS_VERSION="#$VERSION"
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000044CONFIG_FLAGS=""
45if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
46if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
Thomas Gleixner4b950bb2019-07-28 20:27:41 +020047if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49# Truncate to maximum length
Linus Torvalds1da177e2005-04-16 15:20:36 -070050UTS_LEN=64
Masahiro Yamadae8193652019-12-06 22:03:01 +090051UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53# Generate a temporary compile.h
54
Masahiro Yamadab79c6aa2019-01-17 19:02:44 +090055{ echo /\* This file is auto generated, version $VERSION \*/
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000056 if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
Masahiro Yamada38385f82014-04-28 16:26:18 +090057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 echo \#define UTS_MACHINE \"$ARCH\"
59
Masahiro Yamadae8193652019-12-06 22:03:01 +090060 echo \#define UTS_VERSION \"$UTS_VERSION\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Masahiro Yamadac8f3dea2019-12-06 22:03:02 +090062 printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
Masahiro Yamadae8193652019-12-06 22:03:01 +090063 echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Kees Cook4dcc9a82020-04-02 01:18:37 -070065 LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
66 | sed 's/[[:space:]]*$//')
67 printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
Masahiro Yamadab79c6aa2019-01-17 19:02:44 +090068} > .tmpcompile
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70# Only replace the real compile.h if the new one is different,
71# in order to preserve the timestamp and avoid unnecessary
72# recompilations.
73# We don't consider the file changed if only the date/time changed.
74# 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
79if [ -r $TARGET ] && \
Michal Marek061296d2011-03-31 17:13:55 +020080 grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
81 grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 cmp -s .tmpver.1 .tmpver.2; then
83 rm -f .tmpcompile
84else
Mike Frysingerd03fab42008-11-06 03:31:22 -050085 vecho " UPD $TARGET"
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 mv -f .tmpcompile $TARGET
87fi
88rm -f .tmpver.1 .tmpver.2