btrfs-progs: library version defines
[platform/upstream/btrfs-progs.git] / version.sh
1 #!/bin/bash
2 #
3 # determine-version -- report a useful version for releases
4 #
5 # Copyright 2008, Aron Griffis <agriffis@n01se.net>
6 # Copyright 2008, Oracle
7 # Released under the GNU GPLv2
8  
9 v="v3.16"
10
11 lib_major=0
12 lib_minor=1
13 lib_patchlevel=1
14
15 which git &> /dev/null
16 if [ $? == 0 -a -d .git ]; then
17     if head=`git rev-parse --verify HEAD 2>/dev/null`; then
18         if tag=`git describe --tags 2>/dev/null`; then
19             v="$tag"
20         fi
21
22         # Are there uncommitted changes?
23         git update-index --refresh --unmerged > /dev/null
24         if git diff-index --name-only HEAD | grep -v "^scripts/package" \
25             | read dummy; then
26             v="$v"-dirty
27         fi
28     fi
29 fi
30
31 echo "/* NOTE: this file is autogenerated by version.sh, do not edit */" > .build-version.h
32 echo "#ifndef __BUILD_VERSION" >> .build-version.h
33 echo >> .build-version.h
34 echo "#define __BUILD_VERSION" >> .build-version.h
35 echo >> .build-version.h
36 echo "#define BTRFS_LIB_MAJOR $lib_major" >> .build-version.h
37 echo "#define BTRFS_LIB_MINOR $lib_minor" >> .build-version.h
38 echo "#define BTRFS_LIB_PATCHLEVEL $lib_patchlevel" >> .build-version.h
39 echo >> .build-version.h
40 echo "#define BTRFS_LIB_VERSION ( BTRFS_LIB_MAJOR * 10000 + \\" >> .build-version.h
41 echo "                            BTRFS_LIB_MINOR * 100 + \\" >> .build-version.h
42 echo "                            BTRFS_LIB_PATCHLEVEL )" >> .build-version.h
43 echo >> .build-version.h
44 echo "#define BTRFS_BUILD_VERSION \"Btrfs $v\"" >> .build-version.h
45 echo "#endif" >> .build-version.h
46
47 diff -q version.h .build-version.h >& /dev/null
48
49 if [ $? == 0 ]; then
50     rm .build-version.h
51     exit 0
52 fi
53
54 mv .build-version.h version.h