build:wafsamba: Remove unnecessary parameters to cmd_and_log
[sfrench/samba-autobuild/.git] / third_party / waf / waflib / extras / cfg_cross_gnu.py
1 #!/usr/bin/python
2 # -*- coding: utf-8 vi:ts=4:noexpandtab
3 # Tool to provide dedicated variables for cross-compilation
4
5 __author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
6 __copyright__ = "Jérôme Carretero, 2014"
7
8 """
9
10 This tool allows to use environment variables to define cross-compilation things,
11 mostly used when you use build variants.
12
13 The variables are obtained from the environment in 3 ways:
14
15 1. By defining CHOST, they can be derived as ${CHOST}-${TOOL}
16 2. By defining HOST_x
17 3. By defining ${CHOST//-/_}_x
18
19 Usage:
20
21 - In your build script::
22
23     def configure(cfg):
24       ...
25       conf.load('c_cross_gnu')
26       for variant in x_variants:
27         conf.xcheck_host()
28         conf.xcheck_host_var('POUET')
29         ...
30
31       ...
32
33 - Then::
34
35     CHOST=arm-hardfloat-linux-gnueabi waf configure
36
37     env arm-hardfloat-linux-gnueabi-CC="clang -..." waf configure
38
39     CFLAGS=... CHOST=arm-hardfloat-linux-gnueabi HOST_CFLAGS=-g waf configure
40
41     HOST_CC="clang -..." waf configure
42
43 """
44
45 import os
46 from waflib import Utils, Configure
47
48 try:
49         from shlex import quote
50 except ImportError:
51         from pipes import quote
52
53 def get_chost_stuff(conf):
54         """
55         Get the CHOST environment variable contents
56         """
57         chost = None
58         chost_envar = None
59         if conf.env.CHOST:
60                 chost = conf.env.CHOST[0]
61                 chost_envar = chost.replace('-', '_')
62         return chost, chost_envar
63
64
65 @Configure.conf
66 def xcheck_envar(conf, name, wafname=None, cross=False):
67         wafname = wafname or name
68         envar = os.environ.get(name, None)
69
70         if envar is None:
71                 return
72
73         value = Utils.to_list(envar) if envar != '' else [envar]
74
75         conf.env[wafname] = value
76         if cross:
77                 pretty = 'cross-compilation %s' % wafname
78         else:
79                 pretty = wafname
80         conf.msg('Will use %s' % pretty,
81          " ".join(quote(x) for x in value))
82
83 @Configure.conf
84 def xcheck_host_prog(conf, name, tool, wafname=None):
85         wafname = wafname or name
86
87         chost, chost_envar = get_chost_stuff(conf)
88
89         specific = None
90         if chost:
91                 specific = os.environ.get('%s_%s' % (chost_envar, name), None)
92
93         if specific:
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))
99                 return
100         else:
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' \
106                          % (name, name),
107                          " ".join(quote(x) for x in value))
108                         return
109
110         if conf.env[wafname]:
111                 return
112
113         value = None
114         if chost:
115                 value = '%s-%s' % (chost, tool)
116
117         if value:
118                 conf.env[wafname] = value
119                 conf.msg('Will use cross-compilation %s from CHOST' \
120                  % wafname, value)
121
122 @Configure.conf
123 def xcheck_host_envar(conf, name, wafname=None):
124         wafname = wafname or name
125
126         chost, chost_envar = get_chost_stuff(conf)
127
128         specific = None
129         if chost:
130                 specific = os.environ.get('%s_%s' % (chost_envar, name), None)
131
132         if specific:
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))
138                 return
139
140
141         envar = os.environ.get('HOST_%s' % name, None)
142         if envar is None:
143                 return
144
145         value = Utils.to_list(envar) if envar != '' else [envar]
146
147         conf.env[wafname] = value
148         conf.msg('Will use cross-compilation %s from HOST_%s' \
149          % (name, name),
150          " ".join(quote(x) for x in value))
151
152
153 @Configure.conf
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')
169
170         if not conf.env.env:
171                 conf.env.env = {}
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]