18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciif [ $# -eq 1 ] ; then 58c2ecf20Sopenharmony_ci OUTPUT=$1 68c2ecf20Sopenharmony_cifi 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciGVF=${OUTPUT}PERF-VERSION-FILE 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciLF=' 118c2ecf20Sopenharmony_ci' 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci# 148c2ecf20Sopenharmony_ci# First check if there is a .git to get the version from git describe 158c2ecf20Sopenharmony_ci# otherwise try to get the version from the kernel Makefile 168c2ecf20Sopenharmony_ci# 178c2ecf20Sopenharmony_ciCID= 188c2ecf20Sopenharmony_ciTAG= 198c2ecf20Sopenharmony_ciif test -d ../../.git -o -f ../../.git 208c2ecf20Sopenharmony_cithen 218c2ecf20Sopenharmony_ci TAG=$(git describe --abbrev=0 --match "v[0-9].[0-9]*" 2>/dev/null ) 228c2ecf20Sopenharmony_ci CID=$(git log -1 --abbrev=12 --pretty=format:"%h" 2>/dev/null) && CID="-g$CID" 238c2ecf20Sopenharmony_cielif test -f ../../PERF-VERSION-FILE 248c2ecf20Sopenharmony_cithen 258c2ecf20Sopenharmony_ci TAG=$(cut -d' ' -f3 ../../PERF-VERSION-FILE | sed -e 's/\"//g') 268c2ecf20Sopenharmony_cifi 278c2ecf20Sopenharmony_ciif test -z "$TAG" 288c2ecf20Sopenharmony_cithen 298c2ecf20Sopenharmony_ci TAG=$(MAKEFLAGS= make -sC ../.. kernelversion) 308c2ecf20Sopenharmony_cifi 318c2ecf20Sopenharmony_ciVN="$TAG$CID" 328c2ecf20Sopenharmony_ciif test -n "$CID" 338c2ecf20Sopenharmony_cithen 348c2ecf20Sopenharmony_ci # format version string, strip trailing zero of sublevel: 358c2ecf20Sopenharmony_ci VN=$(echo "$VN" | sed -e 's/-/./g;s/\([0-9]*[.][0-9]*\)[.]0/\1/') 368c2ecf20Sopenharmony_cifi 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ciVN=$(expr "$VN" : v*'\(.*\)') 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciif test -r $GVF 418c2ecf20Sopenharmony_cithen 428c2ecf20Sopenharmony_ci VC=$(sed -e 's/^#define PERF_VERSION "\(.*\)"/\1/' <$GVF) 438c2ecf20Sopenharmony_cielse 448c2ecf20Sopenharmony_ci VC=unset 458c2ecf20Sopenharmony_cifi 468c2ecf20Sopenharmony_citest "$VN" = "$VC" || { 478c2ecf20Sopenharmony_ci echo >&2 " PERF_VERSION = $VN" 488c2ecf20Sopenharmony_ci echo "#define PERF_VERSION \"$VN\"" >$GVF 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci 52