summaryrefslogtreecommitdiffstats
path: root/git-amb/git-amb.in
blob: 5753cd4608dddfc6a77329b58e8fad342a07df63 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/sh
# git-amb - git automake build utility
# Copyright (C) 2007 Hans Ulrich Niedermann <hun@n-dimensional.de>
#
# Build automake based git checkout in branch specific build and install trees.
# That makes it easy to compare build results from different branches.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA


# Known to work and tested with
#  - git 1.5.3.4

case "$1" in
	-V|--version)
	    echo "$self (@PACKAGE_NAME@) @PACKAGE_VERSION@"
	    exit 0
	    ;;
esac

USAGE="<command> [params...]"

LONG_USAGE="\
Build automake based git checkout in branch specific build and install trees.
For more details, see the git-amb(1) man page."
. git-sh-setup

require_work_tree

self="$(basename "$0")"

amb_detect_configure() {
    for configure_ac in \
	"${top_srcdir}/configure.ac" \
	"${top_srcdir}/configure.in"
    do
	if test -s "${configure_ac}"; then
	    break
	fi
	configure_ac=""
    done
    test -z "${configure_ac}" && die "configure.{ac,in} not found"
    configure="$top_srcdir/configure"
}

cond_cat_path() {
    path="."
    for dir
    do
	if echo "$dir" | grep '^/' > /dev/null; then
	    path="$dir"
	else
	    path="$path/$dir"
	fi
    done
    echo "$path"
}

amb_init() {
    # Equivalent bzr code:
    #   bzr log -r -1.. | sed -n 's/^branch nick: //p'
    if test "x$1" = "x"; then
	git_branch="$(git branch | sed -n 's/^* //p')"
    elif git branch | sed 's/^[ *] //' | grep "$1" > /dev/null; then
	git_branch="${1}"
    else
	die "Invalid branch \"$1\" given."
    fi
    test "x.git" = "x$(basename "$GIT_DIR")" || die "GIT_DIR=$GIT_DIR is not foo/.git"
    top_srcdir="$(cd_to_toplevel && pwd)"

    tmp="$(git-config amb.builddir)" || tmp="$GIT_DIR/amb/build"
    top_builddir="$(cond_cat_path "${top_srcdir}" "$tmp" "${git_branch}")"

    tmp="$(git-config amb.installdir)" || tmp="$GIT_DIR/amb/install"
    top_installdir="$(cond_cat_path "${top_srcdir}" "$tmp" "$git_branch")"

    amb_detect_configure
}

amb_autoreconf() {
    echo "$self: Running autoreconf for branch ${git_branch}"
    autoreconf -vis "$@" "$top_srcdir"
}

amb_cond_autoreconf() {
    if test ! -s "$configure" || test "$configure_ac" -nt "$configure"; then
	    amb_autoreconf
    fi
}

amb_configure() {
    amb_cond_autoreconf
    echo "$self: Running configure for branch ${git_branch}"
    mkdir -p "$top_builddir"
    cd "$top_builddir"
    "$top_srcdir/configure" --prefix="$top_installdir" --enable-maintainer-mode "$@"
}

amb_cond_configure() {
    test -s "$top_builddir/Makefile" || amb_configure
}

amb_make() {
    amb_cond_configure
    echo "$self: Running make for branch ${git_branch}"
    cd "$top_builddir"
    make "$@"
}

amb_printvars() {
    echo "$self: Settings for branch ${git_branch}"
    echo "$self:  source dir $top_srcdir"
    echo "$self:   build dir $top_builddir"
    echo "$self: install dir $top_installdir"
}

amb_purge() {
    echo "$self: Purging branch ${git_branch} build and install"
    echo "$self: Purging $top_builddir..."
    rm -rf "$top_builddir"
    echo "$self: Purging $top_installdir..."
    rm -rf "$top_installdir"
    echo "$self: Finished."
}

amb_uninstall() {
    echo "$self: Uninstalling branch ${git_branch}"
    echo "$self: Purging $top_builddir..."
    rm -rf "$top_installdir"
    echo "$self: Finished."
}

amb_shell() {
    if test -d "$top_builddir"; then :; else
	die "Build directory does not exist yet: ${top_builddir}"
    fi
    echo "$self: Starting shell for branch ${git_branch}"
    export git_amb_srcdir="top_srcdir"
    export git_amb_builddir="top_builddir"
    export git_amb_installdir="top_installdir"
    amb_printvars
    export PS1="\
[Ctrl-D or 'exit' to quit $self shell for branch ${git_branch}]\n\
[<$self> \w]\n\
[<$(echo "$self" | sed 's/./-/g')> \u@\h \W]\$ \
"
    cd "$top_builddir" && ${SHELL} "$@"
}

# Abort on error
set -e

# The great command case
command="$1"
if shift; then
    case "$command" in
	builddir)
	    amb_init "$@"
	    echo "$top_builddir"
	    ;;
	installdir)
	    amb_init "$@"
	    echo "$top_installdir"
	    ;;
	autoreconf)
	    amb_init
	    amb_autoreconf "$@"
	    amb_printvars
	    ;;
	configure)
	    amb_init
	    amb_configure "$@"
	    amb_printvars
	    ;;
	make)
	    amb_init
	    amb_make "$@"
	    amb_printvars
	    ;;
	clean)
	    amb_init "$@"
	    amb_make clean
	    amb_printvars
	    ;;
	distclean)
	    amb_init "$@"
	    amb_make distclean
	    amb_printvars
	    ;;
	purge)
	    amb_init "$@"
	    amb_purge
	    ;;
	uninstall)
	    amb_init "$@"
	    amb_uninstall
	    ;;
	sh)
	    amb_init
	    amb_shell "$@"
	    amb_printvars
	    ;;
	*)
	    die "Invalid command line parameter: \"$command\""
	    ;;
    esac
else
    amb_init
    amb_printvars
fi

# End of file.