abuild: add amove func to move from $pkgdir to $subpkgdir

moving files and directories from $pkgdir to $subpkgdir is a common
pattern, so make a helper function for this.

usage: amove FILESPEC...

FILESPEC is a list of files or patterns/globs that will be exanded by
the shell.

amove will clean up empty directories after moving the files/dirs.

Example usage:

  amove 'usr/lib/lib*.a'
  amove 'etc/*.d' # moves both etc/conf.d and etc/init.d
  amove 'lib/*.so' 'usr/lib/*.so'

  cd "$pkgdir"
  find usr -name '*.h' | xargs amove

This is based on the work of Chloe Kudryavtsev:
https://github.com/alpinelinux/abuild/pull/92
This commit is contained in:
Natanael Copa 2019-10-01 16:25:45 +01:00
parent 610f1982ef
commit aa86438443

View File

@ -72,6 +72,29 @@ error() {
logcmd "ERROR: $pkgname: $1"
}
amove() {
[ -n "$subpkgdir" ] || return 1
# store directory
d="$(pwd -L)"
cd "$pkgdir"
local pattern f
for pattern; do
for f in ${pattern#/}; do # let shell expand the pattern
# only create dir if needed
if [ "${f%/*}" != "$f" ]; then
mkdir -p "$subpkgdir/${f%/*}"
fi
mv -v "$pkgdir"/$f "$subpkgdir/${f%/*}"
# cleanup
rmdir -p "$f" || rmdir -p "${f%/*}" || true
done
done
cd "$d"
}
cross_creating() {
test "$CHOST" != "$CTARGET" -a -n "$CBUILDROOT"
}