tests: default: funnyordie.json: Update
[libquvi-scripts.git] / gen-ver.sh
blob414a01bb44430acb95d34208175ed4604e7fa7ca
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 VN=`perl -ne'/(\d+)\.(\d+)\.(\d+)/ && print "$1.$2.$3"' < "$m4"`
43 [ -z $VN ] && exit $?
45 # Use the "git describe" instead, if .git is present
46 if test -d "$path/.git" -o -f "$path/.git" ; then
47 _VN=`git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null`
48 [ -n "$_VN" ] && VN=$_VN
51 echo $VN
54 help()
56 echo "Usage: $0 [-h] [top_srcdir]
57 -h Show this help and exit
58 Run without options to print version. Define top_srcdir if run outside
59 the top source directory."
60 exit 0
63 while [ $# -gt 0 ]
65 case "$1" in
66 -h) help;;
67 *) break;;
68 esac
69 shift
70 done
72 gen_version $1