#!/bin/sh # Embed web/ into .gen/web_assets.inc as C byte arrays (the same trick the # Makefile uses for src/models_builtin.json). POSIX sh on purpose: the musl # and busybox build environments have no bash. Usage: # sh scripts/embed_web.sh [out.inc] [web-dir] set -eu ROOT="$(cd "$(dirname "$0")/.." && pwd)" OUT="${1:-$ROOT/.gen/web_assets.inc}" DIR="${2:-$ROOT/web}" FILES="index.html app.js style.css favicon.svg" mkdir -p "$(dirname "$OUT")" { echo "/* Generated by scripts/embed_web.sh from web/ - do not edit. */" for f in $FILES; do [ -f "$DIR/$f" ] || continue var="wui_asset_$(echo "$f" | tr -c 'a-zA-Z0-9' '_')" echo "static const unsigned char ${var}[] = {" od -An -v -tx1 "$DIR/$f" | sed 's/\([0-9a-f][0-9a-f]\)/0x\1,/g' echo "0x00};" done echo "static const wui_asset_t wui_assets[] = {" for f in $FILES; do [ -f "$DIR/$f" ] || continue var="wui_asset_$(echo "$f" | tr -c 'a-zA-Z0-9' '_')" case "$f" in *.html) ctype="text/html; charset=utf-8" ;; *.js) ctype="text/javascript; charset=utf-8" ;; *.css) ctype="text/css; charset=utf-8" ;; *.svg) ctype="image/svg+xml" ;; *) ctype="application/octet-stream" ;; esac echo " {\"$f\", \"$ctype\", ${var}, sizeof(${var}) - 1}," done echo "};" echo "static const int wui_asset_count = (int)(sizeof(wui_assets) / sizeof(wui_assets[0]));" } > "$OUT.tmp" mv "$OUT.tmp" "$OUT" echo "embedded $(wc -c < "$OUT") bytes of C into $OUT"