#!/bin/bash

perk=/usr/bin/perk
test -x $perk || {
    cat > /dev/null
    exit 0
}

[ $# -ge 1 ] || {
    cat > /dev/null
    exit 0
}

case $1 in
-P|--provides)
    while read filename ; do
    case "${filename}" in
    *.so*)
	if [ -L ${filename} ]; then
		# Skip symlink files
		continue
	fi
	# Print the name of the library with correct multilibbing
	DIR="`dirname ${filename}`"
	FILE="`basename ${filename}`"
	if [[ $DIR =~ "/lib64" ]]; then
		echo -n "${FILE}(64bit)\n"
	fi
	if [[ $DIR =~ "/lib32" ]]; then
		echo -n "${FILE}(32bit)\n"
	fi
    esac
    done
    ;;
-R|--requires)
    while read filename ; do
	# Print the name of the library with correct multilibbing
	DIR="`dirname ${filename}`"
	FILE="`basename ${filename}`"
	PEDEPS="`perk -d ${filename}`"
	readarray -t DEPS <<<"$PEDEPS"
	if [[ $DIR =~ "/lib64" ]]; then
		for dep in "${DEPS[@]}"
		do
			echo -n "${dep}(64bit)\n"
		done
	fi
	if [[ $DIR =~ "/lib32" ]]; then
		for dep in "${DEPS[@]}"
		do
			echo -n "${dep}(32bit)\n"
		done
	fi
    done
    ;;
esac
exit 0
