/[gentoo-x86]/eclass/kde4-functions.eclass
Gentoo

Contents of /eclass/kde4-functions.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.54 - (show annotations) (download)
Wed Jun 15 22:03:13 2011 UTC (3 years, 6 months ago) by abcd
Branch: MAIN
Changes since 1.53: +39 -116 lines
The Great KDE Slot Move: gentoo-x86 Edition (move all the kde-base/ packages from version-specific slots to :4)

1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/kde4-functions.eclass,v 1.52 2011/06/15 00:11:05 abcd Exp $
4
5 inherit versionator
6
7 # @ECLASS: kde4-functions.eclass
8 # @MAINTAINER:
9 # kde@gentoo.org
10 # @BLURB: Common ebuild functions for KDE 4 packages
11 # @DESCRIPTION:
12 # This eclass contains all functions shared by the different eclasses,
13 # for KDE 4 ebuilds.
14
15 # @ECLASS-VARIABLE: EAPI
16 # @DESCRIPTION:
17 # Currently kde4 eclasses support EAPI 3 and 4.
18 case ${EAPI:-0} in
19 4|3) : ;;
20 *) die "EAPI=${EAPI} is not supported" ;;
21 esac
22
23 # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
24 # @DESCRIPTION:
25 # For use only in very few well-defined cases; normally it should be unset.
26 # If this variable is set, all calls to add_kdebase_dep return a dependency on
27 # at least this version, independent of the version of the package itself.
28 # If you know exactly that one specific NEW KDE component builds and runs fine
29 # with all the rest of KDE at an OLDER version, you can set this old version here.
30 # Warning- may lead to general instability and kill your pet targh.
31
32 # @ECLASS-VARIABLE: KDEBASE
33 # @DESCRIPTION:
34 # This gets set to a non-zero value when a package is considered a kde or
35 # koffice ebuild.
36 if [[ ${CATEGORY} = kde-base ]]; then
37 debug-print "${ECLASS}: KDEBASE ebuild recognized"
38 KDEBASE=kde-base
39 elif [[ ${KMNAME-${PN}} = koffice ]]; then
40 debug-print "${ECLASS}: KOFFICE ebuild recognized"
41 KDEBASE=koffice
42 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
43 debug-print "${ECLASS}: KDEVELOP ebuild recognized"
44 KDEBASE=kdevelop
45 fi
46
47 # determine the build type
48 if [[ ${PV} = *9999* ]]; then
49 BUILD_TYPE="live"
50 else
51 BUILD_TYPE="release"
52 fi
53 export BUILD_TYPE
54
55 # Set reponame and SCM for moduleses that have fully migrated to git
56 # (hack - it's here because it needs to be before SCM inherits from kde4-base)
57 if [[ ${BUILD_TYPE} == live ]]; then
58 case "${KMNAME}" in
59 kdebase-workspace)
60 KDE_SCM="git"
61 EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
62 ;;
63 kdebase-runtime)
64 KDE_SCM="git"
65 EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
66 ;;
67 kdebase-apps)
68 KDE_SCM="git"
69 EGIT_REPONAME=${EGIT_REPONAME:=kde-baseapps}
70 ;;
71 kde-workspace|kde-runtime|kde-baseapps)
72 KDE_SCM="git"
73 ;;
74 esac
75 fi
76
77 # @ECLASS-VARIABLE: KDE_SCM
78 # @DESCRIPTION:
79 # If this is a live package which scm does it use
80 # Everything else uses svn by default
81 KDE_SCM="${KDE_SCM:-svn}"
82 case ${KDE_SCM} in
83 svn|git) ;;
84 *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
85 esac
86
87 # @ECLASS-VARIABLE: KDE_LINGUAS
88 # @DESCRIPTION:
89 # This is a whitespace-separated list of translations this ebuild supports.
90 # These translations are automatically added to IUSE. Therefore ebuilds must set
91 # this variable before inheriting any eclasses. To enable only selected
92 # translations, ebuilds must call enable_selected_linguas(). kde4-{base,meta}.eclass does
93 # this for you.
94 #
95 # Example: KDE_LINGUAS="en_GB de nl"
96 if [[ ${BUILD_TYPE} != live || -n ${KDE_LINGUAS_LIVE_OVERRIDE} ]]; then
97 for _lingua in ${KDE_LINGUAS}; do
98 IUSE="${IUSE} linguas_${_lingua}"
99 done
100 fi
101
102 # @FUNCTION: buildsycoca
103 # @DESCRIPTION:
104 # Function to rebuild the KDE System Configuration Cache.
105 # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
106 buildsycoca() {
107 debug-print-function ${FUNCNAME} "$@"
108
109 # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
110
111 # fix permission for some directories
112 for x in usr/share/{config,kde4}; do
113 DIRS=${EROOT}usr
114 [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
115 # fixes Bug 318237
116 if use userland_BSD ; then
117 [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
118 local stat_rtn="$?"
119 else
120 [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
121 local stat_rtn=$?
122 fi
123 if [[ $stat_rtn != 1 ]] ; then
124 ewarn "QA Notice:"
125 ewarn "Package ${PN} is breaking ${EROOT}${x} permissions."
126 ewarn "Please report this issue to gentoo bugzilla."
127 einfo "Permissions will get adjusted automatically now."
128 find "${EROOT}${x}" -type d -print0 | xargs -0 chmod 755
129 fi
130 done
131 }
132
133 # @FUNCTION: comment_all_add_subdirectory
134 # @USAGE: [list of directory names]
135 # @DESCRIPTION:
136 # Recursively comment all add_subdirectory instructions in listed directories,
137 # except those in cmake/.
138 comment_all_add_subdirectory() {
139 find "$@" -name CMakeLists.txt -print0 | grep -vFzZ "./cmake" | \
140 xargs -0 sed -i \
141 -e '/^[[:space:]]*add_subdirectory/s/^/#DONOTCOMPILE /' \
142 -e '/^[[:space:]]*ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
143 -e '/^[[:space:]]*macro_optional_add_subdirectory/s/^/#DONOTCOMPILE /' \
144 -e '/^[[:space:]]*MACRO_OPTIONAL_ADD_SUBDIRECTORY/s/^/#DONOTCOMPILE /' \
145 || die "${LINENO}: Initial sed died"
146 }
147
148 # @FUNCTION: enable_selected_linguas
149 # @DESCRIPTION:
150 # Enable translations based on LINGUAS settings and translations supported by
151 # the package (see KDE_LINGUAS). By default, translations are found in "${S}"/po
152 # but this default can be overridden by defining KDE_LINGUAS_DIR.
153 enable_selected_linguas() {
154 debug-print-function ${FUNCNAME} "$@"
155
156 local x
157
158 # if there is no linguas defined we enable everything
159 if ! $(env | grep -q "^LINGUAS="); then
160 return 0
161 fi
162
163 # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
164 # @DESCRIPTION:
165 # Specified folder where application translations are located.
166 # Can be defined as array of folders where translations are located.
167 # Note that space separated list of dirs is not supported.
168 # Default value is set to "po".
169 if [[ "$(declare -p KDE_LINGUAS_DIR 2>/dev/null 2>&1)" == "declare -a"* ]]; then
170 debug-print "$FUNCNAME: we have these subfolders defined: ${KDE_LINGUAS_DIR}"
171 for x in ${KDE_LINGUAS_DIR[@]}; do
172 _enable_selected_linguas_dir ${x}
173 done
174 else
175 KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
176 _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
177 fi
178 }
179
180 # @FUNCTION: enable_selected_doc_linguas
181 # @DESCRIPTION:
182 # Enable only selected linguas enabled doc folders.
183 enable_selected_doc_linguas() {
184 debug-print-function ${FUNCNAME} "$@"
185
186 # if there is no linguas defined we enable everything
187 if ! $(env | grep -q "^LINGUAS="); then
188 return 0
189 fi
190
191 # @ECLASS-VARIABLE: KDE_DOC_DIRS
192 # @DESCRIPTION:
193 # Variable specifying whitespace separated patterns for documentation locations.
194 # Default is "doc/%lingua"
195 KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
196 local linguas
197 for pattern in ${KDE_DOC_DIRS}; do
198
199 local handbookdir=`dirname ${pattern}`
200 local translationdir=`basename ${pattern}`
201 # Do filename pattern supplied, treat as directory
202 [[ ${handbookdir} = '.' ]] && handbookdir=${translationdir} && translationdir=
203 [[ -d ${handbookdir} ]] || die 'wrong doc dir specified'
204
205 if ! use handbook; then
206 # Disable whole directory
207 sed -e "/add_subdirectory[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
208 -e "/ADD_SUBDIRECTORY[[:space:]]*([[:space:]]*${handbookdir}[[:space:]]*)/s/^/#DONOTCOMPILE /" \
209 -i CMakeLists.txt || die 'failed to comment out all handbooks'
210 else
211 # Disable subdirectories recursively
212 comment_all_add_subdirectory "${handbookdir}"
213 # Add requested translations
214 local lingua
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}"
221 fi
222 fi
223 done
224 fi
225
226 done
227 [[ -n "${linguas}" ]] && einfo "Enabling handbook translations:${linguas}"
228 }
229
230 # @FUNCTION: migrate_store_dir
231 # @DESCRIPTION:
232 # Universal store dir migration
233 # * performs split of kdebase to kdebase-apps when needed
234 # * moves playground/extragear kde4-base-style to toplevel dir
235 migrate_store_dir() {
236 if [[ ${KDE_SCM} != svn ]]; then
237 die "migrate_store_dir() only makes sense for subversion"
238 fi
239
240 local cleandir="${ESVN_STORE_DIR}/KDE"
241
242 if [[ -d ${cleandir} ]]; then
243 ewarn "'${cleandir}' has been found. Moving contents to new location."
244 addwrite "${ESVN_STORE_DIR}"
245 # Split kdebase
246 local module
247 if pushd "${cleandir}"/kdebase/kdebase > /dev/null; then
248 for module in `find . -maxdepth 1 -type d -name [a-z0-9]\*`; do
249 module="${module#./}"
250 mkdir -p "${ESVN_STORE_DIR}/kdebase-${module}" && mv -f "${module}" "${ESVN_STORE_DIR}/kdebase-${module}" || \
251 die "Failed to move to '${ESVN_STORE_DIR}/kdebase-${module}'."
252 done
253 popd > /dev/null
254 rm -fr "${cleandir}/kdebase" || \
255 die "Failed to remove ${cleandir}/kdebase. You need to remove it manually."
256 fi
257 # Move the rest
258 local pkg
259 for pkg in "${cleandir}"/*; do
260 mv -f "${pkg}" "${ESVN_STORE_DIR}"/ || eerror "Failed to move '${pkg}'"
261 done
262 rmdir "${cleandir}" || die "Could not move obsolete KDE store dir. Please move '${cleandir}' contents to appropriate location (possibly ${ESVN_STORE_DIR}) and manually remove '${cleandir}' in order to continue."
263 fi
264
265 if ! hasq kde4-meta ${INHERITED}; then
266 case ${KMNAME} in
267 extragear*|playground*)
268 local scmlocalpath="${ESVN_STORE_DIR}"/"${KMNAME}"/"${PN}"
269 if [[ -d "${scmlocalpath}" ]]; then
270 local destdir="${ESVN_STORE_DIR}"/"${ESVN_PROJECT}"/"`basename "${ESVN_REPO_URI}"`"
271 ewarn "'${scmlocalpath}' has been found."
272 ewarn "Moving contents to new location: ${destdir}"
273 addwrite "${ESVN_STORE_DIR}"
274 mkdir -p "${ESVN_STORE_DIR}"/"${ESVN_PROJECT}" && mv -f "${scmlocalpath}" "${destdir}" \
275 || die "Failed to move to '${scmlocalpath}'"
276 # Try cleaning empty directories
277 rmdir "`dirname "${scmlocalpath}"`" 2> /dev/null
278 fi
279 ;;
280 esac
281 fi
282 }
283
284 # Functions handling KMLOADLIBS and KMSAVELIBS
285
286 # @FUNCTION: save_library_dependencies
287 # @DESCRIPTION:
288 # Add exporting CMake dependencies for current package
289 save_library_dependencies() {
290 local depsfile="${T}/${PN}"
291
292 ebegin "Saving library dependencies in ${depsfile##*/}"
293 echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
294 die "Failed to save the library dependencies."
295 eend $?
296 }
297
298 # @FUNCTION: install_library_dependencies
299 # @DESCRIPTION:
300 # Install generated CMake library dependencies to /var/lib/kde
301 install_library_dependencies() {
302 local depsfile="${T}/${PN}"
303
304 ebegin "Installing library dependencies as ${depsfile##*/}"
305 insinto /var/lib/kde
306 doins "${depsfile}" || die "Failed to install library dependencies."
307 eend $?
308 }
309
310 # @FUNCTION: load_library_dependencies
311 # @DESCRIPTION:
312 # Inject specified library dependencies in current package
313 load_library_dependencies() {
314 local pn i depsfile
315 ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
316
317 i=0
318 for pn in ${KMLOADLIBS} ; do
319 ((i++))
320 depsfile="${EPREFIX}/var/lib/kde/${pn}"
321 [[ -r ${depsfile} ]] || depsfile="${EPREFIX}/var/lib/kde/${pn}:$(get_kde_version)"
322 [[ -r ${depsfile} ]] || die "Depsfile '${depsfile}' not accessible. You probably need to reinstall ${pn}."
323 sed -i -e "${i}iINCLUDE(\"${depsfile}\")" "${S}/CMakeLists.txt" || \
324 die "Failed to include library dependencies for ${pn}"
325 done
326 eend $?
327 }
328
329 # @FUNCTION: add_blocker
330 # @DESCRIPTION:
331 # Create correct RDEPEND value for blocking correct package.
332 # Useful for file-collision blocks.
333 # Parameters are package and version(s) to block.
334 # add_blocker kdelibs 4.2.4
335 # If no version is specified, then all versions will be blocked.
336 # If the version is 0, then no versions will be blocked.
337 # If a second version ending in ":3.5" is passed, then the version listed for
338 # that slot will be blocked as well.
339 #
340 # Examples:
341 # # Block all versions of kdelibs
342 # add_blocker kdelibs
343 #
344 # # Block all versions of kdelibs older than 4.3.50
345 # add_blocker kdelibs 4.3.50
346 #
347 # # Block kdelibs 3.5.10 and older, but not any version of
348 # # kdelibs from KDE 4
349 # add_blocker kdelibs 0 3.5.10:3.5
350 add_blocker() {
351 debug-print-function ${FUNCNAME} "$@"
352
353 [[ -z ${1} ]] && die "Missing parameter"
354 local pkg=kde-base/$1 atom old_ver="unset" use
355 if [[ $pkg == *\[*\] ]]; then
356 use=${pkg/#*\[/[}
357 pkg=${pkg%\[*\]}
358 fi
359
360 [[ "$3" == *:3.5 ]] && old_ver=${3%:3.5}
361
362 # If the version passed is "0", do nothing
363 if [[ ${2} != 0 ]]; then
364 # If no version was passed, block all versions in this slot
365 if [[ -z ${2} ]]; then
366 atom=${pkg}
367 # If the version passed begins with a "<", then use "<" instead of "<="
368 elif [[ ${2::1} == "<" ]]; then
369 # this also removes the first character of the version, which is a "<"
370 atom="<${pkg}-${2:1}"
371 else
372 atom="<=${pkg}-${2}"
373 fi
374 RDEPEND+=" !${atom}:4${use}"
375 fi
376
377 # Do the same thing as above for :3.5, except that we don't want any
378 # output if no parameter was passed.
379 if [[ ${old_ver} != "unset" ]]; then
380 if [[ -z ${old_ver} ]]; then
381 atom=${pkg}
382 elif [[ ${old_ver::1} == "<" ]]; then
383 atom="<${pkg}-${old_ver:1}"
384 else
385 atom="<=${pkg}-${old_ver}"
386 fi
387 RDEPEND+=" !${atom}:3.5${use}"
388 fi
389 }
390
391 # @FUNCTION: add_kdebase_dep
392 # @DESCRIPTION:
393 # Create proper dependency for kde-base/ dependencies.
394 # This takes 1 to 3 arguments. The first being the package name, the optional
395 # second is additional USE flags to append, and the optional third is the
396 # version to use instead of the automatic version (use sparingly).
397 # The output of this should be added directly to DEPEND/RDEPEND, and may be
398 # wrapped in a USE conditional (but not an || conditional without an extra set
399 # of parentheses).
400 add_kdebase_dep() {
401 debug-print-function ${FUNCNAME} "$@"
402
403 local ver
404
405 if [[ -n ${3} ]]; then
406 ver=${3}
407 elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
408 ver=${KDE_OVERRIDE_MINIMAL}
409 elif [[ ${KDEBASE} != kde-base ]]; then
410 ver=${KDE_MINIMAL}
411 # if building stable-live version depend just on the raw KDE version
412 # to allow merging packages against more stable basic stuff
413 elif [[ ${PV} == *.9999 ]]; then
414 ver=$(get_kde_version)
415 else
416 ver=${PV}
417 fi
418
419 [[ -z ${1} ]] && die "Missing parameter"
420
421 echo " >=kde-base/${1}-${ver}:4[aqua=${2:+,${2}}]"
422 }
423
424 # local function to enable specified translations for specified directory
425 # used from kde4-functions_enable_selected_linguas function
426 _enable_selected_linguas_dir() {
427 local lingua linguas sr_mess wp
428 local dir=${1}
429
430 [[ -d ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
431 comment_all_add_subdirectory "${dir}"
432 pushd "${dir}" > /dev/null
433
434 # fix all various crazy sr@Latn variations
435 # this part is only ease for ebuilds, so there wont be any die when this
436 # fail at any point
437 sr_mess="sr@latn sr@latin sr@Latin"
438 for wp in ${sr_mess}; do
439 [[ -e ${wp}.po ]] && mv "${wp}.po" "sr@Latn.po"
440 if [[ -d ${wp} ]]; then
441 # move dir and fix cmakelists
442 mv "${wp}" "sr@Latn"
443 sed -i \
444 -e "s:${wp}:sr@Latn:g" \
445 CMakeLists.txt
446 fi
447 done
448
449 for lingua in ${KDE_LINGUAS}; do
450 if [[ -e ${lingua}.po ]]; then
451 mv "${lingua}.po" "${lingua}.po.old"
452 fi
453 done
454
455 for lingua in ${KDE_LINGUAS}; do
456 if use linguas_${lingua} ; then
457 if [[ -d ${lingua} ]]; then
458 linguas="${linguas} ${lingua}"
459 sed -e "/add_subdirectory([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
460 -e "/ADD_SUBDIRECTORY([[:space:]]*${lingua}[[:space:]]*)[[:space:]]*$/ s/^#DONOTCOMPILE //" \
461 -i CMakeLists.txt || die "Sed to uncomment linguas_${lingua} failed."
462 fi
463 if [[ -e ${lingua}.po.old ]]; then
464 linguas="${linguas} ${lingua}"
465 mv "${lingua}.po.old" "${lingua}.po"
466 fi
467 fi
468 done
469 [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
470
471 popd > /dev/null
472 }
473
474 # @FUNCTION: get_kde_version
475 # Translates an ebuild version into a major.minor KDE SC
476 # release version. If no version is specified, ${PV} is used.
477 get_kde_version() {
478 local ver=${1:-${PV}}
479 local major=$(get_major_version ${ver})
480 local minor=$(get_version_component_range 2 ${ver})
481 local micro=$(get_version_component_range 3 ${ver})
482 if [[ ${ver} == 9999 ]]; then
483 echo live
484 else
485 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
486 fi
487 }

  ViewVC Help
Powered by ViewVC 1.1.20