938a0dc839799c93ec566779658f7c6d99906849
[nivanova/samba-autobuild/.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='', output_dir='.'):
8     '''Build a IDL file using pidl.
9        This will produce up to 13 output files depending on the options used'''
10
11     bname = source[0:-4]; # strip off the .idl suffix
12     name = "%s_%s" % (pname, bname.upper())
13
14     if not SET_TARGET_TYPE(bld, name, 'PIDL'):
15         return
16
17     bld.SET_BUILD_GROUP('build_source')
18
19     # the output files depend on the options used. Use this dictionary
20     # to map between the options and the resulting file names
21     options_map = { '--header'            : '%s.h',
22                     '--ndr-parser'        : 'ndr_%s.c ndr_%s.h',
23                     '--samba3-ndr-server' : 'srv_%s.c srv_%s.h',
24                     '--samba3-ndr-client' : 'cli_%s.c cli_%s.h',
25                     '--server'            : 'ndr_%s_s.c',
26                     '--client'            : 'ndr_%s_c.c ndr_%s_c.h',
27                     '--python'            : 'py_%s.c',
28                     '--tdr-parser'        : 'tdr_%s.c tdr_%s.h',
29                     }
30
31     table_header_idx = None
32     out_files = []
33     options_list = to_list(options)
34
35     for o in options_list:
36         if o in options_map:
37             ofiles = to_list(options_map[o])
38             for f in ofiles:
39                 out_files.append(os.path.join(output_dir, f % bname))
40                 if f == 'ndr_%s.h':
41                     # remember this one for the tables generation
42                     table_header_idx = len(out_files) - 1
43
44     pidl = bld.srcnode.find_resource('pidl/pidl').relpath_gen(bld.path)
45
46     # the cd .. is needed because pidl currently is sensitive to the directory it is run in
47     t = bld(rule='cd .. && ${PIDL} ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
48             ext_out = '.c',
49             before  = 'cc',
50             shell   = True,
51             source  = source,
52             target  = out_files,
53             name    = name)
54
55     t.env.PIDL = "../pidl/pidl"
56     t.env.OPTIONS = to_list(options)
57     t.env.OUTPUTDIR = 'bin/' + bld.BUILD_PATH(output_dir)
58
59
60     if table_header_idx is not None:
61         pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
62         pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
63
64     t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
65 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
66
67
68 def SAMBA_PIDL_LIST(bld, name, source, options='', output_dir='.'):
69     '''A wrapper for building a set of IDL files'''
70     for p in to_list(source):
71         bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir)
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     pidl_headers = LOCAL_CACHE(self.bld, 'PIDL_HEADERS')
82     for (name, hd) in pidl_headers.items():
83         y = self.bld.name_to_obj(name, self.env)
84         self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
85         y.post()
86         for node in hd:
87             self.source += " " + node.relpath_gen(self.path)
88
89
90 def SAMBA_PIDL_TABLES(bld, name, target):
91     headers = bld.env.PIDL_HEADERS
92     t = bld(
93             features = 'collect',
94             rule     = '${SRC} --output ${TGT} > ${TGT}',
95             ext_out  = '.c',
96             before   = 'cc',
97             shell    = True,
98             source   = '../../librpc/tables.pl',
99             target   = target,
100             name     = name)
101     print name
102 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES
103