Don't use xxd to objectify files.

This commit is contained in:
David Given
2023-10-23 01:03:28 +02:00
parent 8fb786094f
commit 6a00653d1e
2 changed files with 21 additions and 2 deletions

19
build/_objectify.py Normal file
View File

@@ -0,0 +1,19 @@
import sys
from functools import partial
if len(sys.argv) != 3:
sys.exit("Usage: %s <file> <symbol>" % sys.argv[0])
filename = sys.argv[1]
symbol = sys.argv[2]
print("const uint8_t " + symbol + "[] = {")
n = 0
with open(filename, "rb") as in_file:
for c in iter(partial(in_file.read, 1), b""):
print("0x%02X," % ord(c), end="")
n += 1
if n % 16 == 0:
print()
print("};")
print("const size_t " + symbol + "_len = sizeof(" + symbol + ");")

View File

@@ -6,9 +6,9 @@ from os.path import basename
def objectify(self, name, src: Target, symbol):
normalrule(
replaces=self,
ins=[src],
ins=["build/_objectify.py", src],
outs=[basename(filenameof(src)) + ".h"],
commands=["xxd -i -n " + symbol + " {ins} > {outs}"],
commands=["$(PYTHON) {ins[0]} {ins[1]} " + symbol + " > {outs}"],
label="OBJECTIFY",
)