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 ###--------------------------------------------------------------------------
59 unset checkout checkoutrev
62 unset build distcheck debian upload clean vpath native
64 "/etc/mdw-build.conf" \
65 "${XDG_CONFIG_HOME-$HOME/.config}/mdw-build.conf" \
68 if [ -f "$i" ]; then . "$i"; fi
70 : ${checkout=yes} ${checkoutrev=HEAD}
72 : ${setup=yes} ${setupcmd=mdw-setup}
79 : ${DEB_BUILD_OPTIONS=parallel=4}; export DEB_BUILD_OPTIONS
81 ###--------------------------------------------------------------------------
88 Usage: $prog [-vr] BUILDOPT
104 ## Parse simple options.
106 while getopts "hvr" opt; do
113 shift $((OPTIND - 1))
115 ## Parse the build options.
118 checkout) checkout=yes checkoutrev=HEAD ;;
119 checkout=*) checkout=yes checkoutrev=${opt#*=} ;;
120 release) build=release ;;
121 norelease) build=test ;;
122 setup) setup=yes setupcmd=mdw-setup ;;
123 setup=*) setup=yes setupcmd=${opt#*=} ;;
125 distcheck | debian | upload | clean | vpath | native)
128 nocheckout | nosetup | nodistcheck | nodebian | \
129 noupload | noclean | novpath | nonative)
139 ## Parse DEB_BUILD_OPTIONS.
141 set -- $DEB_BUILD_OPTIONS
144 parallel=*) jobs=${opt#*=} ;;
149 case $jobs in 1) ;; *) makeopts="$makeopts -j$jobs" ;; esac
151 ###--------------------------------------------------------------------------
152 ### Utility functions.
154 exec 3>&2 4>/dev/null 5>&2
159 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&5
169 release) fail "$*" ;;
170 *) notify 5 "??? $*" ;;
185 "$@" 2>&3 || fail "$1: exit $?"
188 run () { runx "$@" >&3; }
191 echo -n "(test $*)" >&4
192 if "$@" >&4 2>&4; then
201 ###--------------------------------------------------------------------------
204 ## Find the top-level package directory.
205 while [ ! -f configure.ac -a ! -f configure.in -a \
206 ! -f .links -a ! -d .git ]; do
209 fail "couldn't find top-level directory"
214 assign srcpath $(pwd)
216 ## Build any necessary qualifiers.
218 case ${SBOX_SESSION_DIR+t},${DEB_BUILD_ARCH+t} in
219 t,t) qual=$qual$sep$DEB_BUILD_ARCH; sep=- ;;
220 t,*) fail "unknown build arch" ;;
223 ## Construct the output directory.
224 assign releasepath $srcpath/dist-$build$qual
225 chmod -R +w $releasepath 2>/dev/null || :
226 rm -rf $releasepath 2>/dev/null || :
230 exec 4>$releasepath/mdw-build.log 3>&4 ||
231 fail "Failed to create log."
235 ## Do we have a Git repository?
236 case "$checkout,$setup,$(yesno [ -d $srcpath/.git ])" in
238 fail "Inconsistent options: can't check out without setup."
241 info "No Git repository found."
242 checkout=no gitver=none
246 [ "$(git ls-files -m)" = "" ] ||
247 warn "working tree has uncommitted changes"
251 ## Is there Debian build equipment?
252 case "$debian,$(yesno [ -d $srcpath/debian ])" in
254 info "No debian directory found."
255 debian=no debver=none
261 debver=$(dpkg-parsechangelog | sed -n 's/^Version: //p' | tr \~ -)
262 debsrc=$(dpkg-parsechangelog | sed -n 's/^Source: //p')
263 debname=$(git config user.name) debemail=$(git config user.email)
267 ## Maybe check out a copy of the source.
271 run git clone -sn $srcpath/.git _source
272 assign srcpath $releasepath/_source
274 run git checkout -b mdw-build $checkoutrev
275 gitver=$(git describe --abbrev=4)
279 ## Check the version number.
281 case "$gitver,$debver" in
285 if [ "$gitver" != "$debver" ]; then
286 warn "Git version $gitver doesn't match Debian version $debver"
292 ## Maybe refresh the build machinery.
299 ## Initialize the build directory.
300 case "$vpath,$(yesno [ -e $srcpath/configure ])" in
302 assign buildpath $releasepath/_build
305 run $srcpath/configure
308 info "VPATH build disabled"
309 assign buildpath $srcpath
315 info "no configure script"
316 assign buildpath $srcpath
321 ## Discover the release name.
322 cat >find-distdir.mk <<'EOF'
328 $({ make -f find-distdir.mk print-distdir >/dev/null 2>&1; } 3>&1)
330 ## Get a tarball distribution.
333 run make $makeopts distcheck
336 run make $makeopts dist
344 if ! tar tf $buildpath/$distdir.tar.gz 2>/dev/null | grep -q RELEASE
346 fail "missing RELEASE file in distribution"
351 run mv $buildpath/$distdir.tar.gz .
354 run gpg -u$(mdw-conf releasekey) -ab -o$distdir.tar.gz.gpg \
359 ## Maybe build the Debian packages.
362 run tar xvfz $distdir.tar.gz
366 dver=$(echo $gitver | sed 's/-/+/; s/-/./g')
368 cat - debian/changelog >debian/changelog.new <<EOF
369 $debsrc ($dver) experimental; urgency=low
371 * Hacking in process, not intended for release.
373 -- $debname <$debemail> $now
376 mv debian/changelog.new debian/changelog
379 run dpkg-buildpackage -k$(mdw-conf releasekey)
383 ## Maybe upload Debian packages.
385 case "$upload,$build" in
387 info "Test build: not uploading."
390 run rsync $distdir.tar.gz $distdir.tar.gz.gpg \
391 $(mdw-conf upload-target ftp.distorted.org.uk:~ftp/pub/mdw/)
394 run dput -f $(mdw-conf dput-target distorted) *.changes
402 rm -rf $releasepath/$distdir
403 rm -rf $releasepath/_source
404 rm -rf $releasepath/_build
411 ###----- That's all, folks --------------------------------------------------