1 |
commit: 568bb3ee5558b4d025df691bfeb12065afdef01e |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Fri Nov 27 14:25:08 2015 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Dec 1 22:07:17 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=568bb3ee |
7 |
|
8 |
systemd.eclass: Introduce a common getter for systemd directories |
9 |
|
10 |
Add a _systemd_get_dir function that serves as a common getter for |
11 |
all directories returned by the eclass. Add proper error handling for |
12 |
the variable getter. |
13 |
|
14 |
eclass/systemd.eclass | 38 +++++++++++++++++++++++--------------- |
15 |
1 file changed, 23 insertions(+), 15 deletions(-) |
16 |
|
17 |
diff --git a/eclass/systemd.eclass b/eclass/systemd.eclass |
18 |
index 278d319..245e803 100644 |
19 |
--- a/eclass/systemd.eclass |
20 |
+++ b/eclass/systemd.eclass |
21 |
@@ -34,16 +34,32 @@ esac |
22 |
|
23 |
DEPEND="virtual/pkgconfig" |
24 |
|
25 |
-# @FUNCTION: _systemd_get_unitdir |
26 |
+# @FUNCTION: _systemd_get_dir |
27 |
+# @USAGE: <variable-name> <fallback-directory> |
28 |
# @INTERNAL |
29 |
# @DESCRIPTION: |
30 |
-# Get unprefixed unitdir. |
31 |
-_systemd_get_unitdir() { |
32 |
+# Try to obtain the <variable-name> variable from systemd.pc. |
33 |
+# If pkg-config or systemd is not installed, return <fallback-directory> |
34 |
+# instead. |
35 |
+_systemd_get_dir() { |
36 |
+ [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <variable-name> <fallback-directory>" |
37 |
+ local variable=${1} fallback=${2} d |
38 |
+ |
39 |
if $(tc-getPKG_CONFIG) --exists systemd; then |
40 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)" |
41 |
+ d=$($(tc-getPKG_CONFIG) --variable="${variable}" systemd) || die |
42 |
else |
43 |
- echo /usr/lib/systemd/system |
44 |
+ d=${fallback} |
45 |
fi |
46 |
+ |
47 |
+ echo "${d}" |
48 |
+} |
49 |
+ |
50 |
+# @FUNCTION: _systemd_get_unitdir |
51 |
+# @INTERNAL |
52 |
+# @DESCRIPTION: |
53 |
+# Get unprefixed unitdir. |
54 |
+_systemd_get_unitdir() { |
55 |
+ _systemd_get_dir systemdsystemunitdir /usr/lib/systemd/system |
56 |
} |
57 |
|
58 |
# @FUNCTION: systemd_get_unitdir |
59 |
@@ -62,11 +78,7 @@ systemd_get_unitdir() { |
60 |
# @DESCRIPTION: |
61 |
# Get unprefixed userunitdir. |
62 |
_systemd_get_userunitdir() { |
63 |
- if $(tc-getPKG_CONFIG) --exists systemd; then |
64 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)" |
65 |
- else |
66 |
- echo /usr/lib/systemd/user |
67 |
- fi |
68 |
+ _systemd_get_dir systemduserunitdir /usr/lib/systemd/user |
69 |
} |
70 |
|
71 |
# @FUNCTION: systemd_get_userunitdir |
72 |
@@ -86,11 +98,7 @@ systemd_get_userunitdir() { |
73 |
# @DESCRIPTION: |
74 |
# Get unprefixed utildir. |
75 |
_systemd_get_utildir() { |
76 |
- if $(tc-getPKG_CONFIG) --exists systemd; then |
77 |
- echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)" |
78 |
- else |
79 |
- echo /usr/lib/systemd |
80 |
- fi |
81 |
+ _systemd_get_dir systemdutildir /usr/lib/systemd |
82 |
} |
83 |
|
84 |
# @FUNCTION: systemd_get_utildir |