1 # waf build tool for building IDL files with pidl
3 from TaskGen import taskgen, before
4 import Build, os, string, Utils
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 pidl = bld.srcnode.find_resource('pidl/pidl').relpath_gen(bld.path)
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)}',
55 t.env.PIDL = "../pidl/pidl"
56 t.env.OPTIONS = to_list(options)
57 t.env.OUTPUTDIR = 'bin/' + bld.BUILD_PATH(output_dir)
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])]
64 t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
65 Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL
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
75 #################################################################
76 # the rule for generating the NDR tables
77 from TaskGen import feature, before
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)
87 self.source += " " + node.relpath_gen(self.path)
90 def SAMBA_PIDL_TABLES(bld, name, target):
91 headers = bld.env.PIDL_HEADERS
94 rule = '${SRC} --output ${TGT} > ${TGT}',
98 source = '../../librpc/tables.pl',
102 Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES