Merge branch 'tg/next/1.0_rename_to_0.9' into tg/next/1.0
[libquvi-scripts.git] / gen-ver.sh
blob21abe229c5ffd9c9ed56a2b2654a340507c92e98
1 #!/bin/sh
3 # gen-ver.sh for libquvi-scripts
4 # Copyright (C) 2011 Toni Gundogdu
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301 USA
21 set -e
23 from_file()
25 VN=`cat $1 2>/dev/null`
26 if test -n "$VN"; then
27 echo $VN
28 exit 0
32 gen_version() # $1=path to top source dir
34 path=$1 ; [ -z $path ] && path=.
36 # First check if the version file exists and use its value
37 versionfn="$path/VERSION"
38 [ -f "$versionfn" ] && from_file "$versionfn"
40 # If that file is not found, or fails (e.g. empty), parse from m4/version.m4
41 m4="$path/m4/version.m4"
42 rmaj=`perl -ne'/.*_rmaj.*\[(\d+)\]/ && print "$1"' < "$m4"`
43 rmin=`perl -ne'/.*_rmin.*\[(\d+)\]/ && print "$1"' < "$m4"`
44 rmic=`perl -ne'/.*_rmic.*\[(\d+)\]/ && print "$1"' < "$m4"`
45 VN="$rmaj.$rmin.$rmic"
46 [ -z $VN ] && exit $?
48 # Use the "git describe" instead, if .git is present
49 if test -d "$path/.git" -o -f "$path/.git" ; then
50 _VN=`git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null`
51 [ -n "$_VN" ] && VN=$_VN
54 echo $VN
57 help()
59 echo "Usage: $0 [-h] [top_srcdir]
60 -h Show this help and exit
61 Run without options to print version. Define top_srcdir if run outside
62 the top source directory."
63 exit 0
66 while [ $# -gt 0 ]
68 case "$1" in
69 -h) help;;
70 *) break;;
71 esac
72 shift
73 done
75 gen_version $1