build: split out the extension based build patterns
[samba.git] / buildtools / wafsamba / samba_patterns.py
1 # a waf tool to add extension based build patterns for Samba
2
3 import os, sys, Options
4 import string, Task, Utils, optparse
5 from Configure import conf
6 from Logs import debug
7 from TaskGen import extension
8 from samba_utils import *
9
10
11 ################################################################################
12 # a et task which calls out to compile_et to do the work
13 Task.simple_task_type('et',
14                       '../heimdal_build/et_compile_wrapper.sh . ${TGT[0].bld_dir(env)} default/source4/heimdal_build/compile_et ${SRC[0].abspath(env)} ${TGT[0].bldpath(env)}',
15                       color='BLUE', ext_out='.c',
16                       shell = False)
17
18 @extension('.et')
19 def process_et(self, node):
20     c_node = node.change_ext('.c')
21     h_node  = node.change_ext('.h')
22     self.create_task('et', node, [c_node, h_node])
23     self.allnodes.append(c_node)
24
25
26 ################################################################################
27 # a idl task which calls out to pidl to do the work
28 Task.simple_task_type('idl', '../../pidl/pidl --header --ndr-parser --client --python --server --outputdir=${TGT[0].outputdir} -- ${SRC}', color='BLUE', ext_out='.c')
29
30 @extension('.idl')
31 def process_idl(self, node):
32     bname      = node.file_base()
33     c_node     = NEW_NODE(node, 'ndr_%s.c' % bname)
34     h1_node    = NEW_NODE(node, '%s.h' % bname)
35     h2_node    = NEW_NODE(node, 'ndr_%s.h' % bname)
36     s_node     = NEW_NODE(node, 'ndr_%s_s.c' % bname)
37     cli_node   = NEW_NODE(node, 'ndr_%s_c.c' % bname)
38     cli_h_node = NEW_NODE(node, 'ndr_%s_c.h' % bname)
39     py_node    = NEW_NODE(node, 'py_%s.c' % bname)
40
41
42     dname = os.path.dirname(node.bld_dir(self.env)) + "/gen_ndr"
43     c_node.outputdir = dname
44
45     self.create_task('idl', node, [c_node, h1_node, h2_node, s_node, cli_node, cli_h_node, py_node])
46
47     # reinject the c node to the list of nodes to process
48     self.allnodes.append(c_node)
49
50
51
52
53 ################################################################################
54 # a asn1 task which calls out to asn1_compile_wrapper.sh to do the work
55 Task.simple_task_type('asn1',
56                       '''
57 # shell script to convert ASN1 to C. This could be separated out if we want to
58 set -e
59 compiler=${TGT[0].compiler}
60 destdir=${TGT[0].destdir}
61 wrapper=${TGT[0].asn1wrapper}
62 srcfile=${SRC[0].abspath(env)}
63 asn1name=${TGT[0].asn1name}
64 options="${TGT[0].asn1options}"
65
66 # run the wrapper
67 $wrapper . $destdir $compiler $srcfile $asn1name ${options} --one-code-file
68
69 # that generated 3 files:
70 #    ${asn1name}.hx
71 #    asn1_${asn1name}.x
72 #    ${asn1name}_files
73
74
75 hxfile=$destdir/$asn1name.hx
76 xfile=$destdir/asn1_$asn1name.x
77 listfilee=$destdir/"$asn1name"_files
78
79 cfile=${TGT[0].abspath(env)}
80 hfile=${TGT[1].abspath(env)}
81
82 cp $hxfile $hfile
83 echo '#include "config.h"' > $cfile
84 cat $xfile >> $cfile
85 rm -f $listfile
86
87 ''',
88                       color='BLUE',
89                       ext_out='.c',
90                       shell = True)
91
92 @extension('.asn1')
93 def process_asn1(self, node):
94
95     asn1name = string.replace(node.file(), '.', '_')
96     c_node  = NEW_NODE(node, 'asn1_%s.c' % asn1name)
97     h_node  = NEW_NODE(node, '%s.h' % asn1name)
98
99     c_node.destdir      = "default/source4/heimdal/" + self.asn1directory
100     c_node.asn1options  = self.asn1options
101     c_node.asn1name     = asn1name
102     c_node.asn1wrapper  = "../heimdal_build/asn1_compile_wrapper.sh"
103     c_node.compiler     = "default/source4/heimdal_build/asn1_compile"
104
105     self.create_task('asn1', node, [c_node, h_node])
106     self.allnodes.append(c_node)
107