From 4de611cc1e9c421fa30763f10b564d0e98440196 Mon Sep 17 00:00:00 2001 From: mguinhos Date: Tue, 20 Oct 2026 20:39:57 -0300 Subject: [PATCH] Automacao de empacotamento AppImage (make appimage) - Makefile: alvos "appdir" (monta build/TinyBlocks.AppDir), "appimage" (baixa o appimagetool e gera build/TinyBlocks--x86_64.AppImage), "run-appimage" e "icon". - packaging/: tinyblocks.desktop, AppRun, tinyblocks.png (icone 256x256) e make_icon.py (gera o icone sem dependencias externas). - appdir: * empacota o editor + SDL2/SDL2_ttf (com uma excludelist das libs do sistema: glibc, X11/GL, som, dbus, systemd...); * copia as libraries de extensao (.so + library.toml) para usr/share/tinyblocks/libraries//build; - libman: tb_libman_scan_defaults agora tambem varre libraries ao lado do executavel (usr/share/tinyblocks/libraries e usr/lib/...), de modo que o AppImage acha suas extensoes mesmo rodando fora do repositorio. Verificado: AppImage monta, abre o editor e carrega um .so empacotado (TOML) pela tela "Escolha uma Extensao". --- Makefile | 71 +++++++++++++++ libraries/tinyblocks-libman/src/tb_libman.c | 25 ++++++ packaging/AppRun | 8 ++ packaging/make_icon.py | 91 ++++++++++++++++++++ packaging/tinyblocks.desktop | 11 +++ packaging/tinyblocks.png | Bin 0 -> 3706 bytes 6 files changed, 206 insertions(+) create mode 100644 packaging/AppRun create mode 100644 packaging/make_icon.py create mode 100644 packaging/tinyblocks.desktop create mode 100644 packaging/tinyblocks.png diff --git a/Makefile b/Makefile index 6fd3948..d1d89cc 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ LIB_LDFLAGS := -L$(ED_DIR)/build -L$(GX_DIR)/build -L$(SD_DIR)/build \ .PHONY: all help debug release static shared example sdl2 clean run python-lib mcp-lib json \ editor run-editor run-sdl2 mylib vector customappearance graphics sdl2-backend test-editor \ + appdir appimage run-appimage icon \ test-toml test-plugin test-blueprint \ category-libs category-sos libs \ lib-events lib-control lib-operators lib-variables lib-appearance lib-pen lib-fs \ @@ -228,6 +229,76 @@ editor: static libs $(BUILD)/editor ## Compila o editor visual (estilo Scratch) run-editor: editor ## Compila e abre o editor visual ./$(BUILD)/editor +# ── Empacotamento AppImage ────────────────────────────────────────────── +APP_NAME := TinyBlocks +APP_VER := 0.1.0 +APPDIR := $(BUILD)/$(APP_NAME).AppDir +APPIMAGE := $(BUILD)/$(APP_NAME)-$(APP_VER)-x86_64.AppImage +AITOOL := $(BUILD)/.tools/appimagetool-x86_64.AppImage +AITOOL_URL := https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage +PKG_DIR := packaging + +# Bibliotecas que NAO devem ser empacotadas (glibc, X11/GL/som do sistema). +APPIMAGE_EXCLUDE := ld-linux libc.so libm.so libpthread librt libdl libgcc_s libstdc++ \ + libGL libEGL libGLX libGLdispatch libOpenGL libGLU libdrm libgbm \ + libX11 libxcb libXau libXdmcp libXext libXrender libXfixes libXi libXrandr \ + libXcursor libXss libXinerama libxkbcommon libwayland libdecor \ + libdbus libasound libpulse libpulsecommon libsystemd libudev libselinux libmount + +$(AITOOL): + @mkdir -p $(BUILD)/.tools + @echo "Baixando appimagetool..." + @curl -fL --retry 3 -o $@ $(AITOOL_URL) || { rm -f $@; \ + echo "Falha ao baixar appimagetool. Baixe manualmente em"; \ + echo " $(AITOOL_URL)"; \ + echo "e rode: make appimage APPIMAGETOOL=/caminho/appimagetool"; exit 1; } + @chmod +x $@ + +appdir: editor ## Monta o AppDir (build/TinyBlocks.AppDir) para o AppImage + $(RM) -r $(APPDIR) + mkdir -p $(APPDIR)/usr/bin $(APPDIR)/usr/lib \ + $(APPDIR)/usr/share/applications \ + $(APPDIR)/usr/share/icons/hicolor/256x256/apps + cp $(BUILD)/editor $(APPDIR)/usr/bin/tinyblocks + cp $(PKG_DIR)/tinyblocks.png $(APPDIR)/usr/share/icons/hicolor/256x256/apps/tinyblocks.png + cp $(PKG_DIR)/tinyblocks.png $(APPDIR)/tinyblocks.png + cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/tinyblocks.desktop + cp $(PKG_DIR)/tinyblocks.desktop $(APPDIR)/usr/share/applications/tinyblocks.desktop + cp $(PKG_DIR)/AppRun $(APPDIR)/AppRun + chmod +x $(APPDIR)/AppRun + @echo "Empacotando bibliotecas (exceto as do sistema)..." + @ldd $(BUILD)/editor | awk '/=> \//{print $$1, $$3}' | while read name path; do \ + skip=0; \ + for ex in $(APPIMAGE_EXCLUDE); do case "$$name" in $$ex*) skip=1;; esac; done; \ + [ $$skip -eq 0 ] && cp -L "$$path" $(APPDIR)/usr/lib/ 2>/dev/null || true; \ + done + @echo "Empacotando libraries de extensao (.so + library.toml)..." + @mkdir -p $(APPDIR)/usr/share/tinyblocks/libraries + @for d in $(LIBDIR)/tinyblocks-*/; do \ + name=$$(basename "$$d"); \ + [ -f "$$d"library.toml ] || continue; \ + so=$$(ls "$${d}build/"*.so 2>/dev/null | head -1); \ + [ -n "$$so" ] || continue; \ + mkdir -p "$(APPDIR)/usr/share/tinyblocks/libraries/$$name/build"; \ + cp "$$d"library.toml "$(APPDIR)/usr/share/tinyblocks/libraries/$$name/"; \ + cp "$$so" "$(APPDIR)/usr/share/tinyblocks/libraries/$$name/build/"; \ + done + @echo "AppDir pronto: $(APPDIR)" + +appimage: appdir ## Gera o AppImage portatil (build/TinyBlocks-*.AppImage) + @test -n "$(APPIMAGETOOL)" || $(MAKE) $(AITOOL) + @TOOL="$(if $(APPIMAGETOOL),$(APPIMAGETOOL),$(abspath $(AITOOL)))"; \ + cd $(BUILD) && ARCH=x86_64 APPIMAGE_EXTRACT_AND_RUN=1 \ + "$$TOOL" --no-appstream $(abspath $(APPDIR)) $(abspath $(APPIMAGE)) + @echo "AppImage: $(APPIMAGE)" + @echo "Rode com: $(APPIMAGE)" + +run-appimage: appimage ## Gera e abre o AppImage + ./$(APPIMAGE) + +icon: ## (Re)gera o icone do AppImage (packaging/tinyblocks.png) + python3 $(PKG_DIR)/make_icon.py + # -- Exemplo de library externa (hot reload) --- $(BUILD)/mylib.so: examples/mylib/mylib.c $(LIB_A) $(CC) $(CFLAGS_REL) -Iinclude -fPIC -shared \ diff --git a/libraries/tinyblocks-libman/src/tb_libman.c b/libraries/tinyblocks-libman/src/tb_libman.c index 0a706f5..43ba09b 100644 --- a/libraries/tinyblocks-libman/src/tb_libman.c +++ b/libraries/tinyblocks-libman/src/tb_libman.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "tb_libman.h" @@ -124,9 +125,33 @@ int tb_libman_scan(const char* root, int max_depth) { return scan_dir(root, max_depth); } +/* Varre libraries ao lado do executavel (ex.: AppImage em + * usr/bin/tinyblocks -> usr/share/tinyblocks/libraries). */ +static int scan_exe_roots(void) { + char exe[TBLM_PATH_LEN]; + ssize_t k = readlink("/proc/self/exe", exe, sizeof(exe) - 1); + if (k <= 0) return 0; + exe[k] = 0; + char* slash = strrchr(exe, '/'); + if (!slash) return 0; + *slash = 0; /* diretorio do executavel */ + static const char* rels[] = { + "/../share/tinyblocks/libraries", + "/../lib/tinyblocks/libraries", + }; + int n = 0; + for (int i = 0; i < 2; i++) { + char buf[TBLM_PATH_LEN]; + snprintf(buf, sizeof(buf), "%s%s", exe, rels[i]); + n += tb_libman_scan(buf, 3); + } + return n; +} + int tb_libman_scan_defaults(void) { int n = 0; n += tb_libman_scan("libraries", 3); + n += scan_exe_roots(); const char* home = getenv("HOME"); if (home && home[0]) { char buf[TBLM_PATH_LEN]; diff --git a/packaging/AppRun b/packaging/AppRun new file mode 100644 index 0000000..1c18378 --- /dev/null +++ b/packaging/AppRun @@ -0,0 +1,8 @@ +#!/bin/sh +# AppRun do AppImage do TinyBlocks. +# Descobre o diretorio do proprio AppRun e roda o editor usando as +# bibliotecas empacotadas em usr/lib. +HERE="$(dirname "$(readlink -f "$0")")" +export LD_LIBRARY_PATH="$HERE/usr/lib:$HERE/usr/lib/x86_64-linux-gnu:${LD_LIBRARY_PATH}" +export TINYBLOCKS_APPDIR="$HERE" +exec "$HERE/usr/bin/tinyblocks" "$@" diff --git a/packaging/make_icon.py b/packaging/make_icon.py new file mode 100644 index 0000000..2833b24 --- /dev/null +++ b/packaging/make_icon.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 +"""Gera packaging/tinyblocks.png (icone 256x256 do editor TinyBlocks). + +Sem dependencias: escreve o PNG direto com zlib + struct. Faz supersampling +4x para bordas suaves. Uso: python3 packaging/make_icon.py [saida.png] +""" +import struct, sys, zlib + +S = 4 # supersampling +OUT = 256 +W = OUT * S + +def rrect(x, y, x0, y0, x1, y1, r): + if x < x0 or x > x1 or y < y0 or y > y1: + return False + cx = min(max(x, x0 + r), x1 - r) + cy = min(max(y, y0 + r), y1 - r) + dx, dy = x - cx, y - cy + return dx * dx + dy * dy <= r * r + +def rect(x, y, x0, y0, x1, y1): + return x0 <= x <= x1 and y0 <= y <= y1 + +def tri_signed(px, py, ax, ay, bx, by, cx, cy): + return (px - bx) * (ay - by) - (ax - bx) * (py - by) + +def in_tri(x, y, ax, ay, bx, by, cx, cy): + d1 = tri_signed(x, y, ax, ay, bx, by, cx, cy) + d2 = tri_signed(x, y, bx, by, cx, cy, ax, ay) + d3 = tri_signed(x, y, cx, cy, ax, ay, bx, by) + neg = (d1 < 0) or (d2 < 0) or (d3 < 0) + pos = (d1 > 0) or (d2 > 0) or (d3 > 0) + return not (neg and pos) + +def px(x, y): + # coords em escala OUT (0..256) + X, Y = x / S, y / S + # fundo arredondado azul + if rrect(X, Y, 4, 4, 252, 252, 54): + c = (74, 144, 226) + else: + return (0, 0, 0, 0) + # brilho no topo + if Y < 128: + t = 1.0 - Y / 128.0 + c = (int(c[0] + 40 * t), int(c[1] + 30 * t), int(c[2] + 20 * t)) + # haste da bandeira + if rect(X, Y, 176, 44, 182, 124): + c = (240, 80, 80) + # triangulo verde + if in_tri(X, Y, 183, 44, 216, 58, 183, 74): + c = (76, 175, 80) + # corpo do bloco (branco) + if rrect(X, Y, 60, 108, 196, 200, 16): + c = (245, 247, 250) + # encaixe no topo do bloco + if rrect(X, Y, 106, 86, 150, 118, 9): + c = (245, 247, 250) + # "janela" escura no bloco + if rrect(X, Y, 80, 130, 176, 150, 6): + c = (74, 144, 226) + return (c[0], c[1], c[2], 255) + +def main(): + out = sys.argv[1] if len(sys.argv) > 1 else "packaging/tinyblocks.png" + buf = bytearray() + for oy in range(OUT): + buf.append(0) # filtro 0 por scanline + for ox in range(OUT): + r = g = b = a = 0 + for dy in range(S): + for dx in range(S): + p = px(ox * S + dx, oy * S + dy) + r += p[0]; g += p[1]; b += p[2]; a += p[3] + n = S * S + buf += bytes((r // n, g // n, b // n, a // n)) + + def chunk(tag, data): + return (struct.pack(">I", len(data)) + tag + data + + struct.pack(">I", zlib.crc32(tag + data) & 0xffffffff)) + + png = b"\x89PNG\r\n\x1a\n" + png += chunk(b"IHDR", struct.pack(">IIBBBBB", OUT, OUT, 8, 6, 0, 0, 0)) + png += chunk(b"IDAT", zlib.compress(bytes(buf), 9)) + png += chunk(b"IEND", b"") + with open(out, "wb") as f: + f.write(png) + print("icone escrito:", out) + +if __name__ == "__main__": + main() diff --git a/packaging/tinyblocks.desktop b/packaging/tinyblocks.desktop new file mode 100644 index 0000000..ca3a543 --- /dev/null +++ b/packaging/tinyblocks.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Name=TinyBlocks +GenericName=Editor de blocos +Comment=Editor visual de programacao em blocos (estilo Scratch) +Exec=tinyblocks +Icon=tinyblocks +Terminal=false +Categories=Development;Education;Graphics; +Keywords=scratch;blocos;blocks;programacao; +StartupWMClass=TinyBlocks Editor diff --git a/packaging/tinyblocks.png b/packaging/tinyblocks.png new file mode 100644 index 0000000000000000000000000000000000000000..d87f19b793cc995f7987503796cdb51131873f05 GIT binary patch literal 3706 zcmc&$dpJ~W*I#>^VT>@OP!1Cc zp@%X^k%S(~sT`9O!#EGayVZAnf4={|`?{}d?X~Z9|JHA!Cw&|@#5mBf1VeBkdcL{k!?uV*!|Ofw(Zi)sRx6xac^U>j^ju{rj63a$#%Kd zT^tFcwbTS3RD~i-vEkT=l$zO^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