Blob Blame History Raw
#
# 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_files() {
	if [ "${PKG_INSTALL_FILES:+1}" = 1 ]; then
		if ! rtl_install -v "${PKG_DESTDIR}" ${PKG_INSTALL_FILES}; then
			return 1;
		fi;
	fi;
	return 0;
};

pkgp_install_files_v2() {
	local _ppifv2_status="" _ppifv2_vflag="";

	if [ "${PKG_INSTALL_FILES_V2:+1}" = 1 ]; then
		if rtl_lmatch \$ARG_VERBOSE_TAGS "install" ","; then
			_ppifv2_vflag="-v";
		fi;
		if ! rtl_install_v2							\
				\$_ppifv2_status					\
				-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}"				\
				${_ppifv2_vflag} -- "${PKG_DESTDIR}"			\
				"${PKG_INSTALL_FILES_V2}";
		then
			return 1;
		fi;
	fi;
};

pkgp_install_files_perms() {
	local _ppifp_destdir="" _ppifp_fname="" IFS;

	for _ppifp_destdir in "${PKG_DESTDIR}" "${PKG_DESTDIR_HOST}"; do
		if [ -e "${_ppifp_destdir}" ]; then
			rtl_set_IFS_nl;

			for _ppifp_fname in $(find "${_ppifp_destdir}" -type d); do
				if ! rtl_fileop chmod 0755 "${_ppifp_fname}"; then
					return 1;
				fi;
			done;

			for _ppifp_fname in $(find "${_ppifp_destdir}" \( -not -perm /0111 \) -type f); do
				if ! rtl_fileop chmod 0644 "${_ppifp_fname}"; then
					return 1;
				fi;
			done;

			for _ppifp_fname in $(find "${_ppifp_destdir}" -perm /0111 -type f); do
				if ! rtl_fileop chmod 0755 "${_ppifp_fname}"; then
					return 1;
				fi;
			done;
		fi;
	done;
	return 0;
};

pkgp_install_files_pkgconfig() {
	local _ppifp2_pc_path="";

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

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

pkgp_install_files_strip() {
	local _ppifs_bin_path="" _ppifs_stripfl=0 _ppifs_tree_root="${PKG_DESTDIR}";

	if [ -e "${_ppifs_tree_root}" ]; then
		if rtl_match "${PKG_NAME}" "*_ppifs_minipix"; then
			: $((_ppifs_stripfl=(${ARG_DEBUG_MINIPIX:-0} ? 0 : 1)));
		elif [ "${BUILD_KIND}" = release ]\
		&&   [ "${PKG_BUILD_TYPE}" = native ];
		then
			_ppifs_stripfl=1;
		else
			_ppifs_stripfl=0;
		fi;

		if [ "${_ppifs_stripfl:-0}" -eq 1 ]; then
			for _ppifs_bin_path in $(find "${_ppifs_tree_root}" -perm /a=x -type f); do
				if objdump -sj .debug_frame -j .debug_info "${_ppifs_bin_path}" >/dev/null 2>&1; then
					rtl_log_msg "pkg_strip" "${MSG_pkg_strip}" "${_ppifs_bin_path}";
					if ! "${PKG_TARGET}-strip" "${_ppifs_bin_path}"; then
						return 1;
					fi;
				fi;
			done;
		fi;
	fi;
	return 0;
};

pkg_install_files() {
	local _pif_group_name="${1}" _pif_pkg_name="${2}" _pif_restart_at="${3}";

	if ! pkgp_install_files\
	|| ! pkgp_install_files_v2\
	|| ! pkgp_install_files_perms\
	|| ! pkgp_install_files_pkgconfig\
	|| ! pkgp_install_files_strip;
	then
		return 1;
	fi;
	return 0;
};

# vim:filetype=sh textwidth=0