udev.eclass 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright 1999-2014 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: udev.eclass
  4. # @MAINTAINER:
  5. # udev-bugs@gentoo.org
  6. # @BLURB: Default eclass for determining udev directories.
  7. # @DESCRIPTION:
  8. # Default eclass for determining udev directories.
  9. # @EXAMPLE:
  10. #
  11. # @CODE
  12. # inherit udev
  13. #
  14. # # Example of the eclass usage:
  15. # RDEPEND="virtual/udev"
  16. # DEPEND="${RDEPEND}"
  17. #
  18. # src_configure() {
  19. # econf --with-rulesdir="$(get_udevdir)"/rules.d
  20. # }
  21. #
  22. # src_install() {
  23. # default
  24. # # udev_dorules contrib/99-foomatic
  25. # # udev_newrules contrib/98-foomatic 99-foomatic
  26. # }
  27. # @CODE
  28. if [[ -z ${_UDEV_ECLASS} ]]; then
  29. _UDEV_ECLASS=1
  30. inherit toolchain-funcs
  31. case ${EAPI:-0} in
  32. 0|1|2|3|4|5|6) ;;
  33. *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
  34. esac
  35. RDEPEND=""
  36. DEPEND="virtual/pkgconfig"
  37. # @FUNCTION: _udev_get_udevdir
  38. # @INTERNAL
  39. # @DESCRIPTION:
  40. # Get unprefixed udevdir.
  41. _udev_get_udevdir() {
  42. if $($(tc-getPKG_CONFIG) --exists udev); then
  43. echo "$($(tc-getPKG_CONFIG) --variable=udevdir udev)"
  44. else
  45. echo /lib/udev
  46. fi
  47. }
  48. # @FUNCTION: udev_get_udevdir
  49. # @DESCRIPTION:
  50. # Use the short version $(get_udevdir) instead!
  51. udev_get_udevdir() {
  52. debug-print-function ${FUNCNAME} "${@}"
  53. eerror "This ebuild should be using the get_udevdir() function instead of the deprecated udev_get_udevdir()"
  54. die "Deprecated function call: udev_get_udevdir(), please report to (overlay) maintainers."
  55. }
  56. # @FUNCTION: get_udevdir
  57. # @DESCRIPTION:
  58. # Output the path for the udev directory (not including ${D}).
  59. # This function always succeeds, even if udev is not installed.
  60. # The fallback value is set to /lib/udev
  61. get_udevdir() {
  62. debug-print-function ${FUNCNAME} "${@}"
  63. echo "$(_udev_get_udevdir)"
  64. }
  65. # @FUNCTION: udev_dorules
  66. # @USAGE: rules [...]
  67. # @DESCRIPTION:
  68. # Install udev rule(s). Uses doins, thus it is fatal in EAPI 4
  69. # and non-fatal in earlier EAPIs.
  70. udev_dorules() {
  71. debug-print-function ${FUNCNAME} "${@}"
  72. (
  73. insinto "$(_udev_get_udevdir)"/rules.d
  74. doins "${@}"
  75. )
  76. }
  77. # @FUNCTION: udev_newrules
  78. # @USAGE: oldname newname
  79. # @DESCRIPTION:
  80. # Install udev rule with a new name. Uses newins, thus it is fatal
  81. # in EAPI 4 and non-fatal in earlier EAPIs.
  82. udev_newrules() {
  83. debug-print-function ${FUNCNAME} "${@}"
  84. (
  85. insinto "$(_udev_get_udevdir)"/rules.d
  86. newins "${@}"
  87. )
  88. }
  89. # @FUNCTION: udev_reload
  90. # @DESCRIPTION:
  91. # Run udevadm control --reload to refresh rules and databases
  92. udev_reload() {
  93. if [[ ${ROOT} != "" ]] && [[ ${ROOT} != "/" ]]; then
  94. return 0
  95. fi
  96. if [[ -d ${ROOT}/run/udev ]]; then
  97. ebegin "Running udev control --reload for reloading rules and databases"
  98. udevadm control --reload
  99. eend $?
  100. fi
  101. }
  102. fi