938c5c
#
938c5c
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
938c5c
# set +o errexit -o noglob -o nounset is assumed.
938c5c
#
938c5c
#
938c5c
938c5c
#
010a87
# ex_rtl_install_library_archives() - install library archives and library links (.lib.a) for all libraries (.so) in tree matching lib*
938c5c
# @_dname_base:		base directory pathname
938c5c
# @_mdso_cmd:		mdso command name
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_install_library_archives() {
938c5c
	local	_erila_dname_base="${1}" _erila_mdso_cmd="${2}"			\
938c5c
		_erila_postfix="" _erila_lib_dst_path="" _erila_lib_name=""	\
938c5c
		_erila_lib_src_path="" _erila_so_dst_dir="" _erila_so_src_path="";
938c5c
938c5c
	for _erila_so_src_path in 				\
010a87
		$(find	"${_erila_dname_base}"			\
010a87
			\( -name "*.so" -or -name "*.so.*" \)	\
010a87
			\( -name "lib*" \)			\
938c5c
			-print);
938c5c
	do
938c5c
		if [ "$(readlink -f "${_erila_so_src_path}")" != "/dev/null" ]\
938c5c
		&& rtl_remove_postfix "[0-9.]" "${_erila_so_src_path##*.so}" \$_erila_postfix\
938c5c
		&& [ "${_erila_postfix:+1}" != 1 ]; then
938c5c
938c5c
			case "${_erila_so_src_path}" in
938c5c
			*.so)	_erila_lib_src_path="${_erila_so_src_path%%.so}.lib.a"; ;;
938c5c
			*.so.*)	_erila_lib_src_path="${_erila_so_src_path%%.so.*}.${_erila_so_src_path##*.so.}.lib.a"; ;;
938c5c
			esac;
938c5c
938c5c
			_erila_so_dst_dir="${_erila_so_src_path%/*}";
938c5c
			rtl_basename2 \$_erila_lib_src_path \$_erila_lib_name;
938c5c
			_erila_lib_dst_path="${_erila_so_dst_dir}/${_erila_lib_name}";
938c5c
938c5c
			if [ ! -L "${_erila_lib_src_path}" ]\
938c5c
			&& [ ! -e "${_erila_lib_dst_path}" ]; then
938c5c
				if ! (rtl_basename2 \$_erila_so_src_path \$_erila_fname;		\
938c5c
				      rtl_basename2 \$_erila_lib_dst_path \$_erila_fname_dst;	\
938c5c
				      rtl_dirname2 \$_erila_so_src_path \$_erila_dname;		\
938c5c
				      rtl_fileop cd "${_erila_dname}" &&			\
938c5c
						perk -e "${_erila_fname}"			|\
938c5c
							"${_erila_mdso_cmd}"			\
938c5c
								-i "${_erila_fname_dst}"		\
938c5c
								-n "${_erila_fname}" -);
938c5c
				then
938c5c
					return 1;
938c5c
				fi;
938c5c
			fi;
938c5c
938c5c
			if ! ex_rtl_install_library_link				\
938c5c
					"${_erila_lib_name}" "${_erila_so_dst_dir}"	\
938c5c
					"${_erila_so_src_path}";
938c5c
			then
938c5c
				return 1;
938c5c
			fi;
938c5c
		fi;
938c5c
	done;
938c5c
938c5c
	return 0;
938c5c
};
938c5c
938c5c
#
938c5c
# ex_rtl_install_library_link() - install library archive (.lib.a) link for library (.so)
938c5c
# @_lib_name:	library name
938c5c
# @_so_dir:	library directory pathname
938c5c
# @_so_path:	library file pathname
938c5c
#
938c5c
# Returns:	zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_install_library_link() {
938c5c
	local	_erill_lib_name="${1}" _erill_so_dir="${2}" _erill_so_path="${3}"	\
938c5c
		_erill_lib_link_path="${3%.so*}.lib.a" _erill_fname="" _erill_lib_link_tgt="";
938c5c
938c5c
	if _erill_lib_link_tgt="$(find "${_erill_so_dir}"	\
938c5c
			-name "${_erill_lib_name%%.*}.*.lib.a"	|\
938c5c
			sort | tail -1)"\
938c5c
	&& [ "${_erill_lib_link_tgt:+1}" = 1 ]\
938c5c
	&& [ "${_erill_lib_link_tgt}" != "${_erill_lib_link_path}" ];
938c5c
	then
938c5c
		rtl_basename2 \$_erill_lib_link_tgt \$_erill_fname;
938c5c
938c5c
		if ! rtl_fileop rm "${_erill_lib_link_path}"\
938c5c
		|| ! rtl_fileop ln_symbolic "${_erill_fname}" "${_erill_lib_link_path}"; then
938c5c
			return 1;
938c5c
		fi;
938c5c
	fi;
938c5c
	return 0;
938c5c
};
938c5c
938c5c
# vim:filetype=sh textwidth=0