Drop special handling of MACOSX_DEPLOYMENT_TARGET
[xapian.git] / xapian-maintainer-tools / debian / backport-source-packages
blobb118d7186c9f3818e5a7bca904b54539b64df9e9
1 #!/bin/sh
2 # Backport Debian source packages for Xapian.
4 # Copyright (C) 2004 Richard Boulton
5 # Copyright (C) 2006-2020 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='buster stretch jessie'
30 UBUNTU_CODENAMES='eoan bionic 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 backported version>] [-b <backport #>] SOURCE_PKG VERSION [CODENAME...]"
69 echo
70 echo "e.g.: $0 xapian-core 1.4.11-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 # Remove any backport suffix from any -v option.
82 V_OPT=`printf '%s' "$V_OPT"|sed 's/~bpo.*//'`
83 PKG=$1
84 VERSION=$2
85 shift
86 shift
88 SUFFIX=`echo "$VERSION"|sed 's/.*-/-/'`
89 VERSION=`echo "$VERSION"|sed 's/-[^-]*$//'`
91 # Debian/Ubuntu codename or codenames to build for.
92 # This will be overridden by the command line arguments, if any were passed.
93 CODENAMES="$DEBIAN_CODENAMES $UBUNTU_CODENAMES"
95 # Options to pass to dpkg-buildpackage when building source packages
96 BUILDPACKAGE_SRC_OPTS="-us -uc -d -S $V_OPT --changes-option=-DBinary=dummy"
98 # Add entry to changelog if we're backporting.
99 adjust_changelog() {
100 if [ sid != "$CODENAME" ] ; then
101 base_version=`dpkg-parsechangelog|sed 's/^Version: //p;d'`
102 backport_version=$base_version$BACKPORT_SUFFIX
103 # --force-bad-version needed for backporting, since the "new" version may
104 # be less than the "old". Direct stdin from /dev/null to prevent dch
105 # stopping to confirm the bad version is OK.
106 if [ 1 = "$ubuntu" ] ; then
107 distribution=$CODENAME
108 elif [ "`echo "$DEBIAN_CODENAMES"|cut -d' ' -f1`" = "$CODENAME" ] ; then
109 # Backport for the most recent stable debian release.
110 distribution=$CODENAME-backports
111 else
112 distribution=$CODENAME-backports-sloppy
114 dch --force-bad-version -v "$backport_version" -D "$distribution" \
115 "Rebuild for $CODENAME backports." < /dev/null
119 build_it() {
120 adjust_changelog
122 overrides=
123 case $PKG:$CODENAME:$VERSION in
124 xapian-bindings:jessie:*)
125 # Make sure we add python-xapian to debian/control.
126 overrides='PYTHON_VERSIONS=dummy' ;;
127 xapian-bindings:trusty:*)
128 # Make sure we add python-xapian and python3-xapian to debian/control.
129 overrides='PYTHON_VERSIONS=dummy PYTHON3_VERSIONS=dummy' ;;
130 xapian-bindings:stretch:*|xapian-bindings:xenial:*)
131 # Make sure we add python-xapian and python3-xapian to debian/control.
132 overrides='PYTHON_VERSIONS=dummy PYTHON3_VERSIONS=dummy RUBY_VERSIONS=2.3 RUBY_PROVIDES="X-Dummy: No provides"' ;;
133 xapian-bindings:*:*)
134 # Make sure we add python-xapian and python3-xapian to debian/control.
135 overrides='PYTHON_VERSIONS=dummy PYTHON3_VERSIONS=dummy RUBY_VERSIONS=2.5 RUBY_PROVIDES="X-Dummy: No provides"' ;;
136 esac
138 # libxapian30 (i.e. 1.4.x) is built with C++ "v5" ABI in stretch and newer
139 # and in xenial and newer, so append "v4" to the soname for backports to
140 # older versions so upgrades with the backport installed work cleanly.
141 case $PKG:$VERSION in
142 xapian-core:1.4.*)
143 case $CODENAME in
144 jessie|trusty)
145 perl -i -e 'while (<>) { print; last if /^libxapian_soversion:=/ } while (<>) { print; last unless /\\$/ } print "libxapian_soversion:=\$(libxapian_soversion)v4\n"; while (<>) { s/^(\techo .libxapian.*)>/$1|sed "s,v4,,g" >/; print }' debian/rules
146 sed -i 's/^\(Package: libxapian@LIBXAPIAN_SOVERSION@\)\(.*\)/\1\2\nConflicts: libxapian30\2\nReplaces: libxapian30\2/' debian/control.in
147 dch -a 'debian/control.in,debian/rules: Add v4 suffix to soname. (Closes: #863705)'
149 esac
151 esac
153 # Mainly for Survex.
154 case $CODENAME in
155 trusty|xenial|jessie|stretch)
156 if grep -q libwxgtk3.0-gtk3-dev debian/control ; then
157 sed -i 's/libwxgtk3.0-gtk3-dev/libwxgtk3.0-dev/g' debian/control
158 dch -a 'debian/control: Build with GTK2 version of wxWidgets.'
161 esac
163 case $CODENAME in
164 jessie)
165 if [ "`cat debian/compat`" -gt 10 ] ; then
166 echo 10 > debian/compat
167 sed -i 's/debhelper (>= [^)]*)/debhelper (>= 10)/' debian/control
168 dch -a 'debian/control: Lower debhelper compat level to 10.'
171 trusty|xenial)
172 if [ "`cat debian/compat`" -gt 9 ] ; then
173 echo 9 > debian/compat
174 sed -i 's/debhelper (>= [^)]*)/debhelper (>= 9)/' debian/control
175 dch -a 'debian/control: Lower debhelper compat level to 9.'
176 # Compat 9 doesn't default to parallel building.
177 if grep -q 'dh_auto_test --no-parallel' debian/rules ; then
178 sed -i 's/dh_auto_test --no-parallel/dh_auto_test/' debian/rules
179 dch -a 'debian/rules: Drop --no-parallel from dh_auto_test invocation (debhelper compat level 9 does not default to parallel building).'
183 esac
185 case `grep -c '^[^#]*\<CODENAME\>' debian/rules` in
187 echo 'Failed to grep debian/rules'
188 exit 1
190 [01])
191 # Run maintclean and maint targets, if they exist.
192 fakeroot debian/rules maintclean || true
193 eval fakeroot debian/rules maint $overrides || true
196 # If debian/rules has at least two non-commented out references to
197 # CODENAME then create debian/codename.
198 echo "$CODENAME" > debian/codename
199 # Generates control from control.in (and maybe other files).
200 fakeroot debian/rules maintclean CODENAME="$CODENAME"
201 eval fakeroot debian/rules maint CODENAME="$CODENAME" $overrides
203 esac
205 include_src_opt=
206 case $backport_version in
207 *99$UBUNTU_FIRST+1)
208 # We don't really want to upload the orig tarball for all Ubuntu
209 # backports, only if it isn't already in the archive. So for now, just
210 # upload it for the first codename in alphabetical order, and only if
211 # the BUILD_INT (N in the +N suffix) is 1.
212 include_src_opt=-sa ;;
213 esac
214 debuild ${BUILDPACKAGE_SRC_OPTS} $include_src_opt
216 if [ 1 != "$ubuntu" ] ; then
217 # Debian
218 echo "cd build && sbuild --debbuildopt=$V_OPT -d $CODENAME-backports ${PKG}_$backport_version.dsc"
222 # Get the codename(s) specified by the user.
223 if [ -n "$*" ] ; then
224 CODENAMES=`echo "$*"|sed 's/\<debian\>/'"$DEBIAN_CODENAMES"'/;s/\<ubuntu\>/'"$UBUNTU_CODENAMES"'/'`
227 ubuntu=0
228 for CODENAME in $CODENAMES ; do
229 # Check that the codename is known.
230 DEBIAN_CODENAMES_RE='\('`echo "$DEBIAN_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
231 UBUNTU_CODENAMES_RE='\('`echo "$UBUNTU_CODENAMES"|sed 's/ /\\\|/g'`'\)$'
232 if expr "$CODENAME" : "$DEBIAN_CODENAMES_RE" >/dev/null ; then
233 echo "Making source packages for $CODENAME"
234 if [ -z "$V_OPT" ] ; then
235 echo 'You need to specify -v<last backported version> for debian backports'
236 exit 1
238 elif expr "$CODENAME" : "$UBUNTU_CODENAMES_RE" >/dev/null ; then
239 echo "Making source packages for $CODENAME"
240 ubuntu=1
241 else
242 echo "Codename \"$CODENAME\" not known."
243 echo "Known codenames are: $DEBIAN_CODENAMES $UBUNTU_CODENAMES"
244 exit 1
247 trap "echo \"backport-source-packages failed\"" EXIT
249 # $BACKPORT_SUFFIX holds a suffix to be added to the debian version number for
250 # the backport.
252 # We need to add a suffix to the debian version number for the backported
253 # package to avoid conflicts with the package in unstable.
254 # For Ubuntu we add ".99$CODENAME" since it should sort
255 # before any other modification (and since dapper, Ubuntu codenames are
256 # allocated alphabetically). To handle the wrapping from zesty to artful,
257 # we add ".999$CODENAME" for artful and later. For Debian releases, we use
258 # backports.org-compatible package versions - e.g. we append "~bpo8+1" for
259 # Debian 8 (jessie) (and a suffix starting "~" sorts as less than no suffix).
260 case $CODENAME in
261 buster)
262 BACKPORT_SUFFIX="~bpo10+$BUILD_INT" ;;
263 stretch)
264 BACKPORT_SUFFIX="~bpo9+$BUILD_INT" ;;
265 jessie)
266 BACKPORT_SUFFIX="~bpo8+$BUILD_INT" ;;
268 if [ x"$ubuntu" = x0 ] ; then
269 echo "Debian codename '$CODENAME' not mapped to a ~bpoN suffix"
270 exit 1
272 case $CODENAME in
273 trusty|xenial)
274 BACKPORT_SUFFIX=".99$CODENAME+$BUILD_INT" ;;
276 BACKPORT_SUFFIX=".999$CODENAME+$BUILD_INT" ;;
277 esac
279 esac
281 # Unpack distribution tarballs, and put the debian control files into place,
282 # and build source packages
283 mkdir -p build
284 cd build
285 case $PKG in
286 lib*) DIR=`echo $PKG|cut -c1,2,3,4` ;;
287 *) DIR=`echo $PKG|cut -c1` ;;
288 esac
289 DSC=${PKG}_$VERSION$SUFFIX.dsc
290 if [ -f "$DSC" ] ; then
291 [ -d backup ] || mkdir backup
292 if ! mv "$DSC" backup ; then
293 # Handle dsc being hardlinked into backup already.
294 cmp "$DSC" "backup/$DSC" && rm -f "$DSC"
296 dget -b "file://`pwd`/backup/$DSC"
297 elif [ -f "../$DSC" ] ; then
298 dget -b "file://`cd .. && pwd`/$DSC"
299 else
300 dget "${MIRROR}pool/main/$DIR/$PKG/$DSC"
302 cd ${PKG}-${VERSION}
303 build_it
304 cd ..
305 rm -rf ${PKG}-${VERSION}
306 cd ..
308 echo "Backported ${PKG} ${VERSION} for $CODENAME successfully"
309 done
311 trap - EXIT