/[gentoo-x86]/eclass/scons-utils.eclass
Gentoo

Contents of /eclass/scons-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download)
Sun Oct 30 14:30:24 2011 UTC (3 years ago) by mgorny
Branch: MAIN
Changes since 1.7: +26 -9 lines
Support setting common SCons arguments using myesconsargs.

1 # Copyright 1999-2010 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/scons-utils.eclass,v 1.7 2011/10/30 14:29:54 mgorny Exp $
4
5 # @ECLASS: scons-utils.eclass
6 # @MAINTAINER:
7 # mgorny@gentoo.org
8 # @BLURB: helper functions to deal with SCons buildsystem
9 # @DESCRIPTION:
10 # This eclass provides a set of function to help developers sanely call
11 # dev-util/scons and pass parameters to it.
12 # @EXAMPLE:
13 #
14 # @CODE
15 # inherit scons-utils toolchain-funcs
16 #
17 # EAPI=4
18 #
19 # src_configure() {
20 # myesconsargs=(
21 # CC="$(tc-getCC)"
22 # $(use_scons nls ENABLE_NLS)
23 # )
24 # }
25 #
26 # src_compile() {
27 # escons
28 # }
29 #
30 # src_install() {
31 # escons install
32 # }
33 # @CODE
34
35 # -- public variables --
36
37 # @ECLASS-VARIABLE: SCONS_MIN_VERSION
38 # @DEFAULT_UNSET
39 # @DESCRIPTION:
40 # The minimal version of SCons required for the build to work.
41
42 # @VARIABLE: myesconsargs
43 # @DEFAULT_UNSET
44 # @DESCRIPTION:
45 # List of package-specific options to pass to all SCons calls. Supposed to be
46 # set in src_configure().
47
48 # @ECLASS-VARIABLE: SCONSOPTS
49 # @DEFAULT_UNSET
50 # @DESCRIPTION:
51 # The default set of options to pass to scons. Similar to MAKEOPTS,
52 # supposed to be set in make.conf. If unset, escons() will use cleaned
53 # up MAKEOPTS instead.
54
55 # @ECLASS-VARIABLE: EXTRA_ESCONS
56 # @DEFAULT_UNSET
57 # @DESCRIPTION:
58 # The additional parameters to pass to SCons whenever escons() is used.
59 # Much like EXTRA_EMAKE, this is not supposed to be used in make.conf
60 # and not in ebuilds!
61
62 # @ECLASS-VARIABLE: USE_SCONS_TRUE
63 # @DESCRIPTION:
64 # The default value for truth in scons-use() (1 by default).
65 : ${USE_SCONS_TRUE:=1}
66
67 # @ECLASS-VARIABLE: USE_SCONS_FALSE
68 # @DESCRIPTION:
69 # The default value for false in scons-use() (0 by default).
70 : ${USE_SCONS_FALSE:=0}
71
72 # -- EAPI support check --
73
74 case ${EAPI:-0} in
75 0|1|2|3|4) ;;
76 *) die "EAPI ${EAPI} unsupported."
77 esac
78
79 # -- ebuild variables setup --
80
81 if [[ -n ${SCONS_MIN_VERSION} ]]; then
82 DEPEND=">=dev-util/scons-${SCONS_MIN_VERSION}"
83 else
84 DEPEND="dev-util/scons"
85 fi
86
87 # -- public functions --
88
89 # @FUNCTION: escons
90 # @USAGE: [scons-arg] ...
91 # @DESCRIPTION:
92 # Call scons, passing the supplied arguments, ${myesconsargs[@]},
93 # filtered ${MAKEOPTS}, ${EXTRA_ESCONS}. Similar to emake. Like emake,
94 # this function does die on failure in EAPI 4 (unless called nonfatal).
95 escons() {
96 local ret
97
98 debug-print-function ${FUNCNAME} "${@}"
99
100 # if SCONSOPTS are _unset_, use cleaned MAKEOPTS
101 set -- scons ${SCONSOPTS-$(scons_clean_makeopts)} ${EXTRA_ESCONS} \
102 "${myesconsargs[@]}" "${@}"
103 echo "${@}" >&2
104 "${@}"
105 ret=${?}
106
107 [[ ${ret} -ne 0 && ${EAPI:-0} -ge 4 ]] && die "escons failed."
108 return ${ret}
109 }
110
111 # @FUNCTION: scons_clean_makeopts
112 # @USAGE: [makeflags] [...]
113 # @DESCRIPTION:
114 # Strip the supplied makeflags (or ${MAKEOPTS} if called without
115 # an argument) of options not supported by SCons and make sure --jobs
116 # gets an argument. Output the resulting flag list (suitable
117 # for an assignment to SCONSOPTS).
118 scons_clean_makeopts() {
119 local new_makeopts
120
121 debug-print-function ${FUNCNAME} "${@}"
122
123 if [[ ${#} -eq 0 ]]; then
124 debug-print "Using MAKEOPTS: [${MAKEOPTS}]"
125 set -- ${MAKEOPTS}
126 else
127 # unquote if necessary
128 set -- ${*}
129 fi
130
131 # empty MAKEOPTS give out empty SCONSOPTS
132 # thus, we do need to worry about the initial setup
133 if [[ ${*} = ${_SCONS_CACHE_MAKEOPTS} ]]; then
134 set -- ${_SCONS_CACHE_SCONSOPTS}
135 debug-print "Cache hit: [${*}]"
136 echo ${*}
137 return
138 fi
139 export _SCONS_CACHE_MAKEOPTS=${*}
140
141 while [[ ${#} -gt 0 ]]; do
142 case ${1} in
143 # clean, simple to check -- we like that
144 --jobs=*|--keep-going)
145 new_makeopts=${new_makeopts+${new_makeopts} }${1}
146 ;;
147 # need to take a look at the next arg and guess
148 --jobs)
149 if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
150 new_makeopts="${new_makeopts+${new_makeopts} }${1} ${2}"
151 shift
152 else
153 # no value means no limit, let's pass a random int
154 new_makeopts=${new_makeopts+${new_makeopts} }${1}=5
155 fi
156 ;;
157 # strip other long options
158 --*)
159 ;;
160 # short option hell
161 -*)
162 local str new_optstr
163 new_optstr=
164 str=${1#-}
165
166 while [[ -n ${str} ]]; do
167 case ${str} in
168 k*)
169 new_optstr=${new_optstr}k
170 ;;
171 # -j needs to come last
172 j)
173 if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
174 new_optstr="${new_optstr}j ${2}"
175 shift
176 else
177 new_optstr="${new_optstr}j 5"
178 fi
179 ;;
180 # otherwise, everything after -j is treated as an arg
181 j*)
182 new_optstr=${new_optstr}${str}
183 break
184 ;;
185 esac
186 str=${str#?}
187 done
188
189 if [[ -n ${new_optstr} ]]; then
190 new_makeopts=${new_makeopts+${new_makeopts} }-${new_optstr}
191 fi
192 ;;
193 esac
194 shift
195 done
196
197 set -- ${new_makeopts}
198 export _SCONS_CACHE_SCONSOPTS=${*}
199 debug-print "New SCONSOPTS: [${*}]"
200 echo ${*}
201 }
202
203 # @FUNCTION: use_scons
204 # @USAGE: <use-flag> [var-name] [var-opt-true] [var-opt-false]
205 # @DESCRIPTION:
206 # Output a SCons parameter with value depending on the USE flag state.
207 # If the USE flag is set, output <var-name>=<var-opt-true>; otherwise
208 # <var-name>=<var-opt-false>.
209 #
210 # If <var-name> is omitted, <use-flag> will be used instead. However,
211 # if <use-flag> starts with an exclamation mark (!flag), 'no' will be
212 # prepended to the name (e.g. noflag).
213 #
214 # If <var-opt-true> and/or <var-opt-false> are omitted,
215 # ${USE_SCONS_TRUE} and/or ${USE_SCONS_FALSE} will be used instead.
216 use_scons() {
217 local flag=${1}
218 local varname=${2:-${flag/\!/no}}
219 local vartrue=${3:-${USE_SCONS_TRUE}}
220 local varfalse=${4:-${USE_SCONS_FALSE}}
221
222 debug-print-function ${FUNCNAME} "${@}"
223
224 if [[ ${#} -eq 0 ]]; then
225 eerror "Usage: scons-use <use-flag> [var-name] [var-opt-true] [var-opt-false]"
226 die 'scons-use(): not enough arguments'
227 fi
228
229 if use "${flag}"; then
230 echo "${varname}=${vartrue}"
231 else
232 echo "${varname}=${varfalse}"
233 fi
234 }

  ViewVC Help
Powered by ViewVC 1.1.20