1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 # freedesktop-bugs@gentoo.org
8 # Original author: Gilles Dartiguelongue <eva@gentoo.org>
9 # @SUPPORTED_EAPIS: 4 5 6
10 # @BLURB: Provides phases for XDG compliant packages.
12 # Utility eclass to update the desktop, icon and shared mime info as laid
13 # out in the freedesktop specs & implementations
19 EXPORT_FUNCTIONS src_prepare pkg_preinst pkg_postinst pkg_postrm
21 *) die "EAPI=${EAPI} is not supported" ;;
24 # Avoid dependency loop as both depend on glib-2
25 if [[ ${CATEGORY}/${P} != dev-libs/glib-2.* ]] ; then
27 dev-util/desktop-file-utils
28 x11-misc/shared-mime-info
32 # @FUNCTION: xdg_src_prepare
34 # Prepare sources to work with XDG standards.
38 has ${EAPI:-0} 6 && default
41 # @FUNCTION: xdg_pkg_preinst
43 # Finds .desktop, icon and mime info files for later handling in pkg_postinst.
44 # Locations are stored in XDG_ECLASS_DESKTOPFILES, XDG_ECLASS_ICONFILES
45 # and XDG_ECLASS_MIMEINFOFILES respectively.
49 XDG_ECLASS_DESKTOPFILES=()
50 while IFS= read -r -d '' f; do
51 XDG_ECLASS_DESKTOPFILES+=( ${f} )
52 done < <(cd "${ED}" && find 'usr/share/applications' -type f -print0 2>/dev/null)
54 XDG_ECLASS_ICONFILES=()
55 while IFS= read -r -d '' f; do
56 XDG_ECLASS_ICONFILES+=( ${f} )
57 done < <(cd "${ED}" && find 'usr/share/icons' -type f -print0 2>/dev/null)
59 XDG_ECLASS_MIMEINFOFILES=()
60 while IFS= read -r -d '' f; do
61 XDG_ECLASS_MIMEINFOFILES+=( ${f} )
62 done < <(cd "${ED}" && find 'usr/share/mime' -type f -print0 2>/dev/null)
65 # @FUNCTION: xdg_pkg_postinst
67 # Handle desktop, icon and mime info database updates.
69 if [[ ${#XDG_ECLASS_DESKTOPFILES[@]} -gt 0 ]]; then
70 xdg_desktop_database_update
72 debug-print "No .desktop files to add to database"
75 if [[ ${#XDG_ECLASS_ICONFILES[@]} -gt 0 ]]; then
78 debug-print "No icon files to add to cache"
81 if [[ ${#XDG_ECLASS_MIMEINFOFILES[@]} -gt 0 ]]; then
82 xdg_mimeinfo_database_update
84 debug-print "No mime info files to add to database"
88 # @FUNCTION: xdg_pkg_postrm
90 # Handle desktop, icon and mime info database updates.
92 if [[ ${#XDG_ECLASS_DESKTOPFILES[@]} -gt 0 ]]; then
93 xdg_desktop_database_update
95 debug-print "No .desktop files to add to database"
98 if [[ ${#XDG_ECLASS_ICONFILES[@]} -gt 0 ]]; then
101 debug-print "No icon files to add to cache"
104 if [[ ${#XDG_ECLASS_MIMEINFOFILES[@]} -gt 0 ]]; then
105 xdg_mimeinfo_database_update
107 debug-print "No mime info files to add to database"