I want include binary data in executable.
For this purpose I use such techniques (from my Makefile):
%.o %.h: %.bin
echo "extern const char *$*;" >$*.h
echo '.text; .global $*; $*_data:; .incbin "$*.bin"; $*:; .int $*_data;'
| gcc -x assembler -o $*.o -c -
This cryptic code equivalents to .S file (when 'str.bin' processed):
.text
.global str
str_data:
.incbin "str.bin"
str:
.int str_data # XXX .int or .quad ???
To access the data from str.bin I use in .c:
================================================================
#include "str.h" /* here placed: extern const char *str; */
int foo() {
printf(str);
}
================================================================
In case of 32-bit platform I need wrote '.int', in case of
64-bit platform I need wrote '.quad' in assembler.
To work around I can use #if/#define and preprocess output.
But this seems ugly. Is there portable syntax?