9269566111122b9eacf71e719402686add680d80
[samba.git] / buildtools / wafsamba / samba_pidl.py
1 # waf build tool for building IDL files with pidl
2
3 from TaskGen import taskgen, before
4 import Build, os, string, Utils
5 from samba_utils import *
6
7 def SAMBA_PIDL(bld, pname, source, options=''):
8     '''Build a IDL file using pidl.
9        This will produce 7 output files'''
10
11     bname = source[0:-4];
12     name = "PIDL_%s" % bname.upper()
13
14     if not SET_TARGET_TYPE(bld, name, 'PIDL'):
15         return
16
17     bld.SET_BUILD_GROUP('build_source')
18
19     gen_ndr_dir = '../gen_ndr/'
20     out_files = []
21     out_files.append(gen_ndr_dir + 'ndr_%s.c' % bname)
22     out_files.append(gen_ndr_dir + 'ndr_%s.h' % bname)
23     out_files.append(gen_ndr_dir + '%s.h' % bname)
24     out_files.append(gen_ndr_dir + 'ndr_%s_s.c' % bname)
25     out_files.append(gen_ndr_dir + 'ndr_%s_c.c' % bname)
26     out_files.append(gen_ndr_dir + 'ndr_%s_c.h' % bname)
27     out_files.append(gen_ndr_dir + 'py_%s.c' % bname)
28
29     pidl = bld.srcnode.find_resource('pidl/pidl').relpath_gen(bld.path)
30     t = bld(rule='${PIDL} ${PIDL_BUILD_TYPES} ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
31             ext_out = '.c',
32             before = 'cc',
33             shell = False,
34             source=source,
35             target = out_files,
36             name=name)
37
38     t.env.PIDL = "../../pidl/pidl"
39     t.env.PIDL_BUILD_TYPES = '--header --ndr-parser --client --python --server'.split()
40     t.env.OPTIONS = options
41     t.env.OUTPUTDIR = bld.BUILD_PATH(gen_ndr_dir)
42
43     # I'm creating the list of headers for the tables rule here.
44     # then the tables rule itself is below
45     #t.collect_headers = [bld.path.find_or_declare(out_files[1])] #, bld.path.find_or_declare(out_files[6])]
46     #if name.rfind('PIDL') > -1:
47     #   print name, "t.coll", t.collect_headers
48     #print name, "so bld.PIDL_STUFF is defined", id(bld)
49     try:
50          bld.PIDL_STUFF[name] = [bld.path.find_or_declare(out_files[1])]
51     except AttributeError:
52          bld.PIDL_STUFF = {}
53          bld.PIDL_STUFF[name] = [bld.path.find_or_declare(out_files[1])]
54
55     # I think I need to build this list as absolute paths, then
56     # re-do as relative paths in the tables rule
57     t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
58     #if not 'PIDL_HEADERS' in bld.env:
59     #    bld.env.PIDL_HEADERS = []
60     #bld.env.PIDL_HEADERS.append(gen_ndr_dir + 'ndr_%s.h' % bname)
61
62
63
64 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
65
66
67 #################################################################
68 # define a set of Samba PIDL targets
69 def SAMBA_PIDL_LIST(bld, name, source, options=''):
70     for p in source.split():
71         bld.SAMBA_PIDL(name, p, options)
72 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
73
74
75 #################################################################
76 # the rule for generating the NDR tables
77 from TaskGen import feature, before
78 @feature('collect')
79 @before('exec_rule')
80 def collect(self):
81     for (name, hd) in self.bld.PIDL_STUFF.items():
82         y = self.bld.name_to_obj(name, self.env)
83         if not y:
84             raise "!"+str(name)
85         y.post()
86         for node in hd:
87             self.source += " " + node.relpath_gen(self.path)
88
89 def SAMBA_PIDL_TABLES(bld, name, target):
90     headers = bld.env.PIDL_HEADERS
91     # this print line should tell us what we ended up with
92     # we're ending up with the wrong relative path
93     #print "tables target=%s curdir=%s headers=%s" % (target, bld.curdir, headers)
94     t = bld(
95             features = 'collect',
96             rule='${SRC} --output ${TGT} > ${TGT}',
97             ext_out = '.c',
98             before = 'cc',
99             shell = True,
100             source = '../../librpc/tables.pl',
101             target=target,
102             name=name)
103     print name
104 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES
105