summaryrefslogtreecommitdiff
path: root/scripts/crunch_demo.sh
blob: c88e8d9f4b546bd1a50589e6ce1ca85d2d842e0e (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
38
39
40
41
42
43
44
45
#!/bin/sh
# Build a size-optimized binary and compress it.

set -e

echo "Building stripped binary..."
cmake -S . -B build_strip -DDEMO_STRIP_ALL=ON
cmake --build build_strip -j8

SRC_BIN="build_strip/demo64k"
OUT_BIN="build_strip/demo64k_packed"
OS_NAME=$(uname -s)

if [ "$OS_NAME" = "Darwin" ]; then
    echo "macOS detected. Using 'strip' and 'gzexe' (UPX is unreliable on macOS)."

    # Copy original to output to work on it
    cp "$SRC_BIN" "$OUT_BIN"

    echo "Stripping symbols..."
    strip -u -r "$OUT_BIN"

    if command -v gzexe >/dev/null 2>&1; then
        echo "Compressing with gzexe..."
        gzexe "$OUT_BIN"
        # gzexe creates a backup file ending in ~, remove it
        rm -f "$OUT_BIN~"
    else
        echo "Warning: gzexe not found, skipping compression."
    fi

else
    # Linux / other
    if ! command -v upx >/dev/null 2>&1; then
        echo "Error: upx is not installed or not in PATH."
        echo "Please install it using your package manager."
        exit 1
    fi

    echo "Compressing with UPX..."
    upx --best --lzma -o "$OUT_BIN" "$SRC_BIN"
fi

echo "Done."
ls -lh "$SRC_BIN" "$OUT_BIN"