Browse Source

Use xxd for Mac embedded resources

tags/v0.6.1
Andrew Belt 6 years ago
parent
commit
32acb82842
2 changed files with 21 additions and 6 deletions
  1. +7
    -0
      compile.mk
  2. +14
    -6
      include/util/common.hpp

+ 7
- 0
compile.mk View File

@@ -77,3 +77,10 @@ build/%.bin.o: %
ifdef ARCH_LIN ifdef ARCH_LIN
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@ $(OBJCOPY) -I binary -O elf64-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
endif endif
ifdef ARCH_WIN
$(OBJCOPY) -I binary -O pe-x86-64 -B i386:x86-64 --rename-section .data=.rodata,alloc,load,readonly,data,contents $< $@
endif
ifdef ARCH_MAC
# Apple makes this needlessly complicated, so just generate a C file with an array.
xxd -i $< | $(CC) -c -o $@ -xc -
endif

+ 14
- 6
include/util/common.hpp View File

@@ -63,15 +63,23 @@ to your Makefile and declare
at the root of a .c or .cpp source file. Note that special characters are replaced with "_". Then use at the root of a .c or .cpp source file. Note that special characters are replaced with "_". Then use
BINARY_START(Test_dat) BINARY_START(Test_dat)
BINARY_END(Test_dat) BINARY_END(Test_dat)
to reference the data beginning and end as a void* array and
to reference the data as a char array and
BINARY_SIZE(Test_dat) BINARY_SIZE(Test_dat)
to get its size in bytes. to get its size in bytes.
*/ */
#define BINARY(sym) extern char _binary_##sym##_start, _binary_##sym##_end, _binary_##sym##_size
#define BINARY_START(sym) ((void *) &_binary_##sym##_start)
#define BINARY_END(sym) ((void *) &_binary_##sym##_end)
// The symbol "_binary_##sym##_size" doesn't seem to be valid after a plugin is dynamically loaded, so simply take the difference between the two addresses.
#define BINARY_SIZE(sym) ((size_t) (&_binary_##sym##_end - &_binary_##sym##_start))
#ifdef ARCH_MAC
// Use output from `xxd -i`
#define BINARY(sym) extern unsigned char sym[]; extern unsigned int sym##len
#define BINARY_START(sym) ((void*) sym)
#define BINARY_END(sym) ((void*) sym + sym##len)
#define BINARY_SIZE(sym) (sym##len)
#else
#define BINARY(sym) extern char _binary_##sym##_start, _binary_##sym##_end, _binary_##sym##_size
#define BINARY_START(sym) ((void*) &_binary_##sym##_start)
#define BINARY_END(sym) ((void*) &_binary_##sym##_end)
// The symbol "_binary_##sym##_size" doesn't seem to be valid after a plugin is dynamically loaded, so simply take the difference between the two addresses.
#define BINARY_SIZE(sym) ((size_t) (&_binary_##sym##_end - &_binary_##sym##_start))
#endif




#include "util/math.hpp" #include "util/math.hpp"


Loading…
Cancel
Save