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']
12 with open(src, 'rb') as f:
16 print('Failed to read %s to convert to C array' % (src))
25 # Even files opened in binary mode are read as type "str" in
26 # Python 2, so we need to get the integer ordinal of each
27 # character in the string before we try to convert it to hex.
28 if isinstance(l, str):
29 h = ' '.join(["0x%02X," % ord(x) for x in l])
30 # Files opened in binary mode are read as type "bytes" in
31 # Python 3, so we can convert each individual integer in the
32 # array of bytes to hex directly.
34 h = ' '.join(["0x%02X," % x for x in l])
35 result += "\t\t%s\n" % (h)
38 src_array = c_array(src_blob)
39 if len(src_array) <= 0:
40 print('Failed to convert %s to C array' % (src))
45 #include "lib/util/data_blob.h"
47 const DATA_BLOB *%s(void);
48 const DATA_BLOB *%s(void)
50 \tstatic const uint8_t array[] = {
53 \tstatic const DATA_BLOB blob = {
54 \t\t.data = discard_const_p(uint8_t, array),
55 \t\t.length = ARRAY_SIZE(array),
59 ''' % (fn, fn, src_array)
61 if not samba_utils.save_file(tgt, contents):
62 print('Failed to write C source file %s' % (tgt))
66 winexesvc_binaries = ''
68 if bld.env.WINEXE_CC_WIN32:
72 target='winexesvc32.exe',
73 rule='${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}')
74 vars = {"WINEXE_FN": "winexesvc32_exe_binary"}
76 'winexesvc32_exe_binary',
77 source='winexesvc32.exe',
78 target='winexesvc32_exe_binary.c',
81 rule=generate_winexesvc_c_from_exe)
82 winexesvc_binaries += ' winexesvc32_exe_binary.c'
84 if bld.env.WINEXE_CC_WIN64:
88 target='winexesvc64.exe',
89 rule='${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}')
90 vars = {"WINEXE_FN": "winexesvc64_exe_binary"}
92 'winexesvc64_exe_binary',
93 source='winexesvc64.exe',
94 target='winexesvc64_exe_binary.c',
97 rule=generate_winexesvc_c_from_exe)
98 winexesvc_binaries += ' winexesvc64_exe_binary.c'
100 if winexesvc_binaries != '':
101 bld.SAMBA3_BINARY('winexe',
102 source='winexe.c ' + winexesvc_binaries,
110 enabled=bld.env.build_winexe)