aboutsummaryrefslogtreecommitdiff
path: root/tools/embedded.sh
blob: 0d8f925b0e6feb1aad7ac3672e2040508163e0d8 (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
#!/bin/bash
# This file generate all the embedded binary resources required for OChess to run properly
 
########## RESOURCES ##########
ressources=$(cat <<-EndOfResources
assets/icons/ochess.png
assets/icons/ochess.svg
EndOfResources
)
###############################

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

# 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
includes=""
for res in $ressources
do
    ext="${res##*.}"
    name="$(basename $res .${ext})"
    name_std=${name}_${ext}.hpp # Header name standard
    out="${dst}/${name_std}"
    echo "- Generating ${name_std} resource..."
    bin2c "$res" "${name}_${ext}" # TODO: Apply!
    [ -z "$includes" ] && includes="${name_std}" || includes="${includes} ${name_std}"
done
echo "Please add the following includes to binres.hpp:"
echo "$includes"|tr "[:space:]" "\n"|awk '{print("#include \""$1"\"")}'