summaryrefslogtreecommitdiff
path: root/tests/projects/other/bin2obj
diff options
context:
space:
mode:
Diffstat (limited to 'tests/projects/other/bin2obj')
-rw-r--r--tests/projects/other/bin2obj/src/data.bin1
-rw-r--r--tests/projects/other/bin2obj/src/main.c98
-rw-r--r--tests/projects/other/bin2obj/src/xmake.icobin0 -> 119943 bytes
-rw-r--r--tests/projects/other/bin2obj/test.lua4
-rw-r--r--tests/projects/other/bin2obj/xmake.lua8
5 files changed, 111 insertions, 0 deletions
diff --git a/tests/projects/other/bin2obj/src/data.bin b/tests/projects/other/bin2obj/src/data.bin
new file mode 100644
index 000000000..5d26814ee
--- /dev/null
+++ b/tests/projects/other/bin2obj/src/data.bin
@@ -0,0 +1 @@
+hello xmake!
diff --git a/tests/projects/other/bin2obj/src/main.c b/tests/projects/other/bin2obj/src/main.c
new file mode 100644
index 000000000..bc1d2442f
--- /dev/null
+++ b/tests/projects/other/bin2obj/src/main.c
@@ -0,0 +1,98 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <ctype.h>
+
+extern const uint8_t _binary_data_bin_start[];
+extern const uint8_t _binary_data_bin_end[];
+
+extern const uint8_t _binary_xmake_ico_start[];
+extern const uint8_t _binary_xmake_ico_end[];
+
+static void hexdump(const char* name, const uint8_t* data, uint32_t size) {
+ printf("%s: size: %u bytes\n", name, (unsigned int)size);
+ if (size == 0) {
+ return;
+ }
+
+ // if file is larger than 128 bytes, only dump first 64 and last 64 bytes
+ uint32_t dump_size = size;
+ uint32_t start_offset = 0;
+ uint32_t end_offset = 0;
+ uint32_t skip_size = 0;
+
+ if (size > 128) {
+ dump_size = 64;
+ start_offset = 0;
+ end_offset = size - 64;
+ skip_size = end_offset - start_offset - dump_size;
+ }
+
+ // dump start
+ for (uint32_t offset = start_offset; offset < start_offset + dump_size; offset += 16) {
+ // print offset
+ printf("%08x ", (unsigned int)offset);
+
+ // print hex bytes (8 bytes, space, 8 bytes)
+ for (uint32_t i = 0; i < 16; i++) {
+ if (offset + i < size) {
+ printf("%02x ", data[offset + i]);
+ } else {
+ printf(" ");
+ }
+ if (i == 7) {
+ printf(" ");
+ }
+ }
+
+ // print ASCII representation
+ printf(" |");
+ for (uint32_t i = 0; i < 16 && offset + i < size; i++) {
+ uint8_t c = data[offset + i];
+ printf("%c", isprint(c) ? c : '.');
+ }
+ printf("|\n");
+ }
+
+ // print skip indicator if needed
+ if (skip_size > 0) {
+ printf(" ... (skipped %u bytes) ...\n", (unsigned int)skip_size);
+ }
+
+ // dump end if needed
+ if (size > 128) {
+ for (uint32_t offset = end_offset; offset < size; offset += 16) {
+ // print offset
+ printf("%08x ", (unsigned int)offset);
+
+ // print hex bytes (8 bytes, space, 8 bytes)
+ for (uint32_t i = 0; i < 16; i++) {
+ if (offset + i < size) {
+ printf("%02x ", data[offset + i]);
+ } else {
+ printf(" ");
+ }
+ if (i == 7) {
+ printf(" ");
+ }
+ }
+
+ // print ASCII representation
+ printf(" |");
+ for (uint32_t i = 0; i < 16 && offset + i < size; i++) {
+ uint8_t c = data[offset + i];
+ printf("%c", isprint(c) ? c : '.');
+ }
+ printf("|\n");
+ }
+ }
+}
+
+int main(int argc, char** argv) {
+ const uint32_t _binary_data_bin_size = (uint32_t)(_binary_data_bin_end - _binary_data_bin_start);
+ const uint32_t _binary_xmake_ico_size = (uint32_t)(_binary_xmake_ico_end - _binary_xmake_ico_start);
+
+ hexdump("data.bin", _binary_data_bin_start, _binary_data_bin_size);
+ printf("\n");
+ hexdump("xmake.ico", _binary_xmake_ico_start, _binary_xmake_ico_size);
+ return 0;
+}
diff --git a/tests/projects/other/bin2obj/src/xmake.ico b/tests/projects/other/bin2obj/src/xmake.ico
new file mode 100644
index 000000000..52c8ef389
--- /dev/null
+++ b/tests/projects/other/bin2obj/src/xmake.ico
Binary files differ
diff --git a/tests/projects/other/bin2obj/test.lua b/tests/projects/other/bin2obj/test.lua
new file mode 100644
index 000000000..7f2050b62
--- /dev/null
+++ b/tests/projects/other/bin2obj/test.lua
@@ -0,0 +1,4 @@
+function main(t)
+ t:build()
+end
+
diff --git a/tests/projects/other/bin2obj/xmake.lua b/tests/projects/other/bin2obj/xmake.lua
new file mode 100644
index 000000000..9541e17ae
--- /dev/null
+++ b/tests/projects/other/bin2obj/xmake.lua
@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+ set_kind("binary")
+ add_rules("utils.bin2obj", {extensions = {".bin", ".ico"}})
+ add_files("src/*.c")
+ add_files("src/data.bin", {zeroend = true})
+ add_files("src/xmake.ico", {zeroend = false})