summaryrefslogtreecommitdiffstats
path: root/examples/winexe/wscript_build
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
commit8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch)
tree4099e8021376c7d8c05bdf8503093d80e9c7bad0 /examples/winexe/wscript_build
parentInitial commit. (diff)
downloadsamba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz
samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/winexe/wscript_build')
-rw-r--r--examples/winexe/wscript_build118
1 files changed, 118 insertions, 0 deletions
diff --git a/examples/winexe/wscript_build b/examples/winexe/wscript_build
new file mode 100644
index 0000000..3646834
--- /dev/null
+++ b/examples/winexe/wscript_build
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+
+import samba_utils
+
+def generate_winexesvc_c_from_exe(t):
+ '''generate a C source file with the contents of the given binary'''
+ src = t.inputs[0].bldpath(t.env)
+ tgt = t.outputs[0].bldpath(t.env)
+ fn = t.env.SAMBA_GENERATOR_VARS['WINEXE_FN']
+
+ try:
+ with open(src, 'rb') as f:
+ src_blob = f.read()
+ f.close()
+ except:
+ print('Failed to read %s to convert to C array' % (src))
+ return -1
+
+ def c_array(src):
+ N = 0
+ result = ''
+ while src:
+ l = src[:8]
+ src = src[8:]
+ # Even files opened in binary mode are read as type "str" in
+ # Python 2, so we need to get the integer ordinal of each
+ # character in the string before we try to convert it to hex.
+ if isinstance(l, str):
+ h = ' '.join(["0x%02X," % ord(x) for x in l])
+ # Files opened in binary mode are read as type "bytes" in
+ # Python 3, so we can convert each individual integer in the
+ # array of bytes to hex directly.
+ else:
+ h = ' '.join(["0x%02X," % x for x in l])
+ result += "\t\t%s\n" % (h)
+ return result
+
+ src_array = c_array(src_blob)
+ if len(src_array) <= 0:
+ print('Failed to convert %s to C array' % (src))
+ return -1
+
+ contents = '''
+#include "replace.h"
+#include "lib/util/data_blob.h"
+
+const DATA_BLOB *%s(void);
+const DATA_BLOB *%s(void)
+{
+\tstatic const uint8_t array[] = {
+%s
+\t};
+\tstatic const DATA_BLOB blob = {
+\t\t.data = discard_const_p(uint8_t, array),
+\t\t.length = ARRAY_SIZE(array),
+\t};
+\treturn &blob;
+}
+''' % (fn, fn, src_array)
+
+ if not samba_utils.save_file(tgt, contents):
+ print('Failed to write C source file %s' % (tgt))
+ return -1
+ return 0
+
+winexesvc_binaries = ''
+
+bld.SAMBA_GENERATOR(
+ 'winexesvc32_exe',
+ source='winexesvc.c',
+ target='winexesvc32.exe',
+ rule='${WINEXE_CC_WIN32} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
+ enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
+
+vars = {"WINEXE_FN": "winexesvc32_exe_binary"}
+bld.SAMBA_GENERATOR(
+ 'winexesvc32_exe_binary',
+ source='winexesvc32.exe',
+ target='winexesvc32_exe_binary.c',
+ group='build_source',
+ vars=vars,
+ rule=generate_winexesvc_c_from_exe,
+ enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN32)
+
+if bld.env.WINEXE_CC_WIN32:
+ winexesvc_binaries += ' winexesvc32_exe_binary.c'
+
+bld.SAMBA_GENERATOR(
+ 'winexesvc64_exe',
+ source='winexesvc.c',
+ target='winexesvc64.exe',
+ rule='${WINEXE_CC_WIN64} ${SRC} -o ${TGT} ${WINEXE_LDFLAGS}',
+ enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
+
+vars = {"WINEXE_FN": "winexesvc64_exe_binary"}
+bld.SAMBA_GENERATOR(
+ 'winexesvc64_exe_binary',
+ source='winexesvc64.exe',
+ target='winexesvc64_exe_binary.c',
+ group='build_source',
+ vars=vars,
+ rule=generate_winexesvc_c_from_exe,
+ enabled=bld.env.build_winexe and bld.env.WINEXE_CC_WIN64)
+
+if bld.env.WINEXE_CC_WIN64:
+ winexesvc_binaries += ' winexesvc64_exe_binary.c'
+
+if winexesvc_binaries != '':
+ bld.SAMBA3_BINARY('winexe',
+ source='winexe.c ' + winexesvc_binaries,
+ deps='''
+ CMDLINE_S3
+ samba-credentials
+ LOADPARM_CTX
+ libsmb
+ msrpc3
+ ''',
+ enabled=bld.env.build_winexe)