c3c67cfd610aca0d97c1ef102d7594cd1798cee2
[synfig.git] / synfig-studio / trunk / build_tools / autorevision.sh
1 #!/bin/sh
2
3 # Copyright 2008 Paul Wise
4 #
5 # This package is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of
8 # the License, or (at your option) any later version.
9 #
10 # This package is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14
15
16 get_git_svn_id(){
17         export SCM=git-svn
18         export REVISION=`cd "$1"; git svn find-rev HEAD`
19         export COMPARE="$1/.git/"
20         if [ x = "x$REVISION" ] ; then
21                 # The extra M at the end is for Modified
22                 export REVISION=`cd "$1"; git svn find-rev \`git rev-list --max-count=1 --grep='git-svn-id: ' HEAD\``M
23         fi
24 }
25
26 get_svn_id(){
27         export SCM=svn
28         export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
29 }
30
31
32 HEADER="$2/autorevision.h"
33 SCM=none
34
35
36 if [ ! -f "$HEADER" ] ; then
37         touch -t 197001010101 "$HEADER"
38 fi
39
40
41 # Extract the revision from SVN/git/etc
42 if [ -d "$1/.git/svn" ] ; then
43         get_git_svn_id "$1"
44 elif [ -d "$1/../.git/svn" ] ; then
45         get_git_svn_id "$1/.."
46 elif [ -d "$1/../../.git/svn" ] ; then
47         get_git_svn_id "$1/../.."
48 elif [ -d "$1/.svn" ] ; then
49         COMPARE="$1/.svn"
50         get_svn_id "$1"
51 elif [ -d "$1/_svn" ] ; then
52         COMPARE="$1/_svn"
53         get_svn_id "$1"
54 fi
55
56
57 # Allow overriding both REVISION and DEVEL_VERSION
58 if [ -f "$2/autorevision.conf" ] ; then
59         SCM=manual
60         . "$2/autorevision.conf"
61 fi
62
63
64 # Abort if the header is newer
65 if [ "$COMPARE" -ot "$HEADER" ] ; then return; fi
66
67
68 # Set the development version string
69 if [ x = "x$DEVEL_VERSION" ] ; then
70         if [ x != "x$REVISION" ] ; then
71                 if [ $SCM = svn ] ; then
72                         DEVEL_VERSION="SVN r$REVISION"
73                 elif [ $SCM = git-svn ] ; then
74                         DEVEL_VERSION="SVN r$REVISION (via git)"
75                 elif [ $SCM = manual ] ; then
76                         DEVEL_VERSION="$REVISION (manually configured)"
77                 fi
78         fi
79 fi
80
81
82 # Output the header
83 if [ x != "x$DEVEL_VERSION" ] ; then
84         echo "#define SHOW_EXTRA_INFO" > "$HEADER"
85         echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"
86 fi