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