|
|
ea2531 |
#
|
|
|
ea2531 |
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂa Andrea Illanes Albornoz <lucia@luciaillanes.de>
|
|
|
ea2531 |
# set +o errexit -o noglob -o nounset is assumed.
|
|
|
ea2531 |
#
|
|
|
ea2531 |
#
|
|
|
ea2531 |
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# ex_rtl_build_rpm() - build RPM package
|
|
|
ea2531 |
# @_destdir: package destination directory
|
|
|
ea2531 |
# @_jobs_max: maximum count of simultaneously executing rpmbuild(1) processes
|
|
|
ea2531 |
# @_jobs_semaphore: pathname to current count of simultaneously executing rpmbuild(1) processes semaphore file
|
|
|
ea2531 |
# @_jobs_wait: wait period in seconds when @_jobs_semaphore is locked
|
|
|
ea2531 |
# @_name: package name
|
|
|
ea2531 |
# @_rpms_dname: RPMs directory pathname
|
|
|
ea2531 |
# @_spec_fname: RPM .spec file pathname
|
|
|
ea2531 |
# @_spec_fname_tgt: target package RPM .spec file pathname
|
|
|
ea2531 |
# @_tmp_dname: temporary files directory pathname
|
|
|
ea2531 |
# @_topdir: package top directory
|
|
|
ea2531 |
# @_url: package URL
|
|
|
ea2531 |
# @_version: package version
|
|
|
ea2531 |
# @_version_rpm: package RPM version
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
f96b7a |
# N.B.: The following variables are substituted prior to running rpmbuild(1):
|
|
|
f96b7a |
# %{pkg_destdir}
|
|
|
f96b7a |
# %{pkg_name}
|
|
|
f96b7a |
# %{pkg_url}
|
|
|
f96b7a |
# %{pkg_version_full}
|
|
|
f96b7a |
# %{pkg_version_rpm}
|
|
|
ea2531 |
#
|
|
|
b8fb5c |
# The \n-separated list of package files is inserted after the `%files' line.
|
|
|
b8fb5c |
#
|
|
|
ea2531 |
ex_rtl_build_rpm() {
|
|
|
ea2531 |
local _erbr_destdir="${1}" _erbr_jobs_max="${2}" _erbr_jobs_semaphore="${3}" _erbr_jobs_wait="${4}" \
|
|
|
ea2531 |
_erbr_name="${5}" _erbr_rpms_dname="${6}" _erbr_spec_fname="${7}" _erbr_spec_fname_tgt="${8}" \
|
|
|
ea2531 |
_erbr_tmp_dname="${9}" _erbr_topdir="${10}" _erbr_url="${11}" _erbr_version="${12}" \
|
|
|
ea2531 |
_erbr_version_rpm="${13}" \
|
|
|
b8fb5c |
_erbr_spec_fname_tgt_tmp="" _erbr_job_count=0 _erbr_rc=0 _erbr_rc_jobs=0;
|
|
|
ea2531 |
|
|
|
ea2531 |
(
|
|
|
ea2531 |
while true; do
|
|
|
ea2531 |
(set +o errexit -o noglob -o nounset;
|
|
|
ea2531 |
rtl_flock_acquire 4 || exit $((${?} + 1));
|
|
|
ea2531 |
|
|
|
ea2531 |
read _erbr_job_count <&4;
|
|
|
ea2531 |
if [ "${_erbr_job_count:+1}" != 1 ]; then
|
|
|
ea2531 |
_erbr_job_count=0;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ "${_erbr_job_count}" -ge "${_erbr_jobs_max}" ]; then
|
|
|
ea2531 |
exit 1;
|
|
|
ea2531 |
else
|
|
|
ea2531 |
: $((_erbr_job_count += 1));
|
|
|
ea2531 |
printf "%s" "${_erbr_job_count}" >"${_erbr_jobs_semaphore}" || exit $((${?} + 1));
|
|
|
ea2531 |
exit 0;
|
|
|
ea2531 |
fi) 4<>"${_erbr_jobs_semaphore}";
|
|
|
ea2531 |
_erbr_rc_jobs="${?}";
|
|
|
ea2531 |
|
|
|
ea2531 |
case "${_erbr_rc_jobs}" in
|
|
|
ea2531 |
0) break; ;;
|
|
|
ea2531 |
1) sleep "${_erbr_jobs_wait}" || return "${?}"; ;;
|
|
|
ea2531 |
*) return $((${_erbr_rc_jobs} - 1));
|
|
|
ea2531 |
esac;
|
|
|
ea2531 |
done;
|
|
|
ea2531 |
|
|
|
ea2531 |
trap '
|
|
|
ea2531 |
(set +o errexit -o noglob -o nounset;
|
|
|
ea2531 |
rtl_flock_acquire 4 || exit 1;
|
|
|
ea2531 |
|
|
|
ea2531 |
read _erbr_job_count <&4;
|
|
|
ea2531 |
if [ "${_erbr_job_count:+1}" != 1 ]\
|
|
|
ea2531 |
|| [ "${_erbr_job_count}" -lt 1 ]; then
|
|
|
ea2531 |
_erbr_job_count=1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
: $((_erbr_job_count -= 1));
|
|
|
ea2531 |
printf "%s" "${_erbr_job_count}" >"${_erbr_jobs_semaphore}" || exit 1;
|
|
|
ea2531 |
exit 0) 4<>"${_erbr_jobs_semaphore}"' \
|
|
|
ea2531 |
EXIT HUP INT TERM USR1 USR2;
|
|
|
ea2531 |
|
|
|
b8fb5c |
(
|
|
|
b8fb5c |
_erbr_spec_fname_tgt_tmp="${_erbr_spec_fname_tgt}.tmp";
|
|
|
b8fb5c |
trap "rm -f \"${_erbr_spec_fname_tgt_tmp}\"" EXIT HUP INT TERM USR1 USR2;
|
|
|
b8fb5c |
|
|
|
f96b7a |
#
|
|
|
f96b7a |
# N.B. Keep list in sync w/ list in function documentation comment block at top.
|
|
|
f96b7a |
#
|
|
|
b8fb5c |
if rtl_fileop cp "${_erbr_spec_fname}" "${_erbr_spec_fname_tgt_tmp}" \
|
|
|
b8fb5c |
&& sed -i"" \
|
|
|
b8fb5c |
-ne '/^#REMOVEDBYSED#/!p' \
|
|
|
b8fb5c |
"${_erbr_spec_fname_tgt_tmp}" \
|
|
|
b8fb5c |
&& sed -i"" \
|
|
|
f96b7a |
-e 's#%{pkg_destdir}#'"${_erbr_destdir}"'#g' \
|
|
|
f96b7a |
-e 's#%{pkg_name}#'"${_erbr_name}"'#g' \
|
|
|
f96b7a |
-e 's#%{pkg_url}#'"${_erbr_url}"'#g' \
|
|
|
f96b7a |
-e 's#%{pkg_version_full}#'"${_erbr_version}"'#g' \
|
|
|
f96b7a |
-e 's#%{pkg_version_rpm}#'"${_erbr_version_rpm}"'#g' \
|
|
|
b8fb5c |
"${_erbr_spec_fname_tgt_tmp}" \
|
|
|
b8fb5c |
&& sed -n -e '1,/^%files$/p' \
|
|
|
b8fb5c |
"${_erbr_spec_fname_tgt_tmp}" \
|
|
|
b8fb5c |
> "${_erbr_spec_fname_tgt}" \
|
|
|
b8fb5c |
&& (cd "${_erbr_destdir}"; \
|
|
|
b8fb5c |
find -mindepth 1 \( -type f -or -type l \) | \
|
|
|
caf571 |
sed -e 's,^./,'"/"',' \
|
|
|
caf571 |
-e 's/^/"/' \
|
|
|
caf571 |
-e 's/$/"/') \
|
|
|
b8fb5c |
>> "${_erbr_spec_fname_tgt}" \
|
|
|
b8fb5c |
&& sed -n -e '/^%files$/,${/^%files$/d;p}' \
|
|
|
b8fb5c |
"${_erbr_spec_fname_tgt_tmp}" \
|
|
|
b8fb5c |
>> "${_erbr_spec_fname_tgt}" \
|
|
|
b8fb5c |
; \
|
|
|
f96b7a |
then
|
|
|
b8fb5c |
_erbr_rc=0;
|
|
|
ea2531 |
else
|
|
|
b8fb5c |
_erbr_rc=1;
|
|
|
b8fb5c |
fi;
|
|
|
b8fb5c |
exit "${_erbr_rc}";
|
|
|
b8fb5c |
); _erbr_rc="${?}";
|
|
|
b8fb5c |
|
|
|
b8fb5c |
if [ "${_erbr_rc}" -eq 0 ]; then
|
|
|
ea2531 |
while true; do
|
|
|
ea2531 |
rpmbuild \
|
|
|
ea2531 |
-bb \
|
|
|
ea2531 |
--define "_binary_payload w2T16.xzdio" \
|
|
|
ea2531 |
--define="_tmppath ${_erbr_tmp_dname=}" \
|
|
|
ea2531 |
--define="_topdir ${_erbr_topdir}" \
|
|
|
f96b7a |
--nodeps \
|
|
|
f96b7a |
"${_erbr_spec_fname_tgt}";
|
|
|
ea2531 |
_erbr_rc="${?}";
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ "${_erbr_rc}" -eq 141 ]; then
|
|
|
ea2531 |
_erbr_rc=0; continue;
|
|
|
ea2531 |
else
|
|
|
ea2531 |
break;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
done;
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ "${_erbr_rc}" -eq 0 ]; then
|
|
|
ea2531 |
if ! find "${_erbr_rpms_dname}/${_erbr_name}-${_erbr_version_rpm}/RPMS" \
|
|
|
ea2531 |
-iname \*.rpm -exec cp -pP {} "${_erbr_rpms_dname}/" \; \
|
|
|
ea2531 |
|| ! rtl_fileop rm "${_erbr_rpms_dname}/${_erbr_name}-${_erbr_version_rpm}" \
|
|
|
ea2531 |
|| ! rtl_fileop cp "${_erbr_spec_fname_tgt}" "${_erbr_rpms_dname}/";
|
|
|
ea2531 |
then
|
|
|
ea2531 |
_erbr_rc=1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
exit "${_erbr_rc}";
|
|
|
ea2531 |
);
|
|
|
ea2531 |
_erbr_rc="${?}";
|
|
|
ea2531 |
|
|
|
ea2531 |
return "${_erbr_rc}";
|
|
|
ea2531 |
};
|
|
|
ea2531 |
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# ex_rtl_expand_rpm_version() - expand RPM version strings
|
|
|
ea2531 |
# @_rurl: out reference to package URL
|
|
|
ea2531 |
# @_rversion: out reference to package version
|
|
|
ea2531 |
# @_rversion_rpm: out reference to RPM version string
|
|
|
ea2531 |
# @_subdir: package subdirectory
|
|
|
ea2531 |
# @_url: package URL
|
|
|
ea2531 |
# @_url_censor: package URL filter
|
|
|
ea2531 |
# @_urls_git: package Git URL(s)
|
|
|
ea2531 |
# @_version: package version
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
ea2531 |
#
|
|
|
ea2531 |
ex_rtl_expand_rpm_version() {
|
|
|
ea2531 |
local _ererv_rurl="${1#\$}" _ererv_rversion="${2#\$}" _ererv_rversion_rpm="${3#\$}" \
|
|
|
ea2531 |
_ererv_subdir="${4}" _ererv_url="${5}" _ererv_url_censor="${6}" \
|
|
|
ea2531 |
_ererv_urls_git="${7}" _ererv_version="${8}" \
|
|
|
ea2531 |
_ererv_version_full="" _ererv_version_rpm=""
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ "${_ererv_url:+1}" = 1 ]; then
|
|
|
ea2531 |
_ererv_url="${_ererv_url%% *}";
|
|
|
ea2531 |
_ererv_version_full="${_ererv_version}";
|
|
|
ea2531 |
_ererv_version_rpm="${_ererv_version%%-*}";
|
|
|
ea2531 |
|
|
|
ea2531 |
elif [ "${_ererv_urls_git:+1}" = 1 ]; then
|
|
|
ea2531 |
_ererv_url="${_ererv_urls_git%% *}";
|
|
|
ea2531 |
_ererv_url="${_ererv_url##*=}";
|
|
|
ea2531 |
_ererv_url="${_ererv_url%%@*}";
|
|
|
ea2531 |
|
|
|
ea2531 |
_ererv_version_rpm="$(cd "${_ererv_subdir}" && git rev-parse HEAD)" || return 1;
|
|
|
ea2531 |
_ererv_version_full="${_ererv_version_rpm} ($(cd "${_ererv_subdir}" && git rev-parse --abbrev-ref HEAD))" || return 1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ "${_ererv_url#${_ererv_url_censor}}" != "${_ererv_url}" ]; then
|
|
|
ea2531 |
_ererv_url="Unknown";
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
eval ${_ererv_rurl}='${_ererv_url}';
|
|
|
ea2531 |
eval ${_ererv_rversion}='${_ererv_version_full}';
|
|
|
ea2531 |
eval ${_ererv_rversion_rpm}='${_ererv_version_rpm}';
|
|
|
ea2531 |
|
|
|
ea2531 |
return 0;
|
|
|
ea2531 |
};
|
|
|
ea2531 |
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# ex_rtl_fixup_pkgconfig_paths() - fixup pathname prefixes in pkg-config(1) files
|
|
|
ea2531 |
# @_dname_base: base directory pathname
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
ea2531 |
#
|
|
|
ea2531 |
ex_rtl_fixup_pkgconfig_paths() {
|
|
|
ea2531 |
local _erfpp_dname_base="${1}" \
|
|
|
ea2531 |
_erfpp_pc_path="";
|
|
|
ea2531 |
|
|
|
ea2531 |
for _erfpp_pc_path in $(find "${_erfpp_dname_base=}" -name \*.pc); do
|
|
|
ea2531 |
if [ -n "$(sed -ne '/^libdir=[^$]*$/p' "${_erfpp_pc_path}")" ] \
|
|
|
ea2531 |
&& ! sed -i"" -e '/^libdir=[^$]*$/s/^libdir=\(.*\)$/libdir=${exec_prefix}\1/' \
|
|
|
ea2531 |
-e '/^exec_prefix=$/s/^.*$/exec_prefix=${prefix}/' \
|
|
|
ea2531 |
"${_erfpp_pc_path}";
|
|
|
ea2531 |
then
|
|
|
ea2531 |
return 1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ -n "$(sed -ne '/^includedir=[^$]*$/p' "${_erfpp_pc_path}")" ] \
|
|
|
ea2531 |
&& ! sed -i"" -e '/^includedir=[^$]*$/s/^includedir=\(.*\)$/includedir=${prefix}\1/' \
|
|
|
ea2531 |
"${_erfpp_pc_path}";
|
|
|
ea2531 |
then
|
|
|
ea2531 |
return 1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
done;
|
|
|
ea2531 |
|
|
|
ea2531 |
return 0;
|
|
|
ea2531 |
};
|
|
|
ea2531 |
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# ex_rtl_purge_la_files() - purge .la files in tree
|
|
|
ea2531 |
# @_dname_base: base directory pathname
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
ea2531 |
#
|
|
|
ea2531 |
ex_rtl_purge_la_files() {
|
|
|
ea2531 |
local _erplf_dname_base="${1}" \
|
|
|
ea2531 |
_erplf_la_path="";
|
|
|
ea2531 |
|
|
|
ea2531 |
for _erplf_la_path in $(find \
|
|
|
ea2531 |
"${_erplf_dname_base}" \
|
|
|
ea2531 |
-type f \
|
|
|
ea2531 |
-name \*.la);
|
|
|
ea2531 |
do
|
|
|
ea2531 |
if ! rtl_fileop rm "${_erplf_la_path}"; then
|
|
|
ea2531 |
return 1;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
done;
|
|
|
ea2531 |
return 0;
|
|
|
ea2531 |
};
|
|
|
ea2531 |
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# ex_rtl_strip_files() - strip files of debugging information
|
|
|
ea2531 |
# @_strip_cmd: strip(1) command name
|
|
|
ea2531 |
# @_tree_root: pathname to tree root
|
|
|
ea2531 |
# @--: (ignored)
|
|
|
ea2531 |
# @_log_fn: logging function name; called with @... and pathname of each file stripped
|
|
|
ea2531 |
# @...: @_fn initial arguments list as positional parameters
|
|
|
ea2531 |
#
|
|
|
ea2531 |
# Returns: zero (0) on success, non-zero (>0) on failure
|
|
|
ea2531 |
#
|
|
|
ea2531 |
ex_rtl_strip_files() {
|
|
|
ea2531 |
local _ersf_strip_cmd="${1}" _ersf_tree_root="${2}" \
|
|
|
ea2531 |
_ersf_ignored="${3}" _ersf_log_fn="${4}" \
|
|
|
ea2531 |
_ersf_bin_path="";
|
|
|
ea2531 |
shift 4;
|
|
|
ea2531 |
|
|
|
ea2531 |
if [ -e "${_ersf_tree_root}" ]; then
|
|
|
ea2531 |
for _ersf_bin_path in $(find \
|
|
|
ea2531 |
"${_ersf_tree_root}" \
|
|
|
ea2531 |
-perm /a=x \
|
|
|
ea2531 |
-type f);
|
|
|
ea2531 |
do
|
|
|
ea2531 |
if objdump \
|
|
|
ea2531 |
-sj .debug_frame \
|
|
|
ea2531 |
-j .debug_info \
|
|
|
ea2531 |
"${_ersf_bin_path}" \
|
|
|
ea2531 |
>/dev/null 2>&1;
|
|
|
ea2531 |
then
|
|
|
ea2531 |
if ! "${_ersf_strip_cmd}" "${_ersf_bin_path}"; then
|
|
|
ea2531 |
return 1;
|
|
|
ea2531 |
else
|
|
|
ea2531 |
"${_ersf_log_fn}" "${@}" "${_ersf_bin_path}";
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
done;
|
|
|
ea2531 |
fi;
|
|
|
ea2531 |
|
|
|
ea2531 |
return 0;
|
|
|
ea2531 |
};
|
|
|
ea2531 |
|
|
|
ea2531 |
# vim:filetype=sh textwidth=0
|