Include waf as an extracted source directory, rather than as a one-in-a-file script.
[abartlet/samba.git/.git] / buildtools / wafadmin / Tools / cs.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # Thomas Nagy, 2006 (ita)
4
5 "C# support"
6
7 import TaskGen, Utils, Task, Options
8 from Logs import error
9 from TaskGen import before, after, taskgen, feature
10
11 flag_vars= ['FLAGS', 'ASSEMBLIES']
12
13 @feature('cs')
14 def init_cs(self):
15         Utils.def_attrs(self,
16                 flags = '',
17                 assemblies = '',
18                 resources = '',
19                 uselib = '')
20
21 @feature('cs')
22 @after('init_cs')
23 def apply_uselib_cs(self):
24         if not self.uselib:
25                 return
26         global flag_vars
27         for var in self.to_list(self.uselib):
28                 for v in self.flag_vars:
29                         val = self.env[v+'_'+var]
30                         if val: self.env.append_value(v, val)
31
32 @feature('cs')
33 @after('apply_uselib_cs')
34 @before('apply_core')
35 def apply_cs(self):
36         try: self.meths.remove('apply_core')
37         except ValueError: pass
38
39         # process the flags for the assemblies
40         for i in self.to_list(self.assemblies) + self.env['ASSEMBLIES']:
41                 self.env.append_unique('_ASSEMBLIES', '/r:'+i)
42
43         # process the flags for the resources
44         for i in self.to_list(self.resources):
45                 self.env.append_unique('_RESOURCES', '/resource:'+i)
46
47         # what kind of assembly are we generating?
48         self.env['_TYPE'] = getattr(self, 'type', 'exe')
49
50         # additional flags
51         self.env.append_unique('_FLAGS', self.to_list(self.flags))
52         self.env.append_unique('_FLAGS', self.env.FLAGS)
53
54         # process the sources
55         nodes = [self.path.find_resource(i) for i in self.to_list(self.source)]
56         self.create_task('mcs', nodes, self.path.find_or_declare(self.target))
57
58 Task.simple_task_type('mcs', '${MCS} ${SRC} /target:${_TYPE} /out:${TGT} ${_FLAGS} ${_ASSEMBLIES} ${_RESOURCES}', color='YELLOW')
59
60 def detect(conf):
61         csc = getattr(Options.options, 'cscbinary', None)
62         if csc:
63                 conf.env.MCS = csc
64         conf.find_program(['gmcs', 'mcs'], var='MCS')
65
66 def set_options(opt):
67         opt.add_option('--with-csc-binary', type='string', dest='cscbinary')
68