18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
38c2ecf20Sopenharmony_ci#
48c2ecf20Sopenharmony_ci# Script which prints out the version to use for building cpupowerutils.
58c2ecf20Sopenharmony_ci# Must be called from tools/power/cpupower/
68c2ecf20Sopenharmony_ci# 
78c2ecf20Sopenharmony_ci# Heavily based on tools/perf/util/PERF-VERSION-GEN .
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciLF='
108c2ecf20Sopenharmony_ci'
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci# First check if there is a .git to get the version from git describe
138c2ecf20Sopenharmony_ci# otherwise try to get the version from the kernel makefile
148c2ecf20Sopenharmony_ciif test -d ../../../.git -o -f ../../../.git &&
158c2ecf20Sopenharmony_ci	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
168c2ecf20Sopenharmony_ci	case "$VN" in
178c2ecf20Sopenharmony_ci	*$LF*) (exit 1) ;;
188c2ecf20Sopenharmony_ci	v[0-9]*)
198c2ecf20Sopenharmony_ci		git update-index -q --refresh
208c2ecf20Sopenharmony_ci		test -z "$(git diff-index --name-only HEAD --)" ||
218c2ecf20Sopenharmony_ci		VN="$VN-dirty" ;;
228c2ecf20Sopenharmony_ci	esac
238c2ecf20Sopenharmony_cithen
248c2ecf20Sopenharmony_ci	VN=$(echo "$VN" | sed -e 's/-/./g');
258c2ecf20Sopenharmony_cielse
268c2ecf20Sopenharmony_ci	eval $(grep '^VERSION[[:space:]]*=' ../../../Makefile|tr -d ' ')
278c2ecf20Sopenharmony_ci	eval $(grep '^PATCHLEVEL[[:space:]]*=' ../../../Makefile|tr -d ' ')
288c2ecf20Sopenharmony_ci	eval $(grep '^SUBLEVEL[[:space:]]*=' ../../../Makefile|tr -d ' ')
298c2ecf20Sopenharmony_ci	eval $(grep '^EXTRAVERSION[[:space:]]*=' ../../../Makefile|tr -d ' ')
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	VN="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}${EXTRAVERSION}"
328c2ecf20Sopenharmony_cifi
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciVN=$(expr "$VN" : v*'\(.*\)')
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciecho $VN
37