blob: 6a12dd9f1181c396f30c1e4c7377e8e0d63402cd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001TARGET=$1
2ARCH=$2
3SMP=$3
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +00004PREEMPT=$4
5CC=$5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006
Mike Frysingerd03fab42008-11-06 03:31:22 -05007vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009# If compile.h exists already and we don't own autoconf.h
10# (i.e. we're not the same user who did make *config), don't
11# modify compile.h
12# So "sudo make install" won't change the "compiled by <user>"
13# do "compiled by root"
14
15if [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then
Mike Frysingerd03fab42008-11-06 03:31:22 -050016 vecho " SKIPPED $TARGET"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 exit 0
18fi
19
20# Do not expand names
21set -f
22
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020023# Fix the language to get consistent output
24LC_ALL=C
25export LC_ALL
26
27if [ -z "$KBUILD_BUILD_VERSION" ]; then
28 if [ -r .version ]; then
29 VERSION=`cat .version`
30 else
31 VERSION=0
32 echo 0 > .version
33 fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070034else
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020035 VERSION=$KBUILD_BUILD_VERSION
Linus Torvalds1da177e2005-04-16 15:20:36 -070036fi
37
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020038if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
39 TIMESTAMP=`date`
40else
41 TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
42fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44UTS_VERSION="#$VERSION"
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000045CONFIG_FLAGS=""
46if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
47if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020048UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50# Truncate to maximum length
51
52UTS_LEN=64
53UTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/"
54
55# Generate a temporary compile.h
56
57( echo /\* This file is auto generated, version $VERSION \*/
Sam Ravnborgbd5bdd82005-07-14 20:18:07 +000058 if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 echo \#define UTS_MACHINE \"$ARCH\"
61
62 echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
63
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020064 echo \#define LINUX_COMPILE_TIME \"`date +%T`\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 echo \#define LINUX_COMPILE_BY \"`whoami`\"
66 echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"
67
68 if [ -x /bin/dnsdomainname ]; then
69 echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\"
70 elif [ -x /bin/domainname ]; then
71 echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\"
72 else
73 echo \#define LINUX_COMPILE_DOMAIN
74 fi
75
Sam Ravnborg87c94bf2007-04-01 21:49:27 +020076 echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077) > .tmpcompile
78
79# Only replace the real compile.h if the new one is different,
80# in order to preserve the timestamp and avoid unnecessary
81# recompilations.
82# We don't consider the file changed if only the date/time changed.
83# A kernel config change will increase the generation number, thus
84# causing compile.h to be updated (including date/time) due to the
85# changed comment in the
86# first line.
87
88if [ -r $TARGET ] && \
89 grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \
90 grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \
91 cmp -s .tmpver.1 .tmpver.2; then
92 rm -f .tmpcompile
93else
Mike Frysingerd03fab42008-11-06 03:31:22 -050094 vecho " UPD $TARGET"
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 mv -f .tmpcompile $TARGET
96fi
97rm -f .tmpver.1 .tmpver.2