/[gentoo-x86]/eclass/systemd.eclass
Gentoo

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (show annotations) (download)
Sat Apr 13 22:35:53 2013 UTC (18 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.22: +37 -4 lines
Use pkg-config to query systemd directories.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.22 2013/03/18 06:29:03 mgorny Exp $
4
5 # @ECLASS: systemd.eclass
6 # @MAINTAINER:
7 # systemd@gentoo.org
8 # @BLURB: helper functions to install systemd units
9 # @DESCRIPTION:
10 # This eclass provides a set of functions to install unit files for
11 # sys-apps/systemd within ebuilds.
12 # @EXAMPLE:
13 #
14 # @CODE
15 # inherit autotools-utils systemd
16 #
17 # src_configure() {
18 # local myeconfargs=(
19 # --enable-foo
20 # --disable-bar
21 # )
22 #
23 # systemd_to_myeconfargs
24 # autotools-utils_src_configure
25 # }
26 # @CODE
27
28 inherit toolchain-funcs
29
30 case ${EAPI:-0} in
31 0|1|2|3|4|5) ;;
32 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
33 esac
34
35 DEPEND="virtual/pkgconfig"
36
37 # @FUNCTION: _systemd_get_unitdir
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Get unprefixed unitdir.
41 _systemd_get_unitdir() {
42 if $(tc-getPKG_CONFIG) --exists systemd; then
43 echo "$($(tc-getPKG_CONFIG) --variable=systemdsystemunitdir systemd)"
44 else
45 echo /usr/lib/systemd/system
46 fi
47 }
48
49 # @FUNCTION: systemd_get_unitdir
50 # @DESCRIPTION:
51 # Output the path for the systemd unit directory (not including ${D}).
52 # This function always succeeds, even if systemd is not installed.
53 systemd_get_unitdir() {
54 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
55 debug-print-function ${FUNCNAME} "${@}"
56
57 echo "${EPREFIX}$(_systemd_get_unitdir)"
58 }
59
60 # @FUNCTION: _systemd_get_userunitdir
61 # @INTERNAL
62 # @DESCRIPTION:
63 # Get unprefixed userunitdir.
64 _systemd_get_userunitdir() {
65 if $($(tc-getPKG_CONFIG) --exists systemd); then
66 echo "$($(tc-getPKG_CONFIG) --variable=systemduserunitdir systemd)"
67 else
68 echo /usr/lib/systemd/user
69 fi
70 }
71
72 # @FUNCTION: systemd_get_userunitdir
73 # @DESCRIPTION:
74 # Output the path for the systemd user unit directory (not including
75 # ${D}). This function always succeeds, even if systemd is not
76 # installed.
77 systemd_get_userunitdir() {
78 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
79 debug-print-function ${FUNCNAME} "${@}"
80
81 echo "${EPREFIX}$(_systemd_get_userunitdir)"
82 }
83
84 # @FUNCTION: _systemd_get_utildir
85 # @INTERNAL
86 # @DESCRIPTION:
87 # Get unprefixed utildir.
88 _systemd_get_utildir() {
89 if $($(tc-getPKG_CONFIG) --exists systemd); then
90 echo "$($(tc-getPKG_CONFIG) --variable=systemdutildir systemd)"
91 else
92 echo /usr/lib/systemd
93 fi
94 }
95
96 # @FUNCTION: systemd_get_utildir
97 # @DESCRIPTION:
98 # Output the path for the systemd utility directory (not including
99 # ${D}). This function always succeeds, even if systemd is not
100 # installed.
101 systemd_get_utildir() {
102 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
103 debug-print-function ${FUNCNAME} "${@}"
104
105 echo "${EPREFIX}$(_systemd_get_utildir)"
106 }
107
108 # @FUNCTION: systemd_dounit
109 # @USAGE: unit1 [...]
110 # @DESCRIPTION:
111 # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
112 # and non-fatal in earlier EAPIs.
113 systemd_dounit() {
114 debug-print-function ${FUNCNAME} "${@}"
115
116 local INSDESTTREE
117 insinto "$(_systemd_get_unitdir)"
118 doins "${@}"
119 }
120
121 # @FUNCTION: systemd_newunit
122 # @USAGE: oldname newname
123 # @DESCRIPTION:
124 # Install systemd unit with a new name. Uses newins, thus it is fatal
125 # in EAPI 4 and non-fatal in earlier EAPIs.
126 systemd_newunit() {
127 debug-print-function ${FUNCNAME} "${@}"
128
129 local INSDESTTREE
130 insinto "$(_systemd_get_unitdir)"
131 newins "${@}"
132 }
133
134 # @FUNCTION: systemd_dotmpfilesd
135 # @USAGE: tmpfilesd1 [...]
136 # @DESCRIPTION:
137 # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
138 # in EAPI 4 and non-fatal in earlier EAPIs.
139 systemd_dotmpfilesd() {
140 debug-print-function ${FUNCNAME} "${@}"
141
142 for f; do
143 [[ ${f} == *.conf ]] \
144 || die 'tmpfiles.d files need to have .conf suffix.'
145 done
146
147 local INSDESTTREE
148 insinto /usr/lib/tmpfiles.d/
149 doins "${@}"
150 }
151
152 # @FUNCTION: systemd_newtmpfilesd
153 # @USAGE: oldname newname.conf
154 # @DESCRIPTION:
155 # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
156 # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
157 systemd_newtmpfilesd() {
158 debug-print-function ${FUNCNAME} "${@}"
159
160 [[ ${2} == *.conf ]] \
161 || die 'tmpfiles.d files need to have .conf suffix.'
162
163 local INSDESTTREE
164 insinto /usr/lib/tmpfiles.d/
165 newins "${@}"
166 }
167
168 # @FUNCTION: systemd_enable_service
169 # @USAGE: target service
170 # @DESCRIPTION:
171 # Enable service in desired target, e.g. install a symlink for it.
172 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
173 # EAPIs.
174 systemd_enable_service() {
175 debug-print-function ${FUNCNAME} "${@}"
176
177 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
178
179 local target=${1}
180 local service=${2}
181 local ud=$(_systemd_get_unitdir)
182 local destname=$(basename "${service}")
183
184 dodir "${ud}"/"${target}".wants && \
185 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
186 }
187
188 # @FUNCTION: systemd_with_unitdir
189 # @USAGE: [configure option]
190 # @DESCRIPTION:
191 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
192 # scripts. This function always succeeds. Its output may be quoted in order
193 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
194 # this function.
195 #
196 # If upstream does use invalid configure option to handle installing systemd
197 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
198 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
199 # remember to report a bug upstream as well.
200 systemd_with_unitdir() {
201 debug-print-function ${FUNCNAME} "${@}"
202 local optname=${1:-systemdsystemunitdir}
203
204 echo --with-${optname}="$(systemd_get_unitdir)"
205 }
206
207 # @FUNCTION: systemd_with_utildir
208 # @DESCRIPTION:
209 # Output '--with-systemdsystemutildir' as used by some packages to install
210 # systemd helpers. This function always succeeds. Its output may be quoted
211 # in order to preserve whitespace in paths.
212 systemd_with_utildir() {
213 debug-print-function ${FUNCNAME} "${@}"
214
215 echo --with-systemdutildir="$(systemd_get_utildir)"
216 }
217
218 # @FUNCTION: systemd_to_myeconfargs
219 # @DESCRIPTION:
220 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
221 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
222 # quoting automatically.
223 systemd_to_myeconfargs() {
224 debug-print-function ${FUNCNAME} "${@}"
225
226 myeconfargs=(
227 "${myeconfargs[@]}"
228 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
229 )
230 }
231
232 # @FUNCTION: systemd_update_catalog
233 # @DESCRIPTION:
234 # Update the journald catalog. This needs to be called after installing
235 # or removing catalog files.
236 #
237 # If systemd is not installed, no operation will be done. The catalog
238 # will be (re)built once systemd is installed.
239 #
240 # See: http://www.freedesktop.org/wiki/Software/systemd/catalog
241 systemd_update_catalog() {
242 debug-print-function ${FUNCNAME} "${@}"
243
244 # Make sure to work on the correct system.
245
246 local journalctl=${EPREFIX}/usr/bin/journalctl
247 if [[ -x ${journalctl} ]]; then
248 ebegin "Updating systemd journal catalogs"
249 journalctl --update-catalog
250 eend $?
251 else
252 debug-print "${FUNCNAME}: journalctl not found."
253 fi
254 }

  ViewVC Help
Powered by ViewVC 1.1.20