diff options
Diffstat (limited to 'build/common.mk')
-rw-r--r-- | build/common.mk | 60 |
1 files changed, 60 insertions, 0 deletions
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 |