3
# go.py - Waf tool for the Go programming language
4
# By: Tom Wambold <tom5760@gmail.com>
10
from TaskGen import feature, extension, after
12
Task.simple_task_type('gocompile', '${GOC} ${GOCFLAGS} -o ${TGT} ${SRC}', shell=False)
13
Task.simple_task_type('gopack', '${GOP} grc ${TGT} ${SRC}', shell=False)
14
Task.simple_task_type('golink', '${GOL} ${GOLFLAGS} -o ${TGT} ${SRC}', shell=False)
18
def set_def(var, val):
22
goarch = os.getenv("GOARCH")
25
set_def('GO_PLATFORM', 'i386')
26
elif goarch == 'amd64':
27
set_def('GO_PLATFORM', 'x86_64')
29
set_def('GO_PLATFORM', 'arm')
31
set_def('GO_PLATFORM', platform.machine())
33
if conf.env.GO_PLATFORM == 'x86_64':
34
set_def('GO_COMPILER', '6g')
35
set_def('GO_LINKER', '6l')
36
set_def('GO_EXTENSION', '.6')
37
elif conf.env.GO_PLATFORM in ['i386', 'i486', 'i586', 'i686']:
38
set_def('GO_COMPILER', '8g')
39
set_def('GO_LINKER', '8l')
40
set_def('GO_EXTENSION', '.8')
41
elif conf.env.GO_PLATFORM == 'arm':
42
set_def('GO_COMPILER', '5g')
43
set_def('GO_LINKER', '5l')
44
set_def('GO_EXTENSION', '.5')
46
if not (conf.env.GO_COMPILER or conf.env.GO_LINKER or conf.env.GO_EXTENSION):
47
raise conf.fatal('Unsupported platform ' + platform.machine())
49
set_def('GO_PACK', 'gopack')
50
set_def('GO_PACK_EXTENSION', '.a')
52
conf.find_program(conf.env.GO_COMPILER, var='GOC', mandatory=True)
53
conf.find_program(conf.env.GO_LINKER, var='GOL', mandatory=True)
54
conf.find_program(conf.env.GO_PACK, var='GOP', mandatory=True)
55
conf.find_program('cgo', var='CGO', mandatory=True)
58
def compile_go(self, node):
60
self.go_nodes.append(node)
61
except AttributeError:
62
self.go_nodes = [node]
66
def apply_compile_go(self):
69
except AttributeError:
70
self.go_compile_task = None
72
self.go_compile_task = self.create_task('gocompile',
74
[self.path.find_or_declare(self.target + self.env.GO_EXTENSION)])
76
@feature('gopackage', 'goprogram')
77
@after('apply_compile_go')
78
def apply_goinc(self):
79
if not getattr(self, 'go_compile_task', None):
82
names = self.to_list(getattr(self, 'uselib_local', []))
84
obj = self.name_to_obj(name)
86
raise Utils.WafError('object %r was not found in uselib_local '
87
'(required by %r)' % (lib_name, self.name))
89
self.go_compile_task.set_run_after(obj.go_package_task)
90
self.go_compile_task.dep_nodes.extend(obj.go_package_task.outputs)
91
self.env.append_unique('GOCFLAGS', '-I' + obj.path.abspath(obj.env))
92
self.env.append_unique('GOLFLAGS', '-L' + obj.path.abspath(obj.env))
96
def apply_gopackage(self):
97
self.go_package_task = self.create_task('gopack',
98
self.go_compile_task.outputs[0],
99
self.path.find_or_declare(self.target + self.env.GO_PACK_EXTENSION))
100
self.go_package_task.set_run_after(self.go_compile_task)
101
self.go_package_task.dep_nodes.extend(self.go_compile_task.outputs)
103
@feature('goprogram')
104
@after('apply_goinc')
105
def apply_golink(self):
106
self.go_link_task = self.create_task('golink',
107
self.go_compile_task.outputs[0],
108
self.path.find_or_declare(self.target))
109
self.go_link_task.set_run_after(self.go_compile_task)
110
self.go_link_task.dep_nodes.extend(self.go_compile_task.outputs)