Blame subr.ex/ex_rtl.subr

938c5c
#
938c5c
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
938c5c
# set +o errexit -o noglob -o nounset is assumed.
938c5c
#
938c5c
#
938c5c
938c5c
#
938c5c
# ex_rtl_build_rpm() - build RPM package
938c5c
# @_destdir:		package destination directory
938c5c
# @_name:		package name
938c5c
# @_rpms_dname:		RPMs directory pathname
938c5c
# @_spec_fname:		RPM .spec file pathname
938c5c
# @_spec_fname_tgt:	target package RPM .spec file pathname
938c5c
# @_tmp_dname:		temporary files directory pathname
938c5c
# @_topdir:		package top directory
938c5c
# @_url:		package URL
938c5c
# @_version:		package version
938c5c
# @_version_rpm:	package RPM version
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_build_rpm() {
938c5c
	local	_erbr_destdir="${1}" _erbr_name="${2}" _erbr_rpms_dname="${3}" _erbr_spec_fname="${4}"		\
938c5c
		_erbr_spec_fname_tgt="${5}" _erbr_tmp_dname="${6}" _erbr_topdir="${7}" _erbr_url="${8}"		\
938c5c
		_erbr_version="${9}" _erbr_version_rpm="${10}"							\
938c5c
		_erbr_rc=0;
938c5c
938c5c
	if ! rtl_fileop cp "${_erbr_spec_fname}" "${_erbr_spec_fname_tgt}"; then
938c5c
		return 1;
938c5c
	else
938c5c
		while true; do
938c5c
			rpmbuild						\
938c5c
				-bb						\
938c5c
										\
938c5c
				--define "_binary_payload w2T16.xzdio"		\
938c5c
										\
938c5c
				--define="_tmppath ${_erbr_tmp_dname=}"		\
938c5c
				--define="_topdir ${_erbr_topdir}"		\
938c5c
				--define="pkg_destdir ${_erbr_destdir}"		\
938c5c
				--define="pkg_name ${_erbr_name}"		\
938c5c
				--define="pkg_url ${_erbr_url}"			\
938c5c
				--define="pkg_version_full ${_erbr_version}"	\
938c5c
				--define="pkg_version_rpm ${_erbr_version_rpm}"	\
938c5c
				--nodeps "${_erbr_spec_fname_tgt}";
938c5c
			_erbr_rc="${?}";
938c5c
938c5c
			if [ "${_erbr_rc}" -eq 0 ]; then
938c5c
				break;
938c5c
			elif [ "${_erbr_rc}" -eq 141 ]; then
938c5c
				continue;
938c5c
			else
938c5c
				return "${_erbr_rc}";
938c5c
			fi;
938c5c
		done;
938c5c
938c5c
		if ! find "${_erbr_rpms_dname}/${_erbr_name}-${_erbr_version_rpm}/RPMS"		\
938c5c
			-iname \*.rpm -exec cp -pP {} "${_erbr_rpms_dname}/" \;			\
938c5c
		|| ! rtl_fileop rm "${_erbr_rpms_dname}/${_erbr_name}-${_erbr_version_rpm}"	\
938c5c
		|| ! rtl_fileop cp "${_erbr_spec_fname_tgt}" "${_erbr_rpms_dname}/";
938c5c
		then
938c5c
			return 1;
938c5c
		fi;
938c5c
	fi;
938c5c
938c5c
	return 0;
938c5c
};
938c5c
938c5c
#
938c5c
# ex_rtl_expand_rpm_version() - expand RPM version strings
938c5c
# @_rurl:		out reference to package URL
938c5c
# @_rversion:		out reference to package version
938c5c
# @_rversion_rpm:	out reference to RPM version string
938c5c
# @_subdir:		package subdirectory
938c5c
# @_url:		package URL
938c5c
# @_url_censor:		package URL filter
938c5c
# @_urls_git:		package Git URL(s)
938c5c
# @_version:		package version
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_expand_rpm_version() {
938c5c
	local	_ererv_rurl="${1#\$}" _ererv_rversion="${2#\$}" _ererv_rversion_rpm="${3#\$}"	\
938c5c
		_ererv_subdir="${4}" _ererv_url="${5}" _ererv_url_censor="${6}"			\
938c5c
		_ererv_urls_git="${7}" _ererv_version="${8}"					\
938c5c
		_ererv_version_full="" _ererv_version_rpm=""
938c5c
938c5c
	if [ "${_ererv_url:+1}" = 1 ]; then
938c5c
		_ererv_url="${_ererv_url%% *}";
938c5c
		_ererv_version_full="${_ererv_version}";
938c5c
		_ererv_version_rpm="${_ererv_version%%-*}";
938c5c
938c5c
	elif [ "${_ererv_urls_git:+1}" = 1 ]; then
938c5c
		_ererv_url="${_ererv_urls_git%% *}";
938c5c
		_ererv_url="${_ererv_url##*=}";
938c5c
		_ererv_url="${_ererv_url%%@*}";
938c5c
938c5c
		_ererv_version_rpm="$(cd "${_ererv_subdir}" && git rev-parse HEAD)" || return 1;
938c5c
		_ererv_version_full="${_ererv_version_rpm} ($(cd "${_ererv_subdir}" && git rev-parse --abbrev-ref HEAD))" || return 1;
938c5c
	fi;
938c5c
938c5c
	if [ "${_ererv_url#${_ererv_url_censor}}" != "${_ererv_url}" ]; then
938c5c
		_ererv_url="Unknown";
938c5c
	fi;
938c5c
938c5c
	eval ${_ererv_rurl}='${_ererv_url}';
938c5c
	eval ${_ererv_rversion}='${_ererv_version_full}';
938c5c
	eval ${_ererv_rversion_rpm}='${_ererv_version_rpm}';
938c5c
938c5c
	return 0;
938c5c
};
938c5c
938c5c
#
938c5c
# ex_rtl_fixup_pkgconfig_paths() - fixup pathname prefixes in pkg-config(1) files
938c5c
# @_dname_base:		base directory pathname
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_fixup_pkgconfig_paths() {
938c5c
	local	_erfpp_dname_base="${1}"	\
938c5c
		_erfpp_pc_path="";
938c5c
938c5c
	for _erfpp_pc_path in $(find "${_erfpp_dname_base=}" -name \*.pc); do
938c5c
		if [ -n "$(sed -ne '/^libdir=[^$]*$/p' "${_erfpp_pc_path}")" ]			\
938c5c
		&& ! sed -i""	-e '/^libdir=[^$]*$/s/^libdir=\(.*\)$/libdir=${exec_prefix}\1/'	\
938c5c
				-e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/'		\
938c5c
				"${_erfpp_pc_path}";
938c5c
		then
938c5c
			return 1;
938c5c
		fi;
938c5c
938c5c
		if [ -n "$(sed -ne '/^includedir=[^$]*$/p' "${_erfpp_pc_path}")" ]			\
938c5c
		&& ! sed -i""	-e '/^includedir=[^$]*$/s/^includedir=\(.*\)$/includedir=${prefix}\1/'	\
938c5c
				"${_erfpp_pc_path}";
938c5c
		then
938c5c
			return 1;
938c5c
		fi;
938c5c
	done;
938c5c
938c5c
	return 0;
938c5c
};
938c5c
938c5c
#
938c5c
# ex_rtl_purge_la_files() - purge .la files in tree
938c5c
# @_dname_base:		base directory pathname
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_purge_la_files() {
938c5c
	local	_erplf_dname_base="${1}"	\
938c5c
		_erplf_la_path="";
938c5c
938c5c
	for _erplf_la_path in $(find		\
938c5c
			"${_erplf_dname_base}"	\
938c5c
			-type f			\
938c5c
			-name \*.la);
938c5c
	do
938c5c
		if ! rtl_fileop rm "${_erplf_la_path}"; then
938c5c
			return 1;
938c5c
		fi;
938c5c
	done;
938c5c
	return 0;
938c5c
};
938c5c
938c5c
#
938c5c
# ex_rtl_strip_files() - strip files of debugging information
938c5c
# @_strip_cmd:		strip(1) command name
938c5c
# @_tree_root:		pathname to tree root
938c5c
# @--:			(ignored)
938c5c
# @_log_fn:		logging function name; called with @... and pathname of each file stripped
938c5c
# @...:			@_fn initial arguments list as positional parameters
938c5c
#
938c5c
# Returns:		zero (0) on success, non-zero (>0) on failure
938c5c
#
938c5c
ex_rtl_strip_files() {
938c5c
	local	_ersf_strip_cmd="${1}" _ersf_tree_root="${2}"	\
938c5c
		_ersf_ignored="${3}" _ersf_log_fn="${4}"	\
938c5c
		_ersf_bin_path="";
938c5c
	shift 4;
938c5c
938c5c
	if [ -e "${_ersf_tree_root}" ]; then
938c5c
		for _ersf_bin_path in $(find		\
938c5c
				"${_ersf_tree_root}"	\
938c5c
				-perm /a=x		\
938c5c
				-type f);
938c5c
		do
938c5c
			if objdump				\
938c5c
					-sj .debug_frame	\
938c5c
					-j .debug_info		\
938c5c
					"${_ersf_bin_path}"	\
938c5c
					>/dev/null 2>&1;
938c5c
			then
938c5c
				if ! "${_ersf_strip_cmd}" "${_ersf_bin_path}"; then
938c5c
					return 1;
938c5c
				else
938c5c
					"${_ersf_log_fn}" "${@}" "${_ersf_bin_path}";
938c5c
				fi;
938c5c
			fi;
938c5c
		done;
938c5c
	fi;
938c5c
938c5c
	return 0;
938c5c
};
938c5c
938c5c
# vim:filetype=sh textwidth=0