xdg.eclass 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: xdg.eclass
  4. # @MAINTAINER:
  5. # freedesktop-bugs@gentoo.org
  6. # @AUTHOR:
  7. # Original author: Gilles Dartiguelongue <eva@gentoo.org>
  8. # @BLURB: Provides phases for XDG compliant packages.
  9. # @DESCRIPTION:
  10. # Utility eclass to update the desktop and shared mime info as laid
  11. # out in the freedesktop specs & implementations
  12. inherit xdg-utils
  13. case "${EAPI:-0}" in
  14. 4|5|6)
  15. EXPORT_FUNCTIONS src_prepare pkg_preinst pkg_postinst pkg_postrm
  16. ;;
  17. *) die "EAPI=${EAPI} is not supported" ;;
  18. esac
  19. # Avoid dependency loop as both depend on glib-2
  20. if [[ ${CATEGORY}/${P} != dev-libs/glib-2.* ]] ; then
  21. DEPEND="
  22. dev-util/desktop-file-utils
  23. x11-misc/shared-mime-info
  24. "
  25. fi
  26. # @FUNCTION: xdg_src_prepare
  27. # @DESCRIPTION:
  28. # Prepare sources to work with XDG standards.
  29. xdg_src_prepare() {
  30. xdg_environment_reset
  31. has ${EAPI:-0} 6 && default
  32. }
  33. # @FUNCTION: xdg_pkg_preinst
  34. # @DESCRIPTION:
  35. # Finds .desktop and mime info files for later handling in pkg_postinst.
  36. # Locations are stored in XDG_ECLASS_DESKTOPFILES and XDG_ECLASS_MIMEINFOFILES
  37. # respectively.
  38. xdg_pkg_preinst() {
  39. local f
  40. XDG_ECLASS_DESKTOPFILES=()
  41. while IFS= read -r -d '' f; do
  42. XDG_ECLASS_DESKTOPFILES+=( ${f} )
  43. done < <(cd "${D}" && find 'usr/share/applications' -type f -print0 2>/dev/null)
  44. XDG_ECLASS_MIMEINFOFILES=()
  45. while IFS= read -r -d '' f; do
  46. XDG_ECLASS_MIMEINFOFILES+=( ${f} )
  47. done < <(cd "${D}" && find 'usr/share/mime' -type f -print0 2>/dev/null)
  48. export XDG_ECLASS_DESKTOPFILES XDG_ECLASS_MIMEINFOFILES
  49. }
  50. # @FUNCTION: xdg_pkg_postinst
  51. # @DESCRIPTION:
  52. # Handle desktop and mime info database updates.
  53. xdg_pkg_postinst() {
  54. if [[ ${#XDG_ECLASS_DESKTOPFILES[@]} -gt 0 ]]; then
  55. xdg_desktop_database_update
  56. else
  57. debug-print "No .desktop files to add to database"
  58. fi
  59. if [[ ${#XDG_ECLASS_MIMEINFOFILES[@]} -gt 0 ]]; then
  60. xdg_mimeinfo_database_update
  61. else
  62. debug-print "No mime info files to add to database"
  63. fi
  64. }
  65. # @FUNCTION: xdg_pkg_postrm
  66. # @DESCRIPTION:
  67. # Handle desktop and mime info database updates.
  68. xdg_pkg_postrm() {
  69. if [[ ${#XDG_ECLASS_DESKTOPFILES[@]} -gt 0 ]]; then
  70. xdg_desktop_database_update
  71. else
  72. debug-print "No .desktop files to add to database"
  73. fi
  74. if [[ ${#XDG_ECLASS_MIMEINFOFILES[@]} -gt 0 ]]; then
  75. xdg_mimeinfo_database_update
  76. else
  77. debug-print "No mime info files to add to database"
  78. fi
  79. }