summaryrefslogtreecommitdiff
path: root/build/common.mk
blob: d1262c87da46027e133507ab5851235a6d98fac2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)
Back to https://optics-design.com