mkcompile_h 2.5 KB
Newer Older
1 2
#!/bin/sh

L
Linus Torvalds 已提交
3 4 5
TARGET=$1
ARCH=$2
SMP=$3
S
Sam Ravnborg 已提交
6 7
PREEMPT=$4
CC=$5
L
Linus Torvalds 已提交
8

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

L
Linus Torvalds 已提交
11 12 13 14 15 16
# 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"

17
if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then
18
  vecho "  SKIPPED $TARGET"
L
Linus Torvalds 已提交
19 20 21 22 23 24
  exit 0
fi

# Do not expand names
set -f

25 26 27 28 29 30 31 32 33 34 35
# 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
L
Linus Torvalds 已提交
36
else
37
	VERSION=$KBUILD_BUILD_VERSION
L
Linus Torvalds 已提交
38 39
fi

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

UTS_VERSION="#$VERSION"
S
Sam Ravnborg 已提交
57 58 59
CONFIG_FLAGS=""
if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
60
UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
L
Linus Torvalds 已提交
61 62 63 64

# Truncate to maximum length

UTS_LEN=64
65
UTS_TRUNCATE="cut -b -$UTS_LEN"
L
Linus Torvalds 已提交
66 67 68 69

# Generate a temporary compile.h

( echo /\* This file is auto generated, version $VERSION \*/
S
Sam Ravnborg 已提交
70 71
  if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  
L
Linus Torvalds 已提交
72 73 74 75
  echo \#define UTS_MACHINE \"$ARCH\"

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

76 77
  echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
  echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
L
Linus Torvalds 已提交
78

79
  echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
L
Linus Torvalds 已提交
80 81 82 83 84 85 86 87 88 89 90 91
) > .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
# causing compile.h to be updated (including date/time) due to the 
# changed comment in the
# first line.

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