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.
24 ###--------------------------------------------------------------------------
25 ### Conventions for build systems.
27 ### This script is designed to work with a variety of `make'-based build
28 ### systems, but there are a number of conventions which must be followed if
29 ### this is going to work properly.
31 ### * There must be a `configure.ac', `configure.in', or `.links' file, or
32 ### a `.git' directory in the project top-level, so that we can find it.
34 ### * The following `make' variables must be assigned in the top-level
35 ### Makefile, after `mdw-build' has constructed it.
37 ### distdir The name of the top-level project directory in the
38 ### source distribution, and the base name for
39 ### distribution archives; should be of the form
40 ### `PROJECT-VERSION'.
42 ### The following `make' targets must be available in the top-level
45 ### dist Write to $(distdir).tar.gz a source distribution of
48 ### distcheck As for `dist', but also build and test the project.
50 ### * The source distribution constructed by `make dist' must contain a file
51 ### $(distdir)/RELEASE containing the release name. This isn't currently
52 ### tested, but it might be later.
56 ###--------------------------------------------------------------------------
61 Usage: $0 [-vr] BUILDOPT
75 ## Parse simple options.
77 while getopts "hvr" opt; do
86 ## Parse the build options.
97 checkout) checkout=yes checkoutrev=HEAD ;;
98 checkout=*) checkout=yes checkoutrev=${opt#*=} ;;
99 nocheckout) checkout=no ;;
100 release) build=release ;;
101 norelease) build=test ;;
103 setup | distcheck | debian | upload | clean)
106 nosetup | nodistcheck | nodebian | noupload | noclean)
116 ## Parse DEB_BUILD_OPTIONS.
118 set -- $DEB_BUILD_OPTIONS
121 parallel=*) jobs=${opt#*=} ;;
126 case $jobs in 1) ;; *) makeopts="$makeopts -j$jobs" ;; esac
128 ###--------------------------------------------------------------------------
129 ### Utility functions.
131 exec 3>&2 4>/dev/null 5>&2
136 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&5
146 release) fail "$*" ;;
147 *) notify 5 "??? $*" ;;
162 "$@" 2>&3 || fail "$1: exit $?"
165 run () { runx "$@" >&3; }
168 echo -n "(test $*)" >&4
169 if "$@" >&4 2>&4; then
178 ###--------------------------------------------------------------------------
181 ## Find the top-level package directory.
182 while [ ! -f configure.ac -a ! -f configure.in -a \
183 ! -f .links -a ! -d .git ]; do
186 fail "couldn't find top-level directory"
191 assign srcpath $(pwd)
193 ## Construct the output directory.
194 assign releasepath $srcpath/dist-$build
195 chmod -R +w $releasepath 2>/dev/null || :
196 rm -rf $releasepath 2>/dev/null || :
200 exec 4>$releasepath/mdw-build.log 3>&4 ||
201 fail "Failed to create log."
205 ## Do we have a Git repository?
206 case "$checkout,$setup,$(yesno [ -d $srcpath/.git ])" in
208 fail "Inconsistent options: can't check out without setup."
211 info "No Git repository found."
212 checkout=no gitver=none
216 [ "$(git ls-files -m)" = "" ] ||
217 warn "working tree has uncommitted changes"
218 gitver=$(git describe)
221 ## Is there Debian build equipment?
222 case "$debian,$(yesno [ -d $srcpath/debian ])" in
224 info "No debian directory found."
225 debian=no debver=none
228 debver=$(dpkg-parsechangelog | sed -n 's/^Version: //p')
232 ## Check the version number.
233 case "$gitver,$debver" in
237 [ "$gitver" = "$debver" ] ||
238 warn "Git version $gitver doesn't match Debian version $debver"
242 ## Maybe check ot a copy of the source.
246 run git clone -sn $srcpath/.git _source
247 assign srcpath $releasepath/_source
249 run git checkout -b mdw-build $checkoutrev
253 ## Maybe refresh the build machinery.
260 ## Initialize the build directory.
261 if [ -e $srcpath/configure ]; then
262 assign buildpath $releasepath/_build
265 run $srcpath/configure
267 info "no configure script"
268 assign buildpath $srcpath
272 ## Discover the release name.
273 cat >find-distdir.mk <<'EOF'
278 assign distdir $(make -f find-distdir.mk print-distdir)
280 ## Get a tarball distribution.
283 run make $makeopts distcheck
286 run make $makeopts dist
292 if ! tar tf $buildpath/$distdir.tar.gz 2>/dev/null | grep -q RELEASE; then
293 fail "missing RELEASE file in distribution"
296 run mv $buildpath/$distdir.tar.gz .
298 ## Maybe build the Debian packages.
301 run tar xvfz $distdir.tar.gz
303 run dpkg-buildpackage -k$(mdw-conf releasekey)
307 ## Maybe upload Debian packages.
309 case "$upload,$build" in
311 info "Test build: not uploading."
314 run rsync $distdir.tar.gz \
315 $(mdw-conf upload-target ftp.distorted.org.uk:~ftp/pub/mdw/)
318 run dput -f $(mdw-conf dput-target distorted) *.changes
326 rm -rf $releasepath/$distdir
327 rm -rf $releasepath/_source
328 rm -rf $releasepath/_build
335 ###----- That's all, folks --------------------------------------------------