#!/usr/bin/env bash # Compila o Greed 4.5 do fredygames.com (Matthew T. Day, 1989; mantido por Eric S. Raymond; licenca BSD de 2 # clausulas) em WebAssembly com o Emscripten 6.0.10, sobre a camada de terminal de curses-web/ (curses # desenhado num canvas, mais o termcap que o jogo usa para destacar a linha nova da tabela de recordes; ver # curses-web/README.md). Nenhuma mudanca no codigo do jogo. # # source /emsdk_env.sh # emsdk install 6.0.10 && emsdk activate 6.0.10 # src/FredGames.Bundler/Builds/build-greed.sh # # Fonte: greed_4.5.orig.tar.gz do Debian, conferido pelo SHA-256 e guardado em artifacts/cache/greed/. Os # recordes ficam em /greed-saves/greed.hs (a pagina guarda a pasta no IndexedDB); bsdgames/compat.c da o nome # do jogador ("player", no lugar do getpwuid). # # Saida: artifacts/build/greed-4.5/greed.{js,wasm}, que o bundle.yaml do jogo confere pelo SHA-256. set -euo pipefail VERSION=4.5 SRC_SHA256=17e57e27423a9b3380aeea4e780e4247d9a10c60351c7a8c710744dcf9133ea6 EMSCRIPTEN=6.0.10 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root="$(git -C "$here" rev-parse --show-toplevel 2>/dev/null || pwd)" out="$root/artifacts/build/greed-$VERSION" cache="$root/artifacts/cache/greed" tarball="$cache/greed_$VERSION.orig.tar.gz" . "$here/curses-web/flags.sh" if ! emcc --version 2>/dev/null | head -1 | grep -q " $EMSCRIPTEN "; then echo "Precisa do Emscripten $EMSCRIPTEN no PATH (source /emsdk_env.sh)." >&2 exit 1 fi if [ ! -f "$tarball" ]; then mkdir -p "$cache" curl -fsSL -o "$tarball.part" "https://deb.debian.org/debian/pool/main/g/greed/greed_$VERSION.orig.tar.gz" mv "$tarball.part" "$tarball" fi echo "$SRC_SHA256 $tarball" | shasum -a 256 -c - >&2 rm -rf "$out" mkdir -p "$out/work/obj" "$out/work/src" S="$out/work/src" tar xzf "$tarball" -C "$S" --strip-components=1 objs=() for f in "$S/greed.c" "$here/bsdgames/compat.c" "$CW_DIR/curses.c" "$CW_DIR/termcap.c"; do o="$out/work/obj/$(basename "$f").o" objs+=("$o") emcc "${CW_CFLAGS[@]}" -DSCOREFILE='"/greed-saves/greed.hs"' -DRELEASE="\"$VERSION\"" \ -ffile-prefix-map="$out/work/=" -ffile-prefix-map="$CW_DIR/=curses-web/" -ffile-prefix-map="$here/=" \ -I"$S" -c "$f" -o "$o" done emcc "${objs[@]}" "${CW_LDFLAGS[@]}" -o "$out/greed.js" rm -rf "$out/work" shasum -a 256 "$out/greed.js" "$out/greed.wasm"