mkcompile_h 2.57 KB
Newer Older
1
#!/bin/sh
2
# SPDX-License-Identifier: GPL-2.0
3

Linus Torvalds's avatar
Linus Torvalds committed
4 5 6
TARGET=$1
ARCH=$2
SMP=$3
7
PREEMPT=$4
8 9
PREEMPT_RT=$5
CC=$6
Linus Torvalds's avatar
Linus Torvalds committed
10

11 12
vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }

Linus Torvalds's avatar
Linus Torvalds committed
13 14 15 16 17 18
# If compile.h exists already and we don't own autoconf.h
# (i.e. we're not the same user who did make *config), don't
# modify compile.h
# So "sudo make install" won't change the "compiled by <user>"
# do "compiled by root"

19
if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then
20
  vecho "  SKIPPED $TARGET"
Linus Torvalds's avatar
Linus Torvalds committed
21 22 23 24 25 26
  exit 0
fi

# Do not expand names
set -f

27 28 29 30 31
# Fix the language to get consistent output
LC_ALL=C
export LC_ALL

if [ -z "$KBUILD_BUILD_VERSION" ]; then
32
	VERSION=$(cat .version 2>/dev/null || echo 1)
Linus Torvalds's avatar
Linus Torvalds committed
33
else
34
	VERSION=$KBUILD_BUILD_VERSION
Linus Torvalds's avatar
Linus Torvalds committed
35 36
fi

37 38 39 40 41
if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
	TIMESTAMP=`date`
else
	TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
fi
42
if test -z "$KBUILD_BUILD_USER"; then
43
	LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
44 45 46 47 48 49 50 51
else
	LINUX_COMPILE_BY=$KBUILD_BUILD_USER
fi
if test -z "$KBUILD_BUILD_HOST"; then
	LINUX_COMPILE_HOST=`hostname`
else
	LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
fi
Linus Torvalds's avatar
Linus Torvalds committed
52 53

UTS_VERSION="#$VERSION"
54 55 56
CONFIG_FLAGS=""
if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
57
if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
58
UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
Linus Torvalds's avatar
Linus Torvalds committed
59 60 61 62

# Truncate to maximum length

UTS_LEN=64
63
UTS_TRUNCATE="cut -b -$UTS_LEN"
Linus Torvalds's avatar
Linus Torvalds committed
64 65 66

# Generate a temporary compile.h

67
{ echo /\* This file is auto generated, version $VERSION \*/
68
  if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
69

Linus Torvalds's avatar
Linus Torvalds committed
70 71 72 73
  echo \#define UTS_MACHINE \"$ARCH\"

  echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"

74 75
  echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
  echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
Linus Torvalds's avatar
Linus Torvalds committed
76

77
  echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
78
} > .tmpcompile
Linus Torvalds's avatar
Linus Torvalds committed
79 80 81 82 83 84

# Only replace the real compile.h if the new one is different,
# in order to preserve the timestamp and avoid unnecessary
# recompilations.
# We don't consider the file changed if only the date/time changed.
# A kernel config change will increase the generation number, thus
85
# causing compile.h to be updated (including date/time) due to the
Linus Torvalds's avatar
Linus Torvalds committed
86 87 88 89
# changed comment in the
# first line.

if [ -r $TARGET ] && \
90 91
      grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
      grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
Linus Torvalds's avatar
Linus Torvalds committed
92 93 94
      cmp -s .tmpver.1 .tmpver.2; then
   rm -f .tmpcompile
else
95
   vecho "  UPD     $TARGET"
Linus Torvalds's avatar
Linus Torvalds committed
96 97 98
   mv -f .tmpcompile $TARGET
fi
rm -f .tmpver.1 .tmpver.2