Gentoo Archives: gentoo-commits

From: "Michal Gorny (mgorny)" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: systemd.eclass
Date: Wed, 04 May 2011 10:53:48
Message-Id: 20110504105335.CF92220054@flycatcher.gentoo.org
1 mgorny 11/05/04 10:53:35
2
3 Added: systemd.eclass
4 Log:
5 Introducing systemd.eclass - a helper eclass to handle systemd unit installation.
6
7 Revision Changes Path
8 1.1 eclass/systemd.eclass
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/systemd.eclass?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/systemd.eclass?rev=1.1&content-type=text/plain
12
13 Index: systemd.eclass
14 ===================================================================
15 # Copyright 1999-2011 Gentoo Foundation
16 # Distributed under the terms of the GNU General Public License v2
17 # $Header: /var/cvsroot/gentoo-x86/eclass/systemd.eclass,v 1.1 2011/05/04 10:53:35 mgorny Exp $
18
19 # @ECLASS: systemd.eclass
20 # @MAINTAINER:
21 # mgorny@g.o
22 # @BLURB: helper functions to install systemd units
23 # @DESCRIPTION:
24 # This eclass provides a set of functions to install unit files for
25 # sys-apps/systemd within ebuilds.
26 # @EXAMPLE:
27 #
28 # @CODE
29 # inherit autotools-utils systemd
30 #
31 # src_configure() {
32 # local myeconfargs=(
33 # --enable-foo
34 # --disable-bar
35 # )
36 #
37 # systemd_to_myeconfargs
38 # autotools-utils_src_configure
39 # }
40 # @CODE
41
42 inherit multilib
43
44 case ${EAPI:-0} in
45 0|1|2|3|4) ;;
46 *) die "${ECLASS}.eclass API in EAPI ${EAPI} not yet established."
47 esac
48
49 # @FUNCTION: systemd_get_unitdir
50 # @DESCRIPTION:
51 # Output the path for the systemd unit directory (not including ${D}).
52 # This function always succeeds, even if systemd is not installed.
53 systemd_get_unitdir() {
54 debug-print-function ${FUNCNAME} "${@}"
55
56 echo -n /lib/systemd/system
57 }
58
59 # @FUNCTION: systemd_dounit
60 # @USAGE: unit1 [...]
61 # @DESCRIPTION:
62 # Install systemd unit(s). Uses doins, thus it is fatal in EAPI 4
63 # and non-fatal in earlier EAPIs.
64 systemd_dounit() {
65 debug-print-function ${FUNCNAME} "${@}"
66
67 (
68 insinto "$(systemd_get_unitdir)"
69 doins "${@}"
70 )
71 }
72
73 # @FUNCTION: systemd_enable_service
74 # @USAGE: target service
75 # @DESCRIPTION:
76 # Enable service in desired target, e.g. install a symlink for it.
77 # Uses dosym, thus it is fatal in EAPI 4 and non-fatal in earlier
78 # EAPIs.
79 systemd_enable_service() {
80 debug-print-function ${FUNCNAME} "${@}"
81
82 [[ ${#} -eq 2 ]] || die "Synopsis: systemd_enable_service target service"
83
84 local target=${1}
85 local service=${2}
86 local ud=$(systemd_get_unitdir)
87
88 dodir "${ud}"/"${target}".wants && \
89 dosym ../"${service}" "${ud}"/"${target}".wants
90 }
91
92 # @FUNCTION: systemd_with_unitdir
93 # @DESCRIPTION:
94 # Output '--with-systemdsystemunitdir' as expected by systemd-aware configure
95 # scripts. This function always succeeds. Its output may be quoted in order
96 # to preserve whitespace in paths. systemd_to_myeconfargs() is preferred over
97 # this function.
98 systemd_with_unitdir() {
99 debug-print-function ${FUNCNAME} "${@}"
100
101 echo -n --with-systemdsystemunitdir="$(systemd_get_unitdir)"
102 }
103
104 # @FUNCTION: systemd_to_myeconfargs
105 # @DESCRIPTION:
106 # Add '--with-systemdsystemunitdir' as expected by systemd-aware configure
107 # scripts to the myeconfargs variable used by autotools-utils eclass. Handles
108 # quoting automatically.
109 systemd_to_myeconfargs() {
110 debug-print-function ${FUNCNAME} "${@}"
111
112 myeconfargs=(
113 "${myeconfargs[@]}"
114 --with-systemdsystemunitdir="$(systemd_get_unitdir)"
115 )
116 }