18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciTARGET=$1 58c2ecf20Sopenharmony_ciARCH=$2 68c2ecf20Sopenharmony_ciSMP=$3 78c2ecf20Sopenharmony_ciPREEMPT=$4 88c2ecf20Sopenharmony_ciPREEMPT_RT=$5 98c2ecf20Sopenharmony_ciCC_VERSION="$6" 108c2ecf20Sopenharmony_ciLD=$7 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_civecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; } 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci# Do not expand names 158c2ecf20Sopenharmony_ciset -f 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci# Fix the language to get consistent output 188c2ecf20Sopenharmony_ciLC_ALL=C 198c2ecf20Sopenharmony_ciexport LC_ALL 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciif [ -z "$KBUILD_BUILD_VERSION" ]; then 228c2ecf20Sopenharmony_ci VERSION=$(cat .version 2>/dev/null || echo 1) 238c2ecf20Sopenharmony_cielse 248c2ecf20Sopenharmony_ci VERSION=$KBUILD_BUILD_VERSION 258c2ecf20Sopenharmony_cifi 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 288c2ecf20Sopenharmony_ci TIMESTAMP=`date` 298c2ecf20Sopenharmony_cielse 308c2ecf20Sopenharmony_ci TIMESTAMP=$KBUILD_BUILD_TIMESTAMP 318c2ecf20Sopenharmony_cifi 328c2ecf20Sopenharmony_ciif test -z "$KBUILD_BUILD_USER"; then 338c2ecf20Sopenharmony_ci LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/') 348c2ecf20Sopenharmony_cielse 358c2ecf20Sopenharmony_ci LINUX_COMPILE_BY=$KBUILD_BUILD_USER 368c2ecf20Sopenharmony_cifi 378c2ecf20Sopenharmony_ciif test -z "$KBUILD_BUILD_HOST"; then 388c2ecf20Sopenharmony_ci LINUX_COMPILE_HOST=`uname -n` 398c2ecf20Sopenharmony_cielse 408c2ecf20Sopenharmony_ci LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST 418c2ecf20Sopenharmony_cifi 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciUTS_VERSION="#$VERSION" 448c2ecf20Sopenharmony_ciCONFIG_FLAGS="" 458c2ecf20Sopenharmony_ciif [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi 468c2ecf20Sopenharmony_ciif [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi 478c2ecf20Sopenharmony_ciif [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci# Truncate to maximum length 508c2ecf20Sopenharmony_ciUTS_LEN=64 518c2ecf20Sopenharmony_ciUTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)" 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci# Generate a temporary compile.h 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci{ echo /\* This file is auto generated, version $VERSION \*/ 568c2ecf20Sopenharmony_ci if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci echo \#define UTS_MACHINE \"$ARCH\" 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci echo \#define UTS_VERSION \"$UTS_VERSION\" 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY" 638c2ecf20Sopenharmony_ci echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\" 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \ 668c2ecf20Sopenharmony_ci | sed 's/[[:space:]]*$//') 678c2ecf20Sopenharmony_ci printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION" 688c2ecf20Sopenharmony_ci} > .tmpcompile 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci# Only replace the real compile.h if the new one is different, 718c2ecf20Sopenharmony_ci# in order to preserve the timestamp and avoid unnecessary 728c2ecf20Sopenharmony_ci# recompilations. 738c2ecf20Sopenharmony_ci# We don't consider the file changed if only the date/time changed, 748c2ecf20Sopenharmony_ci# unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for 758c2ecf20Sopenharmony_ci# reproducible builds with that value referring to a commit timestamp). 768c2ecf20Sopenharmony_ci# A kernel config change will increase the generation number, thus 778c2ecf20Sopenharmony_ci# causing compile.h to be updated (including date/time) due to the 788c2ecf20Sopenharmony_ci# changed comment in the 798c2ecf20Sopenharmony_ci# first line. 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ciif [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then 828c2ecf20Sopenharmony_ci IGNORE_PATTERN="UTS_VERSION" 838c2ecf20Sopenharmony_cielse 848c2ecf20Sopenharmony_ci IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED" 858c2ecf20Sopenharmony_cifi 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciif [ -r $TARGET ] && \ 888c2ecf20Sopenharmony_ci grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \ 898c2ecf20Sopenharmony_ci grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \ 908c2ecf20Sopenharmony_ci cmp -s .tmpver.1 .tmpver.2; then 918c2ecf20Sopenharmony_ci rm -f .tmpcompile 928c2ecf20Sopenharmony_cielse 938c2ecf20Sopenharmony_ci vecho " UPD $TARGET" 948c2ecf20Sopenharmony_ci mv -f .tmpcompile $TARGET 958c2ecf20Sopenharmony_cifi 968c2ecf20Sopenharmony_cirm -f .tmpver.1 .tmpver.2 97