summaryrefslogtreecommitdiff
path: root/waflib/extras/cfg_cross_gnu.py
blob: e2ed30f7c2f5449614d888d68e37347f515824de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Tool to provide dedicated variables for cross-compilation

__author__ = __maintainer__ = "Jérôme Carretero <cJ-waf@zougloub.eu>"
__copyright__ = "Jérôme Carretero, 2014"

"""

This tool allows to use environment variables to define cross-compilation things,
mostly used when you use build variants.

Usage:

- In your build script::

    def configure(cfg):
      ...
      conf.load('c_cross_gnu')
      for variant in x_variants:
        conf.xcheck_host()
        conf.xcheck_host_var('POUET')
        ...

      ...

- Then::

    CHOST=arm-hardfloat-linux-gnueabi waf configure

    env arm-hardfloat-linux-gnueabi-CC="clang -..." waf configure

    CFLAGS=... CHOST=arm-hardfloat-linux-gnueabi HOST_CFLAGS=-g waf configure

    HOST_CC="clang -..." waf configure

"""

import os
from waflib import Utils, Configure

try:
	from shlex import quote
except ImportError:
	from pipes import quote

@Configure.conf
def xcheck_prog(conf, var, tool, cross=False):
	value = os.environ.get(var, '')
	value = Utils.to_list(value)

	if not value:
		return

	conf.env[var] = value
	if cross:
		pretty = 'cross-compilation %s' % var
	else:
		pretty = var
	conf.msg('Will use %s' % pretty,
	 " ".join(quote(x) for x in value))

@Configure.conf
def xcheck_envar(conf, name, wafname=None, cross=False):
	wafname = wafname or name
	value = os.environ.get(name, None)
	value = Utils.to_list(value)

	if not value:
		return

	conf.env[wafname] += value
	if cross:
		pretty = 'cross-compilation %s' % wafname
	else:
		pretty = wafname
	conf.msg('Will use %s' % pretty,
	 " ".join(quote(x) for x in value))

@Configure.conf
def xcheck_host_prog(conf, name, tool, wafname=None):
	wafname = wafname or name
	host = conf.env.CHOST
	specific = None
	if host:
		specific = os.environ.get('%s-%s' % (host[0], name), None)

	if specific:
		value = Utils.to_list(specific)
		conf.env[wafname] += value
		conf.msg('Will use cross-compilation %s' % name,
		 " ".join(quote(x) for x in value))
		return

	conf.xcheck_prog('HOST_%s' % name, tool, cross=True)

	if conf.env[wafname]:
		return

	value = None
	if host:
		value = '%s-%s' % (host[0], tool)

	if value:
		conf.env[wafname] = value
		conf.msg('Will use cross-compilation %s' % wafname, value)

@Configure.conf
def xcheck_host_envar(conf, name, wafname=None):
	wafname = wafname or name

	host = conf.env.CHOST
	specific = None
	if host:
		specific = os.environ.get('%s-%s' % (host[0], name), None)

	if specific:
		value = Utils.to_list(specific)
		conf.env[wafname] += value
		conf.msg('Will use cross-compilation %s' % name,
		 " ".join(quote(x) for x in value))
		return

	conf.xcheck_envar('HOST_%s' % name, wafname, cross=True)


@Configure.conf
def xcheck_host(conf):
	conf.xcheck_envar('CHOST', cross=True)
	conf.xcheck_host_prog('CC', 'gcc')
	conf.xcheck_host_prog('CXX', 'g++')
	conf.xcheck_host_prog('LINK_CC', 'gcc')
	conf.xcheck_host_prog('LINK_CXX', 'g++')
	conf.xcheck_host_prog('AR', 'ar')
	conf.xcheck_host_prog('AS', 'as')
	conf.xcheck_host_prog('LD', 'ld')
	conf.xcheck_host_envar('CFLAGS')
	conf.xcheck_host_envar('CXXFLAGS')
	conf.xcheck_host_envar('LDFLAGS', 'LINKFLAGS')
	conf.xcheck_host_envar('LIB')
	conf.xcheck_host_envar('PKG_CONFIG_PATH')
	# TODO find a better solution than this ugliness
	if conf.env.PKG_CONFIG_PATH:
		conf.find_program('pkg-config', var='PKGCONFIG')
		conf.env.PKGCONFIG = [
		 'env', 'PKG_CONFIG_PATH=%s' % (conf.env.PKG_CONFIG_PATH[0])
		] + conf.env.PKGCONFIG