summaryrefslogtreecommitdiff
path: root/buildtools/wafsamba/samba_pidl.py
blob: a108e0399141cb4117721bdf9af2852f1b47b169 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# waf build tool for building IDL files with pidl

from TaskGen import taskgen, before
import Build, os, string, Utils
from samba_utils import *

def SAMBA_PIDL(bld, pname, source, options=''):
    '''Build a IDL file using pidl.
       This will produce 7 output files'''

    bname = source[0:-4];
    name = "PIDL_%s" % bname.upper()

    if not SET_TARGET_TYPE(bld, name, 'PIDL'):
        return

    bld.SET_BUILD_GROUP('build_source')

    gen_ndr_dir = '../gen_ndr/'
    out_files = []
    out_files.append(gen_ndr_dir + 'ndr_%s.c' % bname)
    out_files.append(gen_ndr_dir + 'ndr_%s.h' % bname)
    out_files.append(gen_ndr_dir + '%s.h' % bname)
    out_files.append(gen_ndr_dir + 'ndr_%s_s.c' % bname)
    out_files.append(gen_ndr_dir + 'ndr_%s_c.c' % bname)
    out_files.append(gen_ndr_dir + 'ndr_%s_c.h' % bname)
    out_files.append(gen_ndr_dir + 'py_%s.c' % bname)

    pidl = bld.srcnode.find_resource('pidl/pidl').relpath_gen(bld.path)
    t = bld(rule='${PIDL} ${PIDL_BUILD_TYPES} ${OPTIONS} --outputdir ${OUTPUTDIR} -- ${SRC[0].abspath(env)}',
            ext_out = '.c',
            before = 'cc',
            shell = False,
            source=source,
            target = out_files,
            name=name)

    t.env.PIDL = "../../pidl/pidl"
    t.env.PIDL_BUILD_TYPES = '--header --ndr-parser --client --python --server'.split()
    t.env.OPTIONS = options
    t.env.OUTPUTDIR = bld.BUILD_PATH(gen_ndr_dir)

    try:
         bld.PIDL_STUFF[name] = [bld.path.find_or_declare(out_files[1])]
    except AttributeError:
         bld.PIDL_STUFF = {}
         bld.PIDL_STUFF[name] = [bld.path.find_or_declare(out_files[1])]

    t.more_includes = '#' + bld.path.relpath_gen(bld.srcnode)
Build.BuildContext.SAMBA_PIDL = SAMBA_PIDL


def SAMBA_PIDL_TDR(bld, pname, source, options=''):
    '''Build a IDL file using pidl.
    This will only produce the header and tdr parser'''

    bname = source[0:-4];
    name = "PIDL_%s" % bname.upper()

    if not SET_TARGET_TYPE(bld, name, 'PIDL'):
        return

    bld.SET_BUILD_GROUP('build_source')

    out_files = []
    out_files.append('tdr_%s.c' % bname)
    out_files.append('tdr_%s.h' % bname)

    pidl = bld.srcnode.find_resource('pidl/pidl').relpath_gen(bld.path)
    t = bld(rule='${PIDL} ${PIDL_BUILD_TYPES} ${OPTIONS} --outputdir ${TGT[0].parent.abspath(env)} -- ${SRC[0].abspath(env)}',
            ext_out = '.c',
            before = 'cc',
            shell = True,
            source=source,
            target = out_files,
            name=name)

    t.env.PIDL = "../../pidl/pidl"
    t.env.PIDL_BUILD_TYPES = '--header --tdr-parser'
    t.env.OPTIONS = options

Build.BuildContext.SAMBA_PIDL_TDR = SAMBA_PIDL_TDR


#################################################################
# define a set of Samba PIDL targets
def SAMBA_PIDL_LIST(bld, name, source,options=''):
    for p in source.split():
        bld.SAMBA_PIDL(name, p, options)
Build.BuildContext.SAMBA_PIDL_LIST = SAMBA_PIDL_LIST


#################################################################
# the rule for generating the NDR tables
from TaskGen import feature, before
@feature('collect')
@before('exec_rule')
def collect(self):
    for (name, hd) in self.bld.PIDL_STUFF.items():
        y = self.bld.name_to_obj(name, self.env)
        if not y:
            raise "!"+str(name)
        y.post()
        for node in hd:
            self.source += " " + node.relpath_gen(self.path)

def SAMBA_PIDL_TABLES(bld, name, target):
    headers = bld.env.PIDL_HEADERS
    # this print line should tell us what we ended up with
    # we're ending up with the wrong relative path
    #print "tables target=%s curdir=%s headers=%s" % (target, bld.curdir, headers)
    t = bld(
            features = 'collect',
            rule='${SRC} --output ${TGT} > ${TGT}',
            ext_out = '.c',
            before = 'cc',
            shell = True,
            source = '../../librpc/tables.pl',
            target=target,
            name=name)
    print name
Build.BuildContext.SAMBA_PIDL_TABLES = SAMBA_PIDL_TABLES