#!/bin/sh -e
#
# brp-verify_elf - verify ELF objects.
#
# $Id: brp-verify_elf.in,v 1.9 2003/11/23 21:08:49 ldv Exp $
# Copyright (C) 2002,2003  Dmitry V. Levin <ldv@altlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

. /usr/lib/rpm/functions
ValidateBuildRoot

cd "$RPM_BUILD_ROOT"

export VERIFY_ELF_RPATH=normal
export VERIFY_ELF_TEXTREL=normal

for t in `printf %s "$RPM_VERIFY_ELF_METHOD" |tr , ' '`; do
	case "$t" in
		no|none|skip)
			exit 0
			;;
		rpath)
			VERIFY_ELF_RPATH=normal
			;;
		rpath=*)
			VERIFY_ELF_RPATH="${t#rpath=}"
			;;
		textrel)
			VERIFY_ELF_TEXTREL=normal
			;;
		textrel=*)
			VERIFY_ELF_TEXTREL="${t#textrel=}"
			;;
		normal)
			VERIFY_ELF_RPATH=normal
			VERIFY_ELF_TEXTREL=normal
			;;
		strict)
			VERIFY_ELF_RPATH=strict
			VERIFY_ELF_TEXTREL=strict
			;;
		relaxed)
			VERIFY_ELF_RPATH=relaxed
			VERIFY_ELF_TEXTREL=relaxed
			;;
		*)
			Fatal "Unrecognized verify_elf method: $t"
			;;
	esac
done

[ "$VERIFY_ELF_RPATH" != no ] || VERIFY_ELF_RPATH=
[ -z "$RPM_VERIFY_ELF_RPATH" ] || VERIFY_ELF_RPATH="$RPM_VERIFY_ELF_RPATH"
[ "$VERIFY_ELF_TEXTREL" != no ] || VERIFY_ELF_TEXTREL=
[ -z "$RPM_VERIFY_ELF_TEXTREL" ] || VERIFY_ELF_TEXTREL="$RPM_VERIFY_ELF_TEXTREL"

: ${RPM_VERIFY_ELF_TOPDIR:=}
[ -d "$RPM_BUILD_ROOT$RPM_VERIFY_ELF_TOPDIR" ] || exit 0

echo "Verifying ELF objects in $RPM_BUILD_ROOT$RPM_VERIFY_ELF_TOPDIR (rpath=$VERIFY_ELF_RPATH,textrel=$VERIFY_ELF_TEXTREL)"

find .$RPM_VERIFY_ELF_TOPDIR -type f -print0 |xargs -r0 /usr/lib/rpm/verify-elf
