17c5ca98833dc (Felipe Contreras 2009-09-17 00:38:40 +0300 1) #!/bin/sh
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 2) # SPDX-License-Identifier: GPL-2.0
17c5ca98833dc (Felipe Contreras 2009-09-17 00:38:40 +0300 3)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 4) TARGET=$1
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 5) ARCH=$2
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 6) SMP=$3
bd5bdd875b29e (Sam Ravnborg 2005-07-14 20:18:07 +0000 7) PREEMPT=$4
4b950bb9ac0c7 (Thomas Gleixner 2019-07-28 20:27:41 +0200 8) PREEMPT_RT=$5
9a95015466872 (Masahiro Yamada 2020-04-23 23:23:54 +0900 9) CC_VERSION="$6"
4dcc9a88448a6 (Kees Cook 2020-04-02 01:18:37 -0700 10) LD=$7
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 11)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) # Do not expand names
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) set -f
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14)
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 15) # Fix the language to get consistent output
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 16) LC_ALL=C
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 17) export LC_ALL
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 18)
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 19) if [ -z "$KBUILD_BUILD_VERSION" ]; then
37131ec4f9cb6 (Masahiro Yamada 2017-09-22 14:31:14 +0900 20) VERSION=$(cat .version 2>/dev/null || echo 1)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 21) else
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 22) VERSION=$KBUILD_BUILD_VERSION
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 23) fi
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 24)
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 25) if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 26) TIMESTAMP=`date`
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 27) else
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 28) TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
87c94bfb8ad35 (Sam Ravnborg 2007-04-01 21:49:27 +0200 29) fi
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 30) if test -z "$KBUILD_BUILD_USER"; then
f07726048d599 (Marcin Nowakowski 2011-04-25 13:35:21 +0100 31) LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 32) else
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 33) LINUX_COMPILE_BY=$KBUILD_BUILD_USER
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 34) fi
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 35) if test -z "$KBUILD_BUILD_HOST"; then
1e66d50ad3a1d (Chris Down 2020-10-20 10:34:59 +0100 36) LINUX_COMPILE_HOST=`uname -n`
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 37) else
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 38) LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
53e6892c04110 (Michal Marek 2011-04-05 14:32:30 +0200 39) fi
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 40)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 41) UTS_VERSION="#$VERSION"
bd5bdd875b29e (Sam Ravnborg 2005-07-14 20:18:07 +0000 42) CONFIG_FLAGS=""
bd5bdd875b29e (Sam Ravnborg 2005-07-14 20:18:07 +0000 43) if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
bd5bdd875b29e (Sam Ravnborg 2005-07-14 20:18:07 +0000 44) if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
4b950bb9ac0c7 (Thomas Gleixner 2019-07-28 20:27:41 +0200 45) if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 47) # Truncate to maximum length
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 48) UTS_LEN=64
e8193650bf38b (Masahiro Yamada 2019-12-06 22:03:01 +0900 49) UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 50)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 51) # Generate a temporary compile.h
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 52)
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 53) { echo /\* This file is auto generated, version $VERSION \*/
bd5bdd875b29e (Sam Ravnborg 2005-07-14 20:18:07 +0000 54) if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
38385f8f01803 (Masahiro Yamada 2014-04-28 16:26:18 +0900 55)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 56) echo \#define UTS_MACHINE \"$ARCH\"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 57)
e8193650bf38b (Masahiro Yamada 2019-12-06 22:03:01 +0900 58) echo \#define UTS_VERSION \"$UTS_VERSION\"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 59)
c8f3dea90e381 (Masahiro Yamada 2019-12-06 22:03:02 +0900 60) printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
e8193650bf38b (Masahiro Yamada 2019-12-06 22:03:01 +0900 61) echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 62)
4dcc9a88448a6 (Kees Cook 2020-04-02 01:18:37 -0700 63) LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
4dcc9a88448a6 (Kees Cook 2020-04-02 01:18:37 -0700 64) | sed 's/[[:space:]]*$//')
4dcc9a88448a6 (Kees Cook 2020-04-02 01:18:37 -0700 65) printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 66) } > .tmpcompile
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 67)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 68) # Only replace the real compile.h if the new one is different,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 69) # in order to preserve the timestamp and avoid unnecessary
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 70) # recompilations.
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 71) # We don't consider the file changed if only the date/time changed,
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 72) # unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 73) # reproducible builds with that value referring to a commit timestamp).
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 74) # A kernel config change will increase the generation number, thus
38385f8f01803 (Masahiro Yamada 2014-04-28 16:26:18 +0900 75) # causing compile.h to be updated (including date/time) due to the
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 76) # changed comment in the
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 77) # first line.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 78)
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 79) if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 80) IGNORE_PATTERN="UTS_VERSION"
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 81) else
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 82) IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED"
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 83) fi
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 84)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 85) if [ -r $TARGET ] && \
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 86) grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \
a979522a1a885 (Matthias Maennich 2021-06-12 15:18:38 +0100 87) grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 88) cmp -s .tmpver.1 .tmpver.2; then
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 89) rm -f .tmpcompile
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 90) else
c39013ee64b50 (Masahiro Yamada 2021-05-17 16:03:14 +0900 91) echo " UPD $TARGET"
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 92) mv -f .tmpcompile $TARGET
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 93) fi
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 94) rm -f .tmpver.1 .tmpver.2