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

Contents of /eclass/scons-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Fri Apr 15 20:06:07 2011 UTC (3 years, 7 months ago) by mgorny
Branch: MAIN
Changes since 1.3: +16 -2 lines
Check for EAPI. Make escons fatal in EAPI 4.

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

  ViewVC Help
Powered by ViewVC 1.1.20