1af594f0cSDominik Brodowski#!/bin/sh
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3af594f0cSDominik Brodowski#
4af594f0cSDominik Brodowski# Script which prints out the version to use for building cpupowerutils.
5af594f0cSDominik Brodowski# Must be called from tools/power/cpupower/
6af594f0cSDominik Brodowski# 
7af594f0cSDominik Brodowski# Heavily based on tools/perf/util/PERF-VERSION-GEN .
8af594f0cSDominik Brodowski
9af594f0cSDominik BrodowskiLF='
10af594f0cSDominik Brodowski'
11af594f0cSDominik Brodowski
12af594f0cSDominik Brodowski# First check if there is a .git to get the version from git describe
13af594f0cSDominik Brodowski# otherwise try to get the version from the kernel makefile
14af594f0cSDominik Brodowskiif test -d ../../../.git -o -f ../../../.git &&
15af594f0cSDominik Brodowski	VN=$(git describe --abbrev=4 HEAD 2>/dev/null) &&
16af594f0cSDominik Brodowski	case "$VN" in
17af594f0cSDominik Brodowski	*$LF*) (exit 1) ;;
18af594f0cSDominik Brodowski	v[0-9]*)
19af594f0cSDominik Brodowski		git update-index -q --refresh
20af594f0cSDominik Brodowski		test -z "$(git diff-index --name-only HEAD --)" ||
21af594f0cSDominik Brodowski		VN="$VN-dirty" ;;
22af594f0cSDominik Brodowski	esac
23af594f0cSDominik Brodowskithen
24af594f0cSDominik Brodowski	VN=$(echo "$VN" | sed -e 's/-/./g');
25af594f0cSDominik Brodowskielse
26af594f0cSDominik Brodowski	eval $(grep '^VERSION[[:space:]]*=' ../../../Makefile|tr -d ' ')
27af594f0cSDominik Brodowski	eval $(grep '^PATCHLEVEL[[:space:]]*=' ../../../Makefile|tr -d ' ')
28af594f0cSDominik Brodowski	eval $(grep '^SUBLEVEL[[:space:]]*=' ../../../Makefile|tr -d ' ')
29af594f0cSDominik Brodowski	eval $(grep '^EXTRAVERSION[[:space:]]*=' ../../../Makefile|tr -d ' ')
30af594f0cSDominik Brodowski
31af594f0cSDominik Brodowski	VN="${VERSION}.${PATCHLEVEL}.${SUBLEVEL}${EXTRAVERSION}"
32af594f0cSDominik Brodowskifi
33af594f0cSDominik Brodowski
34af594f0cSDominik BrodowskiVN=$(expr "$VN" : v*'\(.*\)')
35af594f0cSDominik Brodowski
36af594f0cSDominik Brodowskiecho $VN
37