Pan Xiuli | 0e620cd | 2018-08-09 11:45:43 +0800 | [diff] [blame] | 1 | #!/bin/bash |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 2 | |
| 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 |
| 8 | if [ $# -eq 0 ]; then |
| 9 | DIR=`pwd` |
| 10 | else |
| 11 | DIR=$1 |
| 12 | fi |
| 13 | |
Liam Girdwood | 856f768 | 2018-03-21 09:42:02 +0000 | [diff] [blame] | 14 | # get version from git tag |
Pan Xiuli | 0e620cd | 2018-08-09 11:45:43 +0800 | [diff] [blame] | 15 | GIT_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 |
| 18 | if [[ "x$GIT_TAG" == "x" ]] |
| 19 | then |
| 20 | GIT_TAG="v0.0-0-g0000" |
| 21 | fi |
Liam Girdwood | 856f768 | 2018-03-21 09:42:02 +0000 | [diff] [blame] | 22 | |
| 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 Kulesza | 0228d8d | 2018-06-04 12:03:40 +0100 | [diff] [blame] | 25 | if [ $(expr match $GIT_TAG 'SOF_FW_[A-Z]+_' ) -lt 15 ]; then |
Liam Girdwood | 856f768 | 2018-03-21 09:42:02 +0000 | [diff] [blame] | 26 | VER=`echo $GIT_TAG | cut -d_ -f4` |
| 27 | else |
| 28 | VER=$GIT_TAG |
| 29 | fi |
| 30 | |
Liam Girdwood | 83fec15 | 2018-01-11 12:10:03 +0000 | [diff] [blame] | 31 | # create git version if we are a git repo or git worktree |
| 32 | if [ -e $DIR/.git -o -d $DIR/.git ]; then |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 33 | # version for make dist |
Liam Girdwood | 856f768 | 2018-03-21 09:42:02 +0000 | [diff] [blame] | 34 | echo $VER > $DIR/.version |
| 35 | echo $VER > $DIR/.tarball-version |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 36 | |
| 37 | # git commit for IPC |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 38 | echo "#define SOF_TAG \"`git log --pretty=format:\"%h\" -1 | cut -c1-5`\"" > $DIR/src/include/version.h |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 39 | else |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 40 | echo "#define SOF_TAG \"0\"" > $DIR/src/include/version.h |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 41 | fi |
| 42 | |
| 43 | # build counter |
| 44 | if [ -e $DIR/.build ]; then |
| 45 | num=$((`cat $DIR/.build` + 1)) |
| 46 | else |
| 47 | num=0 |
| 48 | fi |
| 49 | |
| 50 | # save and insert build counter |
| 51 | echo $num > $DIR/.build |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 52 | echo "#define SOF_BUILD $num" >> $DIR/src/include/version.h |
Liam Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 53 | |
| 54 | #echo version for AC_INIT |
| 55 | if [ -e $DIR/.version ]; then |
Liam Girdwood | 93d62e5 | 2018-01-10 20:26:08 +0000 | [diff] [blame] | 56 | 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 Girdwood | b14e852 | 2018-01-10 17:36:41 +0000 | [diff] [blame] | 57 | fi |