kde5.eclass: Add KDE_PO_DIRS
[gentoo.git] / eclass / kde5-functions.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: kde5-functions.eclass
5 # @MAINTAINER:
6 # kde@gentoo.org
7 # @SUPPORTED_EAPIS: 6
8 # @BLURB: Common ebuild functions for packages based on KDE Frameworks 5.
9 # @DESCRIPTION:
10 # This eclass contains functions shared by the other KDE eclasses and forms
11 # part of their public API.
12 #
13 # This eclass should (almost) never be inherited directly by an ebuild.
14
15 if [[ -z ${_KDE5_FUNCTIONS_ECLASS} ]]; then
16 _KDE5_FUNCTIONS_ECLASS=1
17
18 inherit toolchain-funcs versionator
19
20 case ${EAPI} in
21         6) ;;
22         *) die "EAPI=${EAPI:-0} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: KDE_BUILD_TYPE
26 # @DESCRIPTION:
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
31         KDE_BUILD_TYPE="live"
32 fi
33 export KDE_BUILD_TYPE
34
35 case ${CATEGORY} in
36         kde-frameworks)
37                 [[ ${KDE_BUILD_TYPE} = live ]] && : ${FRAMEWORKS_MINIMAL:=9999}
38                 ;;
39         kde-plasma)
40                 if [[ ${KDE_BUILD_TYPE} = live ]]; then
41                         : ${QT_MINIMAL:=5.9.1}
42                         : ${FRAMEWORKS_MINIMAL:=9999}
43                 fi
44                 ;;
45         kde-apps)
46                 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 17.12* ]]; then
47                         : ${QT_MINIMAL:=5.9.1}
48                 fi
49                 ;;
50 esac
51
52 # @ECLASS-VARIABLE: QT_MINIMAL
53 # @DESCRIPTION:
54 # Minimum version of Qt to require. This affects add_qt_dep.
55 : ${QT_MINIMAL:=5.7.1}
56
57 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
58 # @DESCRIPTION:
59 # Minimum version of Frameworks to require. This affects add_frameworks_dep.
60 : ${FRAMEWORKS_MINIMAL:=5.40.0}
61
62 # @ECLASS-VARIABLE: PLASMA_MINIMAL
63 # @DESCRIPTION:
64 # Minimum version of Plasma to require. This affects add_plasma_dep.
65 : ${PLASMA_MINIMAL:=5.10.5}
66
67 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
68 # @DESCRIPTION:
69 # Minimum version of KDE Applications to require. This affects add_kdeapps_dep.
70 : ${KDE_APPS_MINIMAL:=14.12.0}
71
72 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
73 # @DEFAULT_UNSET
74 # @DESCRIPTION:
75 # Minimum version of active GCC to require. This is checked in kde5.eclass in
76 # kde5_pkg_pretend and kde5_pkg_setup.
77
78 # @ECLASS-VARIABLE: KDEBASE
79 # @DEFAULT_UNSET
80 # @DESCRIPTION:
81 # This gets set to a non-zero value when a package is considered a
82 # kdevelop ebuild.
83 if [[ ${KMNAME-${PN}} = kdevelop ]]; then
84         KDEBASE=kdevelop
85 fi
86
87 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
88
89 # @ECLASS-VARIABLE: KDE_SCM
90 # @DESCRIPTION:
91 # SCM to use if KDE_BUILD_TYPE is determined to be "live".
92 # Currently, only git is supported.
93 : ${KDE_SCM:=git}
94
95 case ${KDE_SCM} in
96         git) ;;
97         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
98 esac
99
100 # @FUNCTION: _check_gcc_version
101 # @INTERNAL
102 # @DESCRIPTION:
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
106
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#*.}
112
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}"
121
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})."
125         fi
126 }
127
128 # @FUNCTION: _add_category_dep
129 # @INTERNAL
130 # @DESCRIPTION:
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} "$@"
135
136         local category=${1}
137         local package=${2}
138         local use=${3}
139         local version=${4}
140         local slot=${5}
141
142         if [[ -n ${use} ]] ; then
143                 local use="[${use}]"
144         fi
145
146         if [[ -n ${version} ]] ; then
147                 local operator=">="
148                 local version="-${version}"
149         fi
150
151         if [[ -n ${slot} ]] ; then
152                 slot=":${slot}"
153         elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
154                 slot=":${SLOT%\/*}"
155         fi
156
157         echo " ${operator}${category}/${package}${version}${slot}${use}"
158 }
159
160 # @FUNCTION: add_frameworks_dep
161 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
162 # @DESCRIPTION:
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
171 # of parentheses).
172 add_frameworks_dep() {
173         debug-print-function ${FUNCNAME} "$@"
174
175         if [[ $# -gt 4 ]]; then
176                 die "${FUNCNAME} was called with too many arguments"
177         fi
178
179         local version
180
181         if [[ -n ${3} ]]; then
182                 version=${3}
183         elif [[ ${CATEGORY} = kde-frameworks ]]; then
184                 version=$(get_version_component_range 1-2)
185         elif [[ -z ${3} ]] ; then
186                 version=${FRAMEWORKS_MINIMAL}
187         fi
188
189         _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
190 }
191
192 # @FUNCTION: add_plasma_dep
193 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
194 # @DESCRIPTION:
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
203 # of parentheses).
204 add_plasma_dep() {
205         debug-print-function ${FUNCNAME} "$@"
206
207         if [[ $# -gt 4 ]]; then
208                 die "${FUNCNAME} was called with too many arguments"
209         fi
210
211         local version
212
213         if [[ -n ${3} ]]; then
214                 version=${3}
215         elif [[ ${CATEGORY} = kde-plasma ]]; then
216                 version=$(get_version_component_range 1-3)
217         elif [[ -z ${3} ]] ; then
218                 version=${PLASMA_MINIMAL}
219         fi
220
221         _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
222 }
223
224 # @FUNCTION: add_kdeapps_dep
225 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
226 # @DESCRIPTION:
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
235 # of parentheses).
236 add_kdeapps_dep() {
237         debug-print-function ${FUNCNAME} "$@"
238
239         if [[ $# -gt 4 ]]; then
240                 die "${FUNCNAME} was called with too many arguments"
241         fi
242
243         local version
244
245         if [[ -n ${3} ]]; then
246                 version=${3}
247         elif [[ ${CATEGORY} = kde-apps ]]; then
248                 version=$(get_version_component_range 1-3)
249         elif [[ -z ${3} ]] ; then
250                 version=${KDE_APPS_MINIMAL}
251         fi
252
253         _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
254 }
255
256 # @FUNCTION: add_qt_dep
257 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
258 # @DESCRIPTION:
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
267 # of parentheses).
268 add_qt_dep() {
269         debug-print-function ${FUNCNAME} "$@"
270
271         if [[ $# -gt 4 ]]; then
272                 die "${FUNCNAME} was called with too many arguments"
273         fi
274
275         local version=${3}
276         local slot=${4}
277
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
281                 else
282                         version=${QT_MINIMAL}
283                 fi
284         fi
285         if [[ -z ${slot} ]]; then
286                 slot="5"
287         fi
288
289         _add_category_dep dev-qt "${1}" "${2}" "${version}" "${slot}"
290 }
291
292 # @FUNCTION: get_kde_version [version]
293 # @DESCRIPTION:
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.
299 get_kde_version() {
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
305                 echo live
306         else
307                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
308         fi
309 }
310
311 # @FUNCTION: kde_l10n2lingua
312 # @USAGE: <l10n>...
313 # @INTERNAL
314 # @DESCRIPTION:
315 # Output KDE lingua flag name(s) (without prefix(es)) appropriate for
316 # given l10n(s).
317 kde_l10n2lingua() {
318         local l
319         for l; do
320                 case ${l} in
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;;
326                         *) echo "${l/-/_}";;
327                 esac
328         done
329 }
330
331 # @FUNCTION: punt_bogus_dep
332 # @USAGE: <prefix> <dependency>
333 # @DESCRIPTION:
334 # Removes a specified dependency from a find_package call with multiple components.
335 punt_bogus_dep() {
336         local prefix=${1}
337         local dep=${2}
338
339         if [[ ! -e "CMakeLists.txt" ]]; then
340                 return
341         fi
342
343         pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
344
345         # pcregrep returns non-zero on no matches/error
346         if [[ $? != 0 ]] ; then
347                 return
348         fi
349
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))
353
354         sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
355
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
358         fi
359 }
360
361 fi