1 # waf build tool for building IDL files with pidl
3 from TaskGen import before
5 from samba_utils import *
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'''
11 bname = source[0:-4]; # strip off the .idl suffix
12 name = "%s_%s" % (pname, bname.upper())
14 if not SET_TARGET_TYPE(bld, name, 'PIDL'):
17 bld.SET_BUILD_GROUP('build_source')
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',
31 table_header_idx = None
33 options_list = TO_LIST(options)
35 for o in options_list:
37 ofiles = TO_LIST(options_map[o])
39 out_files.append(os.path.join(output_dir, f % bname))
41 # remember this one for the tables generation
42 table_header_idx = len(out_files) - 1
44 # depend on the full pidl sources
45 source = TO_LIST(source)
46 pidl_src = [x.relpath_gen(bld.path) for x in
47 bld.srcnode.ant_glob('pidl/**/*', flat=False)]
48 source.extend(pidl_src)
50 # the cd .. is needed because pidl currently is sensitive to the directory it is run in
51 t = bld(rule='cd .. && ${PIDL} ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
59 t.env.PIDL = "../pidl/pidl"
60 t.env.OPTIONS = TO_LIST(options)
61 t.env.OUTPUTDIR = bld.bldnode.name + '/' + bld.path.find_dir(output_dir).bldpath(t.env)
63 if table_header_idx is not None:
64 pidl_headers = LOCAL_CACHE(bld, 'PIDL_HEADERS')
65 pidl_headers[name] = [bld.path.find_or_declare(out_files[table_header_idx])]
67 t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
68 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
71 def SAMBA_PIDL_LIST(bld, name, source, options='', output_dir='.'):
72 '''A wrapper for building a set of IDL files'''
73 for p in TO_LIST(source):
74 bld.SAMBA_PIDL(name, p, options=options, output_dir=output_dir)
75 Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST
78 #################################################################
79 # the rule for generating the NDR tables
80 from TaskGen import feature, before
84 pidl_headers = LOCAL_CACHE(self.bld, 'PIDL_HEADERS')
85 for (name, hd) in pidl_headers.items():
86 y = self.bld.name_to_obj(name, self.env)
87 self.bld.ASSERT(y is not None, 'Failed to find PIDL header %s' % name)
90 self.source += " " + node.relpath_gen(self.path)
93 def SAMBA_PIDL_TABLES(bld, name, target):
94 headers = bld.env.PIDL_HEADERS
97 rule = '${SRC} --output ${TGT} | sed "s|default/||" > ${TGT}',
101 source = '../../librpc/tables.pl',
104 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES