summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_install_libs.subr
blob: 1894a2d08e08427fdfb641b8d9490ce0259cbe75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# set -o errexit -o noglob are assumed.
#

pkgp_install_lib_check() {
	local _so_path="${1}" _so_ver="${1##*.so}";
	while [ -n "${_so_ver}" ]; do
		if [ "${_so_ver#[0-9.]}" = "${_so_ver}" ]; then
			return 0;
		else
			_so_ver="${_so_ver#[0-9.]}";
		fi;
	done; return 1;
};

pkgp_install_lib_link() {
	local _so_path="${1}" _so_dir="${2}" _lib_name="${3}"				\
		_lib_link_tgt _lib_link_path;
	_lib_link_tgt="$(find "${_so_dir}"						\
			-name "${_lib_name%%.*}.*.lib.a"				|\
			sort | tail -1)";
	if [ -n "${_lib_link_tgt}" ]; then
		_lib_link_path="${_so_path%.so*}.lib.a";
		ex_build_fileop rm "${_lib_link_path}";
		ex_build_fileop ln_symbolic "$(ex_basename "${_lib_link_tgt}")"		\
			"${_lib_link_path}";
	fi;
};

pkg_install_libs() {
	local _so_src_path _so_dst_dir _lib_src_path _lib_name _lib_dst_path;
	if [ "${PKG_BUILD_TYPE}" != "host" ]; then
		for _so_src_path in							\
			$(find	"${PKG_DESTDIR}"					\
				\(  -name "*.so" -or -name "*.so.*" \) -print);
		do	if ! pkgp_install_lib_check "${_so_src_path}"			\
			|| [ "$(readlink -f "${_so_src_path}")" = "/dev/null" ]; then
				continue;
			else	case "${_so_src_path}" in
				*.so)	_lib_src_path="${_so_src_path%%.so}.lib.a"; ;;
				*.so.*)	_lib_src_path="${_so_src_path%%.so.*}.${_so_src_path##*.so.}.lib.a"; ;;
				esac;
				_lib_name="$(ex_basename "${_lib_src_path}")";
				_so_dst_dir="${_so_src_path%/*}";
			fi;
			if [ ! -L "${_lib_src_path}" ]; then
				_lib_dst_path="${_so_dst_dir}/${_lib_name}";
				perk -e "${_so_src_path}"				|\
					"${PKG_TARGET}-mdso"				\
						-i "${_lib_dst_path}"			\
						-n "${_so_src_path}" -;
			fi;
			pkgp_install_lib_link "${_so_src_path}" "${_so_dst_dir}" "${_lib_name}";
		done;
	fi;
};

# vim:filetype=sh