summaryrefslogtreecommitdiffhomepage
path: root/subr/pkg_install_files.subr
blob: 8dc717530194a87f18ece869b980df6ef061681f (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# set +o errexit -o noglob -o nounset is assumed.
#

pkgp_install_files() {
	if [ -n "${PKG_INSTALL_FILES:-}" ]; then
		if ! rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES}; then
			return 1;
		fi;
	fi;
};

pkgp_install_files_v2() {
	local _vflag=""; _status="";

	if [ -n "${PKG_INSTALL_FILES_V2:-}" ]; then
		[ "${ARG_VERBOSE:-0}" -ge 3 ] && _vflag="-v";
		if ! rtl_install_v2							\
				-p "_builddir=${PKG_BUILD_DIR}"				\
				-p "_destdir=${PKG_BASE_DIR}/${PKG_DESTDIR}"		\
				-p "_destdir_host=${PKG_BASE_DIR}/${PKG_DESTDIR_HOST}"	\
				-p "_files=${MIDIPIX_BUILD_PWD}/files/${PKG_NAME}"	\
				-p "_name=${PKG_NAME}"					\
				-p "_prefix=${PKG_PREFIX}"				\
				-p "_prefix_host=${PREFIX}"				\
				-p "_prefix_native=${PREFIX_NATIVE}"			\
				-p "_subdir=${PKG_BASE_DIR}/${PKG_SUBDIR}"		\
				-p "_target=${PKG_TARGET}"				\
				-p "_version=${PKG_VERSION:-}"				\
				-p "_workdir=${BUILD_WORKDIR}"				\
				${_vflag} -- "${PKG_DESTDIR}"				\
				"${PKG_INSTALL_FILES_V2}"; then
			return 1;
		fi;
	fi;
};

pkgp_install_files_perms() {
	local _destdir="" _fname="" IFS;
	for _destdir in "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; do
		if [ -e "${_destdir}" ]; then
			rtl_set_IFS_nl;
			for _fname in $(find "${_destdir}" -type d); do
				if ! rtl_fileop chmod 0755 "${_fname}"; then
					return 1;
				fi;
			done;
			for _fname in $(find "${_destdir}" \( -not -perm /0111 \) -type f); do
				if ! rtl_fileop chmod 0644 "${_fname}"; then
					return 1;
				fi;
			done;
			for _fname in $(find "${_destdir}" -perm /0111 -type f); do
				if ! rtl_fileop chmod 0755 "${_fname}"; then
					return 1;
				fi;
			done;
		fi;
	done;
};

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

pkgp_install_files_strip() {
	local _bin_path="" _stripfl=0 _tree_root="${PKG_DESTDIR}";
	if [ -e "${_tree_root}" ]; then
		if rtl_match "${PKG_NAME}" "*_minipix"; then
			: $((_stripfl=(${ARG_DEBUG_MINIPIX:-0} ? 0 : 1)));
		elif [ "${BUILD_KIND}" = release ]\
		&&   [ "${PKG_BUILD_TYPE}" = native ]; then
			_stripfl=1;
		else
			_stripfl=0;
		fi;
		if [ "${_stripfl:-0}" -eq 1 ]; then
			for _bin_path in $(find "${_tree_root}" -perm /a=x -type f); do
				if objdump -sj .debug_frame -j .debug_info "${_bin_path}" >/dev/null 2>&1; then
					rtl_log_msg info "Stripping %s..." "${_bin_path}";
					if ! "${PKG_TARGET}-strip" "${_bin_path}"; then
						return 1;
					fi;
				fi;
			done;
		fi;
	fi;
};

pkg_install_files() {
	if ! pkgp_install_files\
	|| ! pkgp_install_files_v2\
	|| ! pkgp_install_files_perms\
	|| ! pkgp_install_files_pkgconfig\
	|| ! pkgp_install_files_strip; then
		return 1;
	fi;
};

# vim:filetype=sh