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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Sat Jan 7 17:53:47 2012 UTC (2 years, 8 months ago) by mgorny
Branch: MAIN
Changes since 1.10: +6 -2 lines
Install systemd units to /usr/lib.

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.10 2012/01/05 23:20:02 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_enable_service
99 # @USAGE: target service
100 # @DESCRIPTION:
101 # Enable service in desired target, e.g. install a symlink for it.
102 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
103 # EAPIs.
104 systemd_enable_service() {
105 debug-print-function ${FUNCNAME} "${@}"
106
107 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
108
109 local target=${1}
110 local service=${2}
111 local ud=$(_systemd_get_unitdir)
112 local destname=$(basename "${service}")
113
114 dodir "${ud}"/"${target}".wants && \
115 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
116 }
117
118 # @FUNCTION: systemd_with_unitdir
119 # @USAGE: [configure option]
120 # @DESCRIPTION:
121 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
122 # scripts. This function always succeeds. Its output may be quoted in order
123 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
124 # this function.
125 #
126 # If upstream does use invalid configure option to handle installing systemd
127 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
128 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
129 # remember to report a bug upstream as well.
130 systemd_with_unitdir() {
131 debug-print-function ${FUNCNAME} "${@}"
132 local optname=${1:-systemdsystemunitdir}
133
134 echo -n --with-${optname}="$(systemd_get_unitdir)"
135 }
136
137 # @FUNCTION: systemd_to_myeconfargs
138 # @DESCRIPTION:
139 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
140 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
141 # quoting automatically.
142 systemd_to_myeconfargs() {
143 debug-print-function ${FUNCNAME} "${@}"
144
145 myeconfargs=(
146 "${myeconfargs[@]}"
147 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
148 )
149 }

  ViewVC Help
Powered by ViewVC 1.1.20