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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Sun Jun 19 16:05:10 2011 UTC (3 years, 3 months ago) by mgorny
Branch: MAIN
Changes since 1.4: +15 -1 lines
Add systemd_newunit() to handle @-related renames gracefully.

1 mgorny 1.1 # Copyright 1999-2011 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.5 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.4 2011/06/16 16:39:18 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     #
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     # @DESCRIPTION:
35     # Output the path for the systemd unit directory (not including ${D}).
36     # This function always succeeds, even if systemd is not installed.
37     systemd_get_unitdir() {
38     debug-print-function ${FUNCNAME} "${@}"
39    
40     echo -n /lib/systemd/system
41     }
42    
43     # @FUNCTION: systemd_dounit
44     # @USAGE: unit1 [...]
45     # @DESCRIPTION:
46     # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
47     # and non-fatal in earlier EAPIs.
48     systemd_dounit() {
49     debug-print-function ${FUNCNAME} "${@}"
50    
51     (
52     insinto "$(systemd_get_unitdir)"
53     doins "${@}"
54     )
55     }
56    
57 mgorny 1.5 # @FUNCTION: systemd_newunit
58     # @USAGE: oldname newname
59     # @DESCRIPTION:
60     # Install systemd unit with a new name. Uses newins, thus it is fatal
61     # in EAPI 4 and non-fatal in earlier EAPIs.
62     systemd_newunit() {
63     debug-print-function ${FUNCNAME} "${@}"
64    
65     (
66     insinto "$(systemd_get_unitdir)"
67     newins "${@}"
68     )
69     }
70    
71 mgorny 1.3 # @FUNCTION: systemd_dotmpfilesd
72     # @USAGE: tmpfilesd1 [...]
73     # @DESCRIPTION:
74     # Install systemd tmpfiles.d files. Uses doins, thus it is fatal
75     # in EAPI 4 and non-fatal in earlier EAPIs.
76     systemd_dotmpfilesd() {
77     debug-print-function ${FUNCNAME} "${@}"
78    
79     (
80     insinto /usr/lib/tmpfiles.d/
81     doins "${@}"
82     )
83     }
84    
85 mgorny 1.1 # @FUNCTION: systemd_enable_service
86     # @USAGE: target service
87     # @DESCRIPTION:
88     # Enable service in desired target, e.g. install a symlink for it.
89     # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
90     # EAPIs.
91     systemd_enable_service() {
92     debug-print-function ${FUNCNAME} "${@}"
93    
94     [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
95    
96     local target=${1}
97     local service=${2}
98     local ud=$(systemd_get_unitdir)
99    
100     dodir "${ud}"/"${target}".wants && \
101     dosym ../"${service}" "${ud}"/"${target}".wants
102     }
103    
104     # @FUNCTION: systemd_with_unitdir
105 mgorny 1.4 # @USAGE: [configure option]
106 mgorny 1.1 # @DESCRIPTION:
107     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
108     # scripts. This function always succeeds. Its output may be quoted in order
109     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
110     # this function.
111 mgorny 1.4 #
112     # If upstream does use invalid configure option to handle installing systemd
113     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
114     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
115     # remember to report a bug upstream as well.
116 mgorny 1.1 systemd_with_unitdir() {
117     debug-print-function ${FUNCNAME} "${@}"
118 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
119 mgorny 1.1
120 mgorny 1.4 echo -n --with-${optname}="$(systemd_get_unitdir)"
121 mgorny 1.1 }
122    
123     # @FUNCTION: systemd_to_myeconfargs
124     # @DESCRIPTION:
125     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
126     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
127     # quoting automatically.
128     systemd_to_myeconfargs() {
129     debug-print-function ${FUNCNAME} "${@}"
130    
131     myeconfargs=(
132     "${myeconfargs[@]}"
133     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
134     )
135     }

  ViewVC Help
Powered by ViewVC 1.1.20