aboutsummaryrefslogtreecommitdiff
path: root/tools/embedded.sh
blob: ca70127003f49819a4f7b3eaa05d769ded5054c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# This file generate all the embedded binary resources required for OChess to run properly

########## RESOURCES ##########
ressources=$(cat <<-EndOfResources
assets/boards/chesscom_8bits.png
assets/pieces/cburnett.png
assets/icons/hide.png
assets/icons/mat.png
assets/icons/ochess.png
assets/icons/swap.png
assets/icons/zoomin.png
assets/icons/zoomout.png
EndOfResources
)
###############################

set -e
wai=$(dirname $(readlink -f "$0")) # Current script directory
dst="${wai}/../src/binres/binary_data.hpp"

# Binary to C headers
# $1 is the resource file and $2 the variable name to use in the C code
bin2c () {
    xxd -n "$2" -i "$1"
}

# Generate headers
echo -n > "$dst"
for res in $ressources
do
    ext="${res##*.}"
    name="$(basename $res .${ext})"
    echo "Generating resources for ${name}.${ext}..."
    bin2c "$res" "${name}_${ext}" >> "$dst"
done
echo "Done! The generated resources are accessible here: \"$dst\""