summaryrefslogtreecommitdiff
path: root/buildtools/wafsamba/samba_asn1.py
blob: 4d8c74f3f9689f57a562f86ec386006099deebb1 (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
# samba ASN1 rules

from TaskGen import before
import Build, os
from samba_utils import *
from samba_autoconf import *


def SAMBA_ASN1(bld, name, source,
               options='',
               directory='',
               option_file=None,
               includes=''):
    '''Build a ASN1 file using the asn1 compiler.
       This will produce 2 output files'''
    bname = os.path.basename(source)[0:-5];
    dname = os.path.dirname(source)
    asn1name = "%s_asn1" % bname

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

    # for ASN1 compilation, I always put it in build_source, as it doesn't make
    # sense elsewhere
    bld.SET_BUILD_GROUP('build_source')

    out_files = []
    out_files.append("../heimdal/%s/asn1_%s_asn1.x" % (directory, bname))
    out_files.append("../heimdal/%s/%s_asn1.hx" % (directory, bname))

    # the ${TGT[0].parent.abspath(env)} expression gives us the parent directory of
    # the first target in the build directory
    # SRC[0].abspath(env) gives the absolute path to the source directory for the first
    # source file. Note that in the case of a option_file, we have more than
    # one source file
    cd_rule = 'cd ${TGT[0].parent.abspath(env)}'
    asn1_rule = cd_rule + ' && ${BLDBIN}/asn1_compile ${OPTION_FILE} ${ASN1OPTIONS} --one-code-file ${SRC[0].abspath(env)} ${ASN1NAME}'

    source = TO_LIST(source)
    source.append('asn1_compile')

    if option_file is not None:
        source.append(option_file)

    t = bld(rule=asn1_rule,
            ext_out = '.x',
            before = 'cc',
            shell = True,
            source = source,
            target = out_files,
            name=name + '_ASN1')

    t.env.ASN1NAME     = asn1name
    t.env.ASN1OPTIONS  = options
    t.env.BLDBIN       = os.path.normpath(os.path.join(bld.srcnode.abspath(bld.env), '..'))
    if option_file is not None:
        t.env.OPTION_FILE = "--option-file=%s" % os.path.normpath(os.path.join(bld.curdir, option_file))

    cfile = out_files[0][0:-2] + '.c'
    hfile = out_files[1][0:-3] + '.h',

    # now generate a .c file from the .x file
    t = bld(rule='''( echo '#include "config.h"' && cat ${SRC} ) > ${TGT}''',
            source = out_files[0],
            target = cfile,
            shell = True,
	    ext_out = '.c',
            ext_in = '.x',
            depends_on = name + '_ASN1',
            name = name + '_C')

    # and generate a .h file from the .hx file
    t = bld(rule='cp ${SRC} ${TGT}',
            source = out_files[1],
            ext_out = '.c',
            ext_in = '.x',
            target = hfile,
            depends_on = name + '_ASN1',
            name = name + '_H')

    bld.SET_BUILD_GROUP('main')

    includes = TO_LIST(includes)
    includes.append(os.path.dirname(out_files[0]))

    t = bld(features       = 'cc',
            source         = cfile,
            target         = name,
            samba_cflags   = CURRENT_CFLAGS(bld, name, ''),
            depends_on     = '',
            samba_deps     = TO_LIST('HEIMDAL_ROKEN'),
            samba_includes = includes,
            local_include  = True)

Build.BuildContext.SAMBA_ASN1 = SAMBA_ASN1