#!/bin/bash

# purpose of this test is to check that no generated binary is linked against anything in /opt
#

# If using normal root, avoid check. Will give too much false positive

if [ -z "$RPM_BUILD_ROOT" ]; then
        exit 0
fi

OUT_OF_FS=0

if {
	find "$RPM_BUILD_ROOT"/{bin,sbin} -type f -exec file {} + 2>/dev/null | tee /tmp/find | \
	sed -n -e 's/^\(.*\):[[:space:]]*ELF.*/\1/p;/\/bin\/rpm/d;/\/sbin\/install-info/d' \
	    -e '/shared object/{/\/\(security\|evms\|libnss_\)\//d;s/^\(.*\):[[:space:]]*ELF.*/\1/p}' | \
	xargs -r  ldd | sed -nf /usr/lib/rpm/brp-rootfs.data/ldd.sed | \
	sed -n "/\/opt/s@^\([^:]\+\):.*\(/opt/[^[:blank:]]\+\).*@binary \1 is linked against libraries in /opt (\2)@" | \
	grep 'is linked against libraries in /opt'
    } ; then
    echo ""
    echo "Please adjust the paths in your package"
    echo
    exit 1
fi

exit 0
