#ident	"@(#)r.build	1.5	02/09/23 SMI"	/* SVr4.0  1.6	*/ 

error=no
while read dest
do
	if [ -d $dest ]
	then
		echo "$dest"
		rmdir $dest || error=yes
	elif [ -f $dest ]
	then
		echo "Modifying $dest"

		
		# Strip PKG_INSTALL_ROOT from dest if installation is to an
		# alternate root.

		if [ -n "$PKG_INSTALL_ROOT" -a "$PKG_INSTALL_ROOT" != "/" ]; then
			client_dest=`echo $dest | \
				/usr/bin/nawk -v rootdir="$PKG_INSTALL_ROOT" '{
				    { print substr($0, length(rootdir)+1)} }'`
			savepath=$PKGSAV/build${client_dest}
		else
			savepath=$PKGSAV/build${dest}
		fi

		chmod +x $savepath
#		if $savepath remove $dest > /tmp/$$build
# bug id #1081806
		if $savepath remove > /tmp/$$build
		then
			if [ ! -s /tmp/$$build ]
			then
				rm -f $dest
			else
				cp /tmp/$$build $dest || error=yes
			fi
		else
			error=yes
		fi
		rm -f /tmp/$$build
	else
		[ -r $dest ] && echo "$dest"
		rm -f $dest || error=yes
	fi
done
[ "$error" = yes ] &&
	exit 2
exit 0
