Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / 0.61.09 / 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         else
24                 export REVISION="$REVISION"`cd "$1"; git diff --quiet HEAD || echo M`
25         fi
26 }
27
28 get_svn_id(){
29         export SCM=svn
30         export REVISION=`cd "$1"; svnversion || svn info | sed -n 's/^Revision: \(.*\)/\1/p'`
31 }
32
33
34 HEADER="$2/autorevision.h"
35 SCM=none
36
37
38 if [ ! -f "$HEADER" ] ; then
39         touch -t 197001010101 "$HEADER"
40 fi
41
42
43 # Extract the revision from SVN/git/etc
44 if [ -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/../../.git/svn" ] ; then
49         get_git_svn_id "$1/../.."
50 elif [ -d "$1/.svn" ] ; then
51         COMPARE="$1/.svn"
52         get_svn_id "$1"
53 elif [ -d "$1/_svn" ] ; then
54         COMPARE="$1/_svn"
55         get_svn_id "$1"
56 fi
57
58
59 # Allow overriding both REVISION and DEVEL_VERSION
60 if [ -f "$2/autorevision.conf" ] ; then
61         SCM=manual
62         . "$2/autorevision.conf"
63 fi
64
65
66 # Abort if the header is newer
67 if [ "$COMPARE" -ot "$HEADER" ] ; then exit; fi
68
69
70 # Set the development version string
71 if [ x = "x$DEVEL_VERSION" ] ; then
72         if [ x != "x$REVISION" ] ; then
73                 if [ $SCM = svn ] ; then
74                         DEVEL_VERSION="SVN r$REVISION"
75                 elif [ $SCM = git-svn ] ; then
76                         DEVEL_VERSION="SVN r$REVISION (via git)"
77                 elif [ $SCM = manual ] ; then
78                         DEVEL_VERSION="$REVISION (manually configured)"
79                 fi
80         fi
81 fi
82
83
84 # Output the header
85 if [ x != "x$DEVEL_VERSION" ] ; then
86         echo "#define SHOW_EXTRA_INFO" > "$HEADER"
87         echo "#define DEVEL_VERSION \"$DEVEL_VERSION\"" >> "$HEADER"
88 fi