11da177e4SLinus TorvaldsTARGET=$1 21da177e4SLinus TorvaldsARCH=$2 31da177e4SLinus TorvaldsSMP=$3 4bd5bdd87SSam RavnborgPREEMPT=$4 5bd5bdd87SSam RavnborgCC=$5 61da177e4SLinus Torvalds 7d03fab43SMike Frysingervecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } 8d03fab43SMike Frysinger 91da177e4SLinus Torvalds# If compile.h exists already and we don't own autoconf.h 101da177e4SLinus Torvalds# (i.e. we're not the same user who did make *config), don't 111da177e4SLinus Torvalds# modify compile.h 121da177e4SLinus Torvalds# So "sudo make install" won't change the "compiled by <user>" 131da177e4SLinus Torvalds# do "compiled by root" 141da177e4SLinus Torvalds 151da177e4SLinus Torvaldsif [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then 16d03fab43SMike Frysinger vecho " SKIPPED $TARGET" 171da177e4SLinus Torvalds exit 0 181da177e4SLinus Torvaldsfi 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds# Do not expand names 211da177e4SLinus Torvaldsset -f 221da177e4SLinus Torvalds 2387c94bfbSSam Ravnborg# Fix the language to get consistent output 2487c94bfbSSam RavnborgLC_ALL=C 2587c94bfbSSam Ravnborgexport LC_ALL 2687c94bfbSSam Ravnborg 2787c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_VERSION" ]; then 281da177e4SLinus Torvalds if [ -r .version ]; then 291da177e4SLinus Torvalds VERSION=`cat .version` 301da177e4SLinus Torvalds else 311da177e4SLinus Torvalds VERSION=0 321da177e4SLinus Torvalds echo 0 > .version 331da177e4SLinus Torvalds fi 3487c94bfbSSam Ravnborgelse 3587c94bfbSSam Ravnborg VERSION=$KBUILD_BUILD_VERSION 3687c94bfbSSam Ravnborgfi 371da177e4SLinus Torvalds 3887c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 3987c94bfbSSam Ravnborg TIMESTAMP=`date` 4087c94bfbSSam Ravnborgelse 4187c94bfbSSam Ravnborg TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 4287c94bfbSSam Ravnborgfi 431da177e4SLinus Torvalds 441da177e4SLinus TorvaldsUTS_VERSION="#$VERSION" 45bd5bdd87SSam RavnborgCONFIG_FLAGS="" 46bd5bdd87SSam Ravnborgif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 47bd5bdd87SSam Ravnborgif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 4887c94bfbSSam RavnborgUTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP" 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds# Truncate to maximum length 511da177e4SLinus Torvalds 521da177e4SLinus TorvaldsUTS_LEN=64 531da177e4SLinus TorvaldsUTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/" 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds# Generate a temporary compile.h 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds( echo /\* This file is auto generated, version $VERSION \*/ 58bd5bdd87SSam Ravnborg if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds echo \#define UTS_MACHINE \"$ARCH\" 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" 631da177e4SLinus Torvalds 6487c94bfbSSam Ravnborg echo \#define LINUX_COMPILE_TIME \"`date +%T`\" 651da177e4SLinus Torvalds echo \#define LINUX_COMPILE_BY \"`whoami`\" 661da177e4SLinus Torvalds echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds if [ -x /bin/dnsdomainname ]; then 699c3049c0SFelipe Contreras domain=`dnsdomainname 2> /dev/null` 701da177e4SLinus Torvalds elif [ -x /bin/domainname ]; then 719c3049c0SFelipe Contreras domain=`domainname 2> /dev/null` 729c3049c0SFelipe Contreras fi 739c3049c0SFelipe Contreras 749c3049c0SFelipe Contreras if [ -n "$domain" ]; then 759c3049c0SFelipe Contreras echo \#define LINUX_COMPILE_DOMAIN \"`echo $domain | $UTS_TRUNCATE`\" 761da177e4SLinus Torvalds else 771da177e4SLinus Torvalds echo \#define LINUX_COMPILE_DOMAIN 781da177e4SLinus Torvalds fi 791da177e4SLinus Torvalds 8087c94bfbSSam Ravnborg echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" 811da177e4SLinus Torvalds) > .tmpcompile 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds# Only replace the real compile.h if the new one is different, 841da177e4SLinus Torvalds# in order to preserve the timestamp and avoid unnecessary 851da177e4SLinus Torvalds# recompilations. 861da177e4SLinus Torvalds# We don't consider the file changed if only the date/time changed. 871da177e4SLinus Torvalds# A kernel config change will increase the generation number, thus 881da177e4SLinus Torvalds# causing compile.h to be updated (including date/time) due to the 891da177e4SLinus Torvalds# changed comment in the 901da177e4SLinus Torvalds# first line. 911da177e4SLinus Torvalds 921da177e4SLinus Torvaldsif [ -r $TARGET ] && \ 931da177e4SLinus Torvalds grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \ 941da177e4SLinus Torvalds grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \ 951da177e4SLinus Torvalds cmp -s .tmpver.1 .tmpver.2; then 961da177e4SLinus Torvalds rm -f .tmpcompile 971da177e4SLinus Torvaldselse 98d03fab43SMike Frysinger vecho " UPD $TARGET" 991da177e4SLinus Torvalds mv -f .tmpcompile $TARGET 1001da177e4SLinus Torvaldsfi 1011da177e4SLinus Torvaldsrm -f .tmpver.1 .tmpver.2 102