net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / kde4-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: kde4-functions.eclass
6 # @MAINTAINER:
7 # kde@gentoo.org
8 # @BLURB: Common ebuild functions for KDE 4 packages
9 # @DESCRIPTION:
10 # This eclass contains all functions shared by the different eclasses,
11 # for KDE 4 ebuilds.
12
13 if [[ -z ${_KDE4_FUNCTIONS_ECLASS} ]]; then
14 _KDE4_FUNCTIONS_ECLASS=1
15
16 inherit versionator
17
18 # @ECLASS-VARIABLE: EAPI
19 # @DESCRIPTION:
20 # Currently kde4 eclasses support EAPI 5.
21 case ${EAPI} in
22         5) : ;;
23         *) die "EAPI=${EAPI:-0} is not supported" ;;
24 esac
25
26 # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
27 # @DESCRIPTION:
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.
34
35 # @ECLASS-VARIABLE: KDEBASE
36 # @DESCRIPTION:
37 # This gets set to a non-zero value when a package is considered a kde or
38 # kdevelop ebuild.
39 if [[ ${CATEGORY} = kde-base || ${CATEGORY} = kde-apps ]]; then
40         debug-print "${ECLASS}: KDEBASE ebuild recognized"
41         KDEBASE=kde-base
42 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
43         KDEBASE=kdevelop
44 fi
45
46 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
47
48 # determine the build type
49 if [[ ${PV} = *9999* ]]; then
50         KDE_BUILD_TYPE="live"
51 else
52         KDE_BUILD_TYPE="release"
53 fi
54 export KDE_BUILD_TYPE
55
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
59         case "${KMNAME}" in
60                 kdebase-workspace)
61                         EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
62                 ;;
63                 kdebase-runtime)
64                         EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
65                 ;;
66         esac
67 fi
68
69 # @ECLASS-VARIABLE: KDE_SCM
70 # @DESCRIPTION:
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}"
74 case ${KDE_SCM} in
75         svn|git) ;;
76         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
77 esac
78
79 # @ECLASS-VARIABLE: KDE_LINGUAS
80 # @DESCRIPTION:
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
85 # this for you.
86 #
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}"
91         done
92 fi
93
94 # @FUNCTION: buildsycoca
95 # @DESCRIPTION:
96 # Function to rebuild the KDE System Configuration Cache.
97 # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
98 buildsycoca() {
99         debug-print-function ${FUNCNAME} "$@"
100
101         # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
102
103         # fix permission for some directories
104         for x in usr/share/{config,kde4}; do
105                 DIRS=${EROOT}usr
106                 [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
107                 # fixes Bug 318237
108                 if use userland_BSD ; then
109                         [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
110                         local stat_rtn="$?"
111                 else
112                         [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
113                         local stat_rtn=$?
114                 fi
115                 if [[ $stat_rtn != 1 ]] ; then
116                         ewarn "QA Notice:"
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
121                 fi
122         done
123 }
124
125 # @FUNCTION: comment_all_add_subdirectory
126 # @USAGE: [list of directory names]
127 # @DESCRIPTION:
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" | \
132                 xargs -0 sed -i \
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"
138 }
139
140 # @FUNCTION: enable_selected_linguas
141 # @DESCRIPTION:
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} "$@"
147
148         local x
149
150         # if there is no linguas defined we enable everything
151         if ! $(env | grep -q "^LINGUAS="); then
152                 return 0
153         fi
154
155         # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
156         # @DESCRIPTION:
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}
165                 done
166         else
167                 KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
168                 _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
169         fi
170 }
171
172 # @FUNCTION: enable_selected_doc_linguas
173 # @DESCRIPTION:
174 # Enable only selected linguas enabled doc folders.
175 enable_selected_doc_linguas() {
176         debug-print-function ${FUNCNAME} "$@"
177
178         # @ECLASS-VARIABLE: KDE_DOC_DIRS
179         # @DESCRIPTION:
180         # Variable specifying whitespace separated patterns for documentation locations.
181         # Default is "doc/%lingua"
182         KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
183         local linguas
184         for pattern in ${KDE_DOC_DIRS}; do
185
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'
191
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'
197                 else
198                         # if there is no linguas defined we enable everything (i.e. comment out nothing)
199                         if ! $(env | grep -q "^LINGUAS="); then
200                                 return 0
201                         fi
202
203                         # Disable subdirectories recursively
204                         comment_all_add_subdirectory "${handbookdir}"
205
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"
211                         fi
212
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 # Functions handling KMLOADLIBS and KMSAVELIBS
231
232 # @FUNCTION: save_library_dependencies
233 # @DESCRIPTION:
234 # Add exporting CMake dependencies for current package
235 save_library_dependencies() {
236         local depsfile="${T}/${PN}"
237
238         ebegin "Saving library dependencies in ${depsfile##*/}"
239         echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
240                 die "Failed to save the library dependencies."
241         eend $?
242 }
243
244 # @FUNCTION: install_library_dependencies
245 # @DESCRIPTION:
246 # Install generated CMake library dependencies to /var/lib/kde
247 install_library_dependencies() {
248         local depsfile="${T}/${PN}"
249
250         ebegin "Installing library dependencies as ${depsfile##*/}"
251         insinto /var/lib/kde
252         doins "${depsfile}" || die "Failed to install library dependencies."
253         eend $?
254 }
255
256 # @FUNCTION: load_library_dependencies
257 # @DESCRIPTION:
258 # Inject specified library dependencies in current package
259 load_library_dependencies() {
260         local pn i depsfile
261         ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
262
263         i=0
264         for pn in ${KMLOADLIBS} ; do
265                 ((i++))
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}"
271         done
272         eend $?
273 }
274
275 # @FUNCTION: add_kdeapps_dep
276 # @DESCRIPTION:
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
283 # of parentheses).
284 add_kdeapps_dep() {
285         debug-print-function ${FUNCNAME} "$@"
286
287         local ver
288
289         if [[ -n ${3} ]]; then
290                 ver=${3}
291         elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
292                 ver=${KDE_OVERRIDE_MINIMAL}
293         elif [[ ${KDEBASE} != kde-base ]]; then
294                 ver=${KDE_MINIMAL}
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
298                 ver=4.14.3
299         else
300                 ver=${PV}
301         fi
302
303         [[ -z ${1} ]] && die "Missing parameter"
304
305         #FIXME
306         # Drop aqua= from kf5 packages
307         echo " >=kde-apps/${1}-${ver}:4[aqua=${2:+,${2}}]"
308 }
309
310 # @FUNCTION: add_kdebase_dep
311 # @DESCRIPTION:
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
318 # of parentheses).
319 add_kdebase_dep() {
320         debug-print-function ${FUNCNAME} "$@"
321
322         local ver
323
324         if [[ -n ${3} ]]; then
325                 ver=${3}
326         elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
327                 ver=${KDE_OVERRIDE_MINIMAL}
328         elif [[ ${KDEBASE} != kde-base ]]; then
329                 ver=${KDE_MINIMAL}
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
333                 ver=4.14.3
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)
337         else
338                 ver=${PV}
339         fi
340
341         [[ -z ${1} ]] && die "Missing parameter"
342
343         echo " >=kde-base/${1}-${ver}:4[aqua=${2:+,${2}}]"
344 }
345
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
350         local dir=${1}
351
352         [[ -d  ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
353         comment_all_add_subdirectory "${dir}"
354         pushd "${dir}" > /dev/null || die
355
356         # fix all various crazy sr@Latn variations
357         # this part is only ease for ebuilds, so there wont be any die when this
358         # fail at any point
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
364                         mv "${wp}" "sr@Latn"
365                         sed -i \
366                                 -e "s:${wp}:sr@Latn:g" \
367                                 CMakeLists.txt
368                 fi
369         done
370
371         for lingua in ${KDE_LINGUAS}; do
372                 if [[ -e ${lingua}.po ]]; then
373                         mv "${lingua}.po" "${lingua}.po.old"
374                 fi
375         done
376
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."
384                         fi
385                         if [[ -e ${lingua}.po.old ]]; then
386                                 linguas="${linguas} ${lingua}"
387                                 mv "${lingua}.po.old" "${lingua}.po"
388                         fi
389                 fi
390         done
391         [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
392
393         popd > /dev/null || die
394 }
395
396 # @FUNCTION: get_kde_version
397 # @DESCRIPTION:
398 # Translates an ebuild version into a major.minor KDE SC
399 # release version. If no version is specified, ${PV} is used.
400 get_kde_version() {
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
406                 echo live
407         else
408                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
409         fi
410 }
411
412 fi