Debian Codegraph @

examples/winexe/wscript_build

raw
1 #!/usr/bin/env python
2
3 import samba_utils
4
5 def generate_winexesvc_c_from_exe(t):
6 '''generate a C source file with the contents of the given binary'''
7 src = t.inputs[0].bldpath(t.env)
8 tgt = t.outputs[0].bldpath(t.env)
9 fn = t.env.SAMBA_GENERATOR_VARS['WINEXE_FN']
10
11 try:
12 with open(src, 'rb') as f:
13 src_blob = f.read()
14 f.close()
15 except:
16 print('Failed to read %s to convert to C array' % (src))
17 return -1
18
19 def c_array(src):
20 result = []
21 for i in range(0, len(src), 8):
22 l = src[i:i+8]
23 h = ' '.join(["0x%02X," % x for x in l])
24 result.append(h)
25 return "\n\t\t".join(result)
26
27 src_array = c_array(src_blob)
28 if len(src_array) <= 0:
29 print('Failed to convert %s to C array' % (src))
30 return -1
31
32 contents = '''
33 #include "replace.h"
34 #include "lib/util/data_blob.h"
35
36 const DATA_BLOB *%s(void);
37 const DATA_BLOB *%s(void)
38 {
39 \tstatic const uint8_t array[] = {
40 \t\t%s
41 \t};
42 \tstatic const DATA_BLOB blob = {
43 \t\t.data = discard_const_p(uint8_t, array),
44 \t\t.length = ARRAY_SIZE(array),
45 \t};
46 \treturn &blob;
47 }
48 ''' % (fn, fn, src_array)
49
50 if not samba_utils.save_file(tgt, contents):
51 print('Failed to write C source file %s' % (tgt))
52 return -1
53 return 0
54
55 winexesvc_binaries = ''
56
57 bld.SAMBA_GENERATOR(
58 'winexesvc32_exe',
59 source='winexesvc.c',
60 target='winexesvc32.exe',
61 rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
62 enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
63
64 vars = {"WINEXE_FN": "winexesvc32_exe_binary"}
65 bld.SAMBA_GENERATOR(
66 'winexesvc32_exe_binary',
67 source='winexesvc32.exe',
68 target='winexesvc32_exe_binary.c',
69 group='build_source',
70 vars=vars,
71 rule=generate_winexesvc_c_from_exe,
72 enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
73
74 if bld.env.WINEXE_CC_WIN32:
75 winexesvc_binaries += ' winexesvc32_exe_binary.c'
76
77 bld.SAMBA_GENERATOR(
78 'winexesvc64_exe',
79 source='winexesvc.c',
80 target='winexesvc64.exe',
81 rule='SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH} ${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
82 enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
83
84 vars = {"WINEXE_FN": "winexesvc64_exe_binary"}
85 bld.SAMBA_GENERATOR(
86 'winexesvc64_exe_binary',
87 source='winexesvc64.exe',
88 target='winexesvc64_exe_binary.c',
89 group='build_source',
90 vars=vars,
91 rule=generate_winexesvc_c_from_exe,
92 enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
93
94 if bld.env.WINEXE_CC_WIN64:
95 winexesvc_binaries += ' winexesvc64_exe_binary.c'
96
97 if winexesvc_binaries != '':
98 bld.SAMBA3_BINARY('winexe',
99 source='winexe.c ' + winexesvc_binaries,
100 deps='''
101 CMDLINE_S3
102 samba-credentials
103 LOADPARM_CTX
104 libsmb
105 msrpc3
106 ''',
107 enabled=bld.env.build_winexe)