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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Tue Oct 30 21:56:31 2012 UTC (2 years, 1 month ago) by mgorny
Branch: MAIN
Changes since 1.17: +12 -1 lines
Add systemd_with_utildir() as well.

1 mgorny 1.10 # Copyright 1999-2012 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.17 2012/10/30 21:29:32 mgorny Exp $
4 mgorny 1.1
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 vapier 1.8 #
17 mgorny 1.1 # 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 axs 1.15 0|1|2|3|4|5) ;;
30 mgorny 1.1 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
31     esac
32    
33 mgorny 1.9 # @FUNCTION: _systemd_get_unitdir
34     # @INTERNAL
35     # @DESCRIPTION:
36     # Get unprefixed unitdir.
37     _systemd_get_unitdir() {
38 mgorny 1.16 echo /usr/lib/systemd/system
39 mgorny 1.9 }
40    
41 mgorny 1.1 # @FUNCTION: systemd_get_unitdir
42     # @DESCRIPTION:
43     # Output the path for the systemd unit directory (not including ${D}).
44     # This function always succeeds, even if systemd is not installed.
45     systemd_get_unitdir() {
46 darkside 1.6 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
47 mgorny 1.1 debug-print-function ${FUNCNAME} "${@}"
48    
49 mgorny 1.16 echo "${EPREFIX}$(_systemd_get_unitdir)"
50 mgorny 1.1 }
51    
52 mgorny 1.17 # @FUNCTION: systemd_get_utildir
53     # @DESCRIPTION:
54     # Output the path for the systemd utility directory (not including
55     # ${D}). This function always succeeds, even if systemd is not
56     # installed.
57     systemd_get_utildir() {
58     has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
59     debug-print-function ${FUNCNAME} "${@}"
60    
61     echo "${EPREFIX}/usr/lib/systemd"
62     }
63    
64 mgorny 1.1 # @FUNCTION: systemd_dounit
65     # @USAGE: unit1 [...]
66     # @DESCRIPTION:
67     # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
68     # and non-fatal in earlier EAPIs.
69     systemd_dounit() {
70     debug-print-function ${FUNCNAME} "${@}"
71    
72     (
73 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
74 mgorny 1.1 doins "${@}"
75     )
76     }
77    
78 mgorny 1.5 # @FUNCTION: systemd_newunit
79     # @USAGE: oldname newname
80     # @DESCRIPTION:
81     # Install systemd unit with a new name. Uses newins, thus it is fatal
82     # in EAPI 4 and non-fatal in earlier EAPIs.
83     systemd_newunit() {
84     debug-print-function ${FUNCNAME} "${@}"
85    
86     (
87 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
88 mgorny 1.5 newins "${@}"
89     )
90     }
91    
92 mgorny 1.3 # @FUNCTION: systemd_dotmpfilesd
93     # @USAGE: tmpfilesd1 [...]
94     # @DESCRIPTION:
95     # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
96     # in EAPI 4 and non-fatal in earlier EAPIs.
97     systemd_dotmpfilesd() {
98     debug-print-function ${FUNCNAME} "${@}"
99    
100 mgorny 1.13 for f; do
101     [[ ${f} == *.conf ]] \
102     || die 'tmpfiles.d files need to have .conf suffix.'
103     done
104    
105 mgorny 1.3 (
106     insinto /usr/lib/tmpfiles.d/
107     doins "${@}"
108     )
109     }
110    
111 mgorny 1.12 # @FUNCTION: systemd_newtmpfilesd
112     # @USAGE: oldname newname.conf
113     # @DESCRIPTION:
114     # Install systemd tmpfiles.d file under a new name. Uses newins, thus it
115     # is fatal in EAPI 4 and non-fatal in earlier EAPIs.
116     systemd_newtmpfilesd() {
117     debug-print-function ${FUNCNAME} "${@}"
118    
119 mgorny 1.13 [[ ${2} == *.conf ]] \
120     || die 'tmpfiles.d files need to have .conf suffix.'
121    
122 mgorny 1.12 (
123     insinto /usr/lib/tmpfiles.d/
124     newins "${@}"
125     )
126     }
127    
128 mgorny 1.1 # @FUNCTION: systemd_enable_service
129     # @USAGE: target service
130     # @DESCRIPTION:
131     # Enable service in desired target, e.g. install a symlink for it.
132     # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
133     # EAPIs.
134     systemd_enable_service() {
135     debug-print-function ${FUNCNAME} "${@}"
136    
137     [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
138    
139     local target=${1}
140     local service=${2}
141 mgorny 1.9 local ud=$(_systemd_get_unitdir)
142 mgorny 1.10 local destname=$(basename "${service}")
143 mgorny 1.1
144     dodir "${ud}"/"${target}".wants && \
145 mgorny 1.10 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
146 mgorny 1.1 }
147    
148     # @FUNCTION: systemd_with_unitdir
149 mgorny 1.4 # @USAGE: [configure option]
150 mgorny 1.1 # @DESCRIPTION:
151     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
152     # scripts. This function always succeeds. Its output may be quoted in order
153     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
154     # this function.
155 mgorny 1.4 #
156     # If upstream does use invalid configure option to handle installing systemd
157     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
158     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
159     # remember to report a bug upstream as well.
160 mgorny 1.1 systemd_with_unitdir() {
161     debug-print-function ${FUNCNAME} "${@}"
162 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
163 mgorny 1.1
164 mgorny 1.16 echo --with-${optname}="$(systemd_get_unitdir)"
165 mgorny 1.1 }
166    
167 mgorny 1.18 # @FUNCTION: systemd_with_utildir
168     # @DESCRIPTION:
169     # Output '--with-systemdsystemutildir' as used by some packages to install
170     # systemd helpers. This function always succeeds. Its output may be quoted
171     # in order to preserve whitespace in paths.
172     systemd_with_utildir() {
173     debug-print-function ${FUNCNAME} "${@}"
174    
175     echo --with-systemdutildir="$(systemd_get_utildir)"
176     }
177    
178 mgorny 1.1 # @FUNCTION: systemd_to_myeconfargs
179     # @DESCRIPTION:
180     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
181     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
182     # quoting automatically.
183     systemd_to_myeconfargs() {
184     debug-print-function ${FUNCNAME} "${@}"
185    
186     myeconfargs=(
187     "${myeconfargs[@]}"
188     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
189     )
190     }

  ViewVC Help
Powered by ViewVC 1.1.20