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
|
#!/usr/bin/env python
# encoding: utf-8
# go.py - Waf tool for the Go programming language
# By: Tom Wambold <tom5760@gmail.com>
import platform, os
import Task
import Utils
from TaskGen import feature, extension, after
Task.simple_task_type('gocompile', '${GOC} ${GOCFLAGS} -o ${TGT} ${SRC}', shell=False)
Task.simple_task_type('gopack', '${GOP} grc ${TGT} ${SRC}', shell=False)
Task.simple_task_type('golink', '${GOL} ${GOLFLAGS} -o ${TGT} ${SRC}', shell=False)
def detect(conf):
def set_def(var, val):
if not conf.env[var]:
conf.env[var] = val
goarch = os.getenv("GOARCH")
if goarch == '386':
set_def('GO_PLATFORM', 'i386')
elif goarch == 'amd64':
set_def('GO_PLATFORM', 'x86_64')
elif goarch == 'arm':
set_def('GO_PLATFORM', 'arm')
else:
set_def('GO_PLATFORM', platform.machine())
if conf.env.GO_PLATFORM == 'x86_64':
set_def('GO_COMPILER', '6g')
set_def('GO_LINKER', '6l')
set_def('GO_EXTENSION', '.6')
elif conf.env.GO_PLATFORM in ['i386', 'i486', 'i586', 'i686']:
set_def('GO_COMPILER', '8g')
set_def('GO_LINKER', '8l')
set_def('GO_EXTENSION', '.8')
elif conf.env.GO_PLATFORM == 'arm':
set_def('GO_COMPILER', '5g')
set_def('GO_LINKER', '5l')
set_def('GO_EXTENSION', '.5')
if not (conf.env.GO_COMPILER or conf.env.GO_LINKER or conf.env.GO_EXTENSION):
raise conf.fatal('Unsupported platform ' + platform.machine())
set_def('GO_PACK', 'gopack')
set_def('GO_PACK_EXTENSION', '.a')
conf.find_program(conf.env.GO_COMPILER, var='GOC', mandatory=True)
conf.find_program(conf.env.GO_LINKER, var='GOL', mandatory=True)
conf.find_program(conf.env.GO_PACK, var='GOP', mandatory=True)
conf.find_program('cgo', var='CGO', mandatory=True)
@extension('.go')
def compile_go(self, node):
try:
self.go_nodes.append(node)
except AttributeError:
self.go_nodes = [node]
@feature('go')
@after('apply_core')
def apply_compile_go(self):
try:
nodes = self.go_nodes
except AttributeError:
self.go_compile_task = None
else:
self.go_compile_task = self.create_task('gocompile',
nodes,
[self.path.find_or_declare(self.target + self.env.GO_EXTENSION)])
@feature('gopackage', 'goprogram')
@after('apply_compile_go')
def apply_goinc(self):
if not getattr(self, 'go_compile_task', None):
return
names = self.to_list(getattr(self, 'uselib_local', []))
for name in names:
obj = self.name_to_obj(name)
if not obj:
raise Utils.WafError('object %r was not found in uselib_local '
'(required by %r)' % (lib_name, self.name))
obj.post()
self.go_compile_task.set_run_after(obj.go_package_task)
self.go_compile_task.dep_nodes.extend(obj.go_package_task.outputs)
self.env.append_unique('GOCFLAGS', '-I' + obj.path.abspath(obj.env))
self.env.append_unique('GOLFLAGS', '-L' + obj.path.abspath(obj.env))
@feature('gopackage')
@after('apply_goinc')
def apply_gopackage(self):
self.go_package_task = self.create_task('gopack',
self.go_compile_task.outputs[0],
self.path.find_or_declare(self.target + self.env.GO_PACK_EXTENSION))
self.go_package_task.set_run_after(self.go_compile_task)
self.go_package_task.dep_nodes.extend(self.go_compile_task.outputs)
@feature('goprogram')
@after('apply_goinc')
def apply_golink(self):
self.go_link_task = self.create_task('golink',
self.go_compile_task.outputs[0],
self.path.find_or_declare(self.target))
self.go_link_task.set_run_after(self.go_compile_task)
self.go_link_task.dep_nodes.extend(self.go_compile_task.outputs)
|