From 04b3fcb479f5aaae06d18b315a8bdc8c298f4eae Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 5 Aug 2025 11:28:41 +0200 Subject: removed clustering --- build/Makefile | 45 ++++++++++++++++++++++++ build/common.mk | 60 ++++++++++++++++++++++++++++++++ build/cross-compile.mk | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ build/dependencies.mk | 52 ++++++++++++++++++++++++++++ build/native.mk | 42 ++++++++++++++++++++++ 5 files changed, 293 insertions(+) create mode 100644 build/Makefile create mode 100644 build/common.mk create mode 100644 build/cross-compile.mk create mode 100644 build/dependencies.mk create mode 100644 build/native.mk (limited to 'build') diff --git a/build/Makefile b/build/Makefile new file mode 100644 index 0000000..d77ff68 --- /dev/null +++ b/build/Makefile @@ -0,0 +1,45 @@ +# Main orchestrator Makefile for GlaMaC +# This file coordinates the modular build system + +# Include common configuration first +include common.mk + +# Include build modules +include native.mk +include cross-compile.mk +include dependencies.mk + +# Help system +help: + @echo "GlaMaC Build System" + @echo "" + @echo "Build targets:" + @echo " all - Build for current platform" + @echo " glamac - Build main application only" + @echo " glautils - Build utilities only" + @echo " clean - Clean build files" + @echo " rebuild - Clean and rebuild" +ifeq ($(PLATFORM),linux) + @echo "" + @echo "Cross-compilation (Linux → Windows):" + @echo " win - Build glamac for Windows" + @echo " win-all - Build everything for Windows" + @echo " setup-cross - Setup cross-compilation" +endif + @echo "" + @echo "Dependencies:" + @echo " deps - Install SDL3 dependencies" + @echo " clean-deps - Remove SDL3 dependencies" + @echo "" + @echo "Glass catalog conversion:" + @echo " convert-catalogs - Convert Excel files to JSON" + @echo "" + @echo "Quick start:" +ifeq ($(PLATFORM),linux) + @echo " make deps && make all # Native build" + @echo " make setup-cross && make win # Windows build" +else + @echo " Install SDL3, then: make all" +endif + +.PHONY: help \ No newline at end of file diff --git a/build/common.mk b/build/common.mk new file mode 100644 index 0000000..d1262c8 --- /dev/null +++ b/build/common.mk @@ -0,0 +1,60 @@ +# Common build variables and functions for GlaMaC +# This file contains shared configuration used by all build modules + +# Detect OS and set platform-specific variables +UNAME_S := $(shell uname -s 2>/dev/null || echo Windows_NT) +ifeq ($(UNAME_S),Linux) + PLATFORM := linux + EXE_EXT := + MKDIR := mkdir -p + RM := rm -f + RMDIR := rm -rf + CC := gcc + MINGW_CC := x86_64-w64-mingw32-gcc + SDL3_LIBS := $(shell pkg-config --libs sdl3 SDL3_ttf 2>/dev/null || echo -lSDL3 -lSDL3_ttf) -lm + CROSS_PREFIX := /usr/x86_64-w64-mingw32 +else + PLATFORM := windows + EXE_EXT := .exe + MKDIR := mkdir + RM := del /Q + RMDIR := rmdir /s /q + CC := gcc + SDL3_LIBS := -lSDL3 -lSDL3_ttf -mwindows +endif + +# Directories (relative to project root) +SRCDIR := ../src +BINDIR := ../bin +BINDIR_WIN := ../bin/win +INCDIR := ../include +DLL_CACHE := $(HOME)/.cache/glamac-dlls + +# Base flags +CFLAGS_BASE := -I$(INCDIR) -O2 -flto +# Security and warning flags +SECURITY_FLAGS := -fstack-protector-strong -D_FORTIFY_SOURCE=2 -fPIE +WARNING_FLAGS := -Wall -Wextra -Wformat=2 -Wformat-security -Wnull-dereference -Wstack-protector -Wvla + +# Compiler flags +CFLAGS := $(CFLAGS_BASE) $(SECURITY_FLAGS) $(WARNING_FLAGS) +CFLAGS_NATIVE := $(CFLAGS) -march=native +# Windows cross-compilation flags (without stack protector to avoid libssp dependency) +WARNING_FLAGS_WIN := -Wall -Wextra -Wformat=2 -Wformat-security -Wnull-dereference -Wvla +CFLAGS_CROSS := $(CFLAGS_BASE) $(WARNING_FLAGS_WIN) -I$(CROSS_PREFIX)/include + +# Source files +GLAMAC_SRCS := $(wildcard $(SRCDIR)/glamac/*.c) +GLAUTILS_SRCS := $(wildcard $(SRCDIR)/glautils/*.c) +GLAUTILS_BINS := $(patsubst $(SRCDIR)/glautils/%.c, $(BINDIR)/%$(EXE_EXT), $(GLAUTILS_SRCS)) +GLAUTILS_BINS_WIN := $(patsubst $(SRCDIR)/glautils/%.c, $(BINDIR_WIN)/%.exe, $(GLAUTILS_SRCS)) + +# Glass data dependencies for fgla +GLASS_DATA_SRCS := $(SRCDIR)/glamac/glass_data.c $(SRCDIR)/glamac/glamac_errors.c + +# Common directory creation rules +$(BINDIR): + $(MKDIR) $(BINDIR) + +$(BINDIR_WIN): + $(MKDIR) $(BINDIR_WIN) \ No newline at end of file diff --git a/build/cross-compile.mk b/build/cross-compile.mk new file mode 100644 index 0000000..5dc65f8 --- /dev/null +++ b/build/cross-compile.mk @@ -0,0 +1,94 @@ +# Cross-compilation rules for GlaMaC +# This file contains rules for Windows cross-compilation from Linux + +# Windows cross-compilation (Linux only) +ifeq ($(PLATFORM),linux) + +win: $(BINDIR_WIN)/glamac.exe win-dlls win-data + +win-all: win $(GLAUTILS_BINS_WIN) + +$(BINDIR_WIN)/glamac.exe: $(GLAMAC_SRCS) | $(BINDIR_WIN) + @echo "Cross-compiling glamac for Windows..." + @which $(MINGW_CC) >/dev/null 2>&1 || (echo "ERROR: Install mingw-w64-gcc first" && exit 1) + $(MINGW_CC) $^ $(CFLAGS_CROSS) -L$(CROSS_PREFIX)/lib -lmingw32 -lSDL3 -lSDL3_ttf -mwindows -static-libgcc -o $@ + +$(BINDIR_WIN)/%.exe: $(SRCDIR)/glautils/%.c | $(BINDIR_WIN) + $(MINGW_CC) $< $(CFLAGS_CROSS) -static-libgcc -o $@ + +# Windows DLL management +win-dlls: | $(BINDIR_WIN) + @echo "Getting Windows DLLs..." + @$(MKDIR) $(DLL_CACHE) + @if [ ! -f "$(DLL_CACHE)/SDL3.dll" ]; then \ + echo "Downloading SDL3.dll..."; \ + cd $(DLL_CACHE) && \ + wget -q https://github.com/libsdl-org/SDL/releases/download/release-3.2.10/SDL3-3.2.10-win32-x64.zip && \ + unzip -j SDL3-3.2.10-win32-x64.zip SDL3.dll && \ + $(RM) SDL3-3.2.10-win32-x64.zip; \ + fi + @if [ ! -f "$(DLL_CACHE)/SDL3_ttf.dll" ]; then \ + echo "Downloading SDL3_ttf.dll..."; \ + cd $(DLL_CACHE) && \ + wget -q https://github.com/libsdl-org/SDL_ttf/releases/download/release-3.2.2/SDL3_ttf-3.2.2-win32-x64.zip && \ + unzip -j SDL3_ttf-3.2.2-win32-x64.zip SDL3_ttf.dll && \ + $(RM) SDL3_ttf-3.2.2-win32-x64.zip; \ + fi + @cp $(DLL_CACHE)/*.dll $(BINDIR_WIN)/ + @echo "Windows build ready in $(BINDIR_WIN)/" + +# Copy data files for Windows build +win-data: | $(BINDIR_WIN) + @echo "Copying data files for Windows..." + @$(MKDIR) $(BINDIR_WIN)/data/json + @if [ -f "../data/json/glasses.json" ]; then \ + cp ../data/json/glasses.json $(BINDIR_WIN)/data/json/; \ + cp ../data/json/glasses.json $(BINDIR_WIN)/; \ + echo "Copied glasses.json to Windows build"; \ + else \ + echo "Warning: glasses.json not found, Windows build may use fallback data"; \ + fi + @echo "Copying font for Windows..." + @if [ -f "/usr/share/fonts/TTF/DejaVuSans.ttf" ]; then \ + cp /usr/share/fonts/TTF/DejaVuSans.ttf $(BINDIR_WIN)/; \ + echo "Copied DejaVuSans.ttf to Windows build"; \ + elif [ -f "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf" ]; then \ + cp /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf $(BINDIR_WIN)/; \ + echo "Copied DejaVuSans.ttf to Windows build"; \ + else \ + echo "Warning: DejaVu font not found, Windows build may fail to start"; \ + fi + +# Cross-compilation setup +setup-cross: + @echo "Setting up cross-compilation..." + @which wget >/dev/null 2>&1 || (echo "Install wget first: sudo pacman -S wget" && exit 1) + @which $(MINGW_CC) >/dev/null 2>&1 || (echo "Install mingw-w64-gcc first: sudo pacman -S mingw-w64-gcc" && exit 1) + sudo $(MKDIR) $(CROSS_PREFIX)/include $(CROSS_PREFIX)/lib + @echo "Downloading SDL3 development libraries..." + cd /tmp && \ + wget -q https://github.com/libsdl-org/SDL/releases/download/release-3.2.10/SDL3-devel-3.2.10-mingw.tar.gz && \ + wget -q https://github.com/libsdl-org/SDL_ttf/releases/download/release-3.2.2/SDL3_ttf-devel-3.2.2-mingw.tar.gz && \ + tar -xzf SDL3-devel-3.2.10-mingw.tar.gz && \ + tar -xzf SDL3_ttf-devel-3.2.2-mingw.tar.gz && \ + sudo cp -r SDL3-3.2.10/x86_64-w64-mingw32/include/* $(CROSS_PREFIX)/include/ && \ + sudo cp -r SDL3-3.2.10/x86_64-w64-mingw32/lib/* $(CROSS_PREFIX)/lib/ && \ + sudo cp -r SDL3_ttf-3.2.2/x86_64-w64-mingw32/include/* $(CROSS_PREFIX)/include/ && \ + sudo cp -r SDL3_ttf-3.2.2/x86_64-w64-mingw32/lib/* $(CROSS_PREFIX)/lib/ && \ + $(RM) -rf SDL3-3.2.10* SDL3_ttf-3.2.2* + @echo "Cross-compilation setup complete!" + +else +# Windows host - disable cross-compilation +win win-all win-dlls setup-cross: + @echo "Cross-compilation not available on Windows. Use 'make all' instead." +endif + +# Cross-compilation cleanup +clean-cache: + $(RMDIR) $(DLL_CACHE) 2>/dev/null || true + +clean-all: clean clean-cache clean-deps-files + +# Cross-compilation phony targets +.PHONY: win win-all win-dlls setup-cross win-data clean-cache clean-all \ No newline at end of file diff --git a/build/dependencies.mk b/build/dependencies.mk new file mode 100644 index 0000000..fa10af4 --- /dev/null +++ b/build/dependencies.mk @@ -0,0 +1,52 @@ +# Dependency management for GlaMaC +# This file contains rules for installing and managing dependencies + +# Automatic dependency generation for source files +GLAMAC_DEPS := $(GLAMAC_SRCS:.c=.d) +GLAUTILS_DEPS := $(GLAUTILS_SRCS:.c=.d) +ALL_DEPS := $(GLAMAC_DEPS) $(GLAUTILS_DEPS) + +# Include generated dependencies (suppress errors if files don't exist yet) +-include $(ALL_DEPS) + +# Rule to generate dependency files +%.d: %.c + @$(CC) -MM $(CFLAGS) $< | sed 's|\(.*\)\.o[ ]*:|\1.o \1.d:|' > $@ + +# Clean dependency files +clean-deps-files: + $(RM) $(ALL_DEPS) + +# Add dependency files to clean targets +.PHONY: clean-deps-files + +# Dependency management +deps: +ifeq ($(PLATFORM),linux) + @echo "Installing dependencies..." + sudo pacman -S --needed sdl3 git cmake pkgconf freetype2 python python-pandas python-openpyxl + @echo "Building SDL3_ttf from source..." + cd /tmp && $(RM) -rf SDL_ttf && \ + git clone https://github.com/libsdl-org/SDL_ttf.git && \ + cd SDL_ttf && git checkout release-3.2.2 && \ + cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr && \ + make -C build -j$$(nproc) && sudo make -C build install && \ + sudo ldconfig + @echo "Dependencies installed!" +else + @echo "Install SDL3 development libraries manually on Windows." + @echo "Install Python with pandas and openpyxl for Excel conversion." +endif + +clean-deps: +ifeq ($(PLATFORM),linux) + @echo "Removing SDL3 dependencies..." + sudo pacman -R sdl3 --noconfirm 2>/dev/null || true + sudo $(RM) -f /usr/lib/libSDL3_ttf.so* /usr/lib/libSDL3_ttf.a /usr/lib/pkgconfig/SDL3_ttf.pc + sudo $(RMDIR) /usr/include/SDL3_ttf/ 2>/dev/null || true + sudo ldconfig + @echo "Dependencies removed!" +endif + +# Dependency-related phony targets +.PHONY: deps clean-deps \ No newline at end of file diff --git a/build/native.mk b/build/native.mk new file mode 100644 index 0000000..e4495d5 --- /dev/null +++ b/build/native.mk @@ -0,0 +1,42 @@ +# Native build rules for GlaMaC +# This file contains rules for building on the native platform (Linux/Windows) + +# Default target +all: glamac glautils + +# Native build targets +glamac: $(BINDIR)/glamac$(EXE_EXT) + +glautils: $(GLAUTILS_BINS) + +$(BINDIR)/glamac$(EXE_EXT): $(GLAMAC_SRCS) | $(BINDIR) + @echo "Building glamac..." + $(CC) $^ $(CFLAGS_NATIVE) $(SDL3_LIBS) -o $@ + +# Special rule for fgla which needs glass_data dependencies +$(BINDIR)/fgla$(EXE_EXT): $(SRCDIR)/glautils/fgla.c $(GLASS_DATA_SRCS) | $(BINDIR) + $(CC) $^ $(CFLAGS_NATIVE) -o $@ + +# General rule for other glautils (excluding fgla) +$(BINDIR)/%$(EXE_EXT): $(SRCDIR)/glautils/%.c | $(BINDIR) + $(CC) $< $(CFLAGS_NATIVE) -o $@ + +# Excel to JSON conversion +EXCEL_FILES := $(wildcard ../data/Excel/*.xlsx) +JSON_FILES := $(patsubst ../data/Excel/%.xlsx, ../data/JSON/%.json, $(EXCEL_FILES)) + +convert-catalogs: $(JSON_FILES) + +../data/JSON/%.json: ../data/Excel/%.xlsx ../scripts/excel_to_json.py + @echo "Converting $< to JSON..." + @$(MKDIR) ../data/JSON + @cd .. && python3 scripts/excel_to_json.py $< -o $@ + +# Cleanup +clean: clean-deps-files + $(RMDIR) $(BINDIR) 2>/dev/null || true + +rebuild: clean all + +# Build-related phony targets +.PHONY: all glamac glautils convert-catalogs clean rebuild \ No newline at end of file -- cgit v1.2.3