-
Notifications
You must be signed in to change notification settings - Fork 0
/
hwaf-system.py
195 lines (157 loc) · 4.89 KB
/
hwaf-system.py
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# -*- python -*-
### imports -------------------------------------------------------------------
# stdlib imports ---
import os
import os.path as osp
import platform
import sys
# waf imports ---
from waflib.Configure import conf
import waflib.Context
import waflib.Logs as msg
import waflib.Utils
_heptooldir = osp.dirname(osp.abspath(__file__))
### ---------------------------------------------------------------------------
def options(ctx):
ctx.add_option(
'--cmtcfg',
default=None,
help="The build type. ex: x86_64-linux-gcc-opt")
ctx.add_option(
'--cmtpkgs',
default=None,
help="The directory where pkgs are located")
ctx.load('hwaf-project-mgr', tooldir=_heptooldir)
ctx.load('find_compiler', tooldir=_heptooldir)
return
### ---------------------------------------------------------------------------
def configure(ctx):
#ctx.load('c_config')
#ctx.load('compiler_cc')
#ctx.load('compiler_cxx')
cmtcfg = os.environ.get('CMTCFG', None)
if not cmtcfg and ctx.options.cmtcfg:
cmtcfg = ctx.options.cmtcfg
pass
cfg_arch = None
cfg_os = None
cfg_comp = 'gcc'
cfg_type = None
if not cmtcfg or cmtcfg == 'default':
msg.debug('detecting default CMTCFG...')
cfg_type = 'opt'
if ctx.is_darwin(): cfg_os = 'darwin'
elif ctx.is_linux(): cfg_os = 'linux'
elif ctx.is_freebsd(): cfg_os = 'freebsd'
else: cfg_os = 'win'
if ctx.is_host_32b(): cfg_arch = 'i686'
elif ctx.is_host_64b(): cfg_arch = 'x86_64'
else: cfg_arch = 'x86_64'
cmtcfg = '-'.join([cfg_arch, cfg_os,
cfg_comp, cfg_type])
pass
o = cmtcfg.split('-')
if len(o) != 4:
ctx.fatal(
("Invalid CMTCFG (%s). Expected ARCH-OS-COMP-OPT. " +
"ex: x86_64-linux-gcc-opt") %
cmtcfg)
if o[1].startswith('mac'): o[1] = 'darwin'
if o[1].startswith('slc'): o[1] = 'linux'
#if o[2].startswith('gcc'):
# o[2] = 'gcc'
ctx.env.CMTCFG = cmtcfg
ctx.env.CFG_QUADRUPLET = o
ctx.env.CFG_ARCH, \
ctx.env.CFG_OS, \
ctx.env.CFG_COMPILER, \
ctx.env.CFG_TYPE = ctx.env.CFG_QUADRUPLET
projname = waflib.Context.g_module.APPNAME
if not projname:
projname = osp.basename(os.getcwd())
waflib.Context.g_module.APPNAME = projname
pass
ctx.env.HWAF_PROJECT_NAME = projname
projvers = waflib.Context.g_module.VERSION
if ctx.options.project_version:
projvers = ctx.options.project_version
pass
waflib.Context.g_module.VERSION = projvers
ctx.env.HWAF_PROJECT_VERSION = projvers
if not ctx.env.HWAF_TAGS: ctx.env['HWAF_TAGS'] = {}
if not ctx.env.HWAF_ACTIVE_TAGS: ctx.env['HWAF_ACTIVE_TAGS'] = []
cmtpkgs = os.environ.get('CMTPKGS', None)
if not cmtpkgs and ctx.options.cmtpkgs:
cmtpkgs = ctx.options.cmtpkgs
pass
if not cmtpkgs:
cmtpkgs = 'src'
pass
ctx.env.CMTPKGS = cmtpkgs
if ctx.options.destdir:
ctx.env.DESTDIR = ctx.options.destdir
pass
ctx.env.PREFIX = ctx.options.prefix or "/usr"
relocate_from = ctx.options.relocate_from
if not relocate_from:
relocate_from = ctx.env.PREFIX
pass
ctx.env.HWAF_RELOCATE = relocate_from
# take INSTALL_AREA from PREFIX
ctx.env.INSTALL_AREA = ctx.env.PREFIX
if ctx.env.DESTDIR:
pass
# percolate CMTCFG
ctx.hwaf_declare_tag(ctx.env.CMTCFG, content=ctx.env.CMTCFG.split("-"))
ctx.hwaf_apply_tag(ctx.env.CMTCFG)
# bootstrap the toolchain
ctx.load('find_compiler')
ctx.find_toolchain()
return
### ---------------------------------------------------------------------------
@conf
def is_dbg(ctx):
return '-dbg' in ctx.env.CMTCFG
@conf
def is_opt(ctx):
return '-opt' in ctx.env.CMTCFG
@conf
def is_64b(ctx):
return 'x86_64' in ctx.env.CMTCFG
@conf
def is_32b(ctx):
return not ctx.is_64b()#'i686' in ctx.env.CMTCFG
@conf
def is_host_64b(ctx):
#system, node, release, version, machine, processor = platform.uname()
#return machine == 'x86_64'
return '64bit' in platform.architecture()
@conf
def is_host_32b(ctx):
return not ctx.is_host_64b()
@conf
def is_linux(ctx):
return 'linux' in sys.platform
@conf
def is_freebsd(ctx):
return 'freebsd' in sys.platform
@conf
def is_darwin(ctx):
return 'darwin' in sys.platform
@conf
def is_windows(ctx):
return waflib.Utils.is_win32
#return 'win' in sys.platform
@conf
def dso_ext(ctx):
if ctx.is_linux():
return '.so'
elif ctx.is_darwin():
#return '.dylib'
return '.so'
elif ctx.is_windows():
return '.dll'
elif ctx.is_freebsd():
return '.so'
else:
raise RuntimeError('unhandled platform [%s]' % sys.platform)