net-wireless/hostapd: use #!/sbin/openrc-run instead of #!/sbin/runscript
[gentoo.git] / eclass / kde5-functions.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: kde5-functions.eclass
6 # @MAINTAINER:
7 # kde@gentoo.org
8 # @BLURB: Common ebuild functions for KDE 5 packages
9 # @DESCRIPTION:
10 # This eclass contains all functions shared by the different eclasses,
11 # for KDE 5 ebuilds.
12
13 if [[ -z ${_KDE5_FUNCTIONS_ECLASS} ]]; then
14 _KDE5_FUNCTIONS_ECLASS=1
15
16 inherit toolchain-funcs versionator
17
18 # @ECLASS-VARIABLE: EAPI
19 # @DESCRIPTION:
20 # Currently EAPI 5 and 6 is supported.
21 case ${EAPI} in
22         5|6) ;;
23         *) die "EAPI=${EAPI:-0} is not supported" ;;
24 esac
25
26 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
27 # @DESCRIPTION:
28 # Minimal Frameworks version to require for the package.
29 : ${FRAMEWORKS_MINIMAL:=5.18.0}
30
31 # @ECLASS-VARIABLE: PLASMA_MINIMAL
32 # @DESCRIPTION:
33 # Minimal Plasma version to require for the package.
34 : ${PLASMA_MINIMAL:=5.4.1}
35
36 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
37 # @DESCRIPTION:
38 # Minimal KDE Applications version to require for the package.
39 : ${KDE_APPS_MINIMAL:=14.12.0}
40
41 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
42 # @DESCRIPTION:
43 # Minimal GCC version to require for the package.
44 if [[ ${CATEGORY} = kde-frameworks ]]; then
45         : ${KDE_GCC_MINIMAL:=4.5}
46 else
47         : ${KDE_GCC_MINIMAL:=4.8}
48 fi
49
50
51 # @ECLASS-VARIABLE: KDEBASE
52 # @DESCRIPTION:
53 # This gets set to a non-zero value when a package is considered a
54 # kdevelop ebuild.
55 if [[ ${KMNAME-${PN}} = kdevelop ]]; then
56         KDEBASE=kdevelop
57 fi
58
59 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
60
61 # @ECLASS-VARIABLE: KDE_SCM
62 # @DESCRIPTION:
63 # SCM to use if this is a live ebuild.
64 : ${KDE_SCM:=git}
65
66 case ${KDE_SCM} in
67         git) ;;
68         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
69 esac
70
71 # determine the build type
72 if [[ ${PV} = *9999* ]]; then
73         KDE_BUILD_TYPE="live"
74 else
75         KDE_BUILD_TYPE="release"
76 fi
77 export KDE_BUILD_TYPE
78
79 # @FUNCTION: _check_gcc_version
80 # @INTERNAL
81 # @DESCRIPTION:
82 # Determine if the current GCC version is acceptable, otherwise die.
83 _check_gcc_version() {
84         if [[ ${MERGE_TYPE} != binary ]]; then
85                 local version=$(gcc-version)
86                 local major=${version%.*}
87                 local minor=${version#*.}
88                 local min_major=${KDE_GCC_MINIMAL%.*}
89                 local min_minor=${KDE_GCC_MINIMAL#*.}
90
91                 [[ ${major} -lt ${min_major} ]] || \
92                                 ( [[ ${major} -eq ${min_major} && ${minor} -lt ${min_minor} ]] ) \
93                         && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is required for this package."
94         fi
95 }
96
97 # @FUNCTION: _add_category_dep
98 # @INTERNAL
99 # @DESCRIPTION:
100 # Implementation of add_plasma_dep, add_frameworks_dep, add_kdeapps_dep,
101 # and finally, add_qt_dep.
102 _add_category_dep() {
103         debug-print-function ${FUNCNAME} "$@"
104
105         local category=${1}
106         local package=${2}
107         local use=${3}
108         local version=${4}
109         local slot=${5}
110
111         if [[ -n ${use} ]] ; then
112                 local use="[${use}]"
113         fi
114
115         if [[ -n ${version} ]] ; then
116                 local operator=">="
117                 local version="-$(get_version_component_range 1-3 ${version})"
118         fi
119
120         if [[ -n ${slot} ]] ; then
121                 slot=":${slot}"
122         elif [[ ${SLOT%\/*} = 4 || ${SLOT%\/*} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
123                 slot=":${SLOT%\/*}"
124         fi
125
126         echo " ${operator}${category}/${package}${version}${slot}${use}"
127 }
128
129 # @FUNCTION: add_frameworks_dep
130 # @USAGE: <package> [USE flags] [minimum version]
131 # @DESCRIPTION:
132 # Create proper dependency for kde-frameworks/ dependencies.
133 # This takes 1 to 4 arguments. The first being the package name, the optional
134 # second is additional USE flags to append, and the optional third is the
135 # version to use instead of the automatic version (use sparingly). In addition,
136 # the optional fourth argument defines slot+operator instead of automatic slot
137 # (use even more sparingly).
138 # The output of this should be added directly to DEPEND/RDEPEND, and may be
139 # wrapped in a USE conditional (but not an || conditional without an extra set
140 # of parentheses).
141 add_frameworks_dep() {
142         debug-print-function ${FUNCNAME} "$@"
143
144         local version
145
146         if [[ -n ${3} ]]; then
147                 version=${3}
148         elif [[ ${CATEGORY} = kde-frameworks ]]; then
149                 version=$(get_version_component_range 1-2)
150         elif [[ -z "${version}" ]] ; then
151                 version=${FRAMEWORKS_MINIMAL}
152         fi
153
154         _add_category_dep kde-frameworks "${1}" "${2}" "${version}" "${4}"
155 }
156
157 # @FUNCTION: add_plasma_dep
158 # @USAGE: <package> [USE flags] [minimum version]
159 # @DESCRIPTION:
160 # Create proper dependency for kde-plasma/ dependencies.
161 # This takes 1 to 4 arguments. The first being the package name, the optional
162 # second is additional USE flags to append, and the optional third is the
163 # version to use instead of the automatic version (use sparingly). In addition,
164 # the optional fourth argument defines slot+operator instead of automatic slot
165 # (use even more sparingly).
166 # The output of this should be added directly to DEPEND/RDEPEND, and may be
167 # wrapped in a USE conditional (but not an || conditional without an extra set
168 # of parentheses).
169 add_plasma_dep() {
170         debug-print-function ${FUNCNAME} "$@"
171
172         local version
173
174         if [[ -n ${3} ]]; then
175                 version=${3}
176         elif [[ ${CATEGORY} = kde-plasma ]]; then
177                 version=${PV}
178         elif [[ -z "${version}" ]] ; then
179                 version=${PLASMA_MINIMAL}
180         fi
181
182         _add_category_dep kde-plasma "${1}" "${2}" "${version}" "${4}"
183 }
184
185 # @FUNCTION: add_kdeapps_dep
186 # @USAGE: <package> [USE flags] [minimum version]
187 # @DESCRIPTION:
188 # Create proper dependency for kde-apps/ dependencies.
189 # This takes 1 to 4 arguments. The first being the package name, the optional
190 # second is additional USE flags to append, and the optional third is the
191 # version to use instead of the automatic version (use sparingly). In addition,
192 # the optional fourth argument defines slot+operator instead of automatic slot
193 # (use even more sparingly).
194 # The output of this should be added directly to DEPEND/RDEPEND, and may be
195 # wrapped in a USE conditional (but not an || conditional without an extra set
196 # of parentheses).
197 add_kdeapps_dep() {
198         debug-print-function ${FUNCNAME} "$@"
199
200         local version
201
202         if [[ -n ${3} ]]; then
203                 version=${3}
204         elif [[ ${CATEGORY} = kde-apps ]]; then
205                 version=${PV}
206         elif [[ -z "${version}" ]] ; then
207                 # In KDE applications world, 5.9999 > yy.mm.x
208                 if [[ ${PV} = 5.9999 || ${PV} = 9999 ]]; then
209                         version=5.9999
210                 else
211                         version=${KDE_APPS_MINIMAL}
212                 fi
213         fi
214
215         _add_category_dep kde-apps "${1}" "${2}" "${version}" "${4}"
216 }
217
218 # @FUNCTION: add_qt_dep
219 # @USAGE: <package> [USE flags] [minimum version]
220 # @DESCRIPTION:
221 # Create proper dependency for dev-qt/ dependencies.
222 # This takes 1 to 4 arguments. The first being the package name, the optional
223 # second is additional USE flags to append, and the optional third is the
224 # version to use instead of the automatic version (use sparingly). In addition,
225 # the optional fourth argument defines slot+operator instead of automatic slot
226 # (use even more sparingly).
227 # The output of this should be added directly to DEPEND/RDEPEND, and may be
228 # wrapped in a USE conditional (but not an || conditional without an extra set
229 # of parentheses).
230 add_qt_dep() {
231         debug-print-function ${FUNCNAME} "$@"
232
233         local version
234
235         if [[ -n ${3} ]]; then
236                 version=${3}
237         elif [[ -z "${version}" ]] ; then
238                 version=${QT_MINIMAL}
239         fi
240
241         _add_category_dep dev-qt "${1}" "${2}" "${version}" "${4}"
242 }
243
244 # @FUNCTION: get_kde_version
245 # @DESCRIPTION:
246 # Translates an ebuild version into a major.minor KDE SC
247 # release version. If no version is specified, ${PV} is used.
248 get_kde_version() {
249         local ver=${1:-${PV}}
250         local major=$(get_major_version ${ver})
251         local minor=$(get_version_component_range 2 ${ver})
252         local micro=$(get_version_component_range 3 ${ver})
253         if [[ ${ver} == 9999 ]]; then
254                 echo live
255         else
256                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
257         fi
258 }
259
260 # @FUNCTION: punt_bogus_dep
261 # @USAGE: <prefix> <dependency>
262 # @DESCRIPTION:
263 # Removes a specified dependency from a find_package call with multiple components.
264 punt_bogus_dep() {
265         local prefix=${1}
266         local dep=${2}
267
268         pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
269
270         # pcregrep returns non-zero on no matches/error
271         if [[ $? != 0 ]] ; then
272                 return
273         fi
274
275         local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1)
276         local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1)
277         local last=$(( ${length} + ${first} - 1))
278
279         sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
280
281         if [[ ${length} = 1 ]] ; then
282                 sed -e "/find_package\s*(\s*${prefix}\(\s\+\(REQUIRED\|CONFIG\|COMPONENTS\|\${KF5_VERSION}\)\)\+\s*)/Is/^/# removed by kde5-functions.eclass - /" -i CMakeLists.txt || die
283         fi
284 }
285
286 fi