btrfs-progs: autoconf: add ./configure script
[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.18.2"
10
11 opt=$1
12 lib_major=0
13 lib_minor=1
14 lib_patchlevel=1
15
16 which git &> /dev/null
17 if [ $? == 0 -a -d .git ]; then
18     if head=`git rev-parse --verify HEAD 2>/dev/null`; then
19         if tag=`git describe --tags 2>/dev/null`; then
20             v="$tag"
21         fi
22
23         # Are there uncommitted changes?
24         git update-index --refresh --unmerged > /dev/null
25         if git diff-index --name-only HEAD | grep -v "^scripts/package" \
26             | read dummy; then
27             v="$v"-dirty
28         fi
29     fi
30 fi
31
32 if [ "$opt" = "--configure" ]; then
33         # Omit the trailing newline, so that m4_esyscmd can use the result directly.
34         echo "$v" | tr -d '\n'
35         exit 0
36 fi
37
38 echo "/* NOTE: this file is autogenerated by version.sh, do not edit */" > .build-version.h
39 echo "#ifndef __BUILD_VERSION" >> .build-version.h
40 echo >> .build-version.h
41 echo "#define __BUILD_VERSION" >> .build-version.h
42 echo >> .build-version.h
43 echo "#define BTRFS_LIB_MAJOR $lib_major" >> .build-version.h
44 echo "#define BTRFS_LIB_MINOR $lib_minor" >> .build-version.h
45 echo "#define BTRFS_LIB_PATCHLEVEL $lib_patchlevel" >> .build-version.h
46 echo >> .build-version.h
47 echo "#define BTRFS_LIB_VERSION ( BTRFS_LIB_MAJOR * 10000 + \\" >> .build-version.h
48 echo "                            BTRFS_LIB_MINOR * 100 + \\" >> .build-version.h
49 echo "                            BTRFS_LIB_PATCHLEVEL )" >> .build-version.h
50 echo >> .build-version.h
51 echo "#define BTRFS_BUILD_VERSION \"Btrfs $v\"" >> .build-version.h
52 echo "#endif" >> .build-version.h
53
54 diff -q version.h .build-version.h >& /dev/null
55
56 if [ $? == 0 ]; then
57     rm .build-version.h
58     exit 0
59 fi
60
61 mv .build-version.h version.h