summaryrefslogtreecommitdiffhomepage
path: root/subr.pkg/pkg_install_libs.subr
blob: d19c9565a4d70c1c597b76045166bbd4a20b7d32 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de>
# set +o errexit -o noglob -o nounset is assumed.
#

pkgp_install_libs_purge_la() {
	local _ppilpl_la_path="";

	for _ppilpl_la_path in $(find "${PKG_DESTDIR}" -type f -name \*.la); do
		if ! rtl_fileop rm "${_ppilpl_la_path}"; then
			return 1;
		fi;
	done;
	return 0;
};

pkgp_install_libs_shared_link() {
	local	_ppilsl_lib_name="${1}" _ppilsl_so_dir="${2}" _ppilsl_so_path="${3}"	\
		_ppilsl_lib_link_path="${3%.so*}.lib.a" _ppilsl_fname="" _ppilsl_lib_link_tgt="";

	if _ppilsl_lib_link_tgt="$(find "${_ppilsl_so_dir}" -name "${_ppilsl_lib_name%%.*}.*.lib.a" | sort | tail -1)"\
	&& [ "${_ppilsl_lib_link_tgt:+1}" = 1 ]\
	&& [ "${_ppilsl_lib_link_tgt}" != "${_ppilsl_lib_link_path}" ];
	then
		rtl_basename2 \$_ppilsl_lib_link_tgt \$_ppilsl_fname;

		if ! rtl_fileop rm "${_ppilsl_lib_link_path}"\
		|| ! rtl_fileop ln_symbolic "${_ppilsl_fname}" "${_ppilsl_lib_link_path}"; then
			return 1;
		fi;
	fi;
	return 0;
};

pkgp_install_libs_shared() {
	local	_ppils_postfix="" _ppils_lib_dst_path="" _ppils_lib_name=""	\
		_ppils_lib_src_path="" _ppils_so_dst_dir="" _ppils_so_src_path="";

	if [ "${PKG_BUILD_TYPE}" != "host" ]; then
		for _ppils_so_src_path in 		\
			$(find	"${PKG_DESTDIR}"	\
				\(  -name "*.so" -or -name "*.so.*" \) -print);
		do
			if [ "$(readlink -f "${_ppils_so_src_path}")" != "/dev/null" ]\
			&& rtl_remove_postfix "[0-9.]" "${_ppils_so_src_path##*.so}" \$_ppils_postfix\
			&& [ "${_ppils_postfix:+1}" != 1 ]; then
				case "${_ppils_so_src_path}" in
				*.so)	_ppils_lib_src_path="${_ppils_so_src_path%%.so}.lib.a"; ;;
				*.so.*)	_ppils_lib_src_path="${_ppils_so_src_path%%.so.*}.${_ppils_so_src_path##*.so.}.lib.a"; ;;
				esac;

				_ppils_so_dst_dir="${_ppils_so_src_path%/*}";
				rtl_basename2 \$_ppils_lib_src_path \$_ppils_lib_name;
				_ppils_lib_dst_path="${_ppils_so_dst_dir}/${_ppils_lib_name}";

				if [ ! -L "${_ppils_lib_src_path}" ]\
				&& [ ! -e "${_ppils_lib_dst_path}" ]; then
					if ! (rtl_basename2 \$_ppils_so_src_path \$_ppils_fname;	\
					      rtl_basename2 \$_ppils_lib_dst_path \$_ppils_fname_dst;	\
					      rtl_dirname2 \$_ppils_so_src_path \$_ppils_dname;		\
					      rtl_fileop cd "${_ppils_dname}" &&			\
							perk -e "${_ppils_fname}"			|\
								"${PKG_TARGET}-mdso"			\
									-i "${_ppils_fname_dst}"	\
									-n "${_ppils_fname}" -);
					then
						return 1;
					fi;
				fi;

				if ! pkgp_install_libs_shared_link				\
						"${_ppils_lib_name}" "${_ppils_so_dst_dir}"	\
						"${_ppils_so_src_path}";
				then
					return 1;
				fi;
			fi;
		done;
	fi;

	return 0;
};

pkg_install_libs() {
	local _pil_group_name="${1}" _pil_pkg_name="${2}" _pil_restart_at="${3}";

	if ! pkgp_install_libs_purge_la\
	|| ! pkgp_install_libs_shared;
	then
		return 1;
	fi;
	return 0;
};

# vim:filetype=sh textwidth=0