mkcompile_h 2.52 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 8
PREEMPT=$4
CC=$5
Linus Torvalds's avatar
Linus Torvalds committed
9

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

Linus Torvalds's avatar
Linus Torvalds committed
12 13 14 15 16 17
# 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"

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

# Do not expand names
set -f

26 27 28 29 30 31 32 33 34 35 36
# Fix the language to get consistent output
LC_ALL=C
export LC_ALL

if [ -z "$KBUILD_BUILD_VERSION" ]; then
	if [ -r .version ]; then
		VERSION=`cat .version`
	else
		VERSION=0
		echo 0 > .version
	fi
Linus Torvalds's avatar
Linus Torvalds committed
37
else
38
	VERSION=$KBUILD_BUILD_VERSION
Linus Torvalds's avatar
Linus Torvalds committed
39 40
fi

41 42 43 44 45
if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
	TIMESTAMP=`date`
else
	TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
fi
46
if test -z "$KBUILD_BUILD_USER"; then
47
	LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
48 49 50 51 52 53 54 55
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
56 57

UTS_VERSION="#$VERSION"
58 59 60
CONFIG_FLAGS=""
if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
61
UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
Linus Torvalds's avatar
Linus Torvalds committed
62 63 64 65

# Truncate to maximum length

UTS_LEN=64
66
UTS_TRUNCATE="cut -b -$UTS_LEN"
Linus Torvalds's avatar
Linus Torvalds committed
67 68 69 70

# Generate a temporary compile.h

( echo /\* This file is auto generated, version $VERSION \*/
71
  if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
72

Linus Torvalds's avatar
Linus Torvalds committed
73 74 75 76
  echo \#define UTS_MACHINE \"$ARCH\"

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

77 78
  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
79

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

# 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
88
# causing compile.h to be updated (including date/time) due to the
Linus Torvalds's avatar
Linus Torvalds committed
89 90 91 92
# changed comment in the
# first line.

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