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 | |
Mike Frysinger | d03fab4 | 2008-11-06 03:31:22 -0500 | [diff] [blame] | 7 | vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | # 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 | |
| 15 | if [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then |
Mike Frysinger | d03fab4 | 2008-11-06 03:31:22 -0500 | [diff] [blame] | 16 | vecho " SKIPPED $TARGET" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | exit 0 |
| 18 | fi |
| 19 | |
| 20 | # Do not expand names |
| 21 | set -f |
| 22 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 23 | # Fix the language to get consistent output |
| 24 | LC_ALL=C |
| 25 | export LC_ALL |
| 26 | |
| 27 | if [ -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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | else |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 35 | VERSION=$KBUILD_BUILD_VERSION |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | fi |
| 37 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 38 | if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then |
| 39 | TIMESTAMP=`date` |
| 40 | else |
| 41 | TIMESTAMP=$KBUILD_BUILD_TIMESTAMP |
| 42 | fi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | UTS_VERSION="#$VERSION" |
Sam Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 45 | CONFIG_FLAGS="" |
| 46 | if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi |
| 47 | if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 48 | UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | # Truncate to maximum length |
| 51 | |
| 52 | UTS_LEN=64 |
| 53 | UTS_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 Ravnborg | bd5bdd8 | 2005-07-14 20:18:07 +0000 | [diff] [blame] | 58 | if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | echo \#define UTS_MACHINE \"$ARCH\" |
| 61 | |
| 62 | echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" |
| 63 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 64 | echo \#define LINUX_COMPILE_TIME \"`date +%T`\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | echo \#define LINUX_COMPILE_BY \"`whoami`\" |
| 66 | echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" |
| 67 | |
| 68 | if [ -x /bin/dnsdomainname ]; then |
Felipe Contreras | 9c3049c | 2009-09-17 00:38:39 +0300 | [diff] [blame^] | 69 | domain=`dnsdomainname 2> /dev/null` |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | elif [ -x /bin/domainname ]; then |
Felipe Contreras | 9c3049c | 2009-09-17 00:38:39 +0300 | [diff] [blame^] | 71 | domain=`domainname 2> /dev/null` |
| 72 | fi |
| 73 | |
| 74 | if [ -n "$domain" ]; then |
| 75 | echo \#define LINUX_COMPILE_DOMAIN \"`echo $domain | $UTS_TRUNCATE`\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | else |
| 77 | echo \#define LINUX_COMPILE_DOMAIN |
| 78 | fi |
| 79 | |
Sam Ravnborg | 87c94bf | 2007-04-01 21:49:27 +0200 | [diff] [blame] | 80 | echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | ) > .tmpcompile |
| 82 | |
| 83 | # Only replace the real compile.h if the new one is different, |
| 84 | # in order to preserve the timestamp and avoid unnecessary |
| 85 | # recompilations. |
| 86 | # We don't consider the file changed if only the date/time changed. |
| 87 | # A kernel config change will increase the generation number, thus |
| 88 | # causing compile.h to be updated (including date/time) due to the |
| 89 | # changed comment in the |
| 90 | # first line. |
| 91 | |
| 92 | if [ -r $TARGET ] && \ |
| 93 | grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \ |
| 94 | grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \ |
| 95 | cmp -s .tmpver.1 .tmpver.2; then |
| 96 | rm -f .tmpcompile |
| 97 | else |
Mike Frysinger | d03fab4 | 2008-11-06 03:31:22 -0500 | [diff] [blame] | 98 | vecho " UPD $TARGET" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | mv -f .tmpcompile $TARGET |
| 100 | fi |
| 101 | rm -f .tmpver.1 .tmpver.2 |