3 ### Build script for Debian packages
5 ### (c) 2008 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This program is free software; you can redistribute it and/or modify
11 ### it under the terms of the GNU General Public License as published by
12 ### the Free Software Foundation; either version 2 of the License, or
13 ### (at your option) any later version.
15 ### This program is distributed in the hope that it will be useful,
16 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ### GNU General Public License for more details.
20 ### You should have received a copy of the GNU General Public License
21 ### along with this program; if not, write to the Free Software Foundation,
22 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ###--------------------------------------------------------------------------
31 Usage: $0 [-vr] BUILDOPT
45 ## Parse simple options.
47 while getopts "hvr" opt; do
56 ## Parse the build options.
67 checkout) checkout=yes checkoutrev=HEAD ;;
68 checkout=*) checkout=yes checkoutrev=${opt#*=} ;;
69 nocheckout) checkout=no ;;
70 release) build=release ;;
71 norelease) build=test ;;
73 setup | distcheck | debian | upload | clean)
76 nosetup | nodistcheck | nodebian | noupload | noclean)
86 ###--------------------------------------------------------------------------
87 ### Utility functions.
89 exec 3>&2 4>/dev/null 5>&2
94 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&5
104 release) fail "$*" ;;
105 *) notify 5 "??? $*" ;;
120 "$@" 2>&3 || fail "$1: exit $?"
123 run () { runx "$@" >&3; }
126 echo -n "(test $*)" >&4
127 if "$@" >&4 2>&4; then
136 ###--------------------------------------------------------------------------
139 ## Find the top-level package directory.
140 while [ ! -f configure.ac -a ! -f configure.in -a ! -f .links ]; do
143 fail "couldn't find top-level directory"
148 assign srcpath $(pwd)
150 ## Construct the output directory.
151 assign releasepath $srcpath/dist-$build
152 chmod -R +w $releasepath 2>/dev/null|| :
153 rm -rf $releasepath 2>/dev/null || :
157 exec 4>$releasepath/mdw-build.log 3>&4 ||
158 fail "Failed to create log."
162 ## Do we have a Git repository?
163 case "$checkout,$setup,$(yesno [ -d $srcpath/.git ])" in
165 fail "Inconsistent options: can't check out without setup."
168 info "No Git repository found."
169 checkout=no gitver=none
173 [ "$(git ls-files -m)" = "" ] ||
174 warn "working tree has uncommitted changes"
175 gitver=$(git describe)
178 ## Is there Debian build equipment?
179 case "$debian,$(yesno [ -d $srcpath/debian ])" in
181 info "No debian directory found."
182 debian=no debver=none
185 debver=$(dpkg-parsechangelog | sed -n 's/^Version: //p')
189 ## Check the version number.
190 case "$gitver,$debver" in
194 [ "$gitver" = "$debver" ] ||
195 warn "Git version $gitver doesn't match Debian version $debver"
199 ## Maybe check ot a copy of the source.
203 run git clone -sn $srcpath/.git _source
204 assign srcpath $releasepath/_source
206 run git checkout -b mdw-build $checkoutrev
210 ## Maybe refresh the build machinery.
217 ## Initialize the build directory.
218 if [ -e $srcpath/configure ]; then
219 assign buildpath $releasepath/_build
222 run $srcpath/configure
224 info "no configure script"
225 assign buildpath $srcpath
229 ## Discover the release name.
230 cat >find-distdir.mk <<'EOF'
235 assign distdir $(make -f find-distdir.mk print-distdir)
237 ## Get a tarball distribution.
249 if ! tar tfz $buildpath/$distdir.tar.gz | grep -q RELEASE; then
250 fail "missing RELEASE file in distribution"
253 run mv $buildpath/$distdir.tar.gz .
255 ## Maybe build the Debian packages.
258 run tar xvfz $distdir.tar.gz
260 run dpkg-buildpackage -k$(mdw-conf releasekey)
264 ## Maybe upload Debian packages.
266 case "$upload,$build" in
268 info "Test build: not uploading."
271 run rsync $distdir.tar.gz \
272 $(mdw-conf upload-target metalzone.distorted.org.uk:/home/ftp/pub/mdw/)
275 run dput -f $(mdw-conf dput-target metalzone) *.changes
283 rm -rf $releasepath/$distdir
284 rm -rf $releasepath/_source
285 rm -rf $releasepath/_build
292 ###----- That's all, folks --------------------------------------------------