summaryrefslogtreecommitdiffhomepage
path: root/subr.ex/ex_rtl_midipix.subr
blob: 6c3210355aeb33049f1da66658a6fd7e5cf65479 (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
#
# 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.
#
#

#
# ex_rtl_install_library_archives() - install library archives and library links (.lib.a) for all libraries (.so) in tree
# @_dname_base:		base directory pathname
# @_mdso_cmd:		mdso command name
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
ex_rtl_install_library_archives() {
	local	_erila_dname_base="${1}" _erila_mdso_cmd="${2}"			\
		_erila_postfix="" _erila_lib_dst_path="" _erila_lib_name=""	\
		_erila_lib_src_path="" _erila_so_dst_dir="" _erila_so_src_path="";

	for _erila_so_src_path in 				\
		$(find	"${_erila_dname_base=}"			\
			\(  -name "*.so" -or -name "*.so.*" \)	\
			-print);
	do
		if [ "$(readlink -f "${_erila_so_src_path}")" != "/dev/null" ]\
		&& rtl_remove_postfix "[0-9.]" "${_erila_so_src_path##*.so}" \$_erila_postfix\
		&& [ "${_erila_postfix:+1}" != 1 ]; then

			case "${_erila_so_src_path}" in
			*.so)	_erila_lib_src_path="${_erila_so_src_path%%.so}.lib.a"; ;;
			*.so.*)	_erila_lib_src_path="${_erila_so_src_path%%.so.*}.${_erila_so_src_path##*.so.}.lib.a"; ;;
			esac;

			_erila_so_dst_dir="${_erila_so_src_path%/*}";
			rtl_basename2 \$_erila_lib_src_path \$_erila_lib_name;
			_erila_lib_dst_path="${_erila_so_dst_dir}/${_erila_lib_name}";

			if [ ! -L "${_erila_lib_src_path}" ]\
			&& [ ! -e "${_erila_lib_dst_path}" ]; then
				if ! (rtl_basename2 \$_erila_so_src_path \$_erila_fname;		\
				      rtl_basename2 \$_erila_lib_dst_path \$_erila_fname_dst;	\
				      rtl_dirname2 \$_erila_so_src_path \$_erila_dname;		\
				      rtl_fileop cd "${_erila_dname}" &&			\
						perk -e "${_erila_fname}"			|\
							"${_erila_mdso_cmd}"			\
								-i "${_erila_fname_dst}"		\
								-n "${_erila_fname}" -);
				then
					return 1;
				fi;
			fi;

			if ! ex_rtl_install_library_link				\
					"${_erila_lib_name}" "${_erila_so_dst_dir}"	\
					"${_erila_so_src_path}";
			then
				return 1;
			fi;
		fi;
	done;

	return 0;
};

#
# ex_rtl_install_library_link() - install library archive (.lib.a) link for library (.so)
# @_lib_name:	library name
# @_so_dir:	library directory pathname
# @_so_path:	library file pathname
#
# Returns:	zero (0) on success, non-zero (>0) on failure
#
ex_rtl_install_library_link() {
	local	_erill_lib_name="${1}" _erill_so_dir="${2}" _erill_so_path="${3}"	\
		_erill_lib_link_path="${3%.so*}.lib.a" _erill_fname="" _erill_lib_link_tgt="";

	if _erill_lib_link_tgt="$(find "${_erill_so_dir}"	\
			-name "${_erill_lib_name%%.*}.*.lib.a"	|\
			sort | tail -1)"\
	&& [ "${_erill_lib_link_tgt:+1}" = 1 ]\
	&& [ "${_erill_lib_link_tgt}" != "${_erill_lib_link_path}" ];
	then
		rtl_basename2 \$_erill_lib_link_tgt \$_erill_fname;

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

# vim:filetype=sh textwidth=0