build: fixed the python path in installed python scripts
[samba.git] / buildtools / wafsamba / samba_asn1.py
1 # samba ASN1 rules
2
3 from TaskGen import before
4 import Build, os
5 from samba_utils import *
6 from samba_autoconf import *
7
8
9 def SAMBA_ASN1(bld, name, source,
10                options='',
11                directory='',
12                option_file=None,
13                includes=''):
14     '''Build a ASN1 file using the asn1 compiler.
15        This will produce 2 output files'''
16     bname = os.path.basename(source)[0:-5];
17     dname = os.path.dirname(source)
18     asn1name = "%s_asn1" % bname
19
20     if not SET_TARGET_TYPE(bld, name, 'ASN1'):
21         return
22
23     # for ASN1 compilation, I always put it in build_source, as it doesn't make
24     # sense elsewhere
25     bld.SET_BUILD_GROUP('build_source')
26
27     out_files = []
28     out_files.append("../heimdal/%s/asn1_%s_asn1.x" % (directory, bname))
29     out_files.append("../heimdal/%s/%s_asn1.hx" % (directory, bname))
30
31     # the ${TGT[0].parent.abspath(env)} expression gives us the parent directory of
32     # the first target in the build directory
33     # SRC[0].abspath(env) gives the absolute path to the source directory for the first
34     # source file. Note that in the case of a option_file, we have more than
35     # one source file
36     cd_rule = 'cd ${TGT[0].parent.abspath(env)}'
37     asn1_rule = cd_rule + ' && ${BLDBIN}/asn1_compile ${OPTION_FILE} ${ASN1OPTIONS} --one-code-file ${SRC[0].abspath(env)} ${ASN1NAME}'
38
39     source = TO_LIST(source)
40     source.append('asn1_compile')
41
42     if option_file is not None:
43         source.append(option_file)
44
45     t = bld(rule=asn1_rule,
46             ext_out = '.x',
47             before = 'cc',
48             on_results = True,
49             shell = True,
50             source = source,
51             target = out_files,
52             name=name + '_ASN1')
53
54     t.env.ASN1NAME     = asn1name
55     t.env.ASN1OPTIONS  = options
56     t.env.BLDBIN       = os.path.normpath(os.path.join(bld.srcnode.abspath(bld.env), '..'))
57     if option_file is not None:
58         t.env.OPTION_FILE = "--option-file=%s" % os.path.normpath(os.path.join(bld.curdir, option_file))
59
60     cfile = out_files[0][0:-2] + '.c'
61     hfile = out_files[1][0:-3] + '.h',
62
63     # now generate a .c file from the .x file
64     t = bld(rule='''( echo '#include "config.h"' && cat ${SRC} ) > ${TGT}''',
65             source = out_files[0],
66             target = cfile,
67             shell = True,
68             on_results=True,
69             ext_out = '.c',
70             ext_in = '.x',
71             depends_on = name + '_ASN1',
72             name = name + '_C')
73
74     # and generate a .h file from the .hx file
75     t = bld(rule='cp ${SRC} ${TGT}',
76             source = out_files[1],
77             ext_out = '.c',
78             ext_in = '.x',
79             on_results=True,
80             target = hfile,
81             depends_on = name + '_ASN1',
82             name = name + '_H')
83
84     bld.SET_BUILD_GROUP('main')
85
86     includes = TO_LIST(includes)
87     includes.append(os.path.dirname(out_files[0]))
88
89     t = bld(features       = 'cc',
90             source         = cfile,
91             target         = name,
92             samba_cflags   = CURRENT_CFLAGS(bld, name, ''),
93             depends_on     = '',
94             samba_deps     = TO_LIST('HEIMDAL_ROKEN'),
95             samba_includes = includes,
96             local_include  = True)
97
98 Build.BuildContext.SAMBA_ASN1 = SAMBA_ASN1