1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: kde4-functions.eclass
8 # @BLURB: Common ebuild functions for KDE 4 packages
10 # This eclass contains all functions shared by the different eclasses,
13 if [[ -z ${_KDE4_FUNCTIONS_ECLASS} ]]; then
14 _KDE4_FUNCTIONS_ECLASS=1
18 # @ECLASS-VARIABLE: EAPI
20 # Currently kde4 eclasses support EAPI 5.
23 *) die "EAPI=${EAPI:-0} is not supported" ;;
26 # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
28 # For use only in very few well-defined cases; normally it should be unset.
29 # If this variable is set, all calls to add_kdebase_dep return a dependency on
30 # at least this version, independent of the version of the package itself.
31 # If you know exactly that one specific NEW KDE component builds and runs fine
32 # with all the rest of KDE at an OLDER version, you can set this old version here.
33 # Warning- may lead to general instability and kill your pet targh.
35 # @ECLASS-VARIABLE: KDEBASE
37 # This gets set to a non-zero value when a package is considered a kde or
39 if [[ ${CATEGORY} = kde-base || ${CATEGORY} = kde-apps || ${CATEGORY} = kde-frameworks ]]; then
40 debug-print "${ECLASS}: KDEBASE ebuild recognized"
42 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
46 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
48 # determine the build type
49 if [[ ${PV} = *9999* ]]; then
52 KDE_BUILD_TYPE="release"
56 # Set reponame and SCM for modules that have fully migrated to git
57 # (hack - it's here because it needs to be before SCM inherits from kde4-base)
58 if [[ ${KDE_BUILD_TYPE} == live ]]; then
61 EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
64 EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
69 # @ECLASS-VARIABLE: KDE_SCM
71 # If this is a live package which scm does it use
72 # Everything else uses git by default
73 KDE_SCM="${KDE_SCM:-git}"
76 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
79 # @ECLASS-VARIABLE: KDE_LINGUAS
81 # This is a whitespace-separated list of translations this ebuild supports.
82 # These translations are automatically added to IUSE. Therefore ebuilds must set
83 # this variable before inheriting any eclasses. To enable only selected
84 # translations, ebuilds must call enable_selected_linguas(). kde4-{base,meta}.eclass does
87 # Example: KDE_LINGUAS="de en_GB nl"
88 if [[ ${KDE_BUILD_TYPE} != live || -n ${KDE_LINGUAS_LIVE_OVERRIDE} ]]; then
89 for _lingua in ${KDE_LINGUAS}; do
90 IUSE="${IUSE} linguas_${_lingua}"
94 # @FUNCTION: buildsycoca
96 # Function to rebuild the KDE System Configuration Cache.
97 # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
99 debug-print-function ${FUNCNAME} "$@"
101 # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
103 # fix permission for some directories
104 for x in usr/share/{config,kde4}; do
106 [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
108 if use userland_BSD ; then
109 [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
112 [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
115 if [[ $stat_rtn != 1 ]] ; then
117 ewarn "Package ${PN} is breaking ${EROOT}${x} permissions."
118 ewarn "Please report this issue to gentoo bugzilla."
119 einfo "Permissions will get adjusted automatically now."
120 find "${EROOT}${x}" -type d -print0 | xargs -0 chmod 755
125 # @FUNCTION: comment_all_add_subdirectory
126 # @USAGE: [list of directory names]
128 # Recursively comment all add_subdirectory instructions in listed directories,
129 # except those in cmake/.
130 comment_all_add_subdirectory() {
131 find "$@" -name CMakeLists.txt -print0 | grep -vFzZ "./cmake" | \
133 -e '/^[[:space:]]*add_subdirectory/s/^/#DONOTCOMPILE /' \
134 -e '/^[[:space:]]*ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
135 -e '/^[[:space:]]*macro_optional_add_subdirectory/s/^/#DONOTCOMPILE /' \
136 -e '/^[[:space:]]*MACRO_OPTIONAL_ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
137 || die "${LINENO}: Initial sed died"
140 # @FUNCTION: enable_selected_linguas
142 # Enable translations based on LINGUAS settings and translations supported by
143 # the package (see KDE_LINGUAS). By default, translations are found in "${S}"/po
144 # but this default can be overridden by defining KDE_LINGUAS_DIR.
145 enable_selected_linguas() {
146 debug-print-function ${FUNCNAME} "$@"
150 # if there is no linguas defined we enable everything
151 if ! $(env | grep -q "^LINGUAS="); then
155 # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
157 # Specified folder where application translations are located.
158 # Can be defined as array of folders where translations are located.
159 # Note that space separated list of dirs is not supported.
160 # Default value is set to "po".
161 if [[ "$(declare -p KDE_LINGUAS_DIR 2>/dev/null 2>&1)" == "declare -a"* ]]; then
162 debug-print "$FUNCNAME: we have these subfolders defined: ${KDE_LINGUAS_DIR}"
163 for x in ${KDE_LINGUAS_DIR[@]}; do
164 _enable_selected_linguas_dir ${x}
167 KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
168 _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
172 # @FUNCTION: enable_selected_doc_linguas
174 # Enable only selected linguas enabled doc folders.
175 enable_selected_doc_linguas() {
176 debug-print-function ${FUNCNAME} "$@"
178 # @ECLASS-VARIABLE: KDE_DOC_DIRS
180 # Variable specifying whitespace separated patterns for documentation locations.
181 # Default is "doc/%lingua"
182 KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
184 for pattern in ${KDE_DOC_DIRS}; do
186 local handbookdir=`dirname ${pattern}`
187 local translationdir=`basename ${pattern}`
188 # Do filename pattern supplied, treat as directory
189 [[ ${handbookdir} = '.' ]] && handbookdir=${translationdir} && translationdir=
190 [[ -d ${handbookdir} ]] || die 'wrong doc dir specified'
192 if ! use handbook; then
193 # Disable whole directory
194 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
195 -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
196 -i CMakeLists.txt || die 'failed to comment out all handbooks'
198 # if there is no linguas defined we enable everything (i.e. comment out nothing)
199 if ! $(env | grep -q "^LINGUAS="); then
203 # Disable subdirectories recursively
204 comment_all_add_subdirectory "${handbookdir}"
206 # In certain packages, the default handbook is en_US instead of the usual en. Since there is no en_US 'translation',
207 # it makes no sense to add to KDE_LINGUAS which causes this type of handbook to not be installed.
208 if [[ -d "${handbookdir}/en_US" && ! -d "${handbookdir}/en" ]]; then
209 mv "${handbookdir}/en_US" "${handbookdir}/en" || die
210 sed -e "s/en_US/en/" -i "${handbookdir}/CMakeLists.txt"
213 # Add requested translations
215 for lingua in en ${KDE_LINGUAS}; do
216 if [[ ${lingua} = en ]] || use linguas_${lingua}; then
217 if [[ -d ${handbookdir}/${translationdir//%lingua/${lingua}} ]]; then
218 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
219 -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${translationdir//%lingua/${lingua}}/s/^#DONOTCOMPILE //" \
220 -i "${handbookdir}"/CMakeLists.txt && ! has ${lingua} ${linguas} && linguas="${linguas} ${lingua}"
227 [[ -n "${linguas}" ]] && einfo "Enabling handbook translations:${linguas}"
230 # Functions handling KMLOADLIBS and KMSAVELIBS
232 # @FUNCTION: save_library_dependencies
234 # Add exporting CMake dependencies for current package
235 save_library_dependencies() {
236 local depsfile="${T}/${PN}"
238 ebegin "Saving library dependencies in ${depsfile##*/}"
239 echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
240 die "Failed to save the library dependencies."
244 # @FUNCTION: install_library_dependencies
246 # Install generated CMake library dependencies to /var/lib/kde
247 install_library_dependencies() {
248 local depsfile="${T}/${PN}"
250 ebegin "Installing library dependencies as ${depsfile##*/}"
252 doins "${depsfile}" || die "Failed to install library dependencies."
256 # @FUNCTION: load_library_dependencies
258 # Inject specified library dependencies in current package
259 load_library_dependencies() {
261 ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
264 for pn in ${KMLOADLIBS} ; do
266 depsfile="${EPREFIX}/var/lib/kde/${pn}"
267 [[ -r ${depsfile} ]] || depsfile="${EPREFIX}/var/lib/kde/${pn}:$(get_kde_version)"
268 [[ -r ${depsfile} ]] || die "Depsfile '${depsfile}' not accessible. You probably need to reinstall ${pn}."
269 sed -i -e "${i}iINCLUDE(\"${depsfile}\")" "${S}/CMakeLists.txt" || \
270 die "Failed to include library dependencies for ${pn}"
275 # @FUNCTION: add_kdeapps_dep
277 # Create proper dependency for kde-apps/ dependencies.
278 # This takes 1 to 3 arguments. The first being the package name, the optional
279 # second is additional USE flags to append, and the optional third is the
280 # version to use instead of the automatic version (use sparingly).
281 # The output of this should be added directly to DEPEND/RDEPEND, and may be
282 # wrapped in a USE conditional (but not an || conditional without an extra set
285 debug-print-function ${FUNCNAME} "$@"
289 if [[ -n ${3} ]]; then
291 elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
292 ver=${KDE_OVERRIDE_MINIMAL}
293 elif [[ ${KDEBASE} != kde-base ]]; then
295 # if building kde-apps, live master or stable-live branch,
296 # use the final SC version since there are no further general releases.
297 elif [[ ${CATEGORY} == kde-apps || ${PV} == *9999 ]]; then
303 [[ -z ${1} ]] && die "Missing parameter"
306 # Drop aqua= from kf5 packages
307 echo " >=kde-apps/${1}-${ver}:4[aqua=${2:+,${2}}]"
310 # @FUNCTION: add_kdebase_dep
312 # Create proper dependency for kde-base/ dependencies.
313 # This takes 1 to 3 arguments. The first being the package name, the optional
314 # second is additional USE flags to append, and the optional third is the
315 # version to use instead of the automatic version (use sparingly).
316 # The output of this should be added directly to DEPEND/RDEPEND, and may be
317 # wrapped in a USE conditional (but not an || conditional without an extra set
320 debug-print-function ${FUNCNAME} "$@"
324 if [[ -n ${3} ]]; then
326 elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
327 ver=${KDE_OVERRIDE_MINIMAL}
328 elif [[ ${KDEBASE} != kde-base ]]; then
330 # if building live master or kde-apps, use the final SC version
331 # since there are no further general releases.
332 elif [[ ${CATEGORY} == kde-apps || ${PV} == 9999 ]]; then
334 # if building a live version branch (eg. 4.11.49.9999) use the major version
335 elif [[ ${PV} == *.9999 ]]; then
336 ver=$(get_kde_version)
341 [[ -z ${1} ]] && die "Missing parameter"
343 echo " >=kde-base/${1}-${ver}:4[aqua=${2:+,${2}}]"
346 # local function to enable specified translations for specified directory
347 # used from kde4-functions_enable_selected_linguas function
348 _enable_selected_linguas_dir() {
349 local lingua linguas sr_mess wp
352 [[ -d ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
353 comment_all_add_subdirectory "${dir}"
354 pushd "${dir}" > /dev/null || die
356 # fix all various crazy sr@Latn variations
357 # this part is only ease for ebuilds, so there wont be any die when this
359 sr_mess="sr@latn sr@latin sr@Latin"
360 for wp in ${sr_mess}; do
361 [[ -e ${wp}.po ]] && mv "${wp}.po" "sr@Latn.po"
362 if [[ -d ${wp} ]]; then
363 # move dir and fix cmakelists
366 -e "s:${wp}:sr@Latn:g" \
371 for lingua in ${KDE_LINGUAS}; do
372 if [[ -e ${lingua}.po ]]; then
373 mv "${lingua}.po" "${lingua}.po.old"
377 for lingua in ${KDE_LINGUAS}; do
378 if use linguas_${lingua} ; then
379 if [[ -d ${lingua} ]]; then
380 linguas="${linguas} ${lingua}"
381 sed -e "/add_subdirectory([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
382 -e "/ADD_SUBDIRECTORY([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
383 -i CMakeLists.txt || die "Sed to uncomment linguas_${lingua} failed."
385 if [[ -e ${lingua}.po.old ]]; then
386 linguas="${linguas} ${lingua}"
387 mv "${lingua}.po.old" "${lingua}.po"
391 [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
393 popd > /dev/null || die
396 # @FUNCTION: get_kde_version
398 # Translates an ebuild version into a major.minor KDE SC
399 # release version. If no version is specified, ${PV} is used.
401 local ver=${1:-${PV}}
402 local major=$(get_major_version ${ver})
403 local minor=$(get_version_component_range 2 ${ver})
404 local micro=$(get_version_component_range 3 ${ver})
405 if [[ ${ver} == 9999 ]]; then
408 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))