Make TradWeight a simple subclass and deprecate
[xapian.git] / xapian-maintainer-tools / debian / backport-source-packages
blob2c4cb72c3ca8a26cefc0bdc50edd8f431ad8be7b
1 #!/bin/sh
2 # Backport Debian source packages for Xapian.
4 # Copyright (C) 2004 Richard Boulton
5 # Copyright (C) 2006-2024 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='bookworm bullseye'
30 UBUNTU_CODENAMES='noble mantic jammy focal bionic xenial'
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 backported version>] [-b <backport #>] SOURCE_PKG VERSION [CODENAME...]"
69 echo
70 echo "e.g.: $0 xapian-core 1.4.11-1 xenial"
71 echo
72 echo 'If -b not specified, default is 1'
73 echo
74 echo 'If no codenames are specified, the default is to backport for all of them.'
75 echo
76 echo "Currently, the recognised values are:"
77 echo " $DEBIAN_CODENAMES"
78 echo " $UBUNTU_CODENAMES"
79 echo "And the magic values which expand to the above lists:"
80 echo " debian ubuntu"
81 exit ${HELP_RC:-1}
84 # Remove any backport suffix from any -v option.
85 V_OPT=`printf '%s' "$V_OPT"|sed 's/~bpo.*//'`
86 PKG=$1
87 VERSION=$2
88 shift
89 shift
91 SUFFIX=$VERSION
92 VERSION=`echo "$VERSION"|sed 's/-[^-]*$//'`
93 if [ "$VERSION" = "$SUFFIX" ] ; then
94 # Native package version so SUFFIX is empty.
95 SUFFIX=
96 else
97 SUFFIX=`expr substr "$SUFFIX" \( 1 + length "$VERSION" \) 999`
100 # Debian/Ubuntu codename or codenames to build for.
101 # This will be overridden by the command line arguments, if any were passed.
102 CODENAMES="$DEBIAN_CODENAMES $UBUNTU_CODENAMES"
104 # Options to pass to dpkg-buildpackage when building source packages
105 BUILDPACKAGE_SRC_OPTS="-us -uc -d -S $V_OPT --changes-option=-DBinary=dummy"
107 # Add entry to changelog if we're backporting.
108 adjust_changelog() {
109 if [ sid != "$CODENAME" ] ; then
110 base_version=`dpkg-parsechangelog|sed 's/^Version: //p;d'`
111 backport_version=$base_version$BACKPORT_SUFFIX
112 # --force-bad-version needed for backporting, since the "new" version may
113 # be less than the "old". Direct stdin from /dev/null to prevent dch
114 # stopping to confirm the bad version is OK.
115 if [ 1 = "$ubuntu" ] ; then
116 distribution=$CODENAME
117 elif [ "`echo "$DEBIAN_CODENAMES"|cut -d' ' -f1`" = "$CODENAME" ] ; then
118 # Backport for the most recent stable debian release.
119 distribution=$CODENAME-backports
120 else
121 distribution=$CODENAME-backports-sloppy
123 dch --force-bad-version -v "$backport_version" -D "$distribution" \
124 "Rebuild for $CODENAME backports." < /dev/null
128 build_it() {
129 adjust_changelog
131 # If debian/control.in exists then modify that, otherwise debian/control.
132 for CONTROL_SOURCE in debian/control.in debian/control ; do
133 test -f "$CONTROL_SOURCE" && break
134 done
136 overrides=
137 case $PKG:$CODENAME:$VERSION in
138 xapian-bindings:stretch:*|xapian-bindings:xenial:*)
139 # Make sure we add python3-xapian to debian/control.
140 overrides='PYTHON3_VERSIONS=dummy RUBY_VERSIONS=2.3 RUBY_PROVIDES="X-Dummy: No provides"' ;;
141 xapian-bindings:*:*)
142 # Make sure we add python3-xapian to debian/control.
143 overrides='PYTHON3_VERSIONS=dummy RUBY_VERSIONS=2.5 RUBY_PROVIDES="X-Dummy: No provides"' ;;
144 esac
146 # Mainly for Survex.
147 case $CODENAME in
148 jammy|focal|bionic|bullseye|buster)
149 if grep -q libwxgtk3.2-dev $CONTROL_SOURCE ; then
150 sed -i 's/libwxgtk3.2-dev/libwxgtk3.0-gtk3-dev/g' $CONTROL_SOURCE
151 dch -a "$CONTROL_SOURCE: Build with wxWidgets 3.0."
154 xenial|stretch)
155 if grep -q libwxgtk3.2-dev $CONTROL_SOURCE ; then
156 sed -i 's/libwxgtk3.2-dev/libwxgtk3.0-dev/g' $CONTROL_SOURCE
157 dch -a "$CONTROL_SOURCE: Build with wxWidgets 3.0."
158 elif grep -q libwxgtk3.0-gtk3-dev $CONTROL_SOURCE ; then
159 sed -i 's/libwxgtk3.0-gtk3-dev/libwxgtk3.0-dev/g' $CONTROL_SOURCE
160 dch -a "$CONTROL_SOURCE: Build with GTK2 version of wxWidgets."
163 esac
165 case $CODENAME in
166 xenial)
167 if [ -f "debian/compat" ] && [ "`cat debian/compat`" -gt 9 ] ; then
168 echo 9 > debian/compat
169 sed -i 's/debhelper (>= [^)]*)/debhelper (>= 9)/' $CONTROL_SOURCE
170 dch -a "$CONTROL_SOURCE: Lower debhelper compat level to 9."
171 # Compat 9 doesn't default to parallel building.
172 if grep -q 'dh_auto_test --no-parallel' debian/rules ; then
173 sed -i 's/dh_auto_test --no-parallel/dh_auto_test/' debian/rules
174 dch -a 'debian/rules: Drop --no-parallel from dh_auto_test invocation (debhelper compat level 9 does not default to parallel building).'
176 else
177 COMPAT=`sed '/@XS_RUBY_VERSIONS@/d' $CONTROL_SOURCE|grep-dctrl -n -sBuild-Depends . -`
178 case $COMPAT in
179 *debhelper-compat*)
180 COMPAT=`echo "$COMPAT"|sed 's/.*debhelper-compat *(= *\([0-9]\+\)).*/\1/p;d'`
181 # Switch to a versioned debhelper dependency and create debian/compat.
182 if [ "$CONTROL_SOURCE" != debian/control ] ; then
183 # Fix generated debian/control as well to avoid error from `debian/rules clean`
184 # due to having debian/compat and a debhelper-compat dependency.
185 sed -i "s/debhelper-compat *(= *[0-9]\+)/debhelper (>= $COMPAT)/" debian/control
187 sed -i "s/debhelper-compat *(= *[0-9]\+)/debhelper (>= $COMPAT)/" $CONTROL_SOURCE
188 echo "$COMPAT" > debian/compat
189 dch -a "$CONTROL_SOURCE,debian/compat: Use older way to specify debhelper compat level."
190 cat >> debian/rules <<END
192 override_dh_dwz:
194 override_dh_builddeb:
195 DH_COMPAT=10 dh_builddeb
197 dch -a "debian/rules: Disable use of dwz to workaround bug in old dwz version"
198 dch -a "debian/rules: Force DH_COMPAT=10 for dh_builddeb"
200 esac
203 esac
205 if [ "$PKG" = debhelper ] ; then
206 case $CODENAME in
207 xenial)
208 sed -i \
209 -e "s/\(dh-autoreconf (>=\) 17/\1 12/" \
210 -e "s/\(dh-strip-nondeterminism (>=\) 0.028/\1 0.015/" \
211 $CONTROL_SOURCE
212 dch -a "$CONTROL_SOURCE: Relax dependencies on dh-autoreconf and dh-strip-nondeterminism."
214 esac
217 case `grep -c '^[^#]*\<CODENAME\>' debian/rules` in
219 echo 'Failed to grep debian/rules'
220 exit 1
222 [01])
223 # Run maintclean and maint targets, if they exist.
224 if grep -qw maintclean debian/rules ; then
225 fakeroot debian/rules maintclean
227 if grep -qw maint debian/rules ; then
228 eval fakeroot debian/rules maint $overrides
232 # If debian/rules has at least two non-commented out references to
233 # CODENAME then create debian/codename.
234 echo "$CODENAME" > debian/codename
235 # Generates control from control.in (and maybe other files).
236 fakeroot debian/rules maintclean CODENAME="$CODENAME"
237 eval fakeroot debian/rules maint CODENAME="$CODENAME" $overrides
239 esac
241 include_src_opt=
242 case $backport_version in
243 *99$UBUNTU_FIRST+1)
244 # We don't really want to upload the orig tarball for all Ubuntu
245 # backports, only if it isn't already in the archive. So for now, just
246 # upload it for the first codename in alphabetical order, and only if
247 # the BUILD_INT (N in the +N suffix) is 1.
248 include_src_opt=-sa ;;
249 esac
250 debuild ${BUILDPACKAGE_SRC_OPTS} $include_src_opt
252 if [ 1 != "$ubuntu" ] ; then
253 # Debian
254 echo "cd build && sbuild --debbuildopt=$V_OPT -d $CODENAME-backports ${PKG}_$backport_version.dsc"
258 # Get the codename(s) specified by the user.
259 if [ -n "$*" ] ; then
260 CODENAMES=`echo "$*"|sed 's/\<debian\>/'"$DEBIAN_CODENAMES"'/;s/\<ubuntu\>/'"$UBUNTU_CODENAMES"'/'`
263 ubuntu=0
264 for CODENAME in $CODENAMES ; do
265 # Check that the codename is known.
266 DEBIAN_CODENAMES_RE='\('`echo "$DEBIAN_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
267 UBUNTU_CODENAMES_RE='\('`echo "$UBUNTU_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
268 if expr "$CODENAME" : "$DEBIAN_CODENAMES_RE" >/dev/null ; then
269 echo "Making source packages for $CODENAME"
270 if [ -z "$V_OPT" ] ; then
271 echo 'You need to specify -v<last backported version> for debian backports'
272 exit 1
274 elif expr "$CODENAME" : "$UBUNTU_CODENAMES_RE" >/dev/null ; then
275 echo "Making source packages for $CODENAME"
276 ubuntu=1
277 else
278 echo "Codename \"$CODENAME\" not known."
279 echo "Known codenames are: $DEBIAN_CODENAMES $UBUNTU_CODENAMES"
280 exit 1
283 trap "echo \"backport-source-packages failed\"" EXIT
285 # $BACKPORT_SUFFIX holds a suffix to be added to the debian version number for
286 # the backport.
288 # We need to add a suffix to the debian version number for the backported
289 # package to avoid conflicts with the package in unstable.
290 # For Ubuntu we add ".99$CODENAME" since it should sort
291 # before any other modification (and since dapper, Ubuntu codenames are
292 # allocated alphabetically). To handle the wrapping from zesty to artful,
293 # we add ".999$CODENAME" for artful and later. For Debian releases, we use
294 # backports.org-compatible package versions - e.g. we append "~bpo10+1" for
295 # Debian 10 (buster) (and a suffix starting "~" sorts as less than no suffix).
296 case $CODENAME in
297 bookworm)
298 BACKPORT_SUFFIX="~bpo12+$BUILD_INT" ;;
299 bullseye)
300 BACKPORT_SUFFIX="~bpo11+$BUILD_INT" ;;
301 buster)
302 BACKPORT_SUFFIX="~bpo10+$BUILD_INT" ;;
303 stretch)
304 BACKPORT_SUFFIX="~bpo9+$BUILD_INT" ;;
306 if [ x"$ubuntu" = x0 ] ; then
307 echo "Debian codename '$CODENAME' not mapped to a ~bpoN suffix"
308 exit 1
310 case $CODENAME in
311 xenial)
312 BACKPORT_SUFFIX=".99$CODENAME+$BUILD_INT" ;;
314 BACKPORT_SUFFIX=".999$CODENAME+$BUILD_INT" ;;
315 esac
317 esac
319 # Unpack distribution tarballs, and put the debian control files into place,
320 # and build source packages
321 mkdir -p build
322 cd build
323 case $PKG in
324 lib*) DIR=`echo $PKG|cut -c1,2,3,4` ;;
325 *) DIR=`echo $PKG|cut -c1` ;;
326 esac
327 DSC=${PKG}_$VERSION$SUFFIX.dsc
328 if [ -f "$DSC" ] ; then
329 [ -d backup ] || mkdir backup
330 if ! mv "$DSC" backup ; then
331 # Handle dsc being hardlinked into backup already.
332 cmp "$DSC" "backup/$DSC" && rm -f "$DSC"
334 dget -b "file://`pwd`/backup/$DSC"
335 elif [ -f "../$DSC" ] ; then
336 dget -b "file://`cd .. && pwd`/$DSC"
337 else
338 dget "${MIRROR}pool/main/$DIR/$PKG/$DSC"
340 cd ${PKG}-${VERSION}
341 build_it
342 cd ..
343 rm -rf ${PKG}-${VERSION}
344 cd ..
346 echo "Backported ${PKG} ${VERSION} for $CODENAME successfully"
347 done
349 trap - EXIT