aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>2022-03-31 06:56:33 +0500
committerAnna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>2022-03-31 06:57:38 +0500
commitbd38be65c80afe2e7ec56e4cc05b5e8388170fa3 (patch)
treeaa7e3183876ebe633717200aaa732f996bae4333
parentapp-crypt/certbot-dns-desec: initial import (diff)
downloadguru-bd38be65.tar.gz
guru-bd38be65.tar.bz2
guru-bd38be65.zip
qbs.eclass: new eclass
Signed-off-by: Anna (cybertailor) Vyalkova <cyber+gentoo@sysrq.in>
-rw-r--r--eclass/qbs.eclass186
1 files changed, 186 insertions, 0 deletions
diff --git a/eclass/qbs.eclass b/eclass/qbs.eclass
new file mode 100644
index 000000000..6c3f06310
--- /dev/null
+++ b/eclass/qbs.eclass
@@ -0,0 +1,186 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: qbs.eclass
+# @AUTHOR:
+# Anna Vyalkova <cyber+gentoo@sysrq.in>
+# @MAINTAINER:
+# Anna Vyalkova <cyber+gentoo@sysrq.in>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: qmake-utils
+# @BLURB: eclass to build qbs-based packages
+# @DESCRIPTION:
+# Utility eclass providing wrapper functions for Qbs build system.
+
+if [[ ! ${_QBS_ECLASS} ]]; then
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI} unsupported."
+esac
+
+inherit multiprocessing toolchain-funcs qmake-utils
+
+# @ECLASS-VARIABLE: QBS_COMMAND_ECHO_MODE
+# @USER_VARIABLE
+# @DESCRIPTION:
+# Determines what kind of output to show when executing commands. Possible
+# values are:
+#
+# - silent
+#
+# - summary
+#
+# - command-line (the default)
+#
+# - command-line-with-environment
+: ${QBS_COMMAND_ECHO_MODE:=command-line}
+
+BDEPEND="dev-util/qbs"
+
+EXPORT_FUNCTIONS src_configure src_compile src_install
+
+# @FUNCTION: eqbs
+# @USAGE: [<qbs args>...]
+# @DESCRIPTION:
+# Run Qbs. This command dies on failure.
+eqbs() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ set -- qbs "${@}"
+ einfo "${@}"
+ "${@}" || die -n
+
+ local ret=${?}
+ return ${ret}
+}
+
+# @FUNCTION: _flags_to_js_array
+# @INTERNAL
+# @USAGE: [<flags>...]
+# @RETURN: arguments quoted and separated by comma
+_flags_to_js_array() {
+ if [[ ! ${@} ]]; then
+ echo "[]"
+ else
+ local -a array
+ printf -v array "'%s', " "${@}"
+ echo "[${array%, }]"
+ fi
+}
+
+# @FUNCTION: _filter_ldflags
+# @INTERNAL
+# @USAGE: [<ldflags>...]
+# @RETURN: flags for the linker (with -Wl and -Xlinker removed)
+_filter_ldflags() {
+ local -a flags
+ while [[ ${@} ]]; do
+ if [[ ${1} == -Wl,* ]]; then
+ IFS=, read -ra flags <<< "${1#-Wl,}"
+ printf "%s " "${flags[@]}"
+ elif [[ ${1} == -Xlinker ]]; then
+ shift
+ printf "%s " "${1}"
+ fi
+ shift
+ done
+}
+
+# @FUNCTION: qbs_src_configure
+# @DESCRIPTION:
+# Setup toolchain and Qt for the "gentoo" profile.
+# Set Qbs preferences to match user settings. Configure build flags and
+# installation prefix.
+qbs_src_configure() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ eqbs setup-toolchains "$(tc-getCC)" gentooToolchain
+ eqbs config profiles.gentooToolchain.archiverPath "$(tc-getAR)"
+ eqbs config profiles.gentooToolchain.assemblerPath "$(tc-getAS)"
+ eqbs config profiles.gentooToolchain.nmPath "$(tc-getNM)"
+ eqbs config profiles.gentooToolchain.objcopyPath "$(tc-getOBJCOPY)"
+ eqbs config profiles.gentooToolchain.stripPath "$(tc-getSTRIP)"
+
+ eqbs setup-qt "$(qt5_get_bindir)/qmake" gentoo
+ qbs_config baseProfile gentooToolchain
+
+ qbs_config preferences.jobs "$(makeopts_jobs)"
+ if [[ "${NOCOLOR}" == true || "${NOCOLOR}" == yes ]]; then
+ qbs_config preferences.useColoredOutput false
+ fi
+
+ qbs_config qbs.installPrefix "${EPREFIX}/usr"
+ qbs_config qbs.sysroot "${ESYSROOT}"
+ qbs_config qbs.optimization "" # don't add unwanted flags
+
+ qbs_config cpp.cFlags "$(_flags_to_js_array ${CFLAGS})"
+ qbs_config cpp.cppFlags "$(_flags_to_js_array ${CPPFLAGS})"
+ qbs_config cpp.cxxFlags "$(_flags_to_js_array ${CXXFLAGS})"
+ qbs_config cpp.linkerFlags "$(_flags_to_js_array $(_filter_ldflags ${LDFLAGS}))"
+}
+
+# @FUNCTION: qbs_config
+# @USAGE: <key> <value>
+# @DESCRIPTION:
+# Set a preference for the "gentoo" profile.
+qbs_config() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ (( $# == 2 )) || \
+ die "${FUNCNAME} takes exactly two arguments"
+
+ local key=${1}
+ local value=${2}
+
+ eqbs config "profiles.gentoo.${key}" "${value}"
+}
+
+# @FUNCTION: qbs_src_compile
+# @USAGE: [<qbs args>...]
+# @DESCRIPTION:
+# General function for compiling with qbs. All arguments are passed
+# to qbs_build.
+qbs_src_compile() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ qbs_build "${@}"
+}
+
+# @FUNCTION: qbs_build
+# @USAGE: [<qbs args>...]
+# @DESCRIPTION:
+# Build the package using qbs build.
+qbs_build() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local qbsargs=(
+ --no-install
+ --command-echo-mode "${QBS_COMMAND_ECHO_MODE}"
+ profile:gentoo
+ config:release
+ )
+
+ eqbs build "${@}" "${qbsargs[@]}"
+}
+
+# @FUNCTION: qbs_src_install
+# @USAGE: [<qbs args>...]
+# @DESCRIPTION:
+# Install the package using qbs install.
+qbs_src_install() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local qbsargs=(
+ --no-build
+ --install-root "${D}"
+ --command-echo-mode "${QBS_COMMAND_ECHO_MODE}"
+ profile:gentoo
+ config:release
+ )
+
+ eqbs install "${@}" "${qbsargs[@]}"
+}
+
+_QBS_ECLASS=1
+fi