]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/linuxptp.git/blob - version.sh
phc2sys: update '-s' option
[processor-sdk/linuxptp.git] / version.sh
1 #!/bin/sh
2 #
3 # This scripts takes the major and minor release numbers and adds
4 # local version information from the git version control system.
5 # Adapted from scripts/setlocalversion in the Linux kernel sources.
6 #
7 major=1
8 minor=8
9 extra=
11 usage() {
12         echo "Usage: $0 [srctree]" >&2
13         exit 1
14 }
16 srctree=.
17 if test $# -gt 0; then
18         srctree=$1
19         shift
20 fi
21 if test $# -gt 0 -o ! -d "$srctree"; then
22         usage
23 fi
25 scm_version()
26 {
27         cd "$srctree"
29         # Check for git and a git repo.
30         if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
32                 # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
33                 # it, because this version is defined in the top level Makefile.
34                 if [ -z "`git describe --exact-match 2>/dev/null`" ]; then
36                         # If we are past a tagged commit (like
37                         # "v2.6.30-rc5-302-g72357d5"), we pretty print it.
38                         if atag="`git describe 2>/dev/null`"; then
39                                 echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}'
41                         # If we don't have a tag at all we print -g{commitish}.
42                         else
43                                 printf '%s%s' -g $head
44                         fi
45                 fi
47                 # Update index only on r/w media
48                 [ -w . ] && git update-index --refresh --unmerged > /dev/null
50                 # Check for uncommitted changes
51                 if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
52                         printf '%s' -dirty
53                 fi
55                 # All done with git
56                 return
57         fi
58 }
60 res="${major}.${minor}${extra}$(scm_version)"
61 echo "$res"