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 99a950154SMasahiro YamadaCC_VERSION="$6" 104dcc9a88SKees CookLD=$7 111da177e4SLinus Torvalds 12d03fab43SMike Frysingervecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } 13d03fab43SMike Frysinger 141da177e4SLinus Torvalds# Do not expand names 151da177e4SLinus Torvaldsset -f 161da177e4SLinus Torvalds 1787c94bfbSSam Ravnborg# Fix the language to get consistent output 1887c94bfbSSam RavnborgLC_ALL=C 1987c94bfbSSam Ravnborgexport LC_ALL 2087c94bfbSSam Ravnborg 2187c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_VERSION" ]; then 2237131ec4SMasahiro Yamada VERSION=$(cat .version 2>/dev/null || echo 1) 2387c94bfbSSam Ravnborgelse 2487c94bfbSSam Ravnborg VERSION=$KBUILD_BUILD_VERSION 2587c94bfbSSam Ravnborgfi 261da177e4SLinus Torvalds 2787c94bfbSSam Ravnborgif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 2887c94bfbSSam Ravnborg TIMESTAMP=`date` 2987c94bfbSSam Ravnborgelse 3087c94bfbSSam Ravnborg TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 3187c94bfbSSam Ravnborgfi 3253e6892cSMichal Marekif test -z "$KBUILD_BUILD_USER"; then 33f0772604SMarcin Nowakowski LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/') 3453e6892cSMichal Marekelse 3553e6892cSMichal Marek LINUX_COMPILE_BY=$KBUILD_BUILD_USER 3653e6892cSMichal Marekfi 3753e6892cSMichal Marekif test -z "$KBUILD_BUILD_HOST"; then 3853e6892cSMichal Marek LINUX_COMPILE_HOST=`hostname` 3953e6892cSMichal Marekelse 4053e6892cSMichal Marek LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST 4153e6892cSMichal Marekfi 421da177e4SLinus Torvalds 431da177e4SLinus TorvaldsUTS_VERSION="#$VERSION" 44bd5bdd87SSam RavnborgCONFIG_FLAGS="" 45bd5bdd87SSam Ravnborgif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 46bd5bdd87SSam Ravnborgif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 474b950bb9SThomas Gleixnerif [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds# Truncate to maximum length 501da177e4SLinus TorvaldsUTS_LEN=64 51e8193650SMasahiro YamadaUTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds# Generate a temporary compile.h 541da177e4SLinus Torvalds 55b79c6aa6SMasahiro Yamada{ 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 60e8193650SMasahiro Yamada echo \#define UTS_VERSION \"$UTS_VERSION\" 611da177e4SLinus Torvalds 62c8f3dea9SMasahiro Yamada printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" 63e8193650SMasahiro Yamada echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" 641da177e4SLinus Torvalds 654dcc9a88SKees Cook LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \ 664dcc9a88SKees Cook | sed 's/[[:space:]]*$//') 674dcc9a88SKees Cook printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION" 68b79c6aa6SMasahiro Yamada} > .tmpcompile 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds# Only replace the real compile.h if the new one is different, 711da177e4SLinus Torvalds# in order to preserve the timestamp and avoid unnecessary 721da177e4SLinus Torvalds# recompilations. 731da177e4SLinus Torvalds# We don't consider the file changed if only the date/time changed. 741da177e4SLinus Torvalds# A kernel config change will increase the generation number, thus 751da177e4SLinus Torvalds# causing compile.h to be updated (including date/time) due to the 761da177e4SLinus Torvalds# changed comment in the 771da177e4SLinus Torvalds# first line. 781da177e4SLinus Torvalds 791da177e4SLinus Torvaldsif [ -r $TARGET ] && \ 80061296dcSMichal Marek grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \ 81061296dcSMichal Marek grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \ 821da177e4SLinus Torvalds cmp -s .tmpver.1 .tmpver.2; then 831da177e4SLinus Torvalds rm -f .tmpcompile 841da177e4SLinus Torvaldselse 85d03fab43SMike Frysinger vecho " UPD $TARGET" 861da177e4SLinus Torvalds mv -f .tmpcompile $TARGET 871da177e4SLinus Torvaldsfi 881da177e4SLinus Torvaldsrm -f .tmpver.1 .tmpver.2 89