Index: tools/mkarray.py
===================================================================
--- tools/mkarray.py	(revision 2628642fbacaaace0098326703f7d066483e2760)
+++ tools/mkarray.py	(revision de1712e4e19c9ccc82703e05e5f4805fdb28a75b)
@@ -28,19 +28,40 @@
 #
 """
-C structure creator
+Binary inline data packer
 """
 
 import sys
 import os
-import struct
+import zlib
+import zipfile
+import binascii
 
 def usage(prname):
 	"Print usage syntax"
-	print("%s <DESTINATION> <LABEL> <AS_PROLOG> [SOURCE ...]" % prname)
+	print("%s [--deflate] <DESTINATION> <LABEL> <AS_PROLOG> [SOURCE ...]" % prname)
+
+def arg_check():
+	if (len(sys.argv) < 4):
+		usage(sys.argv[0])
+		sys.exit()
+
+def deflate(data):
+	"Compress using deflate algorithm (without any headers)"
+	return zlib.compress(data, 9)[2:-4]
+
+def chunks(string, length):
+	"Produce string chunks"
+	for start in range(0, len(string), length):
+		yield string[start:start + length]
 
 def main():
-	if (len(sys.argv) < 4):
-		usage(sys.argv[0])
-		return
+	arg_check()
+	
+	if sys.argv[1] == "--deflate":
+		sys.argv.pop(1)
+		arg_check()
+		compress = True
+	else:
+		compress = False
 	
 	dest = sys.argv[1]
@@ -49,8 +70,13 @@
 	
 	header_ctx = []
+	desc_ctx = []
+	size_ctx = []
 	data_ctx = []
+	
+	src_cnt = 0
 	
 	for src in sys.argv[4:]:
 		basename = os.path.basename(src)
+		plainname = os.path.splitext(basename)[0]
 		symbol = basename.replace(".", "_")
 		
@@ -61,68 +87,87 @@
 		src_in.close()
 		
-		data_rec = "\t.byte "
+		length = len(src_data)
 		
-		fmt = 'B'
-		item_size = struct.calcsize(fmt)
-		offset = 0
-		cnt = 0
+		if compress:
+			src_data = deflate(src_data)
 		
-		while (len(src_data[offset:]) >= item_size):
-			byte = struct.unpack_from(fmt, src_data, offset)
-			
-			if (offset > 0):
-				if ((cnt % 15) == 0):
-					data_rec += "\n\t.byte "
-				else:
-					data_rec += ", "
-			
-			data_rec += "0x%x" % byte
-			offset += item_size
-			cnt += 1
+		if sys.version_info < (3,):
+			src_data = bytearray(src_data)
 		
-		data_rec += "\n"
+		length_out = len(src_data)
 		
-		header_ctx.append("extern uint64_t %s_size;" % symbol)
 		header_ctx.append("extern uint8_t %s[];" % symbol)
-		
-		data_ctx.append(".globl %s_size" % symbol)
-		data_ctx.append(".balign 8");
-		data_ctx.append(".size %s_size, 8" % symbol)
-		data_ctx.append("%s_size:" % symbol)
-		data_ctx.append("\t.quad %u\n" % offset)
+		header_ctx.append("extern size_t %s_size;" % symbol)
 		
 		data_ctx.append(".globl %s" % symbol)
 		data_ctx.append(".balign 8")
-		data_ctx.append(".size %s, %u" % (symbol, offset))
+		data_ctx.append(".size %s, %u" % (symbol, length_out))
 		data_ctx.append("%s:" % symbol)
-		data_ctx.append(data_rec)
+		data_ctx.append("\t.byte 0x" + ', 0x'.join(chunks(binascii.b2a_hex(src_data), 2)) + "\n")
+		
+		desc_field = []
+		desc_field.append("\t{")
+		desc_field.append("\t\t.name = \"%s\"," % plainname)
+		desc_field.append("\t\t.addr = (void *) %s," % symbol)
+		desc_field.append("\t\t.size = %u," % length_out)
+		desc_field.append("\t\t.inflated = %u" % length)
+		desc_field.append("\t}")
+		
+		desc_ctx.append("\n".join(desc_field))
+		
+		size_ctx.append("size_t %s_size = %u;" % (symbol, length_out))
+		
+		src_cnt += 1
 	
-	header = open("%s.h" % dest, "w")
+	archive = zipfile.ZipFile("%s.zip" % dest, "w", zipfile.ZIP_STORED)
 	
-	header.write('/***************************************\n')
-	header.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
-	header.write(' * Generated by: tools/mkarray.py      *\n')
-	header.write(' ***************************************/\n\n')
-	header.write("#ifndef %s_H_\n" % label)
-	header.write("#define %s_H_\n\n" % label)
-	header.write("#include <stddef.h>\n")
-	header.write("#include <stdint.h>\n\n")
-	header.write("\n".join(header_ctx))
-	header.write("\n\n")
-	header.write("#endif\n")
+	data = ''
+	data += '/***************************************\n'
+	data += ' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n'
+	data += ' * Generated by: tools/mkarray.py      *\n'
+	data += ' ***************************************/\n\n'
+	data += "#ifndef %sS_H_\n" % label.upper()
+	data += "#define %sS_H_\n\n" % label.upper()
+	data += "#include <stddef.h>\n"
+	data += "#include <stdint.h>\n\n"
+	data += "#define %sS  %u\n\n" % (label.upper(), src_cnt)
+	data += "typedef struct {\n"
+	data += "\tconst char *name;\n"
+	data += "\tvoid *addr;\n"
+	data += "\tsize_t size;\n"
+	data += "\tsize_t inflated;\n"
+	data += "} %s_t;\n\n" % label
+	data += "extern %s_t %ss[];\n\n" % (label, label)
+	data += "\n".join(header_ctx)
+	data += "\n\n"
+	data += "#endif\n"
+	archive.writestr("%s.h" % dest, data)
 	
-	header.close()
+	data = ''
+	data += '/***************************************\n'
+	data += ' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n'
+	data += ' * Generated by: tools/mkarray.py      *\n'
+	data += ' ***************************************/\n\n'
+	data += as_prolog
+	data += '.data\n\n'
+	data += "\n".join(data_ctx)
+	data += "\n"
+	archive.writestr("%s.s" % dest, data)
 	
-	data = open("%s.s" % dest, "w")
+	data = ''
+	data += '/***************************************\n'
+	data += ' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n'
+	data += ' * Generated by: tools/mkarray.py      *\n'
+	data += ' ***************************************/\n\n'
+	data += "#include \"%s.h\"\n\n" % dest
+	data += "%s_t %ss[] = {\n" % (label, label)
+	data += ",\n".join(desc_ctx)
+	data += "\n"
+	data += "};\n\n"
+	data += "\n".join(size_ctx)
+	data += "\n"
+	archive.writestr("%s_desc.c" % dest, data)
 	
-	data.write('/***************************************\n')
-	data.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
-	data.write(' * Generated by: tools/mkarray.py      *\n')
-	data.write(' ***************************************/\n\n')
-	data.write(as_prolog)
-	data.write('.data\n\n')
-	data.write("\n".join(data_ctx))
-	
-	data.close()
+	archive.close()
 
 if __name__ == '__main__':
