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