Last active
October 15, 2015 17:13
-
-
Save alucryd/1b1bf95c426fb45a81fa to your computer and use it in GitHub Desktop.
Compute depends array for PKGBUILDs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/zsh | |
# Usage: pkgbuild-depends /path/to/elf1 /path/to/elf2... | |
# pkgbuild-depends -p package | |
while getopts 'p:m' opt; do | |
case $opt in | |
p) | |
files=($(pacman -Ql $OPTARG | cut -d' ' -f2)) | |
;; | |
m) | |
repos=(multilib alucryd-multilib) | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[[ -z $files ]] && files=($@) | |
[[ -z $repos ]] && repos=(core extra community alucryd pantheon) | |
blacklist=(dropbox gcc-libs-multilib openstack-guest-agents-unix plex-media-server teamviewer vagrant) | |
libs=($(readelf -d ${files[@]} 2>/dev/null | grep 'Shared library' | sort | uniq | sed 's/.*\[\(.*\)\]/\1/')) | |
for lib in ${libs[@]}; do | |
echo "Looking for $lib" | |
if [[ $lib == libGL.so.* || $lib == libEGL.so.* ]]; then | |
if [[ $repos[1] == multilib ]]; then | |
echo "Found in lib32-libgl" | |
depends+=(lib32-libgl) | |
else | |
echo "Found in libgl" | |
depends+=(libgl) | |
fi | |
else | |
if [[ -n $(pacman -Ss ${lib/.so*/.so}) ]]; then | |
echo "Found ${lib/so*/so}" | |
depends+=(${lib/so*/so}) | |
else | |
for repo in ${repos[@]}; do | |
pkgs=($(pkgfile -R $repo $lib | sed "s/$repo\///")) | |
for pkg in ${pkgs[@]}; do | |
echo "Found in $pkg" | |
needed=true | |
for pkg_bl in ${blacklist[@]}; do | |
if [[ $pkg == $pkg_bl ]]; then | |
needed=false | |
fi | |
done | |
if [[ $needed == true ]]; then | |
depends+=($pkg) | |
fi | |
done | |
done | |
fi | |
fi | |
echo "" | |
done | |
sortdeps() { | |
for d in ${depends[@]}; do | |
echo $d; | |
done | sort | uniq | |
} | |
depends=($(sortdeps)) | |
depends="('$(echo ${(o)depends} | sed "s/ /\' \'/g")')" | |
echo "depends=$depends" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment