1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: kde4-functions.eclass
7 # @BLURB: Common ebuild functions for KDE 4 packages
9 # This eclass contains all functions shared by the different eclasses,
12 if [[ -z ${_KDE4_FUNCTIONS_ECLASS} ]]; then
13 _KDE4_FUNCTIONS_ECLASS=1
17 # @ECLASS-VARIABLE: EAPI
19 # Currently kde4 eclasses support EAPI 5 and 6.
22 *) die "EAPI=${EAPI:-0} is not supported" ;;
25 # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
27 # For use only in very few well-defined cases; normally it should be unset.
28 # If this variable is set, all calls to add_kdebase_dep return a dependency on
29 # at least this version, independent of the version of the package itself.
30 # If you know exactly that one specific NEW KDE component builds and runs fine
31 # with all the rest of KDE at an OLDER version, you can set this old version here.
32 # Warning- may lead to general instability and kill your pet targh.
34 # @ECLASS-VARIABLE: KDEBASE
36 # This gets set to a non-zero value when a package is considered a kde or
38 if [[ ${CATEGORY} = kde-base || ${CATEGORY} == kde-plasma || ${CATEGORY} = kde-apps || ${CATEGORY} = kde-frameworks ]]; then
39 debug-print "${ECLASS}: KDEBASE ebuild recognized"
41 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
45 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
47 # determine the build type
48 if [[ ${PV} = *9999* ]]; then
51 KDE_BUILD_TYPE="release"
55 # Set reponame and SCM for modules that have fully migrated to git
56 # (hack - it's here because it needs to be before SCM inherits from kde4-base)
57 if [[ ${KDE_BUILD_TYPE} == live ]]; then
60 EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
63 EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
68 # @ECLASS-VARIABLE: KDE_SCM
70 # If this is a live package which scm does it use
71 # Everything else uses git by default
72 KDE_SCM="${KDE_SCM:-git}"
75 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
78 # @FUNCTION: kde4_lingua_to_l10n
82 # Output l10n flag name(s) (without prefix(es)) appropriate for given KDE
84 kde4_lingua_to_l10n() {
88 ca@valencia) echo ca-valencia;;
89 sr@ijekavian) echo sr-ijekavsk;;
90 sr@ijekavianlatin) echo sr-Latn-ijekavsk;;
91 sr@latin|sr@Latn) echo sr-Latn;;
92 uz@cyrillic) echo uz-Cyrl;;
93 *@*) die "${FUNCNAME}: Unhandled KDE_LINGUAS: ${l}";;
99 # @ECLASS-VARIABLE: KDE_LINGUAS
101 # This is a whitespace-separated list of translations this ebuild supports.
102 # These translations are automatically added to IUSE. Therefore ebuilds must set
103 # this variable before inheriting any eclasses. To enable only selected
104 # translations, ebuilds must call enable_selected_linguas(). kde4-{base,meta}.eclass does
107 # Example: KDE_LINGUAS="de en_GB nl"
108 if [[ ${KDE_BUILD_TYPE} != live || -n ${KDE_LINGUAS_LIVE_OVERRIDE} ]]; then
109 for _lingua in $(kde4_lingua_to_l10n ${KDE_LINGUAS}); do
110 IUSE="${IUSE} l10n_${_lingua}"
114 # @FUNCTION: buildsycoca
116 # Function to rebuild the KDE System Configuration Cache.
117 # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
119 debug-print-function ${FUNCNAME} "$@"
121 # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
123 # fix permission for some directories
124 for x in usr/share/{config,kde4}; do
126 [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
128 if use userland_BSD ; then
129 [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
132 [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
135 if [[ $stat_rtn != 1 ]] ; then
137 ewarn "Package ${PN} is breaking ${EROOT}${x} permissions."
138 ewarn "Please report this issue to gentoo bugzilla."
139 einfo "Permissions will get adjusted automatically now."
140 find "${EROOT}${x}" -type d -print0 | xargs -0 chmod 755
145 # @FUNCTION: comment_all_add_subdirectory
146 # @USAGE: [list of directory names]
148 # Recursively comment all add_subdirectory instructions in listed directories,
149 # except those in cmake/.
150 comment_all_add_subdirectory() {
151 find "$@" -name CMakeLists.txt -print0 | grep -vFzZ "./cmake" | \
153 -e '/^[[:space:]]*add_subdirectory/s/^/#DONOTCOMPILE /' \
154 -e '/^[[:space:]]*ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
155 -e '/^[[:space:]]*macro_optional_add_subdirectory/s/^/#DONOTCOMPILE /' \
156 -e '/^[[:space:]]*MACRO_OPTIONAL_ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
157 || die "${LINENO}: Initial sed died"
160 # @FUNCTION: enable_selected_linguas
162 # Enable translations based on L10N settings and translations supported by
163 # the package (see KDE_LINGUAS). By default, translations are found in "${S}"/po
164 # but this default can be overridden by defining KDE_LINGUAS_DIR.
165 enable_selected_linguas() {
166 debug-print-function ${FUNCNAME} "$@"
170 # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
172 # Specified folder where application translations are located.
173 # Can be defined as array of folders where translations are located.
174 # Note that space separated list of dirs is not supported.
175 # Default value is set to "po".
176 if [[ "$(declare -p KDE_LINGUAS_DIR 2>/dev/null 2>&1)" == "declare -a"* ]]; then
177 debug-print "$FUNCNAME: we have these subfolders defined: ${KDE_LINGUAS_DIR}"
178 for x in ${KDE_LINGUAS_DIR[@]}; do
179 _enable_selected_linguas_dir ${x}
182 KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
183 _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
187 # @FUNCTION: enable_selected_doc_linguas
189 # Enable only selected L10N enabled doc folders.
190 enable_selected_doc_linguas() {
191 debug-print-function ${FUNCNAME} "$@"
193 # @ECLASS-VARIABLE: KDE_DOC_DIRS
195 # Variable specifying whitespace separated patterns for documentation locations.
196 # Default is "doc/%lingua"
197 KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
199 for pattern in ${KDE_DOC_DIRS}; do
201 local handbookdir=`dirname ${pattern}`
202 local translationdir=`basename ${pattern}`
203 # Do filename pattern supplied, treat as directory
204 [[ ${handbookdir} = '.' ]] && handbookdir=${translationdir} && translationdir=
205 [[ -d ${handbookdir} ]] || die 'wrong doc dir specified'
207 if ! use handbook; then
208 # Disable whole directory
209 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
210 -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
211 -i CMakeLists.txt || die 'failed to comment out all handbooks'
213 # Disable subdirectories recursively
214 comment_all_add_subdirectory "${handbookdir}"
216 # In certain packages, the default handbook is en_US instead of the usual en. Since there is no en_US 'translation',
217 # it makes no sense to add to KDE_LINGUAS which causes this type of handbook to not be installed.
218 if [[ -d "${handbookdir}/en_US" && ! -d "${handbookdir}/en" ]]; then
219 mv "${handbookdir}/en_US" "${handbookdir}/en" || die
220 sed -e "s/en_US/en/" -i "${handbookdir}/CMakeLists.txt"
223 # Add requested translations
225 for lingua in en ${KDE_LINGUAS}; do
226 if [[ ${lingua} = en ]] || use "l10n_$(kde4_lingua_to_l10n "${lingua}")"; then
227 if [[ -d ${handbookdir}/${translationdir//%lingua/${lingua}} ]]; then
228 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
229 -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
230 -i "${handbookdir}"/CMakeLists.txt && ! has ${lingua} ${linguas} && linguas="${linguas} ${lingua}"
237 [[ -n "${linguas}" ]] && einfo "Enabling handbook translations:${linguas}"
240 # Functions handling KMLOADLIBS and KMSAVELIBS
242 # @FUNCTION: save_library_dependencies
244 # Add exporting CMake dependencies for current package
245 save_library_dependencies() {
246 local depsfile="${T}/${PN}"
248 ebegin "Saving library dependencies in ${depsfile##*/}"
249 echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
250 die "Failed to save the library dependencies."
254 # @FUNCTION: install_library_dependencies
256 # Install generated CMake library dependencies to /var/lib/kde
257 install_library_dependencies() {
258 local depsfile="${T}/${PN}"
260 ebegin "Installing library dependencies as ${depsfile##*/}"
262 doins "${depsfile}" || die "Failed to install library dependencies."
266 # @FUNCTION: load_library_dependencies
268 # Inject specified library dependencies in current package
269 load_library_dependencies() {
271 ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
274 for pn in ${KMLOADLIBS} ; do
276 depsfile="${EPREFIX}/var/lib/kde/${pn}"
277 [[ -r ${depsfile} ]] || depsfile="${EPREFIX}/var/lib/kde/${pn}:$(get_kde_version)"
278 [[ -r ${depsfile} ]] || die "Depsfile '${depsfile}' not accessible. You probably need to reinstall ${pn}."
279 sed -i -e "${i}iINCLUDE(\"${depsfile}\")" "${S}/CMakeLists.txt" || \
280 die "Failed to include library dependencies for ${pn}"
285 # @FUNCTION: add_kdeapps_dep
287 # Create proper dependency for kde-apps/ dependencies.
288 # This takes 1 to 3 arguments. The first being the package name, the optional
289 # second is additional USE flags to append, and the optional third is the
290 # version to use instead of the automatic version (use sparingly).
291 # The output of this should be added directly to DEPEND/RDEPEND, and may be
292 # wrapped in a USE conditional (but not an || conditional without an extra set
295 debug-print-function ${FUNCNAME} "$@"
299 if [[ -n ${2} ]] ; then
303 if [[ -n ${3} ]]; then
305 elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
306 ver=${KDE_OVERRIDE_MINIMAL}
307 elif [[ ${KDEBASE} != kde-base ]]; then
309 # if building kde-apps, live master or stable-live branch,
310 # use the final SC version since there are no further general releases.
311 # except when it is kdepim split packages, which rely on same-version deps
312 elif [[ ${CATEGORY} == kde-apps || ${PV} == *9999 ]] && [[ ${KMNAME} != "kdepim" ]]; then
318 [[ -z ${1} ]] && die "Missing parameter"
320 echo " >=kde-apps/${1}-${ver}:4${use}"
323 # @FUNCTION: add_kdebase_dep
325 # Create proper dependency for kde-base/ dependencies.
326 # This takes 1 to 3 arguments. The first being the package name, the optional
327 # second is additional USE flags to append, and the optional third is the
328 # version to use instead of the automatic version (use sparingly).
329 # The output of this should be added directly to DEPEND/RDEPEND, and may be
330 # wrapped in a USE conditional (but not an || conditional without an extra set
333 debug-print-function ${FUNCNAME} "$@"
337 if [[ -n ${2} ]] ; then
341 if [[ -n ${3} ]]; then
343 elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
344 ver=${KDE_OVERRIDE_MINIMAL}
345 elif [[ ${KDEBASE} != kde-base ]]; then
347 # if building live master or kde-apps, use the final SC version
348 # since there are no further general releases.
349 elif [[ ${CATEGORY} == kde-apps || ${PV} == 9999 ]]; then
351 # if building a live version branch (eg. 4.11.49.9999) use the major version
352 elif [[ ${PV} == *.9999 ]]; then
353 ver=$(get_kde_version)
358 [[ -z ${1} ]] && die "Missing parameter"
360 echo " >=kde-base/${1}-${ver}:4${use}"
363 # local function to enable specified translations for specified directory
364 # used from kde4-functions_enable_selected_linguas function
365 _enable_selected_linguas_dir() {
366 local lingua linguas sr_mess wp
369 [[ -d ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
370 comment_all_add_subdirectory "${dir}"
371 pushd "${dir}" > /dev/null || die
373 # fix all various crazy sr@Latn variations
374 # this part is only ease for ebuilds, so there wont be any die when this
376 sr_mess="sr@latn sr@latin sr@Latin"
377 for wp in ${sr_mess}; do
378 [[ -e ${wp}.po ]] && mv "${wp}.po" "sr@Latn.po"
379 if [[ -d ${wp} ]]; then
380 # move dir and fix cmakelists
383 -e "s:${wp}:sr@Latn:g" \
388 for lingua in ${KDE_LINGUAS}; do
389 if [[ -e ${lingua}.po ]]; then
390 mv "${lingua}.po" "${lingua}.po.old"
394 for lingua in ${KDE_LINGUAS}; do
395 if use "l10n_$(kde4_lingua_to_l10n ${lingua})" ; then
396 if [[ -d ${lingua} ]]; then
397 linguas="${linguas} ${lingua}"
398 sed -e "/add_subdirectory([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
399 -e "/ADD_SUBDIRECTORY([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
400 -i CMakeLists.txt || die "Sed to uncomment linguas_${lingua} failed."
402 if [[ -e ${lingua}.po.old ]]; then
403 linguas="${linguas} ${lingua}"
404 mv "${lingua}.po.old" "${lingua}.po"
408 [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
410 popd > /dev/null || die
413 # @FUNCTION: get_kde_version
415 # Translates an ebuild version into a major.minor KDE SC
416 # release version. If no version is specified, ${PV} is used.
418 local ver=${1:-${PV}}
419 local major=$(get_major_version ${ver})
420 local minor=$(get_version_component_range 2 ${ver})
421 local micro=$(get_version_component_range 3 ${ver})
422 if [[ ${ver} == 9999 ]]; then
425 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))