Build para Windows: make exe (MinGW + pacotes do MSYS2)

make exe gera build/win-x86_64/TinyBlocks/TinyBlocks.exe com as DLLs e o
zip; make run-exe abre no Wine. As dependencias (SDL2, SDL2_ttf, libpng,
freetype, openssl, zlib, regex) vem dos pacotes MinGW do MSYS2, com as
dependencias resolvidas pelo indice do repositorio
(packaging/windows/msys2_deps.py). O POSIX que falta fica em
packaging/windows/compat (dlfcn, pwd, uname, mkdir, sysconf, setenv,
readlink de /proc/self/exe, strndup, getline, open_memstream).

No Windows uma DLL nao ve os simbolos do .exe, entao o editor, os modulos
dele (TB_ED_STATIC_MODULES) e as libraries de extensao (TB_STATIC_EXTRAS)
entram no executavel; TB_STATIC_BUILD deixa o TB_API vazio. Socket e
servidor MCP ganham uma camada sobre o Winsock; o kernel do GEMM so usa
target_clones no ELF. O pacote leva a fonte DejaVu (procurada ao lado do
executavel pelo SDL2 e pela opentype) e os certificados raiz
(certs/ca-bundle.crt, carregados pela ssl).

Testado no Wine 9: interface, HTTPS com verificacao, tensor, informacoes
do sistema e grafico em PNG.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-27 00:22:00 -03:00
1 parent 829bc67142
commit 7538d48a13
21 files changed
+820 -61

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
/* dlfcn.h para Windows (build MinGW): dlopen/dlsym/dlclose/dlerror sobre
LoadLibrary/GetProcAddress, em tb_win_compat.c. */
#ifndef TB_WIN_DLFCN_H
#define TB_WIN_DLFCN_H
#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_LOCAL 0
#define RTLD_GLOBAL 0x100
void* dlopen(const char* path, int flags);
void* dlsym(void* handle, const char* name);
int dlclose(void* handle);
char* dlerror(void);
#endif
+7
View File
@@ -0,0 +1,7 @@
/* pwd.h para Windows (build MinGW): so o nome e a pasta do usuario. */
#ifndef TB_WIN_PWD_H
#define TB_WIN_PWD_H
struct passwd { char* pw_name; char* pw_dir; };
int getuid(void);
struct passwd* getpwuid(int uid);
#endif
+6
View File
@@ -0,0 +1,6 @@
/* sys/utsname.h para Windows (build MinGW): sistema, versao e arquitetura. */
#ifndef TB_WIN_UTSNAME_H
#define TB_WIN_UTSNAME_H
struct utsname { char sysname[65], nodename[65], release[65], version[65], machine[65]; };
int uname(struct utsname* u);
#endif
+175
View File
@@ -0,0 +1,175 @@
/* tb_win_compat.c - implementacoes do tb_win_compat.h, dlfcn.h, pwd.h e
sys/utsname.h desta pasta (build Windows). */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <direct.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dlfcn.h"
#include "pwd.h"
#include "sys/utsname.h"
int tb_win_mkdir(const char* p, int mode) { (void)mode; return _mkdir(p); }
long tb_win_sysconf(int name) {
SYSTEM_INFO si;
GetSystemInfo(&si);
if (name == 84) return (long)si.dwNumberOfProcessors; /* _SC_NPROCESSORS_ONLN */
if (name == 30) return (long)si.dwPageSize; /* _SC_PAGESIZE */
if (name == 85) { /* _SC_PHYS_PAGES */
MEMORYSTATUSEX m;
m.dwLength = sizeof(m);
return GlobalMemoryStatusEx(&m) ? (long)(m.ullTotalPhys / si.dwPageSize) : -1;
}
return -1;
}
int tb_win_setenv(const char* k, const char* v, int over) {
if (!over && getenv(k)) return 0;
return _putenv_s(k, v) == 0 ? 0 : -1;
}
int tb_win_unsetenv(const char* k) { return _putenv_s(k, "") == 0 ? 0 : -1; }
ssize_t tb_win_readlink(const char* path, char* buf, size_t cap) {
if (strcmp(path, "/proc/self/exe") != 0 || cap == 0) return -1;
DWORD n = GetModuleFileNameA(NULL, buf, (DWORD)cap);
if (n == 0 || n >= cap) return -1;
for (DWORD i = 0; i < n; i++) if (buf[i] == '\\') buf[i] = '/';
return (ssize_t)n; /* como readlink: sem o '\0' */
}
char* tb_win_strndup(const char* s, size_t n) {
size_t len = 0;
while (len < n && s[len]) len++;
char* r = malloc(len + 1);
if (r) { memcpy(r, s, len); r[len] = 0; }
return r;
}
ssize_t tb_win_getline(char** line, size_t* cap, FILE* f) {
if (!line || !cap || !f) return -1;
size_t n = 0;
int c;
while ((c = fgetc(f)) != EOF) {
if (n + 2 > *cap) {
size_t nc = *cap ? *cap * 2 : 128;
char* p = realloc(*line, nc);
if (!p) return -1;
*line = p; *cap = nc;
}
(*line)[n++] = (char)c;
if (c == '\n') break;
}
if (n == 0) return -1;
(*line)[n] = 0;
return (ssize_t)n;
}
/* -- open_memstream: um arquivo temporario lembrado aqui; o fclose dele le
o conteudo para o buffer do chamador (como no POSIX) e apaga o arquivo */
#undef fclose
typedef struct { FILE* f; char** buf; size_t* len; char path[MAX_PATH]; } MemStream;
static MemStream s_ms[8];
FILE* tb_win_open_memstream(char** buf, size_t* len) {
for (int i = 0; i < 8; i++) {
if (s_ms[i].f) continue;
char dir[MAX_PATH], path[MAX_PATH];
if (!GetTempPathA(sizeof(dir), dir) || !GetTempFileNameA(dir, "tbm", 0, path)) return NULL;
FILE* f = fopen(path, "w+b");
if (!f) { DeleteFileA(path); return NULL; }
s_ms[i].f = f;
s_ms[i].buf = buf;
s_ms[i].len = len;
memcpy(s_ms[i].path, path, sizeof(path));
return f;
}
return NULL;
}
int tb_win_fclose(FILE* f) {
for (int i = 0; f && i < 8; i++) {
if (s_ms[i].f != f) continue;
fflush(f);
long n = ftell(f);
if (n < 0) n = 0;
char* b = malloc((size_t)n + 1);
if (b) { rewind(f); n = (long)fread(b, 1, (size_t)n, f); b[n] = 0; }
*s_ms[i].buf = b;
if (s_ms[i].len) *s_ms[i].len = b ? (size_t)n : 0;
int r = fclose(f);
DeleteFileA(s_ms[i].path);
s_ms[i].f = NULL;
return r;
}
return fclose(f);
}
/* -- dlfcn ------------------------------------------------------------- */
static char s_dl_err[256];
void* dlopen(const char* path, int flags) {
(void)flags;
HMODULE h = path ? LoadLibraryA(path) : GetModuleHandleA(NULL);
if (!h) snprintf(s_dl_err, sizeof(s_dl_err), "LoadLibrary('%s') falhou (erro %lu)", path, GetLastError());
return (void*)h;
}
void* dlsym(void* h, const char* name) {
FARPROC p = GetProcAddress((HMODULE)h, name);
if (!p) snprintf(s_dl_err, sizeof(s_dl_err), "simbolo '%s' nao encontrado", name);
void* r;
memcpy(&r, &p, sizeof(r));
return r;
}
int dlclose(void* h) { return FreeLibrary((HMODULE)h) ? 0 : -1; }
char* dlerror(void) {
static char out[256];
if (!s_dl_err[0]) return NULL;
snprintf(out, sizeof(out), "%s", s_dl_err);
s_dl_err[0] = 0;
return out;
}
/* -- pwd --------------------------------------------------------------- */
int getuid(void) { return 0; }
struct passwd* getpwuid(int uid) {
static char name[256], dir[512];
static struct passwd pw;
(void)uid;
DWORD n = sizeof(name);
if (!GetUserNameA(name, &n)) snprintf(name, sizeof(name), "%s", getenv("USERNAME") ? getenv("USERNAME") : "");
const char* h = getenv("USERPROFILE");
snprintf(dir, sizeof(dir), "%s", h ? h : "");
pw.pw_name = name;
pw.pw_dir = dir;
return &pw;
}
/* -- uname ------------------------------------------------------------- */
int uname(struct utsname* u) {
OSVERSIONINFOA v;
memset(&v, 0, sizeof(v));
v.dwOSVersionInfoSize = sizeof(v);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
GetVersionExA(&v);
#pragma GCC diagnostic pop
snprintf(u->sysname, sizeof(u->sysname), "Windows");
snprintf(u->release, sizeof(u->release), "%lu.%lu.%lu", v.dwMajorVersion, v.dwMinorVersion, v.dwBuildNumber);
snprintf(u->version, sizeof(u->version), "%s", v.szCSDVersion);
DWORD n = sizeof(u->nodename);
if (!GetComputerNameA(u->nodename, &n)) u->nodename[0] = 0;
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
snprintf(u->machine, sizeof(u->machine), "%s",
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ? "x86_64" :
si.wProcessorArchitecture == 12 /* ARM64 */ ? "aarch64" : "i686");
return 0;
}
+56
View File
@@ -0,0 +1,56 @@
/*
* tb_win_compat.h - o pouco de POSIX que o TinyBlocks usa e o MinGW nao tem.
* So entra na build Windows (incluido em todo fonte com -include, junto com
* os headers desta pasta: dlfcn.h, pwd.h, sys/utsname.h). O codigo do
* projeto continua escrito para POSIX. As implementacoes ficam em
* tb_win_compat.c, para nao espalhar o windows.h (e os nomes dele) por
* todos os fontes.
*
* mkdir(p, modo) -> _mkdir(p)
* sysconf(_SC_...) -> GetSystemInfo / GlobalMemoryStatusEx
* setenv / unsetenv -> _putenv_s
* readlink("/proc/self/exe") -> GetModuleFileName (com '/')
* strndup, getline
* open_memstream -> arquivo temporario; o fclose devolve o texto
*/
#ifndef TB_WIN_COMPAT_H
#define TB_WIN_COMPAT_H
#ifdef _WIN32
#include <stddef.h>
#include <sys/types.h>
int tb_win_mkdir(const char* p, int mode);
long tb_win_sysconf(int name);
int tb_win_setenv(const char* k, const char* v, int over);
int tb_win_unsetenv(const char* k);
ssize_t tb_win_readlink(const char* path, char* buf, size_t cap);
char* tb_win_strndup(const char* s, size_t n);
#include <stdio.h>
ssize_t tb_win_getline(char** line, size_t* cap, FILE* f);
FILE* tb_win_open_memstream(char** buf, size_t* len);
int tb_win_fclose(FILE* f);
/* Os headers do sistema antes das macros: a declaracao original fica intacta */
#include <direct.h>
#include <io.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#define mkdir(p, m) tb_win_mkdir((p), (m))
#define _SC_NPROCESSORS_ONLN 84
#define _SC_PHYS_PAGES 85
#define _SC_PAGESIZE 30
#define sysconf(n) tb_win_sysconf(n)
#define setenv(k, v, o) tb_win_setenv((k), (v), (o))
#define unsetenv(k) tb_win_unsetenv(k)
#define readlink(p, b, c) tb_win_readlink((p), (b), (c))
#define strndup(s, n) tb_win_strndup((s), (n))
#define getline(l, c, f) tb_win_getline((l), (c), (f))
#define open_memstream(b, n) tb_win_open_memstream((b), (n))
#define fclose(f) tb_win_fclose(f)
#endif /* _WIN32 */
#endif
+107
View File
@@ -0,0 +1,107 @@
#!/usr/bin/env python3
"""
Baixa pacotes MinGW do repositorio do MSYS2 (com as dependencias) e extrai
numa pasta: include/, lib/ e bin/ (as DLLs) para compilar o TinyBlocks para
Windows a partir do Linux.
msys2_deps.py <x86_64|i686> <pasta-destino> pacote [pacote ...]
Os pacotes sao nomes sem prefixo (SDL2, libpng...). O indice do repositorio
(<repo>.db) diz o arquivo e as dependencias de cada pacote. Os arquivos
baixados ficam em <destino>/../cache e nao sao baixados de novo.
"""
import io, os, re, subprocess, sys, tarfile, urllib.request
MIRROR = os.environ.get("MSYS2_MIRROR", "https://repo.msys2.org/mingw")
REPO = {"x86_64": ("mingw64", "mingw-w64-x86_64-"), "i686": ("mingw32", "mingw-w64-i686-")}
# Pacotes que nao precisam ir junto (o compilador ja traz o runtime)
SKIP = {"crt", "headers", "libgccjit"}
def fetch(url, path):
if os.path.exists(path):
return path
print("baixando", url, flush=True)
tmp = path + ".parte"
with urllib.request.urlopen(url, timeout=60) as r, open(tmp, "wb") as f:
while True:
b = r.read(1 << 16)
if not b:
break
f.write(b)
os.replace(tmp, path)
return path
def unzst(path):
return subprocess.run(["zstd", "-dc", path], check=True, capture_output=True).stdout
def read_db(arch, cache):
repo, prefix = REPO[arch]
db = fetch(f"{MIRROR}/{arch}/{repo}.db", os.path.join(cache, f"{repo}.db"))
raw = open(db, "rb").read()
if raw[:4] == b"\x28\xb5\x2f\xfd": # zstd
raw = unzst(db)
pk = {}
with tarfile.open(fileobj=io.BytesIO(raw)) as t:
for m in t:
if not m.name.endswith("/desc"):
continue
fields, key = {}, None
for line in t.extractfile(m).read().decode().splitlines():
if line.startswith("%") and line.endswith("%"):
key = line.strip("%"); fields[key] = []
elif line and key:
fields[key].append(line)
name = fields["NAME"][0]
info = {"file": fields["FILENAME"][0], "deps": fields.get("DEPENDS", [])}
pk[name] = info
for p in fields.get("PROVIDES", []):
pk.setdefault(re.split(r"[<>=]", p)[0], info)
return pk, prefix
def main():
if len(sys.argv) < 4 or sys.argv[1] not in REPO:
sys.exit(__doc__)
arch, dest, wanted = sys.argv[1], os.path.abspath(sys.argv[2]), sys.argv[3:]
cache = os.path.join(os.path.dirname(dest), "cache")
os.makedirs(cache, exist_ok=True)
pk, prefix = read_db(arch, cache)
todo, seen = [prefix + w for w in wanted], set()
while todo:
n = re.split(r"[<>=]", todo.pop())[0]
if n in seen or n[len(prefix):] in SKIP:
continue
seen.add(n)
if n not in pk:
sys.exit(f"pacote nao encontrado no MSYS2: {n}")
todo += pk[n]["deps"]
os.makedirs(dest, exist_ok=True)
root = REPO[arch][0] + "/"
for n in sorted(seen):
f = pk[n]["file"]
path = fetch(f"{MIRROR}/{arch}/{f}", os.path.join(cache, f))
data = unzst(path) if f.endswith(".zst") else open(path, "rb").read()
with tarfile.open(fileobj=io.BytesIO(data)) as t:
for m in t:
if not m.name.startswith(root) or not (m.isfile() or m.isdir()):
continue
rel = m.name[len(root):]
if not rel or rel.startswith(("share/doc", "share/man", "share/info", "share/locale")):
continue
out = os.path.join(dest, rel)
if not os.path.abspath(out).startswith(dest + os.sep):
continue # nada fora da pasta
if m.isdir():
os.makedirs(out, exist_ok=True)
else:
os.makedirs(os.path.dirname(out), exist_ok=True)
with open(out, "wb") as o:
o.write(t.extractfile(m).read())
print(f"{len(seen)} pacotes em {dest}")
if __name__ == "__main__":
main()
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env python3
"""png2ico.py <entrada.png> <saida.ico>: um .ico com o PNG dentro (Vista+)."""
import struct, sys
png = open(sys.argv[1], "rb").read()
w, h = struct.unpack(">II", png[16:24])
entry = struct.pack("<BBBBHHII", w % 256, h % 256, 0, 0, 1, 32, len(png), 6 + 16)
open(sys.argv[2], "wb").write(struct.pack("<HHH", 0, 1, 1) + entry + png)
+26
View File
@@ -0,0 +1,26 @@
/* Recursos do TinyBlocks.exe: icone e versao */
#include <winver.h>
1 ICON "tinyblocks.ico"
1 VERSIONINFO
FILEVERSION 0,1,0,0
PRODUCTVERSION 0,1,0,0
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "041604B0"
BEGIN
VALUE "FileDescription", "TinyBlocks - linguagem de blocos"
VALUE "ProductName", "TinyBlocks"
VALUE "ProductVersion", "0.1.0"
VALUE "OriginalFilename", "TinyBlocks.exe"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0416, 1200
END
END
+129
View File
@@ -0,0 +1,129 @@
# ── Build para Windows (.exe) com MinGW-w64, a partir do Linux ──────────
# Incluido pelo Makefile da raiz. Alvos:
# make exe -> build/win-x86_64/TinyBlocks/ (TinyBlocks.exe + DLLs) e o .zip
# make run-exe -> abre o .exe no Wine
# make exe WIN_ARCH=i686 (32 bits)
#
# As dependencias (SDL2, SDL2_ttf, libpng, freetype, openssl, zlib, regex)
# vem dos pacotes MinGW do MSYS2 (packaging/windows/msys2_deps.py), baixados
# uma vez para build/.win-deps. O POSIX que falta no Windows esta em
# packaging/windows/compat. Diferente do Linux, o editor, os modulos dele e
# as libraries entram todos no .exe (no Windows uma DLL nao enxerga os
# simbolos do .exe, entao nao ha hot reload das libraries).
WIN_ARCH ?= x86_64
WIN_CC := $(WIN_ARCH)-w64-mingw32-gcc-posix
WIN_RC := $(WIN_ARCH)-w64-mingw32-windres
WIN_OBJDUMP := $(WIN_ARCH)-w64-mingw32-objdump
WIN_BITS := $(if $(filter x86_64,$(WIN_ARCH)),64,32)
WIN_DEPS := $(BUILD)/.win-deps/$(WIN_ARCH)
WIN_OUT := $(BUILD)/win-$(WIN_ARCH)
WOBJ := $(WIN_OUT)/obj
WIN_PKG := $(WIN_OUT)/$(APP_NAME)
WIN_EXE := $(WIN_PKG)/$(APP_NAME).exe
WIN_ZIP := $(BUILD)/$(APP_NAME)-$(APP_VER)-win$(WIN_BITS).zip
WIN_COMPAT := packaging/windows/compat
# -mwindows: sem janela de console (WIN_SUBSYS=-mconsole para ver o printf)
WIN_SUBSYS ?= -mwindows
# A fonte da interface vai junto (o Windows nao tem a DejaVu)
WIN_FONTS := /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf /usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf
WIN_FONT_LICENSE := /usr/share/doc/fonts-dejavu-core/copyright
# Certificados raiz para o HTTPS (o OpenSSL no Windows nao le os do
# sistema): o bundle da Mozilla da maquina de build; senao, o do MSYS2
WIN_CA_HOST := /etc/ssl/certs/ca-certificates.crt
WIN_DEP_PKGS := SDL2 SDL2_ttf libpng freetype openssl zlib libsystre ca-certificates
# Libraries que entram no .exe: as de categoria e de app (como no Linux),
# as que o editor ja linka, e as de extensao (no Linux viriam como .so)
WIN_EXTRA_LIBS := base64 curves ppm bmp png image vg svg regex markdown opentype
WIN_LIB_DIRS := $(foreach l,$(CAT_LIBS) $(APP_LIBS) $(WIN_EXTRA_LIBS) \
editor a11y mcp-server graphics sdl2 toml json xml csv blueprint scratchblocks api libman syntax, \
$(LIBDIR)/tinyblocks-$(l)) \
$(ED_DIR)/libraries/tinyblocks-editor-widgets \
$(ED_DIR)/libraries/tinyblocks-editor-image \
$(ED_DIR)/libraries/tinyblocks-editor-files
WIN_SRCS := $(WIN_COMPAT)/tb_win_compat.c $(wildcard src/*.c) $(foreach d,$(WIN_LIB_DIRS),$(wildcard $(d)/src/*.c)) examples/editor/main.c
WIN_OBJS := $(patsubst %.c,$(WOBJ)/%.o,$(WIN_SRCS))
WIN_INCS := -Iinclude $(foreach d,$(wildcard $(LIBDIR)/*/include) $(wildcard $(ED_DIR)/libraries/*/include),-I$(d)) \
-I$(WIN_COMPAT) -I$(WIN_DEPS)/include -I$(WIN_DEPS)/include/SDL2 -I$(WIN_DEPS)/include/freetype2
WIN_CFLAGS := -std=c11 -O2 -DNDEBUG -D_POSIX_C_SOURCE=200809L -D_WIN32_WINNT=0x0601 \
-DTB_STATIC_BUILD -DTB_ED_STATIC_MODULES -DTB_STATIC_EXTRAS \
-include $(WIN_COMPAT)/tb_win_compat.h $(WIN_INCS) -w
WIN_LDLIBS := -L$(WIN_DEPS)/lib -lSDL2_ttf -lSDL2 -lpng16 -lfreetype -lssl -lcrypto -lz -lsystre \
-lws2_32 -lcrypt32 -lole32 -lshell32 -luser32 -lgdi32 -lwinmm -lm \
-static-libgcc -Wl,-Bstatic -lpthread -Wl,-Bdynamic
# Flags de cada parte (como nos Makefiles delas)
$(WOBJ)/$(ED_DIR)/%.o: WIN_DEFS := -DTB_EDITOR_PRIVATE_API -DTB_MCP_SERVER_PRIVATE_API
$(WOBJ)/$(ED_DIR)/libraries/tinyblocks-editor-image/%.o: WIN_DEFS := -DTB_EDITOR_PRIVATE_API -DTB_EDITOR_IMAGE_BUILD
$(WOBJ)/$(ED_DIR)/libraries/tinyblocks-editor-files/%.o: WIN_DEFS := -DTB_EDITOR_PRIVATE_API -DTB_EDITOR_FILES_BUILD
$(WOBJ)/$(LIBDIR)/tinyblocks-mcp-server/%.o: WIN_DEFS := -DTB_MCP_SERVER_PRIVATE_API
$(WOBJ)/$(LIBDIR)/tinyblocks-graphics/%.o: WIN_DEFS := -DTB_GRAPHICS_DEFAULT_SDL2
$(WOBJ)/examples/editor/%.o: WIN_DEFS := -DTB_EDITOR_PRIVATE_API
$(WIN_DEPS)/.ok:
@echo "Baixando as dependencias Windows ($(WIN_ARCH)) do MSYS2..."
python3 -I packaging/windows/msys2_deps.py $(WIN_ARCH) $(WIN_DEPS) $(WIN_DEP_PKGS)
@touch $@
$(WOBJ)/%.o: %.c $(WIN_DEPS)/.ok $(WIN_COMPAT)/tb_win_compat.h
@mkdir -p $(dir $@)
@echo " CC(win) $<"
@$(WIN_CC) -I$(dir $<) -I$(dir $<)../include $(WIN_CFLAGS) $(WIN_DEFS) -MMD -MP -c $< -o $@
-include $(WIN_OBJS:.o=.d)
# Icone: o PNG do AppImage dentro de um .ico (o Windows aceita PNG no ICO)
$(WOBJ)/tinyblocks.ico: $(PKG_DIR)/tinyblocks.png
@mkdir -p $(dir $@)
python3 -I packaging/windows/png2ico.py $< $@
$(WOBJ)/icon.o: packaging/windows/tinyblocks.rc $(WOBJ)/tinyblocks.ico
$(WIN_RC) -I $(WOBJ) $< -O coff -o $@
$(WIN_EXE): $(WIN_OBJS) $(WOBJ)/icon.o
@mkdir -p $(dir $@)
$(WIN_CC) $(WIN_SUBSYS) $^ -o $@ $(WIN_LDLIBS)
# Copia para o pacote as DLLs que o .exe importa (e as que elas importam),
# como o "ldd" do AppImage; as do sistema (KERNEL32, USER32...) ficam.
win-pkg: $(WIN_EXE)
@echo "Copiando as DLLs necessarias..."
@todo="$(WIN_EXE)"; seen=""; \
while [ -n "$$todo" ]; do \
todo=$$(echo $$todo); f=$${todo%% *}; [ "$$todo" = "$$f" ] && todo="" || todo=$${todo#* }; \
[ -n "$$f" ] || continue; \
for d in $$(LC_ALL=C $(WIN_OBJDUMP) -p "$$f" | awk '/DLL Name:/{print $$3}'); do \
src="$(WIN_DEPS)/bin/$$d"; \
[ -f "$$src" ] || continue; \
case " $$seen " in *" $$d "*) continue;; esac; \
seen="$$seen $$d"; cp "$$src" $(WIN_PKG)/; todo="$$todo $$src"; \
done; \
done; echo " DLLs:$$seen"
@mkdir -p $(WIN_PKG)/certs $(WIN_PKG)/fonts
@if [ -s $(WIN_CA_HOST) ]; then cp $(WIN_CA_HOST) $(WIN_PKG)/certs/ca-bundle.crt; \
else cp $(WIN_DEPS)/share/pki/ca-trust-source/ca-bundle.trust.crt $(WIN_PKG)/certs/ca-bundle.crt; fi
@cp $(WIN_FONTS) $(WIN_PKG)/fonts/ || { echo "Falta a fonte DejaVu (pacote fonts-dejavu-core)"; exit 1; }
@cp $(WIN_FONT_LICENSE) $(WIN_PKG)/fonts/LICENSE.txt 2>/dev/null || true
@cp -r examples/gan-animais $(WIN_PKG)/exemplos-gan-animais 2>/dev/null || true
@printf '%s\r\n' "TinyBlocks $(APP_VER) para Windows ($(WIN_ARCH))" "" \
"Abra TinyBlocks.exe. As DLLs desta pasta precisam ficar junto dele." \
"Fonte: DejaVu Sans (licenca livre, ver fonts/LICENSE.txt)." > $(WIN_PKG)/LEIA-ME.txt
exe: win-pkg ## Gera o TinyBlocks.exe para Windows (build/win-x86_64/TinyBlocks e o .zip)
@rm -f $(WIN_ZIP)
@cd $(WIN_OUT) && python3 -I -m zipfile -c $(abspath $(WIN_ZIP)) $(APP_NAME)
@echo "Windows: $(WIN_EXE)"
@echo "Zip: $(WIN_ZIP)"
run-exe: win-pkg ## Gera e abre o .exe no Wine
cd $(WIN_PKG) && wine $(APP_NAME).exe
clean-exe: ## Apaga a build Windows (mantem as dependencias baixadas)
$(RM) -r $(WIN_OUT)
.PHONY: exe run-exe win-pkg clean-exe