1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: scons-utils.eclass
8 # @BLURB: helper functions to deal with SCons buildsystem
10 # This eclass provides a set of function to help developers sanely call
11 # dev-util/scons and pass parameters to it.
15 # inherit scons-utils toolchain-funcs
22 # $(use_scons nls ENABLE_NLS)
31 # # note: this can be DESTDIR, INSTALL_ROOT, ... depending on package
32 # escons DESTDIR="${D}" install
36 # -- public variables --
38 # @ECLASS-VARIABLE: SCONS_MIN_VERSION
41 # The minimal version of SCons required for the build to work.
43 # @VARIABLE: myesconsargs
46 # List of package-specific options to pass to all SCons calls. Supposed to be
47 # set in src_configure().
49 # @ECLASS-VARIABLE: SCONSOPTS
52 # The default set of options to pass to scons. Similar to MAKEOPTS,
53 # supposed to be set in make.conf. If unset, escons() will use cleaned
54 # up MAKEOPTS instead.
56 # @ECLASS-VARIABLE: EXTRA_ESCONS
59 # The additional parameters to pass to SCons whenever escons() is used.
60 # Much like EXTRA_EMAKE, this is not supposed to be used in make.conf
63 # @ECLASS-VARIABLE: USE_SCONS_TRUE
65 # The default value for truth in scons-use() (1 by default).
66 : ${USE_SCONS_TRUE:=1}
68 # @ECLASS-VARIABLE: USE_SCONS_FALSE
70 # The default value for false in scons-use() (0 by default).
71 : ${USE_SCONS_FALSE:=0}
73 # -- EAPI support check --
77 *) die "EAPI ${EAPI} unsupported."
80 # -- ebuild variables setup --
82 if [[ -n ${SCONS_MIN_VERSION} ]]; then
83 DEPEND=">=dev-util/scons-${SCONS_MIN_VERSION}"
85 DEPEND="dev-util/scons"
88 # -- public functions --
91 # @USAGE: [scons-arg] ...
93 # Call scons, passing the supplied arguments, ${myesconsargs[@]},
94 # filtered ${MAKEOPTS}, ${EXTRA_ESCONS}. Similar to emake. Like emake,
95 # this function does die on failure in EAPI 4 (unless called nonfatal).
99 debug-print-function ${FUNCNAME} "${@}"
101 # if SCONSOPTS are _unset_, use cleaned MAKEOPTS
102 set -- scons ${SCONSOPTS-$(scons_clean_makeopts)} ${EXTRA_ESCONS} \
103 "${myesconsargs[@]}" "${@}"
108 [[ ${ret} -ne 0 ]] && has "${EAPI:-0}" 4 5 && die "escons failed."
112 # @FUNCTION: scons_clean_makeopts
113 # @USAGE: [makeflags] [...]
115 # Strip the supplied makeflags (or ${MAKEOPTS} if called without
116 # an argument) of options not supported by SCons and make sure --jobs
117 # gets an argument. Output the resulting flag list (suitable
118 # for an assignment to SCONSOPTS).
119 scons_clean_makeopts() {
122 debug-print-function ${FUNCNAME} "${@}"
124 if [[ ${#} -eq 0 ]]; then
125 debug-print "Using MAKEOPTS: [${MAKEOPTS}]"
128 # unquote if necessary
132 # empty MAKEOPTS give out empty SCONSOPTS
133 # thus, we do need to worry about the initial setup
134 if [[ ${*} = ${_SCONS_CACHE_MAKEOPTS} ]]; then
135 set -- ${_SCONS_CACHE_SCONSOPTS}
136 debug-print "Cache hit: [${*}]"
140 export _SCONS_CACHE_MAKEOPTS=${*}
142 while [[ ${#} -gt 0 ]]; do
144 # clean, simple to check -- we like that
145 --jobs=*|--keep-going)
146 new_makeopts=${new_makeopts+${new_makeopts} }${1}
148 # need to take a look at the next arg and guess
150 if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
151 new_makeopts="${new_makeopts+${new_makeopts} }${1} ${2}"
154 # no value means no limit, let's pass a random int
155 new_makeopts=${new_makeopts+${new_makeopts} }${1}=5
158 # strip other long options
167 while [[ -n ${str} ]]; do
170 new_optstr=${new_optstr}k
172 # -j needs to come last
174 if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
175 new_optstr="${new_optstr}j ${2}"
178 new_optstr="${new_optstr}j 5"
181 # otherwise, everything after -j is treated as an arg
183 new_optstr=${new_optstr}${str}
190 if [[ -n ${new_optstr} ]]; then
191 new_makeopts=${new_makeopts+${new_makeopts} }-${new_optstr}
198 set -- ${new_makeopts}
199 export _SCONS_CACHE_SCONSOPTS=${*}
200 debug-print "New SCONSOPTS: [${*}]"
204 # @FUNCTION: use_scons
205 # @USAGE: <use-flag> [var-name] [var-opt-true] [var-opt-false]
207 # Output a SCons parameter with value depending on the USE flag state.
208 # If the USE flag is set, output <var-name>=<var-opt-true>; otherwise
209 # <var-name>=<var-opt-false>.
211 # If <var-name> is omitted, <use-flag> will be used instead. However,
212 # if <use-flag> starts with an exclamation mark (!flag), 'no' will be
213 # prepended to the name (e.g. noflag).
215 # If <var-opt-true> and/or <var-opt-false> are omitted,
216 # ${USE_SCONS_TRUE} and/or ${USE_SCONS_FALSE} will be used instead.
219 local varname=${2:-${flag/\!/no}}
220 local vartrue=${3:-${USE_SCONS_TRUE}}
221 local varfalse=${4:-${USE_SCONS_FALSE}}
223 debug-print-function ${FUNCNAME} "${@}"
225 if [[ ${#} -eq 0 ]]; then
226 eerror "Usage: scons-use <use-flag> [var-name] [var-opt-true] [var-opt-false]"
227 die 'scons-use(): not enough arguments'
230 if use "${flag}"; then
231 echo "${varname}=${vartrue}"
233 echo "${varname}=${varfalse}"