117c5ca98SFelipe Contreras#!/bin/sh 217c5ca98SFelipe Contreras 31da177e4SLinus TorvaldsTARGET=$1 41da177e4SLinus TorvaldsARCH=$2 51da177e4SLinus TorvaldsSMP=$3 6bd5bdd87SSam RavnborgPREEMPT=$4 7bd5bdd87SSam RavnborgCC=$5 81da177e4SLinus Torvalds 9d03fab43SMike Frysingervecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } 10d03fab43SMike Frysinger 111da177e4SLinus Torvalds# If compile.h exists already and we don't own autoconf.h 121da177e4SLinus Torvalds# (i.e. we're not the same user who did make *config), don't 131da177e4SLinus Torvalds# modify compile.h 141da177e4SLinus Torvalds# So "sudo make install" won't change the "compiled by <user>" 151da177e4SLinus Torvalds# do "compiled by root" 161da177e4SLinus Torvalds 17264a2683SSam Ravnborgif [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then 18d03fab43SMike Frysinger vecho " SKIPPED $TARGET" 191da177e4SLinus Torvalds exit 0 201da177e4SLinus Torvaldsfi 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds# Do not expand names 231da177e4SLinus Torvaldsset -f 241da177e4SLinus Torvalds 2587c94bfbSSam Ravnborg# Fix the language to get consistent output 2687c94bfbSSam RavnborgLC_ALL=C 2787c94bfbSSam Ravnborgexport LC_ALL 2887c94bfbSSam Ravnborg 2987c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_VERSION" ]; then 301da177e4SLinus Torvalds if [ -r .version ]; then 311da177e4SLinus Torvalds VERSION=`cat .version` 321da177e4SLinus Torvalds else 331da177e4SLinus Torvalds VERSION=0 341da177e4SLinus Torvalds echo 0 > .version 351da177e4SLinus Torvalds fi 3687c94bfbSSam Ravnborgelse 3787c94bfbSSam Ravnborg VERSION=$KBUILD_BUILD_VERSION 3887c94bfbSSam Ravnborgfi 391da177e4SLinus Torvalds 4087c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 4187c94bfbSSam Ravnborg TIMESTAMP=`date` 4287c94bfbSSam Ravnborgelse 4387c94bfbSSam Ravnborg TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 4487c94bfbSSam Ravnborgfi 451da177e4SLinus Torvalds 461da177e4SLinus TorvaldsUTS_VERSION="#$VERSION" 47bd5bdd87SSam RavnborgCONFIG_FLAGS="" 48bd5bdd87SSam Ravnborgif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 49bd5bdd87SSam Ravnborgif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 5087c94bfbSSam RavnborgUTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP" 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds# Truncate to maximum length 531da177e4SLinus Torvalds 541da177e4SLinus TorvaldsUTS_LEN=64 5517c5ca98SFelipe ContrerasUTS_TRUNCATE="cut -b -$UTS_LEN" 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds# Generate a temporary compile.h 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds( echo /\* This file is auto generated, version $VERSION \*/ 60bd5bdd87SSam Ravnborg if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds echo \#define UTS_MACHINE \"$ARCH\" 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\" 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds echo \#define LINUX_COMPILE_BY \"`whoami`\" 671da177e4SLinus Torvalds echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\" 681da177e4SLinus Torvalds 6987c94bfbSSam Ravnborg echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\" 701da177e4SLinus Torvalds) > .tmpcompile 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds# Only replace the real compile.h if the new one is different, 731da177e4SLinus Torvalds# in order to preserve the timestamp and avoid unnecessary 741da177e4SLinus Torvalds# recompilations. 751da177e4SLinus Torvalds# We don't consider the file changed if only the date/time changed. 761da177e4SLinus Torvalds# A kernel config change will increase the generation number, thus 771da177e4SLinus Torvalds# causing compile.h to be updated (including date/time) due to the 781da177e4SLinus Torvalds# changed comment in the 791da177e4SLinus Torvalds# first line. 801da177e4SLinus Torvalds 811da177e4SLinus Torvaldsif [ -r $TARGET ] && \ 82061296dcSMichal Marek grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \ 83061296dcSMichal Marek grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \ 841da177e4SLinus Torvalds cmp -s .tmpver.1 .tmpver.2; then 851da177e4SLinus Torvalds rm -f .tmpcompile 861da177e4SLinus Torvaldselse 87d03fab43SMike Frysinger vecho " UPD $TARGET" 881da177e4SLinus Torvalds mv -f .tmpcompile $TARGET 891da177e4SLinus Torvaldsfi 901da177e4SLinus Torvaldsrm -f .tmpver.1 .tmpver.2 91