1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: kde5-functions.eclass
8 # @BLURB: Common ebuild functions for packages based on KDE Frameworks 5.
10 # This eclass contains functions shared by the other KDE eclasses and forms
11 # part of their public API.
13 # This eclass should (almost) never be inherited directly by an ebuild.
15 if [[ -z ${_KDE5_FUNCTIONS_ECLASS} ]]; then
16 _KDE5_FUNCTIONS_ECLASS=1
18 inherit toolchain-funcs versionator
22 *) die "EAPI=${EAPI:-0} is not supported" ;;
25 # @ECLASS-VARIABLE: KDE_BUILD_TYPE
27 # If PV matches "*9999*", this is automatically set to "live".
28 # Otherwise, this is automatically set to "release".
29 KDE_BUILD_TYPE="release"
30 if [[ ${PV} = *9999* ]]; then
37 [[ ${PV} = 5.45* ]] && : ${QT_MINIMAL:=5.9.4}
38 [[ ${KDE_BUILD_TYPE} = live ]] && : ${FRAMEWORKS_MINIMAL:=9999}
41 [[ ${PV} = 5.12* ]] && : ${QT_MINIMAL:=5.9.1}
42 if [[ ${KDE_BUILD_TYPE} = live ]]; then
43 : ${QT_MINIMAL:=5.9.1}
44 : ${FRAMEWORKS_MINIMAL:=9999}
48 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 18.04* ]]; then
49 : ${FRAMEWORKS_MINIMAL:=5.44.0}
51 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 17.12* ]]; then
52 : ${QT_MINIMAL:=5.9.1}
57 # @ECLASS-VARIABLE: QT_MINIMAL
59 # Minimum version of Qt to require. This affects add_qt_dep.
60 : ${QT_MINIMAL:=5.7.1}
62 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
64 # Minimum version of Frameworks to require. This affects add_frameworks_dep.
65 : ${FRAMEWORKS_MINIMAL:=5.43.0}
67 # @ECLASS-VARIABLE: PLASMA_MINIMAL
69 # Minimum version of Plasma to require. This affects add_plasma_dep.
70 : ${PLASMA_MINIMAL:=5.11.5}
72 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
74 # Minimum version of KDE Applications to require. This affects add_kdeapps_dep.
75 : ${KDE_APPS_MINIMAL:=14.12.0}
77 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
80 # Minimum version of active GCC to require. This is checked in kde5.eclass in
81 # kde5_pkg_pretend and kde5_pkg_setup.
83 # @ECLASS-VARIABLE: KDEBASE
86 # This gets set to a non-zero value when a package is considered a
88 if [[ ${KMNAME-${PN}} = kdevelop ]]; then
92 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
94 # @ECLASS-VARIABLE: KDE_SCM
96 # SCM to use if KDE_BUILD_TYPE is determined to be "live".
97 # Currently, only git is supported.
102 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
105 # @FUNCTION: _check_gcc_version
108 # Determine if the current GCC version is acceptable, otherwise die.
109 _check_gcc_version() {
110 if [[ ${MERGE_TYPE} != binary && -v KDE_GCC_MINIMAL ]] && tc-is-gcc; then
112 local version=$(gcc-version)
113 local major=${version%.*}
114 local minor=${version#*.}
115 local min_major=${KDE_GCC_MINIMAL%.*}
116 local min_minor=${KDE_GCC_MINIMAL#*.}
118 debug-print "GCC version check activated"
119 debug-print "Version detected:"
120 debug-print " - Full: ${version}"
121 debug-print " - Major: ${major}"
122 debug-print " - Minor: ${minor}"
123 debug-print "Version required:"
124 debug-print " - Major: ${min_major}"
125 debug-print " - Minor: ${min_minor}"
127 [[ ${major} -lt ${min_major} ]] || \
128 ( [[ ${major} -eq ${min_major} && ${minor} -lt ${min_minor} ]] ) \
129 && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is required for this package (found ${version})."
133 # @FUNCTION: _add_category_dep
136 # Implementation of add_plasma_dep, add_frameworks_dep, add_kdeapps_dep,
137 # and finally, add_qt_dep.
138 _add_category_dep() {
139 debug-print-function ${FUNCNAME} "$@"
147 if [[ -n ${use} ]] ; then
151 if [[ -n ${version} ]] ; then
153 local version="-${version}"
156 if [[ -n ${slot} ]] ; then
158 elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
162 echo " ${operator}${category}/${package}${version}${slot}${use}"
165 # @FUNCTION: add_frameworks_dep
166 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
168 # Create proper dependency for kde-frameworks/ dependencies.
169 # This takes 1 to 4 arguments. The first being the package name, the optional
170 # second is additional USE flags to append, and the optional third is the
171 # version to use instead of the automatic version (use sparingly). In addition,
172 # the optional fourth argument defines slot+operator instead of automatic slot
173 # (use even more sparingly).
174 # The output of this should be added directly to DEPEND/RDEPEND, and may be
175 # wrapped in a USE conditional (but not an || conditional without an extra set
177 add_frameworks_dep() {
178 debug-print-function ${FUNCNAME} "$@"
180 if [[ $# -gt 4 ]]; then
181 die "${FUNCNAME} was called with too many arguments"
186 if [[ -n ${3} ]]; then
188 elif [[ ${CATEGORY} = kde-frameworks ]]; then
189 version=$(get_version_component_range 1-2)
190 elif [[ -z ${3} ]] ; then
191 version=${FRAMEWORKS_MINIMAL}
194 _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
197 # @FUNCTION: add_plasma_dep
198 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
200 # Create proper dependency for kde-plasma/ dependencies.
201 # This takes 1 to 4 arguments. The first being the package name, the optional
202 # second is additional USE flags to append, and the optional third is the
203 # version to use instead of the automatic version (use sparingly). In addition,
204 # the optional fourth argument defines slot+operator instead of automatic slot
205 # (use even more sparingly).
206 # The output of this should be added directly to DEPEND/RDEPEND, and may be
207 # wrapped in a USE conditional (but not an || conditional without an extra set
210 debug-print-function ${FUNCNAME} "$@"
212 if [[ $# -gt 4 ]]; then
213 die "${FUNCNAME} was called with too many arguments"
218 if [[ -n ${3} ]]; then
220 elif [[ ${CATEGORY} = kde-plasma ]]; then
221 version=$(get_version_component_range 1-3)
222 elif [[ -z ${3} ]] ; then
223 version=${PLASMA_MINIMAL}
226 _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
229 # @FUNCTION: add_kdeapps_dep
230 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
232 # Create proper dependency for kde-apps/ dependencies.
233 # This takes 1 to 4 arguments. The first being the package name, the optional
234 # second is additional USE flags to append, and the optional third is the
235 # version to use instead of the automatic version (use sparingly). In addition,
236 # the optional fourth argument defines slot+operator instead of automatic slot
237 # (use even more sparingly).
238 # The output of this should be added directly to DEPEND/RDEPEND, and may be
239 # wrapped in a USE conditional (but not an || conditional without an extra set
242 debug-print-function ${FUNCNAME} "$@"
244 if [[ $# -gt 4 ]]; then
245 die "${FUNCNAME} was called with too many arguments"
250 if [[ -n ${3} ]]; then
252 elif [[ ${CATEGORY} = kde-apps ]]; then
253 version=$(get_version_component_range 1-3)
254 elif [[ -z ${3} ]] ; then
255 version=${KDE_APPS_MINIMAL}
258 _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
261 # @FUNCTION: add_qt_dep
262 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
264 # Create proper dependency for dev-qt/ dependencies.
265 # This takes 1 to 4 arguments. The first being the package name, the optional
266 # second is additional USE flags to append, and the optional third is the
267 # version to use instead of the automatic version (use sparingly). In addition,
268 # the optional fourth argument defines slot+operator instead of automatic slot
269 # (use even more sparingly).
270 # The output of this should be added directly to DEPEND/RDEPEND, and may be
271 # wrapped in a USE conditional (but not an || conditional without an extra set
274 debug-print-function ${FUNCNAME} "$@"
276 if [[ $# -gt 4 ]]; then
277 die "${FUNCNAME} was called with too many arguments"
283 if [[ -z ${version} ]]; then
284 if [[ ${1} = qtwebkit && ${QT_MINIMAL} = 5.9* ]]; then
285 version=5.9.1 # no more upstream release, need bug #624404
287 version=${QT_MINIMAL}
290 if [[ -z ${slot} ]]; then
294 _add_category_dep dev-qt "${1}" "${2}" "${version}" "${slot}"
297 # @FUNCTION: get_kde_version [version]
299 # Translates an ebuild version into a major.minor KDE release version, taking
300 # into account KDE's prerelease versioning scheme.
301 # For example, get_kde_version 17.07.80 will return "17.08".
302 # If the version equals 9999, "live" is returned.
303 # If no version is specified, ${PV} is used.
305 local ver=${1:-${PV}}
306 local major=$(get_major_version ${ver})
307 local minor=$(get_version_component_range 2 ${ver})
308 local micro=$(get_version_component_range 3 ${ver})
309 if [[ ${ver} == 9999 ]]; then
312 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
316 # @FUNCTION: kde_l10n2lingua
320 # Output KDE lingua flag name(s) (without prefix(es)) appropriate for
326 ca-valencia) echo ca@valencia;;
327 sr-ijekavsk) echo sr@ijekavian;;
328 sr-Latn-ijekavsk) echo sr@ijekavianlatin;;
329 sr-Latn) echo sr@latin;;
330 uz-Cyrl) echo uz@cyrillic;;
336 # @FUNCTION: punt_bogus_dep
337 # @USAGE: <prefix> <dependency>
339 # Removes a specified dependency from a find_package call with multiple components.
344 if [[ ! -e "CMakeLists.txt" ]]; then
348 pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
350 # pcregrep returns non-zero on no matches/error
351 if [[ $? != 0 ]] ; then
355 local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1)
356 local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1)
357 local last=$(( ${length} + ${first} - 1))
359 sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
361 if [[ ${length} = 1 ]] ; then
362 sed -e "/find_package\s*(\s*${prefix}\(\s\+\(REQUIRED\|CONFIG\|COMPONENTS\|\${[A-Z0-9_]*}\)\)\+\s*)/Is/^/# removed by kde5-functions.eclass - /" -i CMakeLists.txt || die