| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# extract config.sh.* files from binary packages |
| 4 |
# |
| 5 |
# Copyright 2016 Niko Tyni <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the same terms as Perl itself. |
| 9 |
|
| 10 |
set -e |
| 11 |
|
| 12 |
if [ $# = 0 ]; then |
| 13 |
echo "Usage: $0 <file.deb> [...]" 1>&2 |
| 14 |
exit 1 |
| 15 |
fi |
| 16 |
|
| 17 |
# sanity check |
| 18 |
if [ ! -d debian/cross ]; then |
| 19 |
echo "This program is supposed to run in the perl Debian package source directory" 1>&2 |
| 20 |
exit 1 |
| 21 |
fi |
| 22 |
|
| 23 |
for deb in "$@"; do |
| 24 |
arch=$(dpkg-deb -W --showformat '${Architecture}' "$deb") |
| 25 |
if [ ! -n "$arch" ]; then |
| 26 |
echo "Could not get Debian architecture of $deb" 1>&2 |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
if [ ! -d "debian/cross/$arch" ]; then |
| 30 |
echo "Unknown architecture: $arch (mkdir debian/cross/$arch first?), skipping" 1>&2 |
| 31 |
continue |
| 32 |
fi |
| 33 |
|
| 34 |
archlist="$archlist $arch" |
| 35 |
|
| 36 |
version=$(dpkg-deb -W --showformat '${Version}' "$deb") |
| 37 |
if [ ! -n "$version" ]; then |
| 38 |
echo "Could not get Debian version from $deb" 1>&2 |
| 39 |
exit 1 |
| 40 |
fi |
| 41 |
|
| 42 |
# shameless reliance on GNU tar fancy functionality |
| 43 |
# note that we expand ${arch} in this shell and not the subshell |
| 44 |
# so we don't have to export it |
| 45 |
if ! dpkg-deb --fsys-tarfile "$deb" | tar xf - --wildcards \ |
| 46 |
'*/config.sh.static.gz' \ |
| 47 |
'*/config.sh.debug.gz' \ |
| 48 |
'*/config.sh.shared.gz' \ |
| 49 |
--to-command='sh -c "gzip -dc > debian/cross/'${arch}'/$(basename $TAR_FILENAME .gz)"' |
| 50 |
then |
| 51 |
echo "no config.sh.* files in $deb, skipping" 1>&2 |
| 52 |
continue |
| 53 |
fi |
| 54 |
|
| 55 |
echo "# Extracted from Debian package version $version" >> debian/cross/$arch/config.sh.static |
| 56 |
|
| 57 |
# store debug and shared configs as contextless patches |
| 58 |
# the idea is to make it as easy (heh) as possible for bootstrappers |
| 59 |
# so they only have to craft the static one by hand |
| 60 |
for type in shared debug; do |
| 61 |
( cd debian/cross/$arch && \ |
| 62 |
! diff -u0 config.sh.static config.sh.$type > config.sh.$type.patch && \ |
| 63 |
rm config.sh.$type ) |
| 64 |
done |
| 65 |
|
| 66 |
if [ -d .git ]; then |
| 67 |
git add debian/cross/$arch |
| 68 |
fi |
| 69 |
done |
| 70 |
|
| 71 |
if [ -d .git ]; then |
| 72 |
debs=$(sha1sum "$@") |
| 73 |
git commit -m "Refresh cross build support files for$archlist" \ |
| 74 |
-m "Files extracted by $0 from:" \ |
| 75 |
-m "$debs" |
| 76 |
fi |