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

Contents of /eclass/systemd.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Sat Sep 17 13:48:21 2011 UTC (3 years, 1 month ago) by mgorny
Branch: MAIN
Changes since 1.8: +13 -7 lines
Clean up, fix and simplify prefix support.

1 mgorny 1.1 # Copyright 1999-2011 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 mgorny 1.9 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.8 2011/08/29 01:28:10 vapier 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 mgorny 1.9 # @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 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.9 echo -n "${EPREFIX}$(_systemd_get_unitdir)"
50 mgorny 1.1 }
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 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
62 mgorny 1.1 doins "${@}"
63     )
64     }
65    
66 mgorny 1.5 # @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 mgorny 1.9 insinto "$(_systemd_get_unitdir)"
76 mgorny 1.5 newins "${@}"
77     )
78     }
79    
80 mgorny 1.3 # @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 mgorny 1.1 # @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 mgorny 1.9 local ud=$(_systemd_get_unitdir)
108 mgorny 1.1
109     dodir "${ud}"/"${target}".wants && \
110     dosym ../"${service}" "${ud}"/"${target}".wants
111     }
112    
113     # @FUNCTION: systemd_with_unitdir
114 mgorny 1.4 # @USAGE: [configure option]
115 mgorny 1.1 # @DESCRIPTION:
116     # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
117     # scripts. This function always succeeds. Its output may be quoted in order
118     # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
119     # this function.
120 mgorny 1.4 #
121     # If upstream does use invalid configure option to handle installing systemd
122     # units (e.g. `--with-systemdunitdir'), you can pass the 'suffix' as an optional
123     # argument to this function (`$(systemd_with_unitdir systemdunitdir)'). Please
124     # remember to report a bug upstream as well.
125 mgorny 1.1 systemd_with_unitdir() {
126     debug-print-function ${FUNCNAME} "${@}"
127 mgorny 1.4 local optname=${1:-systemdsystemunitdir}
128 mgorny 1.1
129 mgorny 1.4 echo -n --with-${optname}="$(systemd_get_unitdir)"
130 mgorny 1.1 }
131    
132     # @FUNCTION: systemd_to_myeconfargs
133     # @DESCRIPTION:
134     # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
135     # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
136     # quoting automatically.
137     systemd_to_myeconfargs() {
138     debug-print-function ${FUNCNAME} "${@}"
139    
140     myeconfargs=(
141     "${myeconfargs[@]}"
142     --with-systemdsystemunitdir="$(systemd_get_unitdir)"
143     )
144     }

  ViewVC Help
Powered by ViewVC 1.1.20