Imported Upstream version 1.0beta3
[platform/upstream/syncevolution.git] / gen-autotools.sh
1 #! /bin/sh
2 #
3 # This script generates the autotools configure.in and
4 # Makefile.am files from the information provided by
5 # SyncEvolution and backends in src/backends. The
6 # motivation for this non-standard approach was that
7 # it allows adding new backends without touching core
8 # files, which should have simplified the development of
9 # out-of-tree backends. Now git pretty much removes
10 # the need for such tricks, but it's still around.
11
12 # Another reason for gen-autotools.sh is that it generates
13 # the version in the configure script. This cannot be
14 # done inside the script because autoconf expects a
15 # literal string, not some kind of variable.
16 #
17 # To use the version specified in AC_INIT() unmodified,
18 # the following checks must pass:
19 # - SyncEvolution source is clean (git status reports
20 #   no "modified" files or "untracked" files, or the source
21 #   is not in git at all)
22 # - the source is tagged with the version of SyncEvolution
23 #   (git describe --tags HEAD reports something which matches,
24 #   for example syncevolution-1-0-beta-2a for 1.0beta2a)
25 # - same for libsynthesis, if the SYNTHESISSRC env variable
26 #   is set
27 #
28 # If these tests fail, the version is extended:
29 # +<yyyymmdd>+SE+<status>+SYSYNC+<status>
30 # <yyyymmdd> = date
31 # <status> = <hash>[+unclean]
32 # <hash> = shortened hash from describe (for example, 1040ffd)
33 # +unclean = source was dirty
34
35 set -e
36
37 version=`grep '^AC_INIT' configure-pre.in | sed -e 's/.*\[\(.*\)\])/\1/'`
38 checksource () {
39     dir=$1
40     force=$2
41     dirty=
42     if [ ! -d $dir/.git ]; then
43         return
44     fi
45
46     cur=`pwd`
47     cd $dir
48     
49     if git status | grep -e "modified:" -e "Untracked files:" -q; then
50         dirty=+unclean
51     fi
52     describe=`git describe --tags`
53     hash=`git show-ref --abbrev --hash HEAD`
54     if echo $describe | grep -e '-[0-9]+-[0-9a-f]{8}$' -q; then
55         exact=
56         tag=`echo $describe | sed -e 's/-[0123456789]*-g.*//'`
57     else
58         exact=1
59         tag=$describe
60     fi
61     simpletag=$tag
62     # Hyphens between numbers in the tag are dots in the version
63     # and all other hyphens can be removed.
64     while true; do
65         tmp=`echo $simpletag | sed -e 's/\([0123456789]\)-\([0123456789]\)/\1.\2/'`
66         if [ $tmp = $simpletag ]; then
67             break
68         else
69             simpletag=$tmp
70         fi
71     done
72     simpletag=`echo $simpletag | sed -e 's/-//g'`
73     if [ "$dirty" ] || [ "$force" ]; then
74         # previous check failed, always print hash
75         echo $hash$dirty
76     elif [ "$exact" ] &&
77         echo $simpletag | grep -q "syncevolution${version}\$"; then
78         true
79     else
80         echo $hash$dirty
81     fi
82     cd $cur
83 }
84
85 versionsuffix=
86 syncevo=`checksource .`
87 if [ "$SYNTHESISSRC" ]; then
88     sysync=`checksource $SYNTHESISSRC $syncevo`
89 fi
90 # run check again, to get hash when only libsynthesis failed
91 syncevo=`checksource . $sysync`
92 if [ "$syncevo" ]; then
93     versionsuffix=+SE+$syncevo
94 fi
95 if [ "$sysync" ]; then
96     versionsuffix=$versionsuffix+SYSYNC+$sysync
97 fi
98 if [ "$versionsuffix" ]; then
99     versionsuffix=+`date +%Y%m%d`$versionsuffix
100 fi
101
102
103 # generate configure.in from main configure-*.in pieces
104 # and all backend configure-sub.in pieces
105 rm -f configure.in
106 sed -e "s/^\\(AC_INIT.*\\)\\[\\(.*\\)\\]/\\1[\\2$versionsuffix]/" configure-pre.in >>configure.in
107
108 BACKENDS=
109 SUBS=
110 for sub in src/backends/*/configure-sub.in; do
111     BACKENDS="$BACKENDS `dirname $sub | sed -e 's;^src/;;'`"
112     SUBS="$SUBS $sub"
113     echo "# vvvvvvvvvvvvvv $sub vvvvvvvvvvvvvv" >>configure.in
114     cat $sub >>configure.in
115     echo "AC_CONFIG_FILES(`echo $sub | sed -e s/configure-sub.in/Makefile/`)" >>configure.in
116     echo "# ^^^^^^^^^^^^^^ $sub ^^^^^^^^^^^^^^" >>configure.in
117     echo >>configure.in
118 done
119 cat configure-post.in >>configure.in
120
121 TEMPLATE_FILES=`cd src && find templates -type f \( -name README -o -name '*.png' -o -name '*.svg' -o -name '*.ini' \)`
122 TEMPLATE_FILES=`echo $TEMPLATE_FILES`
123
124 # create Makefile.am files
125 sed -e "s;@BACKEND_REGISTRIES@;`echo src/backends/*/*Register.cpp | sed -e s%src/%%g`;" \
126     -e "s;@BACKENDS@;$BACKENDS;" \
127     -e "s;@TEMPLATE_FILES@;$TEMPLATE_FILES;" \
128      src/Makefile-gen.am >src/Makefile.am
129
130 sed -e "s;@CONFIG_SUBS@;$SUBS;" \
131     Makefile-gen.am >Makefile.am
132
133 # create LINGUAS file: every .po is included
134 (cd po && ls -1 *.po | sort -u | sed -e 's/.po$//' > LINGUAS)