backport-source-packages: Drop handling for precise
[xapian.git] / xapian-maintainer-tools / debian / backport-source-packages
blobfbe77fe2540617aca8fe48d6a3b7bcfadd922468
1 #!/bin/sh
2 # Backport Debian source packages for Xapian.
4 # Copyright (C) 2004 Richard Boulton
5 # Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2015,2016,2017,2018 Olly Betts
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20 # USA
22 # Dependencies:
23 # dch from package devscripts.
25 set -e
27 MIRROR=http://httpredir.debian.org/debian/
29 DEBIAN_CODENAMES='stretch jessie'
30 UBUNTU_CODENAMES='bionic artful xenial trusty'
31 UBUNTU_FIRST=`echo "$UBUNTU_CODENAMES"|sed 's/.* //'`
33 V_OPT=
34 BUILD_INT=1
35 HELP_RC=
36 while true ; do
37 case $1 in
38 -v)
39 V_OPT="$1$2"
40 shift
42 -v*)
43 V_OPT=$1
45 -b)
46 BUILD_INT=$2
47 shift
49 -b*)
50 BUILD_INT=`expr substr "$1" 3 9999`
52 --help)
53 HELP_RC=0
54 break
56 -*)
57 HELP_RC=1
58 break
61 break
63 esac
64 shift
65 done
67 if [ -n "$HELP_RC" -o $# -lt 2 ] ; then
68 echo "Usage: $0 [-v <last uploaded version>] [-b <backport #>] SOURCE_PKG VERSION [CODENAME...]"
69 echo
70 echo "e.g.: $0 xapian-core 1.2.15-1 xenial"
71 echo 'If no codenames are specified, the default is to backport for all of them.'
72 echo
73 echo "Currently, the recognised values are:"
74 echo " $DEBIAN_CODENAMES"
75 echo " $UBUNTU_CODENAMES"
76 echo "And the magic values which expand to the above lists:"
77 echo " debian ubuntu"
78 exit ${HELP_RC:-1}
81 PKG=$1
82 VERSION=$2
83 shift
84 shift
86 SUFFIX=`echo "$VERSION"|sed 's/.*-/-/'`
87 VERSION=`echo "$VERSION"|sed 's/-[^-]*$//'`
89 # Debian/Ubuntu codename or codenames to build for.
90 # This will be overridden by the command line arguments, if any were passed.
91 CODENAMES="$DEBIAN_CODENAMES $UBUNTU_CODENAMES"
93 # Options to pass to dpkg-buildpackage when building source packages
94 BUILDPACKAGE_SRC_OPTS="-us -uc -d -S $V_OPT"
96 # Add entry to changelog if we're backporting.
97 adjust_changelog() {
98 if [ sid != "$CODENAME" ] ; then
99 base_version=`dpkg-parsechangelog|sed 's/^Version: //p;d'`
100 backport_version=$base_version$BACKPORT_SUFFIX
101 # --force-bad-version needed for backporting, since the "new" version may
102 # be less than the "old". Direct stdin from /dev/null to prevent dch
103 # stopping to confirm the bad version is OK.
104 if [ 1 = "$ubuntu" ] ; then
105 distribution=$CODENAME
106 elif [ "`echo "$DEBIAN_CODENAMES"|cut -d' ' -f1`" = "$CODENAME" ] ; then
107 # Backport for the most recent stable debian release.
108 distribution=$CODENAME-backports
109 else
110 distribution=$CODENAME-backports-sloppy
112 dch --force-bad-version -v "$backport_version" -D "$distribution" \
113 "Rebuild for $CODENAME backports." < /dev/null
117 build_it() {
118 adjust_changelog
120 overrides=
121 case $PKG:$CODENAME:$VERSION in
122 xapian-core:*:1.2.*)
123 # So we can create the backport source packages on debian unstable.
124 overrides='libxapian_soversion=22 other_abi_suffix=v5' ;;
125 xapian-bindings:trusty:1.2.*)
126 # Make sure we add python-xapian to debian/control.
127 overrides='PYTHON_VERSIONS=dummy RUBY_VERSIONS="2.0" RUBY_PROVIDES="X-Dummy: No provides"' ;;
128 xapian-bindings:trusty:*)
129 # Make sure we add python-xapian and python3-xapian to debian/control.
130 overrides='PYTHON_VERSIONS=dummy PYTHON3_VERSIONS=dummy' ;;
131 xapian-bindings:xenial:*|xapian-bindings:artful:*|xapian-bindings:bionic:*)
132 # Make sure we add python-xapian (and python3-xapian for 1.4.x packages)
133 # to debian/control.
134 overrides='PYTHON_VERSIONS=dummy PYTHON3_VERSIONS=dummy RUBY_VERSIONS=2.3 RUBY_PROVIDES="X-Dummy: No provides"' ;;
135 xapian-bindings:*:*)
136 # Make sure we add python-xapian to debian/control.
137 overrides='PYTHON_VERSIONS=dummy' ;;
138 esac
140 # libxapian30 (i.e. 1.4.x) is built with C++ "v5" ABI in stretch and newer
141 # and in xenial and newer, so append "v4" to the soname for backports to
142 # older versions so upgrades with the backport installed work cleanly.
143 case $PKG:$VERSION in
144 xapian-core:1.4.*)
145 case $CODENAME in
146 jessie|trusty)
147 perl -i -e 'while (<>) { print; last if /^libxapian_soversion:=/ } while (<>) { print; last unless /\\$/ } print "libxapian_soversion:=\$(libxapian_soversion)v4\n"; while (<>) { print }' debian/rules
148 sed -i 's/^\(Package: libxapian@LIBXAPIAN_SOVERSION@\)\(.*\)/\1\2\nConflicts: libxapian30\2\nReplaces: libxapian30\2/' debian/control.in
149 dch -a 'debian/control.in,debian/rules: Add v4 suffix to soname. (Closes: #863705)'
151 esac
153 esac
155 # Mainly for Survex.
156 case $CODENAME in
157 trusty|xenial|artful|jessie|stretch)
158 if grep -q libwxgtk3.0-gtk3-dev debian/control ; then
159 sed -i 's/libwxgtk3.0-gtk3-dev/libwxgtk3.0-dev/g' debian/control
160 dch -a 'debian/control: Build with GTK2 version of wxWidgets.'
163 esac
165 case `grep -c '^[^#]*\<CODENAME\>' debian/rules` in
167 echo 'Failed to grep debian/rules'
168 exit 1
170 [01])
171 # Run maintclean and maint targets, if they exist.
172 fakeroot debian/rules maintclean || true
173 eval fakeroot debian/rules maint $overrides || true
176 # If debian/rules has at least two non-commented out references to
177 # CODENAME then create debian/codename.
178 echo "$CODENAME" > debian/codename
179 # Generates control from control.in (and maybe other files).
180 fakeroot debian/rules maintclean CODENAME="$CODENAME"
181 eval fakeroot debian/rules maint CODENAME="$CODENAME" $overrides
183 esac
185 include_src_opt=
186 case $backport_version in
187 *99$UBUNTU_FIRST+1)
188 # We don't really want to upload the orig tarball for all Ubuntu
189 # backports, only if it isn't already in the archive. So for now, just
190 # upload it for the first codename in alphabetical order, and only if
191 # the BUILD_INT (N in the +N suffix) is 1.
192 include_src_opt=-sa ;;
193 esac
194 debuild ${BUILDPACKAGE_SRC_OPTS} $include_src_opt
196 if [ 1 != "$ubuntu" ] ; then
197 # Debian
198 echo "cd build && sbuild --debbuildopt=$V_OPT -d $CODENAME-backports ${PKG}_$backport_version.dsc"
202 # Get the codename(s) specified by the user.
203 if [ -n "$*" ] ; then
204 CODENAMES=`echo "$*"|sed 's/\<debian\>/'"$DEBIAN_CODENAMES"'/;s/\<ubuntu\>/'"$UBUNTU_CODENAMES"'/'`
207 ubuntu=0
208 for CODENAME in $CODENAMES ; do
209 # Check that the codename is known.
210 DEBIAN_CODENAMES_RE='\('`echo "$DEBIAN_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
211 UBUNTU_CODENAMES_RE='\('`echo "$UBUNTU_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
212 if expr "$CODENAME" : "$DEBIAN_CODENAMES_RE" >/dev/null ; then
213 echo "Making source packages for $CODENAME"
214 if [ -z "$V_OPT" ] ; then
215 echo 'You need to specify -v<last backported version> for debian backports'
216 exit 1
218 elif expr "$CODENAME" : "$UBUNTU_CODENAMES_RE" >/dev/null ; then
219 echo "Making source packages for $CODENAME"
220 ubuntu=1
221 else
222 echo "Codename \"$CODENAME\" not known."
223 echo "Known codenames are: $DEBIAN_CODENAMES $UBUNTU_CODENAMES"
224 exit 1
227 trap "echo \"backport-source-packages failed\"" EXIT
229 # $BACKPORT_SUFFIX holds a suffix to be added to the debian version number for
230 # the backport.
232 # We need to add a suffix to the debian version number for the backported
233 # package to avoid conflicts with the package in unstable.
234 # For Ubuntu we add ".99$CODENAME" since it should sort
235 # before any other modification (and since dapper, Ubuntu codenames are
236 # allocated alphabetically). To handle the wrapping from zesty to artful,
237 # we add ".999$CODENAME" for artful and later. For Debian releases, we use
238 # backports.org-compatible package versions - e.g. we append "~bpo8+1" for
239 # Debian 8 (jessie) (and a suffix starting "~" sorts as less than no suffix).
240 case $CODENAME in
241 stretch)
242 BACKPORT_SUFFIX="~bpo9+$BUILD_INT" ;;
243 jessie)
244 BACKPORT_SUFFIX="~bpo8+$BUILD_INT" ;;
246 if [ x"$ubuntu" = x0 ] ; then
247 echo "Debian codename '$CODENAME' not mapped to a ~bpoN suffix"
248 exit 1
250 case $CODENAME in
251 trusty|xenial)
252 BACKPORT_SUFFIX=".99$CODENAME+$BUILD_INT" ;;
254 BACKPORT_SUFFIX=".999$CODENAME+$BUILD_INT" ;;
255 esac
257 esac
259 # Unpack distribution tarballs, and put the debian control files into place,
260 # and build source packages
261 mkdir -p build
262 cd build
263 case $PKG in
264 lib*) DIR=`echo $PKG|cut -c1,2,3,4` ;;
265 *) DIR=`echo $PKG|cut -c1` ;;
266 esac
267 DSC=${PKG}_$VERSION$SUFFIX.dsc
268 if [ -f "$DSC" ] ; then
269 [ -d backup ] || mkdir backup
270 if ! mv "$DSC" backup ; then
271 # Handle dsc being hardlinked into backup already.
272 cmp "$DSC" "backup/$DSC" && rm -f "$DSC"
274 dget -b "file://`pwd`/backup/$DSC"
275 else
276 dget "${MIRROR}pool/main/$DIR/$PKG/$DSC"
278 cd ${PKG}-${VERSION}
279 build_it
280 cd ..
281 rm -rf ${PKG}-${VERSION}
282 cd ..
284 echo "Backported ${PKG} ${VERSION} for $CODENAME successfully"
285 done
287 trap - EXIT