Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | TARGET=$1 |
| 2 | ARCH=$2 |
| 3 | SMP=$3 |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 4 | PREEMPT=$4 |
| 5 | CC=$5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
| 7 | # If compile.h exists already and we don't own autoconf.h |
| 8 | # (i.e. we're not the same user who did make *config), don't |
| 9 | # modify compile.h |
| 10 | # So "sudo make install" won't change the "compiled by <user>" |
| 11 | # do "compiled by root" |
| 12 | |
| 13 | if [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then |
| 14 | echo " SKIPPED $TARGET" |
| 15 | exit 0 |
| 16 | fi |
| 17 | |
| 18 | # Do not expand names |
| 19 | set -f |
| 20 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 21 | # Fix the language to get consistent output |
| 22 | LC_ALL=C |
| 23 | export LC_ALL |
| 24 | |
| 25 | if [ -z "$KBUILD_BUILD_VERSION" ]; then |
| 26 | if [ -r .version ]; then |
| 27 | VERSION=`cat .version` |
| 28 | else |
| 29 | VERSION=0 |
| 30 | echo 0 > .version |
| 31 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | else |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 33 | VERSION=$KBUILD_BUILD_VERSION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | fi |
| 35 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 36 | if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then |
| 37 | TIMESTAMP=`date` |
| 38 | else |
| 39 | TIMESTAMP=$KBUILD_BUILD_TIMESTAMP |
| 40 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | UTS_VERSION="#$VERSION" |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 43 | CONFIG_FLAGS="" |
| 44 | if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi |
| 45 | if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 46 | UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | # Truncate to maximum length |
| 49 | |
| 50 | UTS_LEN=64 |
| 51 | UTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/" |
| 52 | |
| 53 | # Generate a temporary compile.h |
| 54 | |
| 55 | ( echo /\* This file is auto generated, version $VERSION \*/ |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 56 | if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | echo \#define UTS_MACHINE \"$ARCH\" |
| 59 | |
| 60 | echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" |
| 61 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 62 | echo \#define LINUX_COMPILE_TIME \"`date +%T`\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | echo \#define LINUX_COMPILE_BY \"`whoami`\" |
| 64 | echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" |
| 65 | |
| 66 | if [ -x /bin/dnsdomainname ]; then |
| 67 | echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\" |
| 68 | elif [ -x /bin/domainname ]; then |
| 69 | echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\" |
| 70 | else |
| 71 | echo \#define LINUX_COMPILE_DOMAIN |
| 72 | fi |
| 73 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 74 | echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | ) > .tmpcompile |
| 76 | |
| 77 | # Only replace the real compile.h if the new one is different, |
| 78 | # in order to preserve the timestamp and avoid unnecessary |
| 79 | # recompilations. |
| 80 | # We don't consider the file changed if only the date/time changed. |
| 81 | # A kernel config change will increase the generation number, thus |
| 82 | # causing compile.h to be updated (including date/time) due to the |
| 83 | # changed comment in the |
| 84 | # first line. |
| 85 | |
| 86 | if [ -r $TARGET ] && \ |
| 87 | grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \ |
| 88 | grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \ |
| 89 | cmp -s .tmpver.1 .tmpver.2; then |
| 90 | rm -f .tmpcompile |
| 91 | else |
| 92 | echo " UPD $TARGET" |
| 93 | mv -f .tmpcompile $TARGET |
| 94 | fi |
| 95 | rm -f .tmpver.1 .tmpver.2 |