#
# 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.
#
# Package {configure,make} command execution
#
#
# ex_pkg_run_configure() - run configure script
# @_ar: ar(1) command name or pathname
# @_cc: C compiler command name or pathname
# @_configure: configure script command name or pathname
# @_cxx: C++ compiler command name or pathname
# @_ld: ld(1) command name or pathname
# @_libtool: libtool(1) command name or pathname or "none"
# @_pkg_config: pkg-config(1) command name or pathname
# @_python: python command name or pathname
# @_ranlib: ranlib(1) command name or pathname
# @--: (ignored)
# @_flags: configure script flags as a whitespace-separated list
# @_flags_extra: extra configure script flags as a whitespace-separated likst
# @_flags_list: configure script flags as a :-separated list
# @_flags_extra_list: extra configure script flags as a :-separated list
# @--: (ignored)
# @_cflags: $CFLAGS
# @_cflags_extra: extra $CFLAGS
# @_cppflags: $CPPFLAGS
# @_cppflags_extra: extra $CPPFLAGS
# @_cxxflags: $CXXFLAGS
# @_cxxflags_extra: extra $CXXFLAGS
# @_ldflags: $LDFLAGS
# @_ldflags_extra: extra $LDFLAGS
# @_pkg_config_libdir: pkg-config(1) search directory
#
# Returns: zero (0) on success, non-zero (>0) on failure
#
ex_pkg_run_configure() {
local _eprc_ar="${1}" _eprc_cc="${2}" _eprc_configure="${3}" _eprc_cxx="${4}" _eprc_ld="${5}" \
_eprc_libtool="${6}" _eprc_pkg_config="${7}" _eprc_python="${8}" _eprc_ranlib="${9}" \
_eprc_ignored="${10}" \
_eprc_flags="${11}" _eprc_flags_extra="${12}" \
_eprc_flags_list="${13}" _eprc_flags_extra_list="${14}" \
_eprc_ignored="${15}" \
_eprc_cflags="${16}" _eprc_cflags_extra="${17}" _eprc_cppflags="${18}" \
_eprc_cppflags_extra="${19}" _eprc_cxxflags="${20}" _eprc_cxxflags_extra="${21}" \
_eprc_ldflags="${22}" _eprc_ldflags_extra="${23}" _eprc_pkg_config_libdir="${24}" \
_eprc_rc=0;
case "${_eprc_libtool:-}" in
none) _eprc_libtool=""; ;;
esac;
[ "${_eprc_cflags_extra:+1}" = 1 ] && _eprc_cflags="${_eprc_cflags:+${_eprc_cflags} }${_eprc_cflags_extra}";
[ "${_eprc_cppflags_extra:+1}" = 1 ] && _eprc_cppflags="${_eprc_cppflags:+${_eprc_cppflags} }${_eprc_cppflags_extra}";
[ "${_eprc_cxxflags_extra:+1}" = 1 ] && _eprc_cxxflags="${_eprc_cxxflags:+${_eprc_cxxflags} }${_eprc_cxxflags_extra}";
[ "${_eprc_ldflags_extra:+1}" = 1 ] && _eprc_ldflags="${_eprc_ldflags:+${_eprc_ldflags} }${_eprc_ldflags_extra}";
(
if [ "${_eprc_libtool:+1}" = 1 ]; then
export MAKE="make LIBTOOL=${_eprc_libtool}";
fi;
[ "${_eprc_ar:+1}" = 1 ] && export AR="${_eprc_ar}";
[ "${_eprc_cc:+1}" = 1 ] && export CC="${_eprc_cc}";
[ "${_eprc_cxx:+1}" = 1 ] && export CXX="${_eprc_cxx}";
[ "${_eprc_ld:+1}" = 1 ] && export LD="${_eprc_ld}";
[ "${_eprc_libtool:+1}" = 1 ] && export LIBTOOL="${_eprc_libtool}";
[ "${_eprc_pkg_config:+1}" = 1 ] && export PKG_CONFIG="${_eprc_pkg_config}";
[ "${_eprc_python:+1}" = 1 ] && export PYTHON="${_eprc_python}";
[ "${_eprc_ranlib:+1}" = 1 ] && export RANLIB="${_eprc_ranlib}";
[ "${_eprc_cflags:+1}" = 1 ] && export CFLAGS="${_eprc_cflags}";
[ "${_eprc_cppflags:+1}" = 1 ] && export CPPFLAGS="${_eprc_cppflags}";
[ "${_eprc_cxxflags:+1}" = 1 ] && export CXXFLAGS="${_eprc_cxxflags}";
[ "${_eprc_ldflags:+1}" = 1 ] && export LDFLAGS="${_eprc_ldflags}";
[ "${_eprc_pkg_config_libdir:+1}" = 1 ] && export PKG_CONFIG_LIBDIR="${_eprc_pkg_config_libdir}";
if [ "${_eprc_flags_list:+1}" = 1 ]; then
rtl_run_cmdlineV ":" "${_eprc_configure}" \
"${_eprc_flags_list}" \
"${_eprc_flags_extra_list:-}" \
;
exit "${?}";
elif [ "${_eprc_flags_extra_list:+1}" = 1 ]; then
rtl_run_cmdlineV ":" "${_eprc_configure}" \
${_eprc_flags:-} \
"${_eprc_flags_extra_list:-}" \
;
exit "${?}";
else
rtl_run_cmdlineV ":" "${_eprc_configure}" \
${_eprc_flags:-} \
${_eprc_flags_extra:-} \
;
exit "${?}";
fi;
);
_eprc_rc="${?}";
return "${_eprc_rc}";
};
#
# ex_pkg_run_configure_cmake() - run configure script
# @_ar: ar(1) command name or pathname
# @_cc: C compiler command name or pathname
# @_ccache: ccache(1) command name or pathname or ""
# @_cmake: CMake command name or pathname
# @_cxx: C++ compiler command name or pathname
# @_ld: ld(1) command name or pathname
# @_pkg_config: pkg-config(1) command name or pathname
# @_python: python command name or pathname
# @_ranlib: ranlib(1) command name or pathname
# @--: (ignored)
# @_build_type: CMake build type (host, cross, native)
# @_cmake_args: additional CMake arguments as a whitespace-separated list
# @_cmake_args_extra: additional CMake extra arguments as a whitespace-separated likst
# @_prefix: build prefix pathname
# @_subdir: CMake build directory pathname
# @_system_name: CMake system name
# @_system_processor: CMake system processor
# @--: (ignored)
# @_cflags: $CFLAGS
# @_cflags_extra: extra $CFLAGS
# @_cppflags: $CPPFLAGS
# @_cppflags_extra: extra $CPPFLAGS
# @_cxxflags: $CXXFLAGS
# @_cxxflags_extra: extra $CXXFLAGS
# @_ldflags: $LDFLAGS
# @_ldflags_extra: extra $LDFLAGS
# @_pkg_config_libdir: pkg-config(1) search directory
#
# Returns: zero (0) on success, non-zero (>0) on failure
#
ex_pkg_run_configure_cmake() {
local _eprcc_ar="${1}" _eprcc_cc="${2}" _eprcc_ccache="${3}" _eprcc_cmake="${4}" \
_eprcc_cxx="${5}" _eprcc_ld="${6}" _eprcc_pkg_config="${7}" _eprcc_python="${8}" \
_eprcc_ranlib="${9}" \
_eprcc_ignored="${10}" \
_eprcc_build_type="${11}" \
_eprcc_cmake_args="${12}" _eprcc_cmake_args_extra="${13}" \
_eprcc_prefix="${14}" _eprcc_subdir="${15}" \
_eprcc_system_name="${16}" _eprcc_system_processor="${17}" \
_eprcc_ignored="${18}" \
_eprcc_cflags="${19}" _eprcc_cflags_extra="${20}" _eprcc_cppflags="${21}" \
_eprcc_cppflags_extra="${22}" _eprcc_cxxflags="${23}" _eprcc_cxxflags_extra="${24}" \
_eprcc_ldflags="${25}" _eprcc_ldflags_extra="${26}" _eprcc_pkg_config_libdir="${27}" \
_eprcc_cmd_name="" _eprcc_cmake_args_auto="" _eprcc_rc=0 _eprcc_vname="" _eprcc_vval=""
[ "${_eprcc_cflags_extra:+1}" = 1 ] && _eprcc_cflags="${_eprcc_cflags:+${_eprcc_cflags} }${_eprcc_cflags_extra}";
[ "${_eprcc_cppflags_extra:+1}" = 1 ] && _eprcc_cppflags="${_eprcc_cppflags:+${_eprcc_cppflags} }${_eprcc_cppflags_extra}";
[ "${_eprcc_cxxflags_extra:+1}" = 1 ] && _eprcc_cxxflags="${_eprcc_cxxflags:+${_eprcc_cxxflags} }${_eprcc_cxxflags_extra}";
[ "${_eprcc_ldflags_extra:+1}" = 1 ] && _eprcc_ldflags="${_eprcc_ldflags:+${_eprcc_ldflags} }${_eprcc_ldflags_extra}";
(
[ "${_eprcc_pkg_config:+1}" = 1 ] && export PKG_CONFIG="${_eprcc_pkg_config}";
[ "${_eprcc_pkg_config_libdir:+1}" = 1 ] && export PKG_CONFIG_LIBDIR="${_eprcc_pkg_config_libdir}";
[ "${_eprcc_python:+1}" = 1 ] && export PYTHON="${_eprcc_python}";
for _eprcc_vname in ar cc cxx ld pkg_config ranlib; do
case "${_eprcc_vname}" in
cc|cxx)
_eprcc_vname="_eprcc_${_eprcc_vname}";
if [ "${_eprcc_ccache:+1}" = 1 ]; then
eval ${_eprcc_vname}="\${${_eprcc_vname}#${_eprcc_ccache} }";
fi;
;;
*)
_eprcc_vname="_eprcc_${_eprcc_vname}";
;;
esac;
if eval [ '"${'"${_eprcc_vname}"':+1}"' = 1 ]\
&& eval [ '"${'"${_eprcc_vname}"'#/}"' = '"${'"${_eprcc_vname}"'}"' ]; then
eval _eprcc_cmd_name="\${${_eprcc_vname}% *}";
eval _eprcc_vval="\${${_eprcc_vname}#* }";
eval ${_eprcc_vname}='$(which "${_eprcc_cmd_name}")' || return 1;
fi;
done;
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_AR=${_eprcc_ar}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_BUILD_TYPE=${_eprcc_build_type}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_C_COMPILER=${_eprcc_cc}" ":";
if [ "${_eprcc_ccache:+1}" = 1 ]; then
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_C_COMPILER_LAUNCHER=${_eprcc_ccache}" ":";
fi;
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_C_FLAGS=${_eprcc_cflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_CPP_FLAGS=${_eprcc_cppflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_CXX_COMPILER=${_eprcc_cxx}" ":";
if [ "${_eprcc_ccache:+1}" = 1 ]; then
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_CXX_COMPILER_LAUNCHER=${_eprcc_ccache}" ":";
fi;
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_CXX_FLAGS=${_eprcc_cxxflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_EXE_LINKER_FLAGS=${_eprcc_ldflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_FIND_ROOT_PATH=${_eprcc_prefix}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_INSTALL_PREFIX=" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_LINKER=${_eprcc_ld}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_MODULE_LINKER_FLAGS=${_eprcc_ldflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_RANLIB=${_eprcc_ranlib}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_SHARED_LINKER_FLAGS=${_eprcc_ldflags}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_SYSTEM_PROCESSOR=${_eprcc_system_processor}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DPKG_CONFIG_EXECUTABLE=${_eprcc_pkg_config}" ":";
case "${_eprcc_build_type}" in
native)
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_SYSROOT=${_eprcc_prefix}" ":";
rtl_lconcat \$_eprcc_cmake_args_auto "-DCMAKE_SYSTEM_NAME=${_eprcc_system_name}" ":";
;;
esac;
rtl_run_cmdlineV ":" "${_eprcc_cmake}" \
"${_eprcc_cmake_args_auto}" \
${_eprcc_cmake_args:-} \
${_eprcc_cmake_args_extra:-} \
"${_eprcc_subdir}";
exit "${?}";
);
_eprcc_rc="${?}";
return "${_eprcc_rc}";
};
#
# ex_pkg_run_make() - run make(1)
# @_ar: ar(1) command name or pathname
# @_cc: C compiler command name or pathname
# @_cxx: C++ compiler command name or pathname
# @_ld: ld(1) command name or pathname
# @_libtool: libtool(1) command name or pathname or "none"
# @_make: make(1) command name or pathname
# @_pkg_config: pkg-config(1) command name or pathname
# @_ranlib: ranlib(1) command name or pathname
# @--: (ignored)
# @_set_ccfl: 1 if CC=... is to be passed to make(1), 0 if CC=... is not to be passed to make(1)
# @_subdir: make(1) -C argument
# @--: (ignored)
# @_makeflags: make(1) flags as a whitespace-separated list
# @_makeflags_extra: extra make(1) flags as a whitespace-separated likst
# @_makeflags_list: make(1) flags as a :-separated list
# @_makeflags_extra_list: extra make(1) flags as a :-separated list
# @_makeflags_loadavg: make(1) -l load argument
# @_makeflags_parallelise: make(1) -j jobs argument
# @_makeflags_verbosity: make(1) Makefile verbosity arguments or "none"
# @--: (ignored)
# @_cflags: $CFLAGS
# @_cflags_extra: extra $CFLAGS
# @_cppflags: $CPPFLAGS
# @_cppflags_extra: extra $CPPFLAGS
# @_cxxflags: $CXXFLAGS
# @_cxxflags_extra: extra $CXXFLAGS
# @_ldflags: $LDFLAGS
# @_ldflags_extra: extra $LDFLAGS
# @_pkg_config_libdir: pkg-config(1) search directory
# @--: (ignored)
# @_destdir_spec: DESTDIR=... specification
# @_target: make(1) target
#
# Returns: zero (0) on success, non-zero (>0) on failure
#
ex_pkg_run_make() {
local _eprm_ar="${1}" _eprm_cc="${2}" _eprm_cxx="${3}" _eprm_ld="${4}" \
_eprm_libtool="${5}" _eprm_make="${6}" _eprm_pkg_config="${7}" _eprm_ranlib="${8}" \
_eprm_ignored="${9}" \
_eprm_set_ccfl="${10}" _eprm_subdir="${11}" \
_eprm_ignored="${12}" \
_eprm_makeflags="${13}" _eprm_makeflags_extra="${14}" _eprm_makeflags_list="${15}" \
_eprm_makeflags_extra_list="${16}" _eprm_makeflags_loadavg="${17}" \
_eprm_makeflags_parallelise="${18}" _eprm_makeflags_verbosity="${19}" \
_eprm_ignored="${20}" \
_eprm_cflags="${21}" _eprm_cflags_extra="${22}" _eprm_cppflags="${23}" \
_eprm_cppflags_extra="${24}" _eprm_cxxflags="${25}" _eprm_cxxflags_extra="${26}" \
_eprm_ldflags="${27}" _eprm_ldflags_extra="${28}" _eprm_pkg_config_libdir="${29}" \
_eprm_ignored="${30}" \
_eprm_destdir_spec="${31}" _eprm_target="${32}" \
_eprm_rc=0;
case "${_eprm_makeflags_loadavg:-}" in
none) _eprm_makeflags_loadavg=""; ;;
esac;
case "${_eprm_libtool:-}" in
none) _eprm_libtool=""; ;;
esac;
case "${_eprm_makeflags_verbosity}" in
none) _eprm_makeflags_verbosity=""; ;;
esac;
case "${_eprm_set_ccfl}" in
1) _eprm_set_ccfl="1"; ;;
*) _eprm_set_ccfl=""; ;;
esac;
(
if [ "${_eprm_libtool:+1}" = 1 ]; then
export MAKE="make LIBTOOL=${_eprm_libtool}";
fi;
if [ "${_eprm_makeflags_list:+1}" = 1 ]; then
rtl_run_cmdlineV ":" "${_eprm_make}" \
AR="${_eprm_ar}" \
${_eprm_set_ccfl:+CC="${_eprm_cc}"} \
${_eprm_set_ccfl:+CXX="${_eprm_cxx}"} \
LD="${_eprm_ld}" \
${_eprm_libtool:+LIBTOOL="${_eprm_libtool}"} \
${_eprm_pkg_config:+PKG_CONFIG="${_eprm_pkg_config}"} \
RANLIB="${_eprm_ranlib}" \
\
"${_eprm_makeflags_list}" \
"${_eprm_makeflags_extra_list:-}" \
${_eprm_makeflags_loadavg:-} \
${_eprm_makeflags_parallelise:-} \
${_eprm_makeflags_verbosity} \
\
${_eprm_cflags:+CFLAGS="${_eprm_cflags}"} \
${_eprm_cflags_extra:+CFLAGS+="${_eprm_cflags_extra}"} \
${_eprm_cppflags:+CPPFLAGS="${_eprm_cppflags}"} \
${_eprm_cppflags_extra:+CPPFLAGS+="${_eprm_cppflags_extra}"} \
${_eprm_cxxflags:+CXXFLAGS="${_eprm_cxxflags}"} \
${_eprm_cxxflags_extra:+CXXFLAGS+="${_eprm_cxxflags_extra}"} \
${_eprm_ldflags:+LDFLAGS="${_eprm_ldflags}"} \
${_eprm_ldflags_extra:+LDFLAGS+="${_eprm_ldflags_extra}"} \
${_eprm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_eprm_pkg_config_libdir}"} \
\
${_eprm_subdir:+-C "${_eprm_subdir}"} \
${_eprm_destdir_spec:+"${_eprm_destdir_spec}"} \
${_eprm_target:+"${_eprm_target}"} \
;
exit "${?}";
elif [ "${_eprm_makeflags_extra_list:+1}" = 1 ]; then
rtl_run_cmdlineV ":" "${_eprm_make}" \
AR="${_eprm_ar}" \
${_eprm_set_ccfl:+CC="${_eprm_cc}"} \
${_eprm_set_ccfl:+CXX="${_eprm_cxx}"} \
LD="${_eprm_ld}" \
${_eprm_libtool:+LIBTOOL="${_eprm_libtool}"} \
${_eprm_pkg_config:+PKG_CONFIG="${_eprm_pkg_config}"} \
RANLIB="${_eprm_ranlib}" \
\
${_eprm_makeflags:-} \
"${_eprm_makeflags_extra_list}" \
${_eprm_makeflags_loadavg:-} \
${_eprm_makeflags_parallelise:-} \
${_eprm_makeflags_verbosity} \
\
${_eprm_cflags:+CFLAGS="${_eprm_cflags}"} \
${_eprm_cflags_extra:+CFLAGS+="${_eprm_cflags_extra}"} \
${_eprm_cppflags:+CPPFLAGS="${_eprm_cppflags}"} \
${_eprm_cppflags_extra:+CPPFLAGS+="${_eprm_cppflags_extra}"} \
${_eprm_cxxflags:+CXXFLAGS="${_eprm_cxxflags}"} \
${_eprm_cxxflags_extra:+CXXFLAGS+="${_eprm_cxxflags_extra}"} \
${_eprm_ldflags:+LDFLAGS="${_eprm_ldflags}"} \
${_eprm_ldflags_extra:+LDFLAGS+="${_eprm_ldflags_extra}"} \
${_eprm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_eprm_pkg_config_libdir}"} \
\
${_eprm_subdir:+-C "${_eprm_subdir}"} \
${_eprm_destdir_spec:+"${_eprm_destdir_spec}"} \
${_eprm_target:+"${_eprm_target}"} \
;
exit "${?}";
else
rtl_run_cmdlineV ":" "${_eprm_make}" \
AR="${_eprm_ar}" \
${_eprm_set_ccfl:+CC="${_eprm_cc}"} \
${_eprm_set_ccfl:+CXX="${_eprm_cxx}"} \
LD="${_eprm_ld}" \
${_eprm_libtool:+LIBTOOL="${_eprm_libtool}"} \
${_eprm_pkg_config:+PKG_CONFIG="${_eprm_pkg_config}"} \
RANLIB="${_eprm_ranlib}" \
\
${_eprm_makeflags:-} \
${_eprm_makeflags_extra:-} \
${_eprm_makeflags_loadavg:-} \
${_eprm_makeflags_parallelise:-} \
${_eprm_makeflags_verbosity} \
\
${_eprm_cflags:+CFLAGS="${_eprm_cflags}"} \
${_eprm_cflags_extra:+CFLAGS+="${_eprm_cflags_extra}"} \
${_eprm_cppflags:+CPPFLAGS="${_eprm_cppflags}"} \
${_eprm_cppflags_extra:+CPPFLAGS+="${_eprm_cppflags_extra}"} \
${_eprm_cxxflags:+CXXFLAGS="${_eprm_cxxflags}"} \
${_eprm_cxxflags_extra:+CXXFLAGS+="${_eprm_cxxflags_extra}"} \
${_eprm_ldflags:+LDFLAGS="${_eprm_ldflags}"} \
${_eprm_ldflags_extra:+LDFLAGS+="${_eprm_ldflags_extra}"} \
${_eprm_pkg_config_libdir:+PKG_CONFIG_LIBDIR="${_eprm_pkg_config_libdir}"} \
\
${_eprm_subdir:+-C "${_eprm_subdir}"} \
${_eprm_destdir_spec:+"${_eprm_destdir_spec}"} \
${_eprm_target:+"${_eprm_target}"} \
;
exit "${?}";
fi;
);
_eprm_rc="${?}";
return "${_eprm_rc}";
};
# vim:filetype=sh textwidth=0