117c5ca98SFelipe Contreras#!/bin/sh 2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 317c5ca98SFelipe Contreras 41da177e4SLinus TorvaldsTARGET=$1 51da177e4SLinus TorvaldsARCH=$2 61da177e4SLinus TorvaldsSMP=$3 7bd5bdd87SSam RavnborgPREEMPT=$4 84b950bb9SThomas GleixnerPREEMPT_RT=$5 94b950bb9SThomas GleixnerCC=$6 101da177e4SLinus Torvalds 11d03fab43SMike Frysingervecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } 12d03fab43SMike Frysinger 131da177e4SLinus Torvalds# If compile.h exists already and we don't own autoconf.h 141da177e4SLinus Torvalds# (i.e. we're not the same user who did make *config), don't 151da177e4SLinus Torvalds# modify compile.h 161da177e4SLinus Torvalds# So "sudo make install" won't change the "compiled by <user>" 171da177e4SLinus Torvalds# do "compiled by root" 181da177e4SLinus Torvalds 19264a2683SSam Ravnborgif [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then 20d03fab43SMike Frysinger vecho " SKIPPED $TARGET" 211da177e4SLinus Torvalds exit 0 221da177e4SLinus Torvaldsfi 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds# Do not expand names 251da177e4SLinus Torvaldsset -f 261da177e4SLinus Torvalds 2787c94bfbSSam Ravnborg# Fix the language to get consistent output 2887c94bfbSSam RavnborgLC_ALL=C 2987c94bfbSSam Ravnborgexport LC_ALL 3087c94bfbSSam Ravnborg 3187c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_VERSION" ]; then 3237131ec4SMasahiro Yamada VERSION=$(cat .version 2>/dev/null || echo 1) 3387c94bfbSSam Ravnborgelse 3487c94bfbSSam Ravnborg VERSION=$KBUILD_BUILD_VERSION 3587c94bfbSSam Ravnborgfi 361da177e4SLinus Torvalds 3787c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 3887c94bfbSSam Ravnborg TIMESTAMP=`date` 3987c94bfbSSam Ravnborgelse 4087c94bfbSSam Ravnborg TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 4187c94bfbSSam Ravnborgfi 4253e6892cSMichal Marekif test -z "$KBUILD_BUILD_USER"; then 43f0772604SMarcin Nowakowski LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/') 4453e6892cSMichal Marekelse 4553e6892cSMichal Marek LINUX_COMPILE_BY=$KBUILD_BUILD_USER 4653e6892cSMichal Marekfi 4753e6892cSMichal Marekif test -z "$KBUILD_BUILD_HOST"; then 4853e6892cSMichal Marek LINUX_COMPILE_HOST=`hostname` 4953e6892cSMichal Marekelse 5053e6892cSMichal Marek LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST 5153e6892cSMichal Marekfi 521da177e4SLinus Torvalds 531da177e4SLinus TorvaldsUTS_VERSION="#$VERSION" 54bd5bdd87SSam RavnborgCONFIG_FLAGS="" 55bd5bdd87SSam Ravnborgif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 56bd5bdd87SSam Ravnborgif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 574b950bb9SThomas Gleixnerif [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds# Truncate to maximum length 601da177e4SLinus TorvaldsUTS_LEN=64 61e8193650SMasahiro YamadaUTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds# Generate a temporary compile.h 641da177e4SLinus Torvalds 65b79c6aa6SMasahiro Yamada{ echo /\* This file is auto generated, version $VERSION \*/ 66bd5bdd87SSam Ravnborg if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds echo \#define UTS_MACHINE \"$ARCH\" 691da177e4SLinus Torvalds 70e8193650SMasahiro Yamada echo \#define UTS_VERSION \"$UTS_VERSION\" 711da177e4SLinus Torvalds 72c8f3dea9SMasahiro Yamada printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" 73e8193650SMasahiro Yamada echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" 741da177e4SLinus Torvalds 75adcc3f7cSJonathan Liu echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\" 76b79c6aa6SMasahiro Yamada} > .tmpcompile 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds# Only replace the real compile.h if the new one is different, 791da177e4SLinus Torvalds# in order to preserve the timestamp and avoid unnecessary 801da177e4SLinus Torvalds# recompilations. 811da177e4SLinus Torvalds# We don't consider the file changed if only the date/time changed. 821da177e4SLinus Torvalds# A kernel config change will increase the generation number, thus 831da177e4SLinus Torvalds# causing compile.h to be updated (including date/time) due to the 841da177e4SLinus Torvalds# changed comment in the 851da177e4SLinus Torvalds# first line. 861da177e4SLinus Torvalds 871da177e4SLinus Torvaldsif [ -r $TARGET ] && \ 88061296dcSMichal Marek grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \ 89061296dcSMichal Marek grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \ 901da177e4SLinus Torvalds cmp -s .tmpver.1 .tmpver.2; then 911da177e4SLinus Torvalds rm -f .tmpcompile 921da177e4SLinus Torvaldselse 93d03fab43SMike Frysinger vecho " UPD $TARGET" 941da177e4SLinus Torvalds mv -f .tmpcompile $TARGET 951da177e4SLinus Torvaldsfi 961da177e4SLinus Torvaldsrm -f .tmpver.1 .tmpver.2 97