mkcompile_h 2.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
TARGET=$1
ARCH=$2
SMP=$3
S
Sam Ravnborg 已提交
4 5
PREEMPT=$4
CC=$5
L
Linus Torvalds 已提交
6

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

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

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

# Do not expand names
set -f

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

38 39 40 41 42
if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
	TIMESTAMP=`date`
else
	TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
fi
L
Linus Torvalds 已提交
43 44

UTS_VERSION="#$VERSION"
S
Sam Ravnborg 已提交
45 46 47
CONFIG_FLAGS=""
if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
48
UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57

# Truncate to maximum length

UTS_LEN=64
UTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/"

# Generate a temporary compile.h

( echo /\* This file is auto generated, version $VERSION \*/
S
Sam Ravnborg 已提交
58 59
  if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  
L
Linus Torvalds 已提交
60 61 62 63
  echo \#define UTS_MACHINE \"$ARCH\"

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

64
  echo \#define LINUX_COMPILE_TIME \"`date +%T`\"
L
Linus Torvalds 已提交
65 66 67 68 69 70 71 72 73 74 75
  echo \#define LINUX_COMPILE_BY \"`whoami`\"
  echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"

  if [ -x /bin/dnsdomainname ]; then
    echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\"
  elif [ -x /bin/domainname ]; then
    echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\"
  else
    echo \#define LINUX_COMPILE_DOMAIN
  fi

76
  echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
L
Linus Torvalds 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
) > .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 ] && \
      grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \
      grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \
      cmp -s .tmpver.1 .tmpver.2; then
   rm -f .tmpcompile
else
94
   vecho "  UPD     $TARGET"
L
Linus Torvalds 已提交
95 96 97
   mv -f .tmpcompile $TARGET
fi
rm -f .tmpver.1 .tmpver.2