aboutsummaryrefslogtreecommitdiff
blob: a0c03336345a63b8487cd8e001ab6a4660761ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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.

case ${EAPI:-0} in
	8) ;;
	*) die "${ECLASS}: EAPI ${EAPI:-0} unsupported."
esac

if [[ ! ${_QBS_ECLASS} ]]; then

inherit flag-o-matic 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-build/meson-format-array
	dev-util/qbs
"

# @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() {
	meson-format-array "${@}" || die
}

# @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 $(raw-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

EXPORT_FUNCTIONS src_configure src_compile src_install