meson.eclass: Don't mix host *FLAGS with build *FLAGS
[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                 [[ ${PV} = 5.45* ]] && : ${QT_MINIMAL:=5.9.4}
38                 [[ ${KDE_BUILD_TYPE} = live ]] && : ${FRAMEWORKS_MINIMAL:=9999}
39                 ;;
40         kde-plasma)
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}
45                 fi
46                 ;;
47         kde-apps)
48                 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 18.04* ]]; then
49                         : ${FRAMEWORKS_MINIMAL:=5.44.0}
50                 fi
51                 if [[ ${KDE_BUILD_TYPE} = live || ${PV} = 17.12* ]]; then
52                         : ${QT_MINIMAL:=5.9.1}
53                 fi
54                 ;;
55 esac
56
57 # @ECLASS-VARIABLE: QT_MINIMAL
58 # @DESCRIPTION:
59 # Minimum version of Qt to require. This affects add_qt_dep.
60 : ${QT_MINIMAL:=5.7.1}
61
62 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
63 # @DESCRIPTION:
64 # Minimum version of Frameworks to require. This affects add_frameworks_dep.
65 : ${FRAMEWORKS_MINIMAL:=5.43.0}
66
67 # @ECLASS-VARIABLE: PLASMA_MINIMAL
68 # @DESCRIPTION:
69 # Minimum version of Plasma to require. This affects add_plasma_dep.
70 : ${PLASMA_MINIMAL:=5.11.5}
71
72 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
73 # @DESCRIPTION:
74 # Minimum version of KDE Applications to require. This affects add_kdeapps_dep.
75 : ${KDE_APPS_MINIMAL:=14.12.0}
76
77 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
78 # @DEFAULT_UNSET
79 # @DESCRIPTION:
80 # Minimum version of active GCC to require. This is checked in kde5.eclass in
81 # kde5_pkg_pretend and kde5_pkg_setup.
82
83 # @ECLASS-VARIABLE: KDEBASE
84 # @DEFAULT_UNSET
85 # @DESCRIPTION:
86 # This gets set to a non-zero value when a package is considered a
87 # kdevelop ebuild.
88 if [[ ${KMNAME-${PN}} = kdevelop ]]; then
89         KDEBASE=kdevelop
90 fi
91
92 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
93
94 # @ECLASS-VARIABLE: KDE_SCM
95 # @DESCRIPTION:
96 # SCM to use if KDE_BUILD_TYPE is determined to be "live".
97 # Currently, only git is supported.
98 : ${KDE_SCM:=git}
99
100 case ${KDE_SCM} in
101         git) ;;
102         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
103 esac
104
105 # @FUNCTION: _check_gcc_version
106 # @INTERNAL
107 # @DESCRIPTION:
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
111
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#*.}
117
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}"
126
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})."
130         fi
131 }
132
133 # @FUNCTION: _add_category_dep
134 # @INTERNAL
135 # @DESCRIPTION:
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} "$@"
140
141         local category=${1}
142         local package=${2}
143         local use=${3}
144         local version=${4}
145         local slot=${5}
146
147         if [[ -n ${use} ]] ; then
148                 local use="[${use}]"
149         fi
150
151         if [[ -n ${version} ]] ; then
152                 local operator=">="
153                 local version="-${version}"
154         fi
155
156         if [[ -n ${slot} ]] ; then
157                 slot=":${slot}"
158         elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
159                 slot=":${SLOT%\/*}"
160         fi
161
162         echo " ${operator}${category}/${package}${version}${slot}${use}"
163 }
164
165 # @FUNCTION: add_frameworks_dep
166 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
167 # @DESCRIPTION:
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
176 # of parentheses).
177 add_frameworks_dep() {
178         debug-print-function ${FUNCNAME} "$@"
179
180         if [[ $# -gt 4 ]]; then
181                 die "${FUNCNAME} was called with too many arguments"
182         fi
183
184         local version
185
186         if [[ -n ${3} ]]; then
187                 version=${3}
188         elif [[ ${CATEGORY} = kde-frameworks ]]; then
189                 version=$(get_version_component_range 1-2)
190         elif [[ -z ${3} ]] ; then
191                 version=${FRAMEWORKS_MINIMAL}
192         fi
193
194         _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
195 }
196
197 # @FUNCTION: add_plasma_dep
198 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
199 # @DESCRIPTION:
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
208 # of parentheses).
209 add_plasma_dep() {
210         debug-print-function ${FUNCNAME} "$@"
211
212         if [[ $# -gt 4 ]]; then
213                 die "${FUNCNAME} was called with too many arguments"
214         fi
215
216         local version
217
218         if [[ -n ${3} ]]; then
219                 version=${3}
220         elif [[ ${CATEGORY} = kde-plasma ]]; then
221                 version=$(get_version_component_range 1-3)
222         elif [[ -z ${3} ]] ; then
223                 version=${PLASMA_MINIMAL}
224         fi
225
226         _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
227 }
228
229 # @FUNCTION: add_kdeapps_dep
230 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
231 # @DESCRIPTION:
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
240 # of parentheses).
241 add_kdeapps_dep() {
242         debug-print-function ${FUNCNAME} "$@"
243
244         if [[ $# -gt 4 ]]; then
245                 die "${FUNCNAME} was called with too many arguments"
246         fi
247
248         local version
249
250         if [[ -n ${3} ]]; then
251                 version=${3}
252         elif [[ ${CATEGORY} = kde-apps ]]; then
253                 version=$(get_version_component_range 1-3)
254         elif [[ -z ${3} ]] ; then
255                 version=${KDE_APPS_MINIMAL}
256         fi
257
258         _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
259 }
260
261 # @FUNCTION: add_qt_dep
262 # @USAGE: <package name> [USE flags] [minimum version] [slot + operator]
263 # @DESCRIPTION:
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
272 # of parentheses).
273 add_qt_dep() {
274         debug-print-function ${FUNCNAME} "$@"
275
276         if [[ $# -gt 4 ]]; then
277                 die "${FUNCNAME} was called with too many arguments"
278         fi
279
280         local version=${3}
281         local slot=${4}
282
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
286                 else
287                         version=${QT_MINIMAL}
288                 fi
289         fi
290         if [[ -z ${slot} ]]; then
291                 slot="5"
292         fi
293
294         _add_category_dep dev-qt "${1}" "${2}" "${version}" "${slot}"
295 }
296
297 # @FUNCTION: get_kde_version [version]
298 # @DESCRIPTION:
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.
304 get_kde_version() {
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
310                 echo live
311         else
312                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
313         fi
314 }
315
316 # @FUNCTION: kde_l10n2lingua
317 # @USAGE: <l10n>...
318 # @INTERNAL
319 # @DESCRIPTION:
320 # Output KDE lingua flag name(s) (without prefix(es)) appropriate for
321 # given l10n(s).
322 kde_l10n2lingua() {
323         local l
324         for l; do
325                 case ${l} in
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;;
331                         *) echo "${l/-/_}";;
332                 esac
333         done
334 }
335
336 # @FUNCTION: punt_bogus_dep
337 # @USAGE: <prefix> <dependency>
338 # @DESCRIPTION:
339 # Removes a specified dependency from a find_package call with multiple components.
340 punt_bogus_dep() {
341         local prefix=${1}
342         local dep=${2}
343
344         if [[ ! -e "CMakeLists.txt" ]]; then
345                 return
346         fi
347
348         pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
349
350         # pcregrep returns non-zero on no matches/error
351         if [[ $? != 0 ]] ; then
352                 return
353         fi
354
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))
358
359         sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
360
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
363         fi
364 }
365
366 fi