1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: kde5-functions.eclass
8 # @BLURB: Common ebuild functions for KDE 5 packages
10 # This eclass contains all functions shared by the different eclasses,
13 if [[ -z ${_KDE5_FUNCTIONS_ECLASS} ]]; then
14 _KDE5_FUNCTIONS_ECLASS=1
16 inherit toolchain-funcs versionator
18 # @ECLASS-VARIABLE: EAPI
20 # Currently EAPI 5 is supported.
23 *) die "EAPI=${EAPI:-0} is not supported" ;;
26 # @ECLASS-VARIABLE: FRAMEWORKS_MINIMAL
28 # Minimal Frameworks version to require for the package.
29 : ${FRAMEWORKS_MINIMAL:=5.15.0}
31 # @ECLASS-VARIABLE: PLASMA_MINIMAL
33 # Minimal Plasma version to require for the package.
34 : ${PLASMA_MINIMAL:=5.4.1}
36 # @ECLASS-VARIABLE: KDE_APPS_MINIMAL
38 # Minimal KDE Applicaions version to require for the package.
39 : ${KDE_APPS_MINIMAL:=14.12.0}
41 # @ECLASS-VARIABLE: KDE_GCC_MINIMAL
43 # Minimal GCC version to require for the package.
44 : ${KDE_GCC_MINIMAL:=4.8}
46 # @ECLASS-VARIABLE: KDEBASE
48 # This gets set to a non-zero value when a package is considered a kde or
50 if [[ ${CATEGORY} = kde-base ]]; then
52 elif [[ ${CATEGORY} = kde-frameworks ]]; then
53 KDEBASE=kde-frameworks
54 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
58 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
60 # @ECLASS-VARIABLE: KDE_SCM
62 # SCM to use if this is a live ebuild.
67 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
70 # determine the build type
71 if [[ ${PV} = *9999* ]]; then
74 KDE_BUILD_TYPE="release"
78 # @FUNCTION: _check_gcc_version
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#*.}
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."
96 # @FUNCTION: _add_kdecategory_dep
99 # Implementation of add_plasma_dep and add_frameworks_dep.
100 _add_kdecategory_dep() {
101 debug-print-function ${FUNCNAME} "$@"
109 if [[ -n ${use} ]] ; then
113 if [[ -n ${version} ]] ; then
115 local version="-$(get_version_component_range 1-3 ${version})"
118 if [[ ${SLOT} = 4 || ${SLOT} = 5 ]] && ! has kde5-meta-pkg ${INHERITED} ; then
122 echo " ${operator}${category}/${package}${version}${slot}${use}"
125 # @FUNCTION: add_frameworks_dep
126 # @USAGE: <package> [USE flags] [minimum version]
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
135 add_frameworks_dep() {
136 debug-print-function ${FUNCNAME} "$@"
140 if [[ -n ${3} ]]; then
142 elif [[ ${CATEGORY} = kde-frameworks ]]; then
143 version=$(get_version_component_range 1-2)
144 elif [[ -z "${version}" ]] ; then
145 version=${FRAMEWORKS_MINIMAL}
148 _add_kdecategory_dep kde-frameworks "${1}" "${2}" "${version}"
151 # @FUNCTION: add_plasma_dep
152 # @USAGE: <package> [USE flags] [minimum version]
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
162 debug-print-function ${FUNCNAME} "$@"
166 if [[ -n ${3} ]]; then
168 elif [[ ${CATEGORY} = kde-plasma ]]; then
170 elif [[ -z "${version}" ]] ; then
171 version=${PLASMA_MINIMAL}
174 _add_kdecategory_dep kde-plasma "${1}" "${2}" "${version}"
177 # @FUNCTION: add_kdeapps_dep
178 # @USAGE: <package> [USE flags] [minimum version]
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
188 debug-print-function ${FUNCNAME} "$@"
192 if [[ -n ${3} ]]; then
194 elif [[ ${CATEGORY} = kde-apps ]]; then
196 elif [[ -z "${version}" ]] ; then
197 # In KDE applications world, 5.9999 > yy.mm.x
198 if [[ ${PV} = 5.9999 || ${PV} = 9999 ]]; then
201 version=${KDE_APPS_MINIMAL}
205 _add_kdecategory_dep kde-apps "${1}" "${2}" "${version}"
208 # @FUNCTION: get_kde_version
210 # Translates an ebuild version into a major.minor KDE SC
211 # release version. If no version is specified, ${PV} is used.
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
220 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
224 # @FUNCTION: punt_bogus_dep
225 # @USAGE: <prefix> <dependency>
227 # Removes a specified dependency from a find_package call with multiple components.
232 pcregrep -Mni "(?s)find_package\s*\(\s*${prefix}.[^)]*?${dep}.*?\)" CMakeLists.txt > "${T}/bogus${dep}"
234 # pcregrep returns non-zero on no matches/error
235 if [[ $? != 0 ]] ; then
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))
243 sed -e "${first},${last}s/${dep}//" -i CMakeLists.txt || die
245 if [[ ${length} = 1 ]] ; then
246 sed -e "/find_package\s*(\s*${prefix}\s*REQUIRED\s*COMPONENTS\s*)/I d" -i CMakeLists.txt || die