s4:libcli/smb2: remove unused variable
[Samba/gebeck_regimport.git] / buildtools / wafadmin / 3rdparty / go.py
blob2d8df0d2b64eba1ea4d14c88830b7da32a599711
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # go.py - Waf tool for the Go programming language
4 # By: Tom Wambold <tom5760@gmail.com>
6 import platform, os
8 import Task
9 import Utils
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)
16 def detect(conf):
18 def set_def(var, val):
19 if not conf.env[var]:
20 conf.env[var] = val
22 goarch = os.getenv("GOARCH")
24 if goarch == '386':
25 set_def('GO_PLATFORM', 'i386')
26 elif goarch == 'amd64':
27 set_def('GO_PLATFORM', 'x86_64')
28 elif goarch == 'arm':
29 set_def('GO_PLATFORM', 'arm')
30 else:
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)
57 @extension('.go')
58 def compile_go(self, node):
59 try:
60 self.go_nodes.append(node)
61 except AttributeError:
62 self.go_nodes = [node]
64 @feature('go')
65 @after('apply_core')
66 def apply_compile_go(self):
67 try:
68 nodes = self.go_nodes
69 except AttributeError:
70 self.go_compile_task = None
71 else:
72 self.go_compile_task = self.create_task('gocompile',
73 nodes,
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):
80 return
82 names = self.to_list(getattr(self, 'uselib_local', []))
83 for name in names:
84 obj = self.name_to_obj(name)
85 if not obj:
86 raise Utils.WafError('object %r was not found in uselib_local '
87 '(required by %r)' % (lib_name, self.name))
88 obj.post()
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))
94 @feature('gopackage')
95 @after('apply_goinc')
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)