blob: 39f17507578dae0c650dc91335e888d9a907ef4a [file] [log] [blame]
Ingo Molnar07800602009-04-20 15:00:56 +02001#!/bin/sh
2
Arnaldo Carvalho de Meloc29ede62010-03-27 14:30:45 -03003if [ $# -eq 1 ] ; then
4 OUTPUT=$1
5fi
6
7GVF=${OUTPUT}PERF-VERSION-FILE
Ingo Molnar07800602009-04-20 15:00:56 +02008
9LF='
10'
11
Ingo Molnar0e2af952012-10-30 09:54:41 +010012#
Thavidu Ranatunga869599c2010-07-05 18:00:15 +100013# First check if there is a .git to get the version from git describe
Ingo Molnar0e2af952012-10-30 09:54:41 +010014# otherwise try to get the version from the kernel Makefile
15#
Robert Richtera4147f02013-05-08 11:43:34 +020016CID=
17TAG=
18if test -d ../../.git -o -f ../../.git
Ingo Molnar07800602009-04-20 15:00:56 +020019then
Robert Richtera4147f02013-05-08 11:43:34 +020020 TAG=$(git describe --abbrev=0 --match "v[0-9].[0-9]*" 2>/dev/null )
21 CID=$(git log -1 --abbrev=4 --pretty=format:"%h" 2>/dev/null) && CID="-g$CID"
David Aherna614d012013-11-06 08:55:35 -070022elif test -f ../../PERF-VERSION-FILE
23then
24 TAG=$(cut -d' ' -f3 ../../PERF-VERSION-FILE | sed -e 's/\"//g')
Robert Richtera4147f02013-05-08 11:43:34 +020025fi
26if test -z "$TAG"
27then
28 TAG=$(MAKEFLAGS= make -sC ../.. kernelversion)
29fi
30VN="$TAG$CID"
31if test -n "$CID"
32then
33 # format version string, strip trailing zero of sublevel:
34 VN=$(echo "$VN" | sed -e 's/-/./g;s/\([0-9]*[.][0-9]*\)[.]0/\1/')
Ingo Molnar07800602009-04-20 15:00:56 +020035fi
36
37VN=$(expr "$VN" : v*'\(.*\)')
38
39if test -r $GVF
40then
Namhyung Kim3cecaa22013-01-16 20:59:53 +090041 VC=$(sed -e 's/^#define PERF_VERSION "\(.*\)"/\1/' <$GVF)
Ingo Molnar07800602009-04-20 15:00:56 +020042else
43 VC=unset
44fi
45test "$VN" = "$VC" || {
Ingo Molnar3fae82d2013-10-09 11:49:28 +020046 echo >&2 " PERF_VERSION = $VN"
Namhyung Kim3cecaa22013-01-16 20:59:53 +090047 echo "#define PERF_VERSION \"$VN\"" >$GVF
Ingo Molnar07800602009-04-20 15:00:56 +020048}
49
50