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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations) (download)
Mon Aug 29 01:28:10 2011 UTC (2 years, 10 months ago) by vapier
Branch: MAIN
Changes since 1.7: +2 -2 lines
trim useless trailing whitespace

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

  ViewVC Help
Powered by ViewVC 1.1.20