Felipe Contreras | 17c5ca9 | 2009-09-17 00:38:40 +0300 | [diff] [blame] | 1 | #!/bin/sh |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Felipe Contreras | 17c5ca9 | 2009-09-17 00:38:40 +0300 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | TARGET=$1 |
| 5 | ARCH=$2 |
| 6 | SMP=$3 |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 7 | PREEMPT=$4 |
Thomas Gleixner | 4b950bb | 2019-07-28 20:27:41 +0200 | [diff] [blame] | 8 | PREEMPT_RT=$5 |
Masahiro Yamada | 9a95015 | 2020-04-23 23:23:54 +0900 | [diff] [blame] | 9 | CC_VERSION="$6" |
Kees Cook | 4dcc9a8 | 2020-04-02 01:18:37 -0700 | [diff] [blame] | 10 | LD=$7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | # Do not expand names |
| 13 | set -f |
| 14 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 15 | # Fix the language to get consistent output |
| 16 | LC_ALL=C |
| 17 | export LC_ALL |
| 18 | |
| 19 | if [ -z "$KBUILD_BUILD_VERSION" ]; then |
Masahiro Yamada | 37131ec | 2017-09-22 14:31:14 +0900 | [diff] [blame] | 20 | VERSION=$(cat .version 2>/dev/null || echo 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | else |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 22 | VERSION=$KBUILD_BUILD_VERSION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | fi |
| 24 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 25 | if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then |
| 26 | TIMESTAMP=`date` |
| 27 | else |
| 28 | TIMESTAMP=$KBUILD_BUILD_TIMESTAMP |
| 29 | fi |
Michal Marek | 53e6892 | 2011-04-05 14:32:30 +0200 | [diff] [blame] | 30 | if test -z "$KBUILD_BUILD_USER"; then |
Marcin Nowakowski | f077260 | 2011-04-25 13:35:21 +0100 | [diff] [blame] | 31 | LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/') |
Michal Marek | 53e6892 | 2011-04-05 14:32:30 +0200 | [diff] [blame] | 32 | else |
| 33 | LINUX_COMPILE_BY=$KBUILD_BUILD_USER |
| 34 | fi |
| 35 | if test -z "$KBUILD_BUILD_HOST"; then |
Chris Down | 1e66d50 | 2020-10-20 10:34:59 +0100 | [diff] [blame] | 36 | LINUX_COMPILE_HOST=`uname -n` |
Michal Marek | 53e6892 | 2011-04-05 14:32:30 +0200 | [diff] [blame] | 37 | else |
| 38 | LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST |
| 39 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | UTS_VERSION="#$VERSION" |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 42 | CONFIG_FLAGS="" |
| 43 | if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi |
| 44 | if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi |
Thomas Gleixner | 4b950bb | 2019-07-28 20:27:41 +0200 | [diff] [blame] | 45 | if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | # Truncate to maximum length |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | UTS_LEN=64 |
Masahiro Yamada | e819365 | 2019-12-06 22:03:01 +0900 | [diff] [blame] | 49 | UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | # Generate a temporary compile.h |
| 52 | |
Masahiro Yamada | b79c6aa | 2019-01-17 19:02:44 +0900 | [diff] [blame] | 53 | { echo /\* This file is auto generated, version $VERSION \*/ |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 54 | if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi |
Masahiro Yamada | 38385f8 | 2014-04-28 16:26:18 +0900 | [diff] [blame] | 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | echo \#define UTS_MACHINE \"$ARCH\" |
| 57 | |
Masahiro Yamada | e819365 | 2019-12-06 22:03:01 +0900 | [diff] [blame] | 58 | echo \#define UTS_VERSION \"$UTS_VERSION\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Masahiro Yamada | c8f3dea | 2019-12-06 22:03:02 +0900 | [diff] [blame] | 60 | printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" |
Masahiro Yamada | e819365 | 2019-12-06 22:03:01 +0900 | [diff] [blame] | 61 | echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Kees Cook | 4dcc9a8 | 2020-04-02 01:18:37 -0700 | [diff] [blame] | 63 | 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 Yamada | b79c6aa | 2019-01-17 19:02:44 +0900 | [diff] [blame] | 66 | } > .tmpcompile |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 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 Maennich | a979522 | 2021-06-12 15:18:38 +0100 | [diff] [blame] | 71 | # 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | # A kernel config change will increase the generation number, thus |
Masahiro Yamada | 38385f8 | 2014-04-28 16:26:18 +0900 | [diff] [blame] | 75 | # causing compile.h to be updated (including date/time) due to the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | # changed comment in the |
| 77 | # first line. |
| 78 | |
Matthias Maennich | a979522 | 2021-06-12 15:18:38 +0100 | [diff] [blame] | 79 | if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then |
| 80 | IGNORE_PATTERN="UTS_VERSION" |
| 81 | else |
| 82 | IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED" |
| 83 | fi |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if [ -r $TARGET ] && \ |
Matthias Maennich | a979522 | 2021-06-12 15:18:38 +0100 | [diff] [blame] | 86 | grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \ |
| 87 | grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | cmp -s .tmpver.1 .tmpver.2; then |
| 89 | rm -f .tmpcompile |
| 90 | else |
Masahiro Yamada | c39013e | 2021-05-17 16:03:14 +0900 | [diff] [blame] | 91 | echo " UPD $TARGET" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | mv -f .tmpcompile $TARGET |
| 93 | fi |
| 94 | rm -f .tmpver.1 .tmpver.2 |