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 \
141 ! -f .links
-a
! -d .git
]; do
144 fail
"couldn't find top-level directory"
149 assign srcpath $
(pwd)
151 ## Construct the output directory.
152 assign releasepath
$srcpath/dist-
$build
153 chmod -R
+w
$releasepath 2>/dev
/null ||
:
154 rm -rf
$releasepath 2>/dev
/null ||
:
158 exec 4>$releasepath/mdw-build.log
3>&4 ||
159 fail
"Failed to create log."
163 ## Do we have a Git repository?
164 case "$checkout,$setup,$(yesno [ -d $srcpath/.git ])" in
166 fail
"Inconsistent options: can't check out without setup."
169 info
"No Git repository found."
170 checkout
=no gitver
=none
174 [ "$(git ls-files -m)" = "" ] ||
175 warn
"working tree has uncommitted changes"
176 gitver
=$
(git describe
)
179 ## Is there Debian build equipment?
180 case "$debian,$(yesno [ -d $srcpath/debian ])" in
182 info
"No debian directory found."
183 debian
=no debver
=none
186 debver
=$
(dpkg-parsechangelog |
sed -n
's/^Version: //p')
190 ## Check the version number.
191 case "$gitver,$debver" in
195 [ "$gitver" = "$debver" ] ||
196 warn
"Git version $gitver doesn't match Debian version $debver"
200 ## Maybe check ot a copy of the source.
204 run git clone
-sn
$srcpath/.git _source
205 assign srcpath
$releasepath/_source
207 run git checkout
-b mdw-build
$checkoutrev
211 ## Maybe refresh the build machinery.
218 ## Initialize the build directory.
219 if [ -e
$srcpath/configure
]; then
220 assign buildpath
$releasepath/_build
223 run
$srcpath/configure
225 info
"no configure script"
226 assign buildpath
$srcpath
230 ## Discover the release name.
231 cat >find-distdir.mk
<<'EOF'
236 assign distdir $
(make -f find-distdir.mk print-distdir
)
238 ## Get a tarball distribution.
250 if ! tar tf
$buildpath/$distdir.
tar.gz
2>/dev
/null |
grep -q RELEASE
; then
251 fail
"missing RELEASE file in distribution"
254 run
mv $buildpath/$distdir.
tar.gz .
256 ## Maybe build the Debian packages.
259 run
tar xvfz
$distdir.
tar.gz
261 run dpkg-buildpackage
-k$
(mdw-conf releasekey
)
265 ## Maybe upload Debian packages.
267 case "$upload,$build" in
269 info
"Test build: not uploading."
272 run rsync
$distdir.
tar.gz \
273 $
(mdw-conf upload-target
ftp.distorted.org.uk
:~
ftp/pub
/mdw
/)
276 run dput
-f $
(mdw-conf dput-target distorted
) *.changes
284 rm -rf
$releasepath/$distdir
285 rm -rf
$releasepath/_source
286 rm -rf
$releasepath/_build
293 ###----- That's all, folks --------------------------------------------------