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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Thu Jan 5 23:20:02 2012 UTC (2 years, 8 months ago) by mgorny
Branch: MAIN
Changes since 1.9: +4 -3 lines
Fix use of dosym with directory destination.

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.9 2011/09/17 13:48:21 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 # @FUNCTION: _systemd_get_unitdir
34 # @INTERNAL
35 # @DESCRIPTION:
36 # Get unprefixed unitdir.
37 _systemd_get_unitdir() {
38 echo -n /lib/systemd/system
39 }
40
41 # @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 has "${EAPI:-0}" 0 1 2 && ! use prefix && EPREFIX=
47 debug-print-function ${FUNCNAME} "${@}"
48
49 echo -n "${EPREFIX}$(_systemd_get_unitdir)"
50 }
51
52 # @FUNCTION: systemd_dounit
53 # @USAGE: unit1 [...]
54 # @DESCRIPTION:
55 # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
56 # and non-fatal in earlier EAPIs.
57 systemd_dounit() {
58 debug-print-function ${FUNCNAME} "${@}"
59
60 (
61 insinto "$(_systemd_get_unitdir)"
62 doins "${@}"
63 )
64 }
65
66 # @FUNCTION: systemd_newunit
67 # @USAGE: oldname newname
68 # @DESCRIPTION:
69 # Install systemd unit with a new name. Uses newins, thus it is fatal
70 # in EAPI 4 and non-fatal in earlier EAPIs.
71 systemd_newunit() {
72 debug-print-function ${FUNCNAME} "${@}"
73
74 (
75 insinto "$(_systemd_get_unitdir)"
76 newins "${@}"
77 )
78 }
79
80 # @FUNCTION: systemd_dotmpfilesd
81 # @USAGE: tmpfilesd1 [...]
82 # @DESCRIPTION:
83 # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
84 # in EAPI 4 and non-fatal in earlier EAPIs.
85 systemd_dotmpfilesd() {
86 debug-print-function ${FUNCNAME} "${@}"
87
88 (
89 insinto /usr/lib/tmpfiles.d/
90 doins "${@}"
91 )
92 }
93
94 # @FUNCTION: systemd_enable_service
95 # @USAGE: target service
96 # @DESCRIPTION:
97 # Enable service in desired target, e.g. install a symlink for it.
98 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
99 # EAPIs.
100 systemd_enable_service() {
101 debug-print-function ${FUNCNAME} "${@}"
102
103 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
104
105 local target=${1}
106 local service=${2}
107 local ud=$(_systemd_get_unitdir)
108 local destname=$(basename "${service}")
109
110 dodir "${ud}"/"${target}".wants && \
111 dosym ../"${service}" "${ud}"/"${target}".wants/"${destname}"
112 }
113
114 # @FUNCTION: systemd_with_unitdir
115 # @USAGE: [configure option]
116 # @DESCRIPTION:
117 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
118 # scripts. This function always succeeds. Its output may be quoted in order
119 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
120 # this function.
121 #
122 # If upstream does use invalid configure option to handle installing systemd
123 # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
124 # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
125 # remember to report a bug upstream as well.
126 systemd_with_unitdir() {
127 debug-print-function ${FUNCNAME} "${@}"
128 local optname=${1:-systemdsystemunitdir}
129
130 echo -n --with-${optname}="$(systemd_get_unitdir)"
131 }
132
133 # @FUNCTION: systemd_to_myeconfargs
134 # @DESCRIPTION:
135 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
136 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
137 # quoting automatically.
138 systemd_to_myeconfargs() {
139 debug-print-function ${FUNCNAME} "${@}"
140
141 myeconfargs=(
142 "${myeconfargs[@]}"
143 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
144 )
145 }

  ViewVC Help
Powered by ViewVC 1.1.20