^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) if [ $# -eq 1 ] ; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) OUTPUT=$1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) GVF=${OUTPUT}PERF-VERSION-FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) LF='
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) '
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # First check if there is a .git to get the version from git describe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # otherwise try to get the version from the kernel Makefile
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) CID=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) TAG=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) if test -d ../../.git -o -f ../../.git
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) TAG=$(git describe --abbrev=0 --match "v[0-9].[0-9]*" 2>/dev/null )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) CID=$(git log -1 --abbrev=12 --pretty=format:"%h" 2>/dev/null) && CID="-g$CID"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) elif test -f ../../PERF-VERSION-FILE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) TAG=$(cut -d' ' -f3 ../../PERF-VERSION-FILE | sed -e 's/\"//g')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if test -z "$TAG"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) TAG=$(MAKEFLAGS= make -sC ../.. kernelversion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) VN="$TAG$CID"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) if test -n "$CID"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) # format version string, strip trailing zero of sublevel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) VN=$(echo "$VN" | sed -e 's/-/./g;s/\([0-9]*[.][0-9]*\)[.]0/\1/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) VN=$(expr "$VN" : v*'\(.*\)')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if test -r $GVF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) VC=$(sed -e 's/^#define PERF_VERSION "\(.*\)"/\1/' <$GVF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) VC=unset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) test "$VN" = "$VC" || {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) echo >&2 " PERF_VERSION = $VN"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) echo "#define PERF_VERSION \"$VN\"" >$GVF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)