2 # -*- coding: utf-8 vi:ts=4:noexpandtab
3 # Tool to provide dedicated variables for cross-compilation
5 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
6 __copyright__ = "Jérôme Carretero, 2014"
10 This tool allows to use environment variables to define cross-compilation things,
11 mostly used when you use build variants.
13 The variables are obtained from the environment in 3 ways:
15 1. By defining CHOST, they can be derived as ${CHOST}-${TOOL}
17 3. By defining ${CHOST//-/_}_x
21 - In your build script::
25 conf.load('c_cross_gnu')
26 for variant in x_variants:
28 conf.xcheck_host_var('POUET')
35 CHOST=arm-hardfloat-linux-gnueabi waf configure
37 env arm-hardfloat-linux-gnueabi-CC="clang -..." waf configure
39 CFLAGS=... CHOST=arm-hardfloat-linux-gnueabi HOST_CFLAGS=-g waf configure
41 HOST_CC="clang -..." waf configure
46 from waflib import Utils, Configure
49 from shlex import quote
51 from pipes import quote
53 def get_chost_stuff(conf):
55 Get the CHOST environment variable contents
60 chost = conf.env.CHOST[0]
61 chost_envar = chost.replace('-', '_')
62 return chost, chost_envar
66 def xcheck_envar(conf, name, wafname=None, cross=False):
67 wafname = wafname or name
68 envar = os.environ.get(name, None)
73 value = Utils.to_list(envar) if envar != '' else [envar]
75 conf.env[wafname] = value
77 pretty = 'cross-compilation %s' % wafname
80 conf.msg('Will use %s' % pretty,
81 " ".join(quote(x) for x in value))
84 def xcheck_host_prog(conf, name, tool, wafname=None):
85 wafname = wafname or name
87 chost, chost_envar = get_chost_stuff(conf)
91 specific = os.environ.get('%s_%s' % (chost_envar, name), None)
94 value = Utils.to_list(specific)
95 conf.env[wafname] += value
96 conf.msg('Will use cross-compilation %s from %s_%s' \
97 % (name, chost_envar, name),
98 " ".join(quote(x) for x in value))
101 envar = os.environ.get('HOST_%s' % name, None)
102 if envar is not None:
103 value = Utils.to_list(envar)
104 conf.env[wafname] = value
105 conf.msg('Will use cross-compilation %s from HOST_%s' \
107 " ".join(quote(x) for x in value))
110 if conf.env[wafname]:
115 value = '%s-%s' % (chost, tool)
118 conf.env[wafname] = value
119 conf.msg('Will use cross-compilation %s from CHOST' \
123 def xcheck_host_envar(conf, name, wafname=None):
124 wafname = wafname or name
126 chost, chost_envar = get_chost_stuff(conf)
130 specific = os.environ.get('%s_%s' % (chost_envar, name), None)
133 value = Utils.to_list(specific)
134 conf.env[wafname] += value
135 conf.msg('Will use cross-compilation %s from %s_%s' \
136 % (name, chost_envar, name),
137 " ".join(quote(x) for x in value))
141 envar = os.environ.get('HOST_%s' % name, None)
145 value = Utils.to_list(envar) if envar != '' else [envar]
147 conf.env[wafname] = value
148 conf.msg('Will use cross-compilation %s from HOST_%s' \
150 " ".join(quote(x) for x in value))
154 def xcheck_host(conf):
155 conf.xcheck_envar('CHOST', cross=True)
156 conf.xcheck_host_prog('CC', 'gcc')
157 conf.xcheck_host_prog('CXX', 'g++')
158 conf.xcheck_host_prog('LINK_CC', 'gcc')
159 conf.xcheck_host_prog('LINK_CXX', 'g++')
160 conf.xcheck_host_prog('AR', 'ar')
161 conf.xcheck_host_prog('AS', 'as')
162 conf.xcheck_host_prog('LD', 'ld')
163 conf.xcheck_host_envar('CFLAGS')
164 conf.xcheck_host_envar('CXXFLAGS')
165 conf.xcheck_host_envar('LDFLAGS', 'LINKFLAGS')
166 conf.xcheck_host_envar('LIB')
167 conf.xcheck_host_envar('PKG_CONFIG_LIBDIR')
168 conf.xcheck_host_envar('PKG_CONFIG_PATH')
172 conf.env.env.update(os.environ)
173 if conf.env.PKG_CONFIG_LIBDIR:
174 conf.env.env['PKG_CONFIG_LIBDIR'] = conf.env.PKG_CONFIG_LIBDIR[0]
175 if conf.env.PKG_CONFIG_PATH:
176 conf.env.env['PKG_CONFIG_PATH'] = conf.env.PKG_CONFIG_PATH[0]