1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#!/bin/bash
set -e
shopt -s extglob
# Set defaults from the running kernel
arch="$(dpkg --print-architecture)"
kernelabi="$(uname -r)"
ff="${kernelabi##+([^-])-?(@(trunk|?(rc)+([0-9])|0.@(bpo|deb+([0-9])).+([0-9]))-)}"
if [ "x$ff" != "x$kernelabi" ]; then
flavour="${ff#@(openvz|rt|vserver|xen)-}"
if [ "x$flavour" != "x$ff" ]; then
featureset="${ff%-$flavour}"
else
featureset=none
fi
else
flavour=
featureset=none
fi
dbginfo=
fuzz=0
jobs=$(nproc)
eval "set -- $(getopt -n "$0" -o "f:gj:s:" -l "fuzz:" -- "$@")"
while true; do
case "$1" in
-f) flavour="$2"; shift 2 ;;
-g) dbginfo=y; shift 1 ;;
-j) jobs="$2"; shift 2 ;;
-s) featureset="$2"; shift 2 ;;
--fuzz) fuzz="$2"; shift 2;;
--) shift 1; break ;;
esac
done
if [ $# -lt 1 ]; then
echo >&2 "Usage: $0 [<options>] <patch>..."
cat >&2 <<EOF
Options:
-f <flavour> specify the 'flavour' of kernel to build, e.g. 686-pae
-g enable debug info
-j <jobs> specify number of compiler jobs to run in parallel
(default: number of available processors)
-s <featureset> specify an optional featureset to apply, e.g. rt
--fuzz <num> set the maximum patch fuzz factor (default: 0)
EOF
exit 2
fi
if [ -z "$flavour" ]; then
echo >&2 "You must specify a flavour to build with the -f option"
exit 2
fi
profiles=nodoc,noudeb,pkg.linux.nosource,pkg.linux.mintools
if [ -z "$dbginfo" ]; then
profiles="$profiles,pkg.linux.nokerneldbg,pkg.linux.nokerneldbginfo"
fi
# Check build-dependencies early if possible
if [ -f debian/control ]; then
dpkg-checkbuilddeps -P"$profiles"
fi
# Provide defaults for DEBEMAIL and DEBFULLNAME
if [[ -z "${DEBEMAIL}" && -z "${EMAIL}" ]]; then
export DEBEMAIL=test-patches@mail.invalid
fi
if [[ -z "${DEBFULLNAME}" && -z "${NAME}" ]]; then
export DEBFULLNAME=test-patches
fi
# Append 'a~test' to Debian version; this should be less than any official
# successor and easily recognisable
version="$(dpkg-parsechangelog | sed 's/^Version: //; t; d')"
if [ "${version%a~test}" = "$version" ]; then
version="$version"a~test
dch -v "$version" --distribution UNRELEASED "Testing patches $*"
fi
# Ignore user's .quiltrc
alias quilt='quilt --quiltrc -'
# Try to clean up any previous test patches
if [ "$featureset" = none ]; then
patchdir=debian/patches
while patch="$(quilt top 2>/dev/null)" && \
[ "${patch#test/}" != "$patch" ]; do
quilt pop -f
done
while patch="$(quilt next 2>/dev/null)" && \
[ "${patch#test/}" != "$patch" ]; do
quilt delete -r "$patch"
done
else
patchdir=debian/patches-${featureset}
sed -i '/^test\//d' $patchdir/series
fi
# Prepare a new directory for the patches
rm -rf $patchdir/test/
mkdir $patchdir/test
# Prepare a new directory for the config; override ABI name, featuresets, flavours
rm -rf debian/config.local
mkdir debian/config.local debian/config.local/"$arch" debian/config.local/"$arch"/"$featureset"
cat >debian/config.local/defines <<EOF
[abi]
abiname: 0.a.test
EOF
cat >debian/config.local/"$arch"/defines <<EOF
[base]
featuresets: $featureset
EOF
cat >debian/config.local/"$arch"/"$featureset"/defines <<EOF
[base]
flavours: $flavour
EOF
if [ "$featureset" = none ]; then
# default-flavour must refer to a flavour that's enabled
cat >>debian/config.local/"$arch"/"$featureset"/defines <<EOF
default-flavour: $flavour
EOF
fi
# Regenerate control and included rules
rm -f debian/control debian/rules.gen
debian/rules debian/control-real && exit 1 || true
test -f debian/control
test -f debian/rules.gen
# Check build-dependencies now that we know debian/control exists
dpkg-checkbuilddeps -P"$profiles"
# Clean up old build; apply existing patches for featureset
debian/rules clean
debian/rules source
# Apply the additional patches
for patch in "$@"; do
patch_abs="$(readlink -f "$patch")"
(cd "debian/build/source_${featureset}" && \
quilt import -P "test/$(basename "$patch")" "$patch_abs" && \
quilt push --fuzz="$fuzz")
done
# Build selected binaries
dpkg-buildpackage -b -P"$profiles" -j"$jobs" -nc -uc
|