summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile33
1 files changed, 21 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index e3d8520..84b2873 100644
--- a/Makefile
+++ b/Makefile
@@ -1,24 +1,28 @@
# Detect OS
UNAME_S := $(shell uname -s)
-CFLAGS_COMMON = -MMD -MP -Wall -Wextra -I./shared
+CFLAGS_COMMON = -MMD -MP -Wall -Wextra -I./shared $(shell pkg-config --cflags raylib)
# Compiler
ifeq ($(UNAME_S),Darwin)
CC = gcc-15
CFLAGS = $(CFLAGS_COMMON) -pthread
- LDFLAGS = -pthread
+ LDFLAGS = -pthread $(shell pkg-config --libs raylib)
else ifeq ($(UNAME_S),Linux)
CC = gcc
CFLAGS = $(CFLAGS_COMMON) -pthread
- LDFLAGS = -pthread
+ LDFLAGS = -pthread $(shell pkg-config --libs raylib)
else
# Windows (MSYS2 MinGW)
CC = gcc
CFLAGS = $(CFLAGS_COMMON)
- LDFLAGS = -lws2_32
+ LDFLAGS = -lws2_32 $(shell pkg-config --libs raylib)
endif
+SHARED_BUILD = build/shared
+SHARED_SRC = $(shell find shared -name "*.c")
+SHARED_OBJ = $(SHARED_SRC:shared/%.c=$(SHARED_BUILD)/%.o)
+
# Directories
SERVER_BUILD = build/server
SERVER_TARGET = bin/server
@@ -31,8 +35,8 @@ CLIENT_SRC = $(shell find client -name "*.c")
CLIENT_OBJ = $(CLIENT_SRC:client/%.c=$(CLIENT_BUILD)/%.o)
# Raylib via pkg-config (works on macOS, Linux, MSYS2)
-CLIENT_CFLAGS = $(CFLAGS) $(shell pkg-config --cflags raylib)
-CLIENT_LDFLAGS = $(LDFLAGS) $(shell pkg-config --libs raylib)
+CLIENT_CFLAGS = $(CFLAGS)
+CLIENT_LDFLAGS = $(LDFLAGS)
# Windows needs extra libs sometimes
ifeq ($(OS),Windows_NT)
@@ -40,8 +44,9 @@ ifeq ($(OS),Windows_NT)
endif
# Dependency files
--include $(SERVER_OBJ:.o=.d)
--include $(CLIENT_OBJ:.o=.d)
+-include $(wildcard $(SHARED_BUILD)/*.d)
+-include $(wildcard $(SERVER_BUILD)/*.d)
+-include $(wildcard $(CLIENT_BUILD)/*.d)
.PHONY: all clean server client
@@ -54,12 +59,16 @@ client: $(CLIENT_TARGET)
bin:
mkdir -p bin
+$(SHARED_BUILD)/%.o: shared/%.c
+ mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) -c $< -o $@
+
# Link targets
-$(SERVER_TARGET): $(SERVER_OBJ) | bin
- $(CC) $(SERVER_OBJ) -o $(SERVER_TARGET) $(LDFLAGS)
+$(SERVER_TARGET): $(SERVER_OBJ) $(SHARED_OBJ) | bin
+ $(CC) $(SERVER_OBJ) $(SHARED_OBJ) -o $(SERVER_TARGET) $(LDFLAGS)
-$(CLIENT_TARGET): $(CLIENT_OBJ) | bin
- $(CC) $(CLIENT_OBJ) -o $(CLIENT_TARGET) $(CLIENT_LDFLAGS)
+$(CLIENT_TARGET): $(CLIENT_OBJ) $(SHARED_OBJ) | bin
+ $(CC) $(CLIENT_OBJ) $(SHARED_OBJ) -o $(CLIENT_TARGET) $(CLIENT_LDFLAGS)
# Compile rules
$(SERVER_BUILD)/%.o: server/%.c