summaryrefslogtreecommitdiff
path: root/gen-autotools.sh
blob: f1c8ba6d3fcb4b230b321f113123eee254c96e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#! /bin/sh
#
# This script generates the autotools configure.in and
# Makefile.am files from the information provided by
# SyncEvolution and backends in src/backends. The
# motivation for this non-standard approach was that
# it allows adding new backends without touching core
# files, which should have simplified the development of
# out-of-tree backends. Now git pretty much removes
# the need for such tricks, but it's still around.

# Another reason for gen-autotools.sh is that it generates
# the version in the configure script. This cannot be
# done inside the script because autoconf expects a
# literal string, not some kind of variable.
#
# To use the version specified in AC_INIT() unmodified,
# the following checks must pass:
# - SyncEvolution source is clean (git status reports
#   no "modified" files or "untracked" files, or the source
#   is not in git at all)
# - the source is tagged with the version of SyncEvolution
#   (git describe --tags HEAD reports something which matches,
#   for example syncevolution-1-0-beta-2a for 1.0beta2a)
# - same for libsynthesis, if the SYNTHESISSRC env variable
#   is set
#
# If these tests fail, the version is extended:
# +<yyyymmdd>+SE+<status>+SYSYNC+<status>
# <yyyymmdd> = date
# <status> = <hash>[+unclean]
# <hash> = shortened hash from describe (for example, 1040ffd)
# +unclean = source was dirty

set -e

version=`grep '^AC_INIT' configure-pre.in | sed -e 's/.*\[\(.*\)\])/\1/'`
checksource () {
    dir=$1
    force=$2
    dirty=
    if [ ! -d $dir/.git ]; then
        return
    fi

    cur=`pwd`
    cd $dir
    
    if git status | grep -e "modified:" -e "Untracked files:" -q; then
        dirty=+unclean
    fi
    describe=`git describe --tags`
    hash=`cat .git/HEAD | sed -e 's/ref: //'`
    hash=`git show-ref --abbrev --hash --verify $hash`
    # detect -<number of changes>-g<hash> suffix added when tag is older than HEAD
    if perl -e "exit !('$describe' =~ m/-[0-9]+-[0-9a-g]{8}\$/);"; then
        # remove suffix to get tag (doesn't matter if we do not pick
        # the most recent one)
        exact=
        tag=`echo $describe | sed -e 's/-[0123456789]*-g.*//'`
    else
        # there is at least one tag matching HEAD;
        # pick the most recent one (based on lexical sorting)
        exact=1
        tag=`git show-ref --tags | grep $hash | sort | tail -1 | sed -e 's;.*refs/tags/;;'`
    fi
    simpletag=$tag
    # Hyphens between numbers in the tag are dots in the version
    # and all other hyphens can be removed.
    while true; do
        tmp=`echo $simpletag | sed -e 's/\([0123456789]\)-\([0123456789]\)/\1.\2/'`
        if [ $tmp = $simpletag ]; then
            break
        else
            simpletag=$tmp
        fi
    done
    simpletag=`echo $simpletag | sed -e 's/-//g'`
    if [ "$dirty" ] || [ "$force" ]; then
        # previous check failed, always print hash
        echo $hash$dirty
    elif [ "$exact" ] &&
        echo $simpletag | grep -q "syncevolution${version}\$"; then
        true
    else
        echo $hash$dirty
    fi
    cd $cur
}

versionsuffix=
syncevo=`checksource .`
if [ "$SYNTHESISSRC" ]; then
    sysync=`checksource $SYNTHESISSRC $syncevo`
fi
# run check again, to get hash when only libsynthesis failed
syncevo=`checksource . $sysync`
if [ "$syncevo" ]; then
    versionsuffix=+SE+$syncevo
fi
if [ "$sysync" ]; then
    versionsuffix=$versionsuffix+SYSYNC+$sysync
fi
if [ "$versionsuffix" ]; then
    versionsuffix=+`date +%Y%m%d`$versionsuffix
fi


# generate configure.in from main configure-*.in pieces
# and all backend configure-sub.in pieces
rm -f configure.in
sed -e "s/^\\(AC_INIT.*\\)\\[\\(.*\\)\\]/\\1[\\2$versionsuffix]/" configure-pre.in >>configure.in

BACKENDS=
SUBS=
for sub in src/backends/*/configure-sub.in; do
    BACKENDS="$BACKENDS `dirname $sub | sed -e 's;^src/;;'`"
    SUBS="$SUBS $sub"
    echo "# vvvvvvvvvvvvvv $sub vvvvvvvvvvvvvv" >>configure.in
    cat $sub >>configure.in
    echo "AC_CONFIG_FILES(`echo $sub | sed -e s/configure-sub.in/Makefile/`)" >>configure.in
    echo "# ^^^^^^^^^^^^^^ $sub ^^^^^^^^^^^^^^" >>configure.in
    echo >>configure.in
done
cat configure-post.in >>configure.in

TEMPLATE_FILES=`cd src && find templates -type f \( -name README -o -name '*.png' -o -name '*.svg' -o -name '*.ini' \) | sort`
TEMPLATE_FILES=`echo $TEMPLATE_FILES`

# create Makefile.am files
sed -e "s;@BACKEND_REGISTRIES@;`echo src/backends/*/*Register.cpp | sed -e s%src/%%g`;" \
    -e "s;@BACKENDS@;$BACKENDS;" \
    -e "s;@TEMPLATE_FILES@;$TEMPLATE_FILES;" \
     src/Makefile-gen.am >src/Makefile.am

sed -e "s;@CONFIG_SUBS@;$SUBS;" \
    Makefile-gen.am >Makefile.am

# create LINGUAS file: every .po is included
(cd po && ls -1 *.po | sort -u | sed -e 's/.po$//' > LINGUAS)