11da177e4SLinus TorvaldsTARGET=$1 21da177e4SLinus TorvaldsARCH=$2 31da177e4SLinus TorvaldsSMP=$3 4bd5bdd87SSam RavnborgPREEMPT=$4 5bd5bdd87SSam RavnborgCC=$5 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds# If compile.h exists already and we don't own autoconf.h 81da177e4SLinus Torvalds# (i.e. we're not the same user who did make *config), don't 91da177e4SLinus Torvalds# modify compile.h 101da177e4SLinus Torvalds# So "sudo make install" won't change the "compiled by <user>" 111da177e4SLinus Torvalds# do "compiled by root" 121da177e4SLinus Torvalds 131da177e4SLinus Torvaldsif [ -r $TARGET -a ! -O include/linux/autoconf.h ]; then 141da177e4SLinus Torvalds echo " SKIPPED $TARGET" 151da177e4SLinus Torvalds exit 0 161da177e4SLinus Torvaldsfi 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds# Do not expand names 191da177e4SLinus Torvaldsset -f 201da177e4SLinus Torvalds 2187c94bfbSSam Ravnborg# Fix the language to get consistent output 2287c94bfbSSam RavnborgLC_ALL=C 2387c94bfbSSam Ravnborgexport LC_ALL 2487c94bfbSSam Ravnborg 2587c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_VERSION" ]; then 261da177e4SLinus Torvalds if [ -r .version ]; then 271da177e4SLinus Torvalds VERSION=`cat .version` 281da177e4SLinus Torvalds else 291da177e4SLinus Torvalds VERSION=0 301da177e4SLinus Torvalds echo 0 > .version 311da177e4SLinus Torvalds fi 3287c94bfbSSam Ravnborgelse 3387c94bfbSSam Ravnborg VERSION=$KBUILD_BUILD_VERSION 3487c94bfbSSam Ravnborgfi 351da177e4SLinus Torvalds 3687c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 3787c94bfbSSam Ravnborg TIMESTAMP=`date` 3887c94bfbSSam Ravnborgelse 3987c94bfbSSam Ravnborg TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 4087c94bfbSSam Ravnborgfi 411da177e4SLinus Torvalds 421da177e4SLinus TorvaldsUTS_VERSION="#$VERSION" 43bd5bdd87SSam RavnborgCONFIG_FLAGS="" 44bd5bdd87SSam Ravnborgif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 45bd5bdd87SSam Ravnborgif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 4687c94bfbSSam RavnborgUTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP" 471da177e4SLinus Torvalds 481da177e4SLinus Torvalds# Truncate to maximum length 491da177e4SLinus Torvalds 501da177e4SLinus TorvaldsUTS_LEN=64 511da177e4SLinus TorvaldsUTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/" 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds# Generate a temporary compile.h 541da177e4SLinus Torvalds 551da177e4SLinus Torvalds( echo /\* This file is auto generated, version $VERSION \*/ 56bd5bdd87SSam Ravnborg if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds echo \#define UTS_MACHINE \"$ARCH\" 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" 611da177e4SLinus Torvalds 6287c94bfbSSam Ravnborg echo \#define LINUX_COMPILE_TIME \"`date +%T`\" 631da177e4SLinus Torvalds echo \#define LINUX_COMPILE_BY \"`whoami`\" 641da177e4SLinus Torvalds echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds if [ -x /bin/dnsdomainname ]; then 671da177e4SLinus Torvalds echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\" 681da177e4SLinus Torvalds elif [ -x /bin/domainname ]; then 691da177e4SLinus Torvalds echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\" 701da177e4SLinus Torvalds else 711da177e4SLinus Torvalds echo \#define LINUX_COMPILE_DOMAIN 721da177e4SLinus Torvalds fi 731da177e4SLinus Torvalds 7487c94bfbSSam Ravnborg echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" 751da177e4SLinus Torvalds) > .tmpcompile 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds# Only replace the real compile.h if the new one is different, 781da177e4SLinus Torvalds# in order to preserve the timestamp and avoid unnecessary 791da177e4SLinus Torvalds# recompilations. 801da177e4SLinus Torvalds# We don't consider the file changed if only the date/time changed. 811da177e4SLinus Torvalds# A kernel config change will increase the generation number, thus 821da177e4SLinus Torvalds# causing compile.h to be updated (including date/time) due to the 831da177e4SLinus Torvalds# changed comment in the 841da177e4SLinus Torvalds# first line. 851da177e4SLinus Torvalds 861da177e4SLinus Torvaldsif [ -r $TARGET ] && \ 871da177e4SLinus Torvalds grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \ 881da177e4SLinus Torvalds grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \ 891da177e4SLinus Torvalds cmp -s .tmpver.1 .tmpver.2; then 901da177e4SLinus Torvalds rm -f .tmpcompile 911da177e4SLinus Torvaldselse 921da177e4SLinus Torvalds echo " UPD $TARGET" 931da177e4SLinus Torvalds mv -f .tmpcompile $TARGET 941da177e4SLinus Torvaldsfi 951da177e4SLinus Torvaldsrm -f .tmpver.1 .tmpver.2 96