Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 TARGET=$1
0005 ARCH=$2
0006 SMP=$3
0007 PREEMPT=$4
0008 PREEMPT_DYNAMIC=$5
0009 PREEMPT_RT=$6
0010 CC_VERSION="$7"
0011 LD=$8
0012 
0013 # Do not expand names
0014 set -f
0015 
0016 # Fix the language to get consistent output
0017 LC_ALL=C
0018 export LC_ALL
0019 
0020 if [ -z "$KBUILD_BUILD_VERSION" ]; then
0021         VERSION=$(cat .version 2>/dev/null || echo 1)
0022 else
0023         VERSION=$KBUILD_BUILD_VERSION
0024 fi
0025 
0026 if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
0027         TIMESTAMP=`date`
0028 else
0029         TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
0030 fi
0031 if test -z "$KBUILD_BUILD_USER"; then
0032         LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
0033 else
0034         LINUX_COMPILE_BY=$KBUILD_BUILD_USER
0035 fi
0036 if test -z "$KBUILD_BUILD_HOST"; then
0037         LINUX_COMPILE_HOST=`uname -n`
0038 else
0039         LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
0040 fi
0041 
0042 UTS_VERSION="#$VERSION"
0043 CONFIG_FLAGS=""
0044 if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
0045 
0046 if [ -n "$PREEMPT_RT" ] ; then
0047         CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"
0048 elif [ -n "$PREEMPT_DYNAMIC" ] ; then
0049         CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_DYNAMIC"
0050 elif [ -n "$PREEMPT" ] ; then
0051         CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"
0052 fi
0053 
0054 # Truncate to maximum length
0055 UTS_LEN=64
0056 UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
0057 
0058 # Generate a temporary compile.h
0059 
0060 { echo /\* This file is auto generated, version $VERSION \*/
0061   if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
0062 
0063   echo \#define UTS_MACHINE \"$ARCH\"
0064 
0065   echo \#define UTS_VERSION \"$UTS_VERSION\"
0066 
0067   printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
0068   echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
0069 
0070   LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
0071                       | sed 's/[[:space:]]*$//')
0072   printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
0073 } > .tmpcompile
0074 
0075 # Only replace the real compile.h if the new one is different,
0076 # in order to preserve the timestamp and avoid unnecessary
0077 # recompilations.
0078 # We don't consider the file changed if only the date/time changed,
0079 # unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for
0080 # reproducible builds with that value referring to a commit timestamp).
0081 # A kernel config change will increase the generation number, thus
0082 # causing compile.h to be updated (including date/time) due to the
0083 # changed comment in the
0084 # first line.
0085 
0086 if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
0087    IGNORE_PATTERN="UTS_VERSION"
0088 else
0089    IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED"
0090 fi
0091 
0092 if [ -r $TARGET ] && \
0093       grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \
0094       grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \
0095       cmp -s .tmpver.1 .tmpver.2; then
0096    rm -f .tmpcompile
0097 else
0098    echo "  UPD     $TARGET"
0099    mv -f .tmpcompile $TARGET
0100 fi
0101 rm -f .tmpver.1 .tmpver.2