#!/usr/bin/env pkgcore-ebuild-helper
# Copyright: 2011 Brian Harring <ferringb@gmail.com>
# License: GPL2/BSD 3 clause

check_args 1 -

libdir=${ED}${DESTTREE}/$(__get_libdir lib)

if [[ ${HELPER_NAME} == "dolib.so" ]]; then
	LIBOPTIONS="-m0755"
elif [[ ${HELPER_NAME} == "dolib.a" ]]; then
	LIBOPTIONS="-m0644"
fi

check_command_or_stop install -d "${libdir}"

for x in "$@"; do
	if [[ -L ${x} ]]; then
		# yes we want readlink, not readlink -f; we want the symlink content,
		# not the resolved symlink target.
		check_command ln -s -- "$(readlink -- "${x}")" "${libdir}/${x##*/}"
	else
		check_command install ${LIBOPTIONS} -- "${x}" "${libdir}"
	fi
done
