summaryrefslogtreecommitdiffhomepage
path: root/subr.ex/ex_rtl.subr
blob: a6177fa70aa1efe9fcecb2049f3a652902ff0554 (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
96
97
98
99
#
# 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_fixup_pkgconfig_paths() - fixup pathname prefixes in pkg-config(1) files
# @_dname_base:		base directory pathname
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
ex_rtl_fixup_pkgconfig_paths() {
	local	_erfpp_dname_base="${1}"	\
		_erfpp_pc_path="";

	for _erfpp_pc_path in $(find "${_erfpp_dname_base=}" -name \*.pc); do
		if [ -n "$(sed -ne '/^libdir=[^$]*$/p' "${_erfpp_pc_path}")" ]			\
		&& ! sed -i""	-e '/^libdir=[^$]*$/s/^libdir=\(.*\)$/libdir=${exec_prefix}\1/'	\
				-e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/'		\
				"${_erfpp_pc_path}";
		then
			return 1;
		fi;

		if [ -n "$(sed -ne '/^includedir=[^$]*$/p' "${_erfpp_pc_path}")" ]			\
		&& ! sed -i""	-e '/^includedir=[^$]*$/s/^includedir=\(.*\)$/includedir=${prefix}\1/'	\
				"${_erfpp_pc_path}";
		then
			return 1;
		fi;
	done;

	return 0;
};

#
# ex_rtl_purge_la_files() - purge .la files in tree
# @_dname_base:		base directory pathname
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
ex_rtl_purge_la_files() {
	local	_erplf_dname_base="${1}"	\
		_erplf_la_path="";

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

#
# ex_rtl_strip_files() - strip files of debugging information
# @_strip_cmd:		strip(1) command name
# @_tree_root:		pathname to tree root
# @--:			(ignored)
# @_log_fn:		logging function name; called with @... and pathname of each file stripped
# @...:			@_fn initial arguments list as positional parameters
#
# Returns:		zero (0) on success, non-zero (>0) on failure
#
ex_rtl_strip_files() {
	local	_ersf_strip_cmd="${1}" _ersf_tree_root="${2}"	\
		_ersf_ignored="${3}" _ersf_log_fn="${4}"	\
		_ersf_bin_path="";
	shift 4;

	if [ -e "${_ersf_tree_root}" ]; then
		for _ersf_bin_path in $(find		\
				"${_ersf_tree_root}"	\
				-perm /a=x		\
				-type f);
		do
			if objdump				\
					-sj .debug_frame	\
					-j .debug_info		\
					"${_ersf_bin_path}"	\
					>/dev/null 2>&1;
			then
				if ! "${_ersf_strip_cmd}" "${_ersf_bin_path}"; then
					return 1;
				else
					"${_ersf_log_fn}" "${@}" "${_ersf_bin_path}";
				fi;
			fi;
		done;
	fi;

	return 0;
};

# vim:filetype=sh textwidth=0