kde5.eclass: Cleanup obsolete blocker
[gentoo.git] / eclass / kde4-functions.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: kde4-functions.eclass
5 # @MAINTAINER:
6 # kde@gentoo.org
7 # @BLURB: Common ebuild functions for KDE 4 packages
8 # @DESCRIPTION:
9 # This eclass contains all functions shared by the different eclasses,
10 # for KDE 4 ebuilds.
11
12 if [[ -z ${_KDE4_FUNCTIONS_ECLASS} ]]; then
13 _KDE4_FUNCTIONS_ECLASS=1
14
15 inherit versionator
16
17 # @ECLASS-VARIABLE: EAPI
18 # @DESCRIPTION:
19 # Currently kde4 eclasses support EAPI 5 and 6.
20 case ${EAPI} in
21         5|6) : ;;
22         *) die "EAPI=${EAPI:-0} is not supported" ;;
23 esac
24
25 # @ECLASS-VARIABLE: KDE_OVERRIDE_MINIMAL
26 # @DESCRIPTION:
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.
33
34 # @ECLASS-VARIABLE: KDEBASE
35 # @DESCRIPTION:
36 # This gets set to a non-zero value when a package is considered a kde or
37 # kdevelop ebuild.
38 if [[ ${CATEGORY} = kde-base || ${CATEGORY} == kde-plasma || ${CATEGORY} = kde-apps || ${CATEGORY} = kde-frameworks ]]; then
39         debug-print "${ECLASS}: KDEBASE ebuild recognized"
40         KDEBASE=kde-base
41 elif [[ ${KMNAME-${PN}} = kdevelop ]]; then
42         KDEBASE=kdevelop
43 fi
44
45 debug-print "${ECLASS}: ${KDEBASE} ebuild recognized"
46
47 # determine the build type
48 if [[ ${PV} = *9999* ]]; then
49         KDE_BUILD_TYPE="live"
50 else
51         KDE_BUILD_TYPE="release"
52 fi
53 export KDE_BUILD_TYPE
54
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
58         case "${KMNAME}" in
59                 kdebase-workspace)
60                         EGIT_REPONAME=${EGIT_REPONAME:=kde-workspace}
61                 ;;
62                 kdebase-runtime)
63                         EGIT_REPONAME=${EGIT_REPONAME:=kde-runtime}
64                 ;;
65         esac
66 fi
67
68 # @ECLASS-VARIABLE: KDE_SCM
69 # @DESCRIPTION:
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}"
73 case ${KDE_SCM} in
74         svn|git) ;;
75         *) die "KDE_SCM: ${KDE_SCM} is not supported" ;;
76 esac
77
78 # @FUNCTION: kde4_lingua_to_l10n
79 # @USAGE: <lingua>...
80 # @INTERNAL
81 # @DESCRIPTION:
82 # Output l10n flag name(s) (without prefix(es)) appropriate for given KDE
83 # locale(s).
84 kde4_lingua_to_l10n() {
85         local l
86         for l; do
87                 case ${l} in
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}";;
94                         *) echo "${l/_/-}";;
95                 esac
96         done
97 }
98
99 # @ECLASS-VARIABLE: KDE_LINGUAS
100 # @DESCRIPTION:
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
105 # this for you.
106 #
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}"
111         done
112 fi
113
114 # @FUNCTION: buildsycoca
115 # @DESCRIPTION:
116 # Function to rebuild the KDE System Configuration Cache.
117 # All KDE ebuilds should run this in pkg_postinst and pkg_postrm.
118 buildsycoca() {
119         debug-print-function ${FUNCNAME} "$@"
120
121         # We no longer need to run kbuildsycoca4, as kded does that automatically, as needed
122
123         # fix permission for some directories
124         for x in usr/share/{config,kde4}; do
125                 DIRS=${EROOT}usr
126                 [[ -d "${EROOT}${x}" ]] || break # nothing to do if directory does not exist
127                 # fixes Bug 318237
128                 if use userland_BSD ; then
129                         [[ $(stat -f %p "${EROOT}${x}") != 40755 ]]
130                         local stat_rtn="$?"
131                 else
132                         [[ $(stat --format=%a "${EROOT}${x}") != 755 ]]
133                         local stat_rtn=$?
134                 fi
135                 if [[ $stat_rtn != 1 ]] ; then
136                         ewarn "QA Notice:"
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
141                 fi
142         done
143 }
144
145 # @FUNCTION: comment_all_add_subdirectory
146 # @USAGE: [list of directory names]
147 # @DESCRIPTION:
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" | \
152                 xargs -0 sed -i \
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"
158 }
159
160 # @FUNCTION: enable_selected_linguas
161 # @DESCRIPTION:
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} "$@"
167
168         local x
169
170         # @ECLASS-VARIABLE: KDE_LINGUAS_DIR
171         # @DESCRIPTION:
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}
180                 done
181         else
182                 KDE_LINGUAS_DIR=${KDE_LINGUAS_DIR:="po"}
183                 _enable_selected_linguas_dir ${KDE_LINGUAS_DIR}
184         fi
185 }
186
187 # @FUNCTION: enable_selected_doc_linguas
188 # @DESCRIPTION:
189 # Enable only selected L10N enabled doc folders.
190 enable_selected_doc_linguas() {
191         debug-print-function ${FUNCNAME} "$@"
192
193         # @ECLASS-VARIABLE: KDE_DOC_DIRS
194         # @DESCRIPTION:
195         # Variable specifying whitespace separated patterns for documentation locations.
196         # Default is "doc/%lingua"
197         KDE_DOC_DIRS=${KDE_DOC_DIRS:='doc/%lingua'}
198         local linguas
199         for pattern in ${KDE_DOC_DIRS}; do
200
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'
206
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'
212                 else
213                         # Disable subdirectories recursively
214                         comment_all_add_subdirectory "${handbookdir}"
215
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"
221                         fi
222
223                         # Add requested translations
224                         local lingua
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}"
231                                         fi
232                                 fi
233                         done
234                 fi
235
236         done
237         [[ -n "${linguas}" ]] && einfo "Enabling handbook translations:${linguas}"
238 }
239
240 # Functions handling KMLOADLIBS and KMSAVELIBS
241
242 # @FUNCTION: save_library_dependencies
243 # @DESCRIPTION:
244 # Add exporting CMake dependencies for current package
245 save_library_dependencies() {
246         local depsfile="${T}/${PN}"
247
248         ebegin "Saving library dependencies in ${depsfile##*/}"
249         echo "EXPORT_LIBRARY_DEPENDENCIES(\"${depsfile}\")" >> "${S}/CMakeLists.txt" || \
250                 die "Failed to save the library dependencies."
251         eend $?
252 }
253
254 # @FUNCTION: install_library_dependencies
255 # @DESCRIPTION:
256 # Install generated CMake library dependencies to /var/lib/kde
257 install_library_dependencies() {
258         local depsfile="${T}/${PN}"
259
260         ebegin "Installing library dependencies as ${depsfile##*/}"
261         insinto /var/lib/kde
262         doins "${depsfile}" || die "Failed to install library dependencies."
263         eend $?
264 }
265
266 # @FUNCTION: load_library_dependencies
267 # @DESCRIPTION:
268 # Inject specified library dependencies in current package
269 load_library_dependencies() {
270         local pn i depsfile
271         ebegin "Injecting library dependencies from '${KMLOADLIBS}'"
272
273         i=0
274         for pn in ${KMLOADLIBS} ; do
275                 ((i++))
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}"
281         done
282         eend $?
283 }
284
285 # @FUNCTION: add_kdeapps_dep
286 # @DESCRIPTION:
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
293 # of parentheses).
294 add_kdeapps_dep() {
295         debug-print-function ${FUNCNAME} "$@"
296
297         local ver
298
299         if [[ -n ${2} ]] ; then
300                 local use="[${2}]"
301         fi
302
303         if [[ -n ${3} ]]; then
304                 ver=${3}
305         elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
306                 ver=${KDE_OVERRIDE_MINIMAL}
307         elif [[ ${KDEBASE} != kde-base ]]; then
308                 ver=${KDE_MINIMAL}
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
313                 ver=4.14.3
314         else
315                 ver=${PV}
316         fi
317
318         [[ -z ${1} ]] && die "Missing parameter"
319
320         echo " >=kde-apps/${1}-${ver}:4${use}"
321 }
322
323 # @FUNCTION: add_kdebase_dep
324 # @DESCRIPTION:
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
331 # of parentheses).
332 add_kdebase_dep() {
333         debug-print-function ${FUNCNAME} "$@"
334
335         local ver
336
337         if [[ -n ${2} ]] ; then
338                 local use="[${2}]"
339         fi
340
341         if [[ -n ${3} ]]; then
342                 ver=${3}
343         elif [[ -n ${KDE_OVERRIDE_MINIMAL} ]]; then
344                 ver=${KDE_OVERRIDE_MINIMAL}
345         elif [[ ${KDEBASE} != kde-base ]]; then
346                 ver=${KDE_MINIMAL}
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
350                 ver=4.14.3
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)
354         else
355                 ver=${PV}
356         fi
357
358         [[ -z ${1} ]] && die "Missing parameter"
359
360         echo " >=kde-base/${1}-${ver}:4${use}"
361 }
362
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
367         local dir=${1}
368
369         [[ -d  ${dir} ]] || die "linguas dir \"${dir}\" does not exist"
370         comment_all_add_subdirectory "${dir}"
371         pushd "${dir}" > /dev/null || die
372
373         # fix all various crazy sr@Latn variations
374         # this part is only ease for ebuilds, so there wont be any die when this
375         # fail at any point
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
381                         mv "${wp}" "sr@Latn"
382                         sed -i \
383                                 -e "s:${wp}:sr@Latn:g" \
384                                 CMakeLists.txt
385                 fi
386         done
387
388         for lingua in ${KDE_LINGUAS}; do
389                 if [[ -e ${lingua}.po ]]; then
390                         mv "${lingua}.po" "${lingua}.po.old"
391                 fi
392         done
393
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."
401                         fi
402                         if [[ -e ${lingua}.po.old ]]; then
403                                 linguas="${linguas} ${lingua}"
404                                 mv "${lingua}.po.old" "${lingua}.po"
405                         fi
406                 fi
407         done
408         [[ -n ${linguas} ]] && echo ">>> Enabling languages: ${linguas}"
409
410         popd > /dev/null || die
411 }
412
413 # @FUNCTION: get_kde_version
414 # @DESCRIPTION:
415 # Translates an ebuild version into a major.minor KDE SC
416 # release version. If no version is specified, ${PV} is used.
417 get_kde_version() {
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
423                 echo live
424         else
425                 (( micro < 50 )) && echo ${major}.${minor} || echo ${major}.$((minor + 1))
426         fi
427 }
428
429 fi