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

L
Linus Torvalds 已提交
4 5 6
TARGET=$1
ARCH=$2
SMP=$3
S
Sam Ravnborg 已提交
7
PREEMPT=$4
8
PREEMPT_RT=$5
9
CC_VERSION="$6"
10
LD=$7
L
Linus Torvalds 已提交
11

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

L
Linus Torvalds 已提交
14 15 16
# Do not expand names
set -f

17 18 19 20 21
# Fix the language to get consistent output
LC_ALL=C
export LC_ALL

if [ -z "$KBUILD_BUILD_VERSION" ]; then
22
	VERSION=$(cat .version 2>/dev/null || echo 1)
L
Linus Torvalds 已提交
23
else
24
	VERSION=$KBUILD_BUILD_VERSION
L
Linus Torvalds 已提交
25 26
fi

27 28 29 30 31
if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
	TIMESTAMP=`date`
else
	TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
fi
32
if test -z "$KBUILD_BUILD_USER"; then
33
	LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
34 35 36 37 38 39 40 41
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
L
Linus Torvalds 已提交
42 43

UTS_VERSION="#$VERSION"
S
Sam Ravnborg 已提交
44 45 46
CONFIG_FLAGS=""
if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
47
if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
L
Linus Torvalds 已提交
48 49 50

# Truncate to maximum length
UTS_LEN=64
51
UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
L
Linus Torvalds 已提交
52 53 54

# Generate a temporary compile.h

55
{ echo /\* This file is auto generated, version $VERSION \*/
S
Sam Ravnborg 已提交
56
  if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
57

L
Linus Torvalds 已提交
58 59
  echo \#define UTS_MACHINE \"$ARCH\"

60
  echo \#define UTS_VERSION \"$UTS_VERSION\"
L
Linus Torvalds 已提交
61

62
  printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
63
  echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
L
Linus Torvalds 已提交
64

65 66 67
  LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
		      | sed 's/[[:space:]]*$//')
  printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
68
} > .tmpcompile
L
Linus Torvalds 已提交
69 70 71 72 73 74

# 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
75
# causing compile.h to be updated (including date/time) due to the
L
Linus Torvalds 已提交
76 77 78 79
# changed comment in the
# first line.

if [ -r $TARGET ] && \
80 81
      grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
      grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
L
Linus Torvalds 已提交
82 83 84
      cmp -s .tmpver.1 .tmpver.2; then
   rm -f .tmpcompile
else
85
   vecho "  UPD     $TARGET"
L
Linus Torvalds 已提交
86 87 88
   mv -f .tmpcompile $TARGET
fi
rm -f .tmpver.1 .tmpver.2