#!/bin/bash # Copyright 2014,2015 Pawel Jewstafjew PawelJewstafjewgmailcom # converts a binary file to a C header file binfile="$1" name="$2" out=${name}.h.tmp size=$(cat "$binfile" | wc --bytes) echo "name=${name}, size=${size}" echo "#ifndef _${name}_H" > ${out} echo "#define _${name}_H" >> ${out} echo "enum {${name}_size = ${size}};" >> ${out} echo "const unsigned char ${name}[${size}] = {" >> ${out} for v in $(od --output-duplicates --width=1 --address=n --format=x1 "$binfile" ) do echo "0x$v," >> ${out} done echo "};" >> ${out} echo "#endif // _${name}_H" >> ${out} mv ${out} ${name}.h