#!/bin/sh

# Sanity check for deliverable binaries, is all the support in place?
# This script implements a selector on output from /usr/bin/ldd.  This
# is only called from "helper" so variables should be in place.

set -u
DEBUG=
LDD=/usr/bin/ldd	# Debian and RedHat
# [ $DISTROVENDOR = SLES8 ] && LDD=somewhere else?
[ ! -x $LDD ] && echo "$0: no $LDD" && exit 0	# it's too bad but not fatal

RETVAL=0
find $OPTTOP -type f -perm +0100 | while read FILE; do	# May have spaces
  [ -n "$DEBUG" ] && echo $FILE
  $LDD "$FILE" 2>/dev/null | while read LINK ARROW TARGET ADDRESS; do
    [ -n "$DEBUG" ] && echo -e "\t$LINK $ARROW $TARGET"
    [ -z "$LINK" ] && continue		# shouldn't happen
    [ "$LINK" = "not" ] && continue	# there will be only one line to read
    [ "$ARROW" != "=>" -o -z "$ADDRESS" ] && continue
    if [ "$TARGET" = "not" ]; then
	D="\"$FILE\" depends on \"$LINK\":\n"
	case "$LINK" in
	    *libcpq*)
	    	# Assume it's satisfied by libraries in the bin directories
		;;
	    *snmp*)
		echo -e "${D}You must install hp's SNMP package with hpmaX"
		echo "and try again.  See the Agent HOWTO for more information."
		RETVAL=1
		;;
	    *stdc*)
		echo -e "${D}Hint: Install your distribution's compatibility"
		echo "standard C++ package, often called compat-libstdc++"
		echo "and try again."
		RETVAL=1
		;;
	    *pthread*)
		echo -e "${D}Your distribution does not support POSIX threads."
		echo "There is no simple way to work around this setup."
		RETVAL=1
		;;
	    *crypt*)
		echo -e "${D}Install your distribution's cryptological package"
		echo "and try again."
		RETVAL=1
		;;
	    *ssl*)
		echo -e "${D}Install your distribution's ssl package"
		echo "and try again."
		RETVAL=1
		;; 
	    *)
	    	echo -e "${D}Unexpected dependency; no hints available."
		RETVAL=1
		;; 
	esac
    fi
  done
done

exit $RETVAL 
