x11-misc/alock: Take ownership of package
[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 is supported.
21 case ${EAPI} in
22         5) ;;
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.15.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 Applicaions 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 : ${KDE_GCC_MINIMAL:=4.8}
45
46 # @ECLASS-VARIABLE: KDEBASE
47 # @DESCRIPTION:
48 # This gets set to a non-zero value when a package is considered a kde or
49 # kdevelop ebuild.
50 if [[ ${CATEGORY} = kde-base ]]; then
51         KDEBASE=kde-base
52 elif [[ ${CATEGORY} = kde-frameworks ]]; then
53         KDEBASE=kde-frameworks
54 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
55         KDEBASE=kdevelop
56 fi
57
58 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
59
60 # @ECLASS-VARIABLE: KDE_SCM
61 # @DESCRIPTION:
62 # SCM to use if this is a live ebuild.
63 : ${KDE_SCM:=git}
64
65 case ${KDE_SCM} in
66         svn|git) ;;
67         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
68 esac
69
70 # determine the build type
71 if [[ ${PV} = *9999* ]]; then
72         KDE_BUILD_TYPE="live"
73 else
74         KDE_BUILD_TYPE="release"
75 fi
76 export KDE_BUILD_TYPE
77
78 # @FUNCTION: _check_gcc_version
79 # @INTERNAL
80 # @DESCRIPTION:
81 # Determine if the current GCC version is acceptable, otherwise die.
82 _check_gcc_version() {
83         if [[ ${MERGE_TYPE} != binary ]]; then
84                 local version=$(gcc-version)
85                 local major=${version%.*}
86                 local minor=${version#*.}
87                 local min_major=${KDE_GCC_MINIMAL%.*}
88                 local min_minor=${KDE_GCC_MINIMAL#*.}
89
90                 [[ ${major} -lt ${min_major} ]] || \
91                                 ( [[ ${major} -eq ${min_major} && ${minor} -lt ${min_minor} ]] ) \
92                         && die "Sorry, but gcc-${KDE_GCC_MINIMAL} or later is required for this package."
93         fi
94 }
95
96 # @FUNCTION: _add_kdecategory_dep
97 # @INTERNAL
98 # @DESCRIPTION:
99 # Implementation of add_plasma_dep and add_frameworks_dep.
100 _add_kdecategory_dep() {
101         debug-print-function ${FUNCNAME} "$@"
102
103         local category=${1}
104         local package=${2}
105         local use=${3}
106         local version=${4}
107         local slot=
108
109         if [[ -n ${use} ]] ; then
110                 local use="[${use}]"
111         fi
112
113         if [[ -n ${version} ]] ; then
114                 local operator=">="
115                 local version="-$(get_version_component_range 1-3 ${version})"
116         fi
117
118         if [[ ${SLOT} = 4 || ${SLOT} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
119                 slot=":${SLOT}"
120         fi
121
122         echo " ${operator}${category}/${package}${version}${slot}${use}"
123 }
124
125 # @FUNCTION: add_frameworks_dep
126 # @USAGE: <package> [USE flags] [minimum version]
127 # @DESCRIPTION:
128 # Create proper dependency for kde-frameworks/ dependencies.
129 # This takes 1 to 3 arguments. The first being the package name, the optional
130 # second is additional USE flags to append, and the optional third is the
131 # version to use instead of the automatic version (use sparingly).
132 # The output of this should be added directly to DEPEND/RDEPEND, and may be
133 # wrapped in a USE conditional (but not an || conditional without an extra set
134 # of parentheses).
135 add_frameworks_dep() {
136         debug-print-function ${FUNCNAME} "$@"
137
138         local version
139
140         if [[ -n ${3} ]]; then
141                 version=${3}
142         elif [[ ${CATEGORY} = kde-frameworks ]]; then
143                 version=$(get_version_component_range 1-2)
144         elif [[ -z "${version}" ]] ; then
145                 version=${FRAMEWORKS_MINIMAL}
146         fi
147
148         _add_kdecategory_dep kde-frameworks "${1}" "${2}" "${version}"
149 }
150
151 # @FUNCTION: add_plasma_dep
152 # @USAGE: <package> [USE flags] [minimum version]
153 # @DESCRIPTION:
154 # Create proper dependency for kde-base/ dependencies.
155 # This takes 1 to 3 arguments. The first being the package name, the optional
156 # second is additional USE flags to append, and the optional third is the
157 # version to use instead of the automatic version (use sparingly).
158 # The output of this should be added directly to DEPEND/RDEPEND, and may be
159 # wrapped in a USE conditional (but not an || conditional without an extra set
160 # of parentheses).
161 add_plasma_dep() {
162         debug-print-function ${FUNCNAME} "$@"
163
164         local version
165
166         if [[ -n ${3} ]]; then
167                 version=${3}
168         elif [[ ${CATEGORY} = kde-plasma ]]; then
169                 version=${PV}
170         elif [[ -z "${version}" ]] ; then
171                 version=${PLASMA_MINIMAL}
172         fi
173
174         _add_kdecategory_dep kde-plasma "${1}" "${2}" "${version}"
175 }
176
177 # @FUNCTION: add_kdeapps_dep
178 # @USAGE: <package> [USE flags] [minimum version]
179 # @DESCRIPTION:
180 # Create proper dependency for kde-apps/ dependencies.
181 # This takes 1 to 3 arguments. The first being the package name, the optional
182 # second is additional USE flags to append, and the optional third is the
183 # version to use instead of the automatic version (use sparingly).
184 # The output of this should be added directly to DEPEND/RDEPEND, and may be
185 # wrapped in a USE conditional (but not an || conditional without an extra set
186 # of parentheses).
187 add_kdeapps_dep() {
188         debug-print-function ${FUNCNAME} "$@"
189
190         local version
191
192         if [[ -n ${3} ]]; then
193                 version=${3}
194         elif [[ ${CATEGORY} = kde-apps ]]; then
195                 version=${PV}
196         elif [[ -z "${version}" ]] ; then
197                 # In KDE applications world, 5.9999 > yy.mm.x
198                 if [[ ${PV} = 5.9999 || ${PV} = 9999 ]]; then
199                         version=5.9999
200                 else
201                         version=${KDE_APPS_MINIMAL}
202                 fi
203         fi
204
205         _add_kdecategory_dep kde-apps "${1}" "${2}" "${version}"
206 }
207
208 # @FUNCTION: get_kde_version
209 # @DESCRIPTION:
210 # Translates an ebuild version into a major.minor KDE SC
211 # release version. If no version is specified, ${PV} is used.
212 get_kde_version() {
213         local ver=${1:-${PV}}
214         local major=$(get_major_version ${ver})
215         local minor=$(get_version_component_range 2 ${ver})
216         local micro=$(get_version_component_range 3 ${ver})
217         if [[ ${ver} == 9999 ]]; then
218                 echo live
219         else
220                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
221         fi
222 }
223
224 # @FUNCTION: punt_bogus_dep
225 # @USAGE: <prefix> <dependency>
226 # @DESCRIPTION:
227 # Removes a specified dependency from a find_package call with multiple components.
228 punt_bogus_dep() {
229         local prefix=${1}
230         local dep=${2}
231
232         pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}.[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
233
234         # pcregrep returns non-zero on no matches/error
235         if [[ $? != 0 ]] ; then
236                 return
237         fi
238
239         local length=$(wc -l "${T}/bogus${dep}" | cut -d " " -f 1)
240         local first=$(head -n 1 "${T}/bogus${dep}" | cut -d ":" -f 1)
241         local last=$(( ${length} + ${first} - 1))
242
243         sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
244
245         if [[ ${length} = 1 ]] ; then
246                 sed -e "/find_package\s*(\s*${prefix}\s*REQUIRED\s*COMPONENTS\s*)/I d" -i CMakeLists.txt || die
247         fi
248 }
249
250 fi