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
L
Linus Torvalds 已提交
45 46

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

# Truncate to maximum length

UTS_LEN=64
55
UTS_TRUNCATE="cut -b -$UTS_LEN"
L
Linus Torvalds 已提交
56 57 58 59

# Generate a temporary compile.h

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

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

66
  echo \#define LINUX_COMPILE_TIME \"`date +%T`\"
L
Linus Torvalds 已提交
67 68 69
  echo \#define LINUX_COMPILE_BY \"`whoami`\"
  echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"

70 71
  domain=`dnsdomainname 2> /dev/null`
  if [ -z "$domain" ]; then
72 73 74 75 76
    domain=`domainname 2> /dev/null`
  fi

  if [ -n "$domain" ]; then
    echo \#define LINUX_COMPILE_DOMAIN \"`echo $domain | $UTS_TRUNCATE`\"
L
Linus Torvalds 已提交
77 78 79 80
  else
    echo \#define LINUX_COMPILE_DOMAIN
  fi

81
  echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
L
Linus Torvalds 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
) > .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
99
   vecho "  UPD     $TARGET"
L
Linus Torvalds 已提交
100 101 102
   mv -f .tmpcompile $TARGET
fi
rm -f .tmpver.1 .tmpver.2