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 upload uploadpath
64 unset build distcheck debian clean vpath native
66 "/etc/mdw-build.conf" \
67 "${XDG_CONFIG_HOME-$HOME/.config}/mdw-build.conf" \
70 if [ -f
"$i" ]; then .
"$i"; fi
74 eval "p=\${$var+t} q=\${$want+t}"
75 case $p,$q in t
,*) ;; *,t
) eval "$var=yes" ;; *) eval "$var=no" ;; esac
77 : ${checkout=yes} ${checkoutrev=HEAD}
79 : ${setup=yes} ${setupcmd=mdw-setup}
85 default_depends sign signkey
86 default_depends upload uploadpath
87 default_depends dput dputtarget
88 : ${DEB_BUILD_OPTIONS=parallel=4}; export DEB_BUILD_OPTIONS
90 ###--------------------------------------------------------------------------
97 Usage: $prog [-vr] BUILDOPT
106 [no]upload[=SERVER:PATH]
115 ## Parse simple options.
117 while getopts "hvr" opt
; do
124 shift $
((OPTIND
- 1))
126 ## Parse the build options.
129 eval "p=\${$want+t}\${$want-nil}"
132 nil
) echo >&2 "$prog: $want not set"; exit 1 ;;
137 checkout
) checkout
=yes checkoutrev
=HEAD
;;
138 checkout
=*) checkout
=yes checkoutrev
=${opt#*=} ;;
139 release
) build
=release
;;
140 norelease
) build
=test ;;
141 setup
) setup
=yes setupcmd
=mdw-setup
;;
142 setup
=*) setup
=yes setupcmd
=${opt#*=} ;;
143 upload
) maybe_set upload uploadpath
;;
144 upload
=*) upload
=yes uploadpath
=${opt#*=} ;;
145 sign
) maybe_set sign signkey
;;
146 sign
=*) sign
=yes signkey
=${opt#*=} ;;
147 dput
) maybe_set dput dputtarget
;;
148 dput
=*) dput
=yes dputtarget
=${opt#*=} ;;
150 distcheck | debian | clean | vpath | native
)
153 nocheckout | nosetup | nodistcheck | nodebian | \
154 noupload | nodput | noclean | novpath | nonative | nosign
)
164 ## Parse DEB_BUILD_OPTIONS.
166 set -- $DEB_BUILD_OPTIONS
169 parallel
=*) jobs=${opt#*=} ;;
174 case $jobs in 1) ;; *) makeopts
="$makeopts -j$jobs" ;; esac
176 ###--------------------------------------------------------------------------
177 ### Utility functions.
179 exec 3>&2 4>/dev
/null
5>&2
184 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)" >&5
194 release
) fail
"$*" ;;
195 *) notify
5 "??? $*" ;;
210 "$@" 2>&3 || fail
"$1: exit $?"
213 run
() { runx
"$@" >&3; }
216 echo -n
"(test $*)" >&4
217 if "$@" >&4 2>&4; then
226 ###--------------------------------------------------------------------------
229 ## Find the top-level package directory.
230 while [ ! -f configure.ac
-a
! -f configure.
in -a \
231 ! -f .links
-a
! -d .git
]; do
234 fail
"couldn't find top-level directory"
239 assign srcpath $
(pwd)
241 ## Build any necessary qualifiers.
243 case ${SBOX_SESSION_DIR+t},${DEB_BUILD_ARCH+t} in
244 t
,t
) qual
=$qual$sep$DEB_BUILD_ARCH; sep
=- ;;
245 t
,*) fail
"unknown build arch" ;;
248 ## Construct the output directory.
249 assign releasepath
$srcpath/dist-
$build$qual
250 chmod -R
+w
$releasepath 2>/dev
/null ||
:
251 rm -rf
$releasepath 2>/dev
/null ||
:
255 exec 4>$releasepath/mdw-build.log
3>&4 ||
256 fail
"Failed to create log."
260 ## Do we have a Git repository?
261 case "$checkout,$setup,$(yesno [ -d $srcpath/.git ])" in
263 fail
"Inconsistent options: can't check out without setup."
266 info
"No Git repository found."
267 checkout
=no gitver
=none
271 [ "$(git ls-files -m)" = "" ] ||
272 warn
"working tree has uncommitted changes"
276 ## Is there Debian build equipment?
277 case "$debian,$(yesno [ -d $srcpath/debian ])" in
279 info
"No debian directory found."
280 debian
=no debver
=none
286 debver
=$
(dpkg-parsechangelog |
sed -n
's/^Version: //p' |
tr \~
-)
287 debsrc
=$
(dpkg-parsechangelog |
sed -n
's/^Source: //p')
288 debname
=$
(git config user.name
) debemail
=$
(git config user.email
)
292 ## Maybe check out a copy of the source.
296 run git clone
-sn
$srcpath/.git _source
297 assign srcpath
$releasepath/_source
299 run git checkout
-b mdw-build
$checkoutrev
300 gitver
=$
(git describe
--abbrev
=4)
304 ## Check the version number.
306 case "$gitver,$debver" in
310 if [ "$gitver" != "$debver" ]; then
311 warn
"Git version $gitver doesn't match Debian version $debver"
317 ## Maybe refresh the build machinery.
324 ## Initialize the build directory.
325 case "$vpath,$(yesno [ -e $srcpath/configure ])" in
327 assign buildpath
$releasepath/_build
330 run
$srcpath/configure
333 info
"VPATH build disabled"
334 assign buildpath
$srcpath
340 info
"no configure script"
341 assign buildpath
$srcpath
346 ## Discover the release name.
347 cat >find-distdir.mk
<<'EOF'
353 $
({ make -f find-distdir.mk print-distdir
>/dev
/null
2>&1; } 3>&1)
355 ## Get a tarball distribution.
358 run
make $makeopts distcheck
361 run
make $makeopts dist
369 if ! tar tf
$buildpath/$distdir.
tar.gz
2>/dev
/null |
grep -q RELEASE
371 fail
"missing RELEASE file in distribution"
376 run
mv $buildpath/$distdir.
tar.gz .
379 run gpg
-u
$signkey -ab
-o
$distdir.
tar.gz.gpg
$distdir.
tar.gz
383 ## Maybe build the Debian packages.
386 run
tar xvfz
$distdir.
tar.gz
390 dver
=$
(echo $gitver |
sed 's/-/+/; s/-/./g')
392 cat - debian
/changelog
>debian
/changelog.new
<<EOF
393 $debsrc ($dver) experimental; urgency=low
395 * Hacking in process, not intended for release.
397 -- $debname <$debemail> $now
400 mv debian
/changelog.new debian
/changelog
404 release
,yes) run dpkg-buildpackage
-k
$signkey ;;
405 no
,*) run dpkg-buildpackage
-us
-uc
;;
410 ## Maybe upload Debian packages.
412 case "$upload,$build" in
413 yes,test) info
"Test build: not uploading." ;;
414 yes,release
) run rsync
$distdir.
tar.gz
$distdir.
tar.gz.gpg
$uploadpath ;;
416 case "$debian,$upload,$dput,$build" in
417 yes,yes,yes,release
) run dput
-f
$dputtarget *.changes
;;
423 rm -rf
$releasepath/$distdir
424 rm -rf
$releasepath/_source
425 rm -rf
$releasepath/_build
432 ###----- That's all, folks --------------------------------------------------