Skip to content

Instantly share code, notes, and snippets.

@nemequ
Created April 3, 2016 02:55
Show Gist options
  • Save nemequ/c1ecc855e112318bb294a9d2462af4cd to your computer and use it in GitHub Desktop.
Save nemequ/c1ecc855e112318bb294a9d2462af4cd to your computer and use it in GitHub Desktop.
Quick and (very) dirty bash script for generating a graphviz dot file showing pkg-config dependencies.
#!/bin/bash
# Quick and (very) dirty bash script for generating a graphviz dot
# file showing pkg-config dependencies.
LIBDIR="lib64"
if [ $# -ne 1 ]; then
echo "Usage: $0 pkg-config-name"
return 1
fi
declare -A DONE
parse_pkg_config() {
if [ "x${DONE[$1]}" != "xTRUE" ]; then
TODO=""
DONE[$1]="TRUE"
OIFS="${IFS}"
while IFS=':' read -ra PKG_PATHS; do
for PKG_PATH in "${PKG_PATHS[@]}"; do
if [ -e "${PKG_PATH}/${1}.pc" ]; then
for PKG in `grep -Pi "^Requires: " "${PKG_PATH}/${1}.pc" | cut -b11- | sed -r 's/ >= [0-9\.]+//g'`; do
echo " \"$1\" -> \"$PKG\";"
TODO="$TODO $PKG"
# parse_pkg_config "$PKG"
done
break;
fi
done
done <<< "${PKG_CONFIG_PATH}:/usr/${LIBDIR}/pkgconfig:/usr/share/pkgconfig:/usr/local/${LIBDIR}/pkgconfig:/usr/local/share/pkgconfig"
IFS="${OIFS}"
for DEP in $TODO; do
parse_pkg_config "$DEP"
done
fi
}
echo "digraph {"
parse_pkg_config "$1"
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment