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