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

Contents of /eclass/scons-utils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Thu Oct 7 19:14:48 2010 UTC (3 years, 6 months ago) by mgorny
Branch: MAIN
Introducing scons-utils.eclass -- a new eclass providing functions to help using SCons buildsystem.

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

  ViewVC Help
Powered by ViewVC 1.1.20