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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Mon Aug 27 21:53:04 2012 UTC (2 years ago) by mgorny
Branch: MAIN
Changes since 1.11: +15 -1 lines
Add systemd_newtmpfilesd().

1 # Copyright 1999-2012 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.11 2012/01/07 17:53:47 mgorny Exp $
4
5 # @ECLASS: systemd.eclass
6 # @MAINTAINER:
7 # mgorny@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 case ${EAPI:-0} in
29 0|1|2|3|4) ;;
30 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31 esac
32
33 # Block systemd version without the migration helper.
34 DEPEND="!<sys-apps/systemd-29-r4
35 !=sys-apps/systemd-37-r1"
36
37 # @FUNCTION: _systemd_get_unitdir
38 # @INTERNAL
39 # @DESCRIPTION:
40 # Get unprefixed unitdir.
41 _systemd_get_unitdir() {
42 echo -n /usr/lib/systemd/system
43 }
44
45 # @FUNCTION: systemd_get_unitdir
46 # @DESCRIPTION:
47 # Output the path for the systemd unit directory (not including ${D}).
48 # This function always succeeds, even if systemd is not installed.
49 systemd_get_unitdir() {
50 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
51 debug-print-function ${FUNCNAME} "${@}"
52
53 echo -n "${EPREFIX}$(_systemd_get_unitdir)"
54 }
55
56 # @FUNCTION: systemd_dounit
57 # @USAGE: unit1 [...]
58 # @DESCRIPTION:
59 # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
60 # and non-fatal in earlier EAPIs.
61 systemd_dounit() {
62 debug-print-function ${FUNCNAME} "${@}"
63
64 (
65 insinto "$(_systemd_get_unitdir)"
66 doins "${@}"
67 )
68 }
69
70 # @FUNCTION: systemd_newunit
71 # @USAGE: oldname newname
72 # @DESCRIPTION:
73 # Install systemd unit with a new name. Uses newins, thus it is fatal
74 # in EAPI 4 and non-fatal in earlier EAPIs.
75 systemd_newunit() {
76 debug-print-function ${FUNCNAME} "${@}"
77
78 (
79 insinto "$(_systemd_get_unitdir)"
80 newins "${@}"
81 )
82 }
83
84 # @FUNCTION: systemd_dotmpfilesd
85 # @USAGE: tmpfilesd1 [...]
86 # @DESCRIPTION:
87 # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
88 # in EAPI 4 and non-fatal in earlier EAPIs.
89 systemd_dotmpfilesd() {
90 debug-print-function ${FUNCNAME} "${@}"
91
92 (
93 insinto /usr/lib/tmpfiles.d/
94 doins "${@}"
95 )
96 }
97
98 # @FUNCTION: systemd_newtmpfilesd
99 # @USAGE: oldname newname.conf
100 # @DESCRIPTION:
101 # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
102 # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
103 systemd_newtmpfilesd() {
104 debug-print-function ${FUNCNAME} "${@}"
105
106 (
107 insinto /usr/lib/tmpfiles.d/
108 newins "${@}"
109 )
110 }
111
112 # @FUNCTION: systemd_enable_service
113 # @USAGE: target service
114 # @DESCRIPTION:
115 # Enable service in desired target, e.g. install a symlink for it.
116 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
117 # EAPIs.
118 systemd_enable_service() {
119 debug-print-function ${FUNCNAME} "${@}"
120
121 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
122
123 local target=${1}
124 local service=${2}
125 local ud=$(_systemd_get_unitdir)
126 local destname=$(basename "${service}")
127
128 dodir "${ud}"/"${target}".wants && \
129 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
130 }
131
132 # @FUNCTION: systemd_with_unitdir
133 # @USAGE: [configure option]
134 # @DESCRIPTION:
135 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
136 # scripts. This function always succeeds. Its output may be quoted in order
137 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
138 # this function.
139 #
140 # If upstream does use invalid configure option to handle installing systemd
141 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
142 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
143 # remember to report a bug upstream as well.
144 systemd_with_unitdir() {
145 debug-print-function ${FUNCNAME} "${@}"
146 local optname=${1:-systemdsystemunitdir}
147
148 echo -n --with-${optname}="$(systemd_get_unitdir)"
149 }
150
151 # @FUNCTION: systemd_to_myeconfargs
152 # @DESCRIPTION:
153 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
154 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
155 # quoting automatically.
156 systemd_to_myeconfargs() {
157 debug-print-function ${FUNCNAME} "${@}"
158
159 myeconfargs=(
160 "${myeconfargs[@]}"
161 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
162 )
163 }

  ViewVC Help
Powered by ViewVC 1.1.20