summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-11-27 15:25:08 +0100
committerMichał Górny <mgorny@gentoo.org>2015-12-01 23:07:17 +0100
commit568bb3ee5558b4d025df691bfeb12065afdef01e (patch)
tree9069f11f1fa39c61be549175fedc2dd51807e438 /eclass/systemd.eclass
parentversion bump (diff)
downloadgentoo-568bb3ee5558b4d025df691bfeb12065afdef01e.tar.gz
gentoo-568bb3ee5558b4d025df691bfeb12065afdef01e.tar.bz2
gentoo-568bb3ee5558b4d025df691bfeb12065afdef01e.zip
systemd.eclass: Introduce a common getter for systemd directories
Add a _systemd_get_dir function that serves as a common getter for all directories returned by the eclass. Add proper error handling for the variable getter.
Diffstat (limited to 'eclass/systemd.eclass')
-rw-r--r--eclass/systemd.eclass38
1 files changed, 23 insertions, 15 deletions
diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass
index 278d319c7c25..245e8034db81 100644
--- a/eclass/systemd.eclass
+++ b/eclass/systemd.eclass
@@ -34,16 +34,32 @@ esac
DEPEND="virtual/pkgconfig"
-# @FUNCTION: _systemd_get_unitdir
+# @FUNCTION: _systemd_get_dir
+# @USAGE: <variable-name> <fallback-directory>
# @INTERNAL
# @DESCRIPTION:
-# Get unprefixed unitdir.
-_systemd_get_unitdir() {
+# Try to obtain the <variable-name> variable from systemd.pc.
+# If pkg-config or systemd is not installed, return <fallback-directory>
+# instead.
+_systemd_get_dir() {
+ [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>"
+ local variable=${1} fallback=${2} d
+
if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
+ d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die
else
- echo /usr/lib/systemd/system
+ d=${fallback}
fi
+
+ echo "${d}"
+}
+
+# @FUNCTION: _systemd_get_unitdir
+# @INTERNAL
+# @DESCRIPTION:
+# Get unprefixed unitdir.
+_systemd_get_unitdir() {
+ _systemd_get_dir systemdsystemunitdir /usr/lib/systemd/system
}
# @FUNCTION: systemd_get_unitdir
@@ -62,11 +78,7 @@ systemd_get_unitdir() {
# @DESCRIPTION:
# Get unprefixed userunitdir.
_systemd_get_userunitdir() {
- if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
- else
- echo /usr/lib/systemd/user
- fi
+ _systemd_get_dir systemduserunitdir /usr/lib/systemd/user
}
# @FUNCTION: systemd_get_userunitdir
@@ -86,11 +98,7 @@ systemd_get_userunitdir() {
# @DESCRIPTION:
# Get unprefixed utildir.
_systemd_get_utildir() {
- if $(tc-getPKG_CONFIG) --exists systemd; then
- echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
- else
- echo /usr/lib/systemd
- fi
+ _systemd_get_dir systemdutildir /usr/lib/systemd
}
# @FUNCTION: systemd_get_utildir