blob: 76a522e89a1342e6e74b72ca7b20dd9d79036417 [file] [log] [blame]
Pan Xiuli0e620cd2018-08-09 11:45:43 +08001#!/bin/bash
Liam Girdwoodb14e8522018-01-10 17:36:41 +00002
3# version for configure, make dist and FW etc
4# usage "version.sh dir"
5# Where dir is the top level directory path.
6
7# use pwd is no path argument is given
8if [ $# -eq 0 ]; then
9 DIR=`pwd`
10else
11 DIR=$1
12fi
13
Liam Girdwood856f7682018-03-21 09:42:02 +000014# get version from git tag
Pan Xiuli0e620cd2018-08-09 11:45:43 +080015GIT_TAG=`git describe --abbrev=4 2>/dev/null`
16
17# may fail to get git describe in some case, add this fallback to handle error
18if [[ "x$GIT_TAG" == "x" ]]
19then
20 GIT_TAG="v0.0-0-g0000"
21fi
Liam Girdwood856f7682018-03-21 09:42:02 +000022
23# Some releases have a SOF_FW_XXX_ prefix on the tag and this prefix
24# must be stripped for usage in version.h. i.e. we just need the number.
Kamil Kulesza0228d8d2018-06-04 12:03:40 +010025if [ $(expr match $GIT_TAG 'SOF_FW_[A-Z]+_' ) -lt 15 ]; then
Liam Girdwood856f7682018-03-21 09:42:02 +000026 VER=`echo $GIT_TAG | cut -d_ -f4`
27else
28 VER=$GIT_TAG
29fi
30
Liam Girdwood83fec152018-01-11 12:10:03 +000031# create git version if we are a git repo or git worktree
32if [ -e $DIR/.git -o -d $DIR/.git ]; then
Liam Girdwoodb14e8522018-01-10 17:36:41 +000033# version for make dist
Liam Girdwood856f7682018-03-21 09:42:02 +000034 echo $VER > $DIR/.version
35 echo $VER > $DIR/.tarball-version
Liam Girdwoodb14e8522018-01-10 17:36:41 +000036
37 # git commit for IPC
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050038 echo "#define SOF_TAG \"`git log --pretty=format:\"%h\" -1 | cut -c1-5`\"" > $DIR/src/include/version.h
Liam Girdwoodb14e8522018-01-10 17:36:41 +000039else
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050040 echo "#define SOF_TAG \"0\"" > $DIR/src/include/version.h
Liam Girdwoodb14e8522018-01-10 17:36:41 +000041fi
42
43# build counter
44if [ -e $DIR/.build ]; then
45 num=$((`cat $DIR/.build` + 1))
46else
47 num=0
48fi
49
50# save and insert build counter
51echo $num > $DIR/.build
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050052echo "#define SOF_BUILD $num" >> $DIR/src/include/version.h
Liam Girdwoodb14e8522018-01-10 17:36:41 +000053
54#echo version for AC_INIT
55if [ -e $DIR/.version ]; then
Liam Girdwood93d62e52018-01-10 20:26:08 +000056 echo -n `cat $DIR/.version | cut -dv -f2 | cut -d. -f1`.`cat $DIR/.version | cut -d. -f2 | cut -d- -f1`.`cat $DIR/.version | cut -d. -f3 | cut -d- -f1`
Liam Girdwoodb14e8522018-01-10 17:36:41 +000057fi