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 [[ ${KDE_BUILD_TYPE} = live ]] && : ${FRAMEWORKS_MINIMAL:=9999}
40 if [[ ${KDE_BUILD_TYPE} = live ]]; then
41 : ${QT_MINIMAL:=5.9.1}
42 : ${FRAMEWORKS_MINIMAL:=9999}
46 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 17.12* ]]; then
47 : ${QT_MINIMAL:=5.9.1}
52 # @ECLASS-VARIABLE: QT_MINIMAL
54 # Minimum version of Qt to require. This affects add_qt_dep.
55 : ${QT_MINIMAL:=5.7.1}
57 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
59 # Minimum version of Frameworks to require. This affects add_frameworks_dep.
60 : ${FRAMEWORKS_MINIMAL:=5.40.0}
62 # @ECLASS-VARIABLE: PLASMA_MINIMAL
64 # Minimum version of Plasma to require. This affects add_plasma_dep.
65 : ${PLASMA_MINIMAL:=5.10.5}
67 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
69 # Minimum version of KDE Applications to require. This affects add_kdeapps_dep.
70 : ${KDE_APPS_MINIMAL:=14.12.0}
72 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
75 # Minimum version of active GCC to require. This is checked in kde5.eclass in
76 # kde5_pkg_pretend and kde5_pkg_setup.
78 # @ECLASS-VARIABLE: KDEBASE
81 # This gets set to a non-zero value when a package is considered a
83 if [[ ${KMNAME-${PN}} = kdevelop ]]; then
87 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
89 # @ECLASS-VARIABLE: KDE_SCM
91 # SCM to use if KDE_BUILD_TYPE is determined to be "live".
92 # Currently, only git is supported.
97 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
100 # @FUNCTION: _check_gcc_version
103 # Determine if the current GCC version is acceptable, otherwise die.
104 _check_gcc_version() {
105 if [[ ${MERGE_TYPE} != binary && -v KDE_GCC_MINIMAL ]] && tc-is-gcc; then
107 local version=$(gcc-version)
108 local major=${version%.*}
109 local minor=${version#*.}
110 local min_major=${KDE_GCC_MINIMAL%.*}
111 local min_minor=${KDE_GCC_MINIMAL#*.}
113 debug-print "GCC version check activated"
114 debug-print "Version detected:"
115 debug-print " - Full: ${version}"
116 debug-print " - Major: ${major}"
117 debug-print " - Minor: ${minor}"
118 debug-print "Version required:"
119 debug-print " - Major: ${min_major}"
120 debug-print " - Minor: ${min_minor}"
122 [[ ${major} -lt ${min_major} ]] || \
123 ( [[ ${major} -eq ${min_major} && ${minor} -lt ${min_minor} ]] ) \
124 && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is required for this package (found ${version})."
128 # @FUNCTION: _add_category_dep
131 # Implementation of add_plasma_dep, add_frameworks_dep, add_kdeapps_dep,
132 # and finally, add_qt_dep.
133 _add_category_dep() {
134 debug-print-function ${FUNCNAME} "$@"
142 if [[ -n ${use} ]] ; then
146 if [[ -n ${version} ]] ; then
148 local version="-${version}"
151 if [[ -n ${slot} ]] ; then
153 elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
157 echo " ${operator}${category}/${package}${version}${slot}${use}"
160 # @FUNCTION: add_frameworks_dep
161 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
163 # Create proper dependency for kde-frameworks/ dependencies.
164 # This takes 1 to 4 arguments. The first being the package name, the optional
165 # second is additional USE flags to append, and the optional third is the
166 # version to use instead of the automatic version (use sparingly). In addition,
167 # the optional fourth argument defines slot+operator instead of automatic slot
168 # (use even more sparingly).
169 # The output of this should be added directly to DEPEND/RDEPEND, and may be
170 # wrapped in a USE conditional (but not an || conditional without an extra set
172 add_frameworks_dep() {
173 debug-print-function ${FUNCNAME} "$@"
175 if [[ $# -gt 4 ]]; then
176 die "${FUNCNAME} was called with too many arguments"
181 if [[ -n ${3} ]]; then
183 elif [[ ${CATEGORY} = kde-frameworks ]]; then
184 version=$(get_version_component_range 1-2)
185 elif [[ -z ${3} ]] ; then
186 version=${FRAMEWORKS_MINIMAL}
189 _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
192 # @FUNCTION: add_plasma_dep
193 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
195 # Create proper dependency for kde-plasma/ dependencies.
196 # This takes 1 to 4 arguments. The first being the package name, the optional
197 # second is additional USE flags to append, and the optional third is the
198 # version to use instead of the automatic version (use sparingly). In addition,
199 # the optional fourth argument defines slot+operator instead of automatic slot
200 # (use even more sparingly).
201 # The output of this should be added directly to DEPEND/RDEPEND, and may be
202 # wrapped in a USE conditional (but not an || conditional without an extra set
205 debug-print-function ${FUNCNAME} "$@"
207 if [[ $# -gt 4 ]]; then
208 die "${FUNCNAME} was called with too many arguments"
213 if [[ -n ${3} ]]; then
215 elif [[ ${CATEGORY} = kde-plasma ]]; then
216 version=$(get_version_component_range 1-3)
217 elif [[ -z ${3} ]] ; then
218 version=${PLASMA_MINIMAL}
221 _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
224 # @FUNCTION: add_kdeapps_dep
225 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
227 # Create proper dependency for kde-apps/ dependencies.
228 # This takes 1 to 4 arguments. The first being the package name, the optional
229 # second is additional USE flags to append, and the optional third is the
230 # version to use instead of the automatic version (use sparingly). In addition,
231 # the optional fourth argument defines slot+operator instead of automatic slot
232 # (use even more sparingly).
233 # The output of this should be added directly to DEPEND/RDEPEND, and may be
234 # wrapped in a USE conditional (but not an || conditional without an extra set
237 debug-print-function ${FUNCNAME} "$@"
239 if [[ $# -gt 4 ]]; then
240 die "${FUNCNAME} was called with too many arguments"
245 if [[ -n ${3} ]]; then
247 elif [[ ${CATEGORY} = kde-apps ]]; then
248 version=$(get_version_component_range 1-3)
249 elif [[ -z ${3} ]] ; then
250 version=${KDE_APPS_MINIMAL}
253 _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
256 # @FUNCTION: add_qt_dep
257 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
259 # Create proper dependency for dev-qt/ dependencies.
260 # This takes 1 to 4 arguments. The first being the package name, the optional
261 # second is additional USE flags to append, and the optional third is the
262 # version to use instead of the automatic version (use sparingly). In addition,
263 # the optional fourth argument defines slot+operator instead of automatic slot
264 # (use even more sparingly).
265 # The output of this should be added directly to DEPEND/RDEPEND, and may be
266 # wrapped in a USE conditional (but not an || conditional without an extra set
269 debug-print-function ${FUNCNAME} "$@"
271 if [[ $# -gt 4 ]]; then
272 die "${FUNCNAME} was called with too many arguments"
278 if [[ -z ${version} ]]; then
279 if [[ ${1} = qtwebkit && ${QT_MINIMAL} = 5.9* ]]; then
280 version=5.9.1 # no more upstream release, need bug #624404
282 version=${QT_MINIMAL}
285 if [[ -z ${slot} ]]; then
289 _add_category_dep dev-qt "${1}" "${2}" "${version}" "${slot}"
292 # @FUNCTION: get_kde_version [version]
294 # Translates an ebuild version into a major.minor KDE release version, taking
295 # into account KDE's prerelease versioning scheme.
296 # For example, get_kde_version 17.07.80 will return "17.08".
297 # If the version equals 9999, "live" is returned.
298 # If no version is specified, ${PV} is used.
300 local ver=${1:-${PV}}
301 local major=$(get_major_version ${ver})
302 local minor=$(get_version_component_range 2 ${ver})
303 local micro=$(get_version_component_range 3 ${ver})
304 if [[ ${ver} == 9999 ]]; then
307 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
311 # @FUNCTION: kde_l10n2lingua
315 # Output KDE lingua flag name(s) (without prefix(es)) appropriate for
321 ca-valencia) echo ca@valencia;;
322 sr-ijekavsk) echo sr@ijekavian;;
323 sr-Latn-ijekavsk) echo sr@ijekavianlatin;;
324 sr-Latn) echo sr@latin;;
325 uz-Cyrl) echo uz@cyrillic;;
331 # @FUNCTION: punt_bogus_dep
332 # @USAGE: <prefix> <dependency>
334 # Removes a specified dependency from a find_package call with multiple components.
339 if [[ ! -e "CMakeLists.txt" ]]; then
343 pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
345 # pcregrep returns non-zero on no matches/error
346 if [[ $? != 0 ]] ; then
350 local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1)
351 local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1)
352 local last=$(( ${length} + ${first} - 1))
354 sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
356 if [[ ${length} = 1 ]] ; then
357 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