meson.eclass: Don't mix host *FLAGS with build *FLAGS
[gentoo.git] / eclass / s6.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: s6.eclass
5 # @MAINTAINER:
6 # William Hubbs <williamh@gentoo.org>
7 # @BLURB: helper functions to install s6 services
8 # @DESCRIPTION:
9 # This eclass provides helpers to install s6 services.
10 # @EXAMPLE:
11 #
12 # @CODE
13 # inherit s6
14 #
15 # src_install() {
16 #       ...
17 #       s6_install_service myservice "${FILESDIR}"/run-s6 "${FILESDIR}"/finish-s6
18 #       ...
19 #       If you want a service to be logged, install the log service as
20 #       shown here.
21 #       s6_install_service myservice/log "${FILESDIR}"/log-run-s6 \
22 #               "${FILESDIR}"/log-finish-s6
23 #       ...
24 # }
25 # @CODE
26
27 case ${EAPI:-0} in
28         5|6) ;;
29         *) die "${ECLASS}.eclass: API in EAPI ${EAPI} not yet established" ;;
30 esac
31
32 # @FUNCTION: _s6_get_servicedir
33 # @INTERNAL
34 # @DESCRIPTION:
35 # Get unprefixed servicedir.
36 _s6_get_servicedir() {
37         echo /var/svc.d
38 }
39
40 # @FUNCTION: s6_get_servicedir
41 # @DESCRIPTION:
42 # Output the path for the s6 service directory (not including ${D}).
43 s6_get_servicedir() {
44         debug-print-function ${FUNCNAME} "${@}"
45
46         echo "${EPREFIX}$(_s6_get_servicedir)"
47 }
48
49 # @FUNCTION: s6_install_service
50 # @USAGE: servicename run finish
51 # @DESCRIPTION:
52 # Install an s6 service.
53 # servicename is the name of the service.
54 # run is the run script for the service.
55 # finish is the optional finish script for the service.
56 s6_install_service() {
57         debug-print-function ${FUNCNAME} "${@}"
58
59         local name="$1"
60         local run="$2"
61         local finish="$3"
62
63         [[ $name ]] ||
64                 die "${ECLASS}.eclass: you must specify the s6 service name"
65         [[ $run ]] ||
66                 die "${ECLASS}.eclass: you must specify the s6 service run script"
67
68         (
69         local servicepath="$(_s6_get_servicedir)/$name"
70         exeinto "$servicepath"
71         newexe "$run" run
72         [[ $finish ]] && newexe "$finish" finish
73         )
74 }
75
76 # @FUNCTION: s6_service_down
77 # @USAGE: servicename
78 # @DESCRIPTION:
79 # Install the "down" flag so this service will not be started by
80 # default.
81 # servicename is the name of the service.
82 s6_service_down() {
83         debug-print-function ${FUNCNAME} "${@}"
84
85         local name="$1"
86
87         [[ $name ]] ||
88                 die "${ECLASS}.eclass: you must specify the s6 service name"
89
90         (
91         touch "$T"/down || die
92         local servicepath="$(_s6_get_servicedir)/$name"
93         insinto "$servicepath"
94         doins "$T"/down
95         )
96 }
97
98 # @FUNCTION: s6_service_nosetsid
99 # @USAGE: servicename
100 # @DESCRIPTION:
101 # Install the "nosetsid" flag so this service will not be made a session
102 # leader.
103 # servicename is the name of the service.
104 s6_service_nosetsid() {
105         debug-print-function ${FUNCNAME} "${@}"
106
107         local name="$1"
108
109         [[ $name ]] ||
110                 die "${ECLASS}.eclass: you must specify the s6 service name"
111
112         (
113         touch "$T"/nosetsid || die
114         local servicepath="$(_s6_get_servicedir)/$name"
115         insinto "$servicepath"
116         doins "$T"/nosetsid
117         )
118 }