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
23 # dch from package devscripts.
27 MIRROR
=http
://httpredir.debian.org
/debian
/
29 DEBIAN_CODENAMES
='bookworm bullseye'
30 UBUNTU_CODENAMES
='noble mantic jammy focal bionic xenial'
31 UBUNTU_LATEST
=`echo "$UBUNTU_CODENAMES"|sed 's/ .*//'`
50 BUILD_INT
=`expr substr "$1" 3 9999`
67 if [ -n "$HELP_RC" -o $# -lt 2 ] ; then
68 echo "Usage: $0 [-v <last backported version>] [-b <backport #>] SOURCE_PKG VERSION [CODENAME...]"
70 echo "e.g.: $0 xapian-core 1.4.11-1 xenial"
72 echo 'If -b not specified, default is 1'
74 echo 'If no codenames are specified, the default is to backport for all of them.'
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:"
84 # Remove any backport suffix from any -v option.
85 V_OPT
=`printf '%s' "$V_OPT"|sed 's/~bpo.*//'`
92 VERSION
=`echo "$VERSION"|sed 's/-[^-]*$//'`
93 if [ "$VERSION" = "$SUFFIX" ] ; then
94 # Native package version so SUFFIX is empty.
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.
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
121 distribution
=$CODENAME-backports-sloppy
123 dch
--force-bad-version -v "$backport_version" -D "$distribution" \
124 "Rebuild for $CODENAME backports." < /dev
/null
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
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"' ;;
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"' ;;
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."
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."
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).'
177 COMPAT
=`sed '/@XS_RUBY_VERSIONS@/d' $CONTROL_SOURCE|grep-dctrl -n -sBuild-Depends . -`
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
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"
205 if [ "$PKG" = debhelper
] ; then
209 -e "s/\(dh-autoreconf (>=\) 17/\1 12/" \
210 -e "s/\(dh-strip-nondeterminism (>=\) 0.028/\1 0.015/" \
212 dch
-a "$CONTROL_SOURCE: Relax dependencies on dh-autoreconf and dh-strip-nondeterminism."
217 case `grep -c '^[^#]*\<CODENAME\>' debian/rules` in
219 echo 'Failed to grep debian/rules'
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
242 case $backport_version in
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 most recent Ubuntu release we currently backport to,
247 # and only if the BUILD_INT (N in the +N suffix) is 1.
248 include_src_opt
=-sa ;;
250 debuild
${BUILDPACKAGE_SRC_OPTS} $include_src_opt
252 if [ 1 != "$ubuntu" ] ; then
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"'/'`
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'
274 elif expr "$CODENAME" : "$UBUNTU_CODENAMES_RE" >/dev
/null
; then
275 echo "Making source packages for $CODENAME"
278 echo "Codename \"$CODENAME\" not known."
279 echo "Known codenames are: $DEBIAN_CODENAMES $UBUNTU_CODENAMES"
283 trap "echo \"backport-source-packages failed\"" EXIT
285 # $BACKPORT_SUFFIX holds a suffix to be added to the debian version number for
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).
298 BACKPORT_SUFFIX
="~bpo12+$BUILD_INT" ;;
300 BACKPORT_SUFFIX
="~bpo11+$BUILD_INT" ;;
302 BACKPORT_SUFFIX
="~bpo10+$BUILD_INT" ;;
304 BACKPORT_SUFFIX
="~bpo9+$BUILD_INT" ;;
306 if [ x
"$ubuntu" = x0
] ; then
307 echo "Debian codename '$CODENAME' not mapped to a ~bpoN suffix"
312 BACKPORT_SUFFIX
=".99$CODENAME+$BUILD_INT" ;;
314 BACKPORT_SUFFIX
=".999$CODENAME+$BUILD_INT" ;;
319 # Unpack distribution tarballs, and put the debian control files into place,
320 # and build source packages
324 lib
*) DIR
=`echo $PKG|cut -c1,2,3,4` ;;
325 *) DIR
=`echo $PKG|cut -c1` ;;
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"
338 dget
"${MIRROR}pool/main/$DIR/$PKG/$DSC"
343 rm -rf ${PKG}-${VERSION}
346 echo "Backported ${PKG} ${VERSION} for $CODENAME successfully"
351 *xapian
*) PPA
=ppa
:xapian
/backports
;;
352 survex
) PPA
=ppa
:survex-devs
/ppa
;;
354 if [ -n "$PPA" ] ; then
355 for CODENAME
in $CODENAMES ; do
356 if [ `expr " $UBUNTU_CODENAMES " : " $CODENAME "` != 0 ] ; then
357 echo "dput -U $PPA build/${PKG}_${VERSION}${BACKPORT_SUFFIX}_source.changes"