diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 40 |
1 files changed, 35 insertions, 5 deletions
@@ -1,7 +1,25 @@ -CC = gcc-15 -CFLAGS = -MMD -MP -Wall -Wextra -pthread -LDFLAGS = -pthread +# Detect OS +UNAME_S := $(shell uname -s) +CFLAGS_COMMON = -MMD -MP -Wall -Wextra -I./shared + +# Compiler +ifeq ($(UNAME_S),Darwin) + CC = gcc-15 + CFLAGS = $(CFLAGS_COMMON) -pthread + LDFLAGS = -pthread +else ifeq ($(UNAME_S),Linux) + CC = gcc + CFLAGS = $(CFLAGS_COMMON) -pthread + LDFLAGS = -pthread +else + # Windows (MSYS2 MinGW) + CC = gcc + CFLAGS = $(CFLAGS_COMMON) + LDFLAGS = -lws2_32 +endif + +# Directories SERVER_BUILD = build/server SERVER_TARGET = bin/server SERVER_SRC = $(shell find server -name "*.c") @@ -11,9 +29,17 @@ CLIENT_BUILD = build/client CLIENT_TARGET = bin/client 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) +# Windows needs extra libs sometimes +ifeq ($(OS),Windows_NT) + CLIENT_LDFLAGS += -lopengl32 -lgdi32 -lwinmm +endif + +# Dependency files -include $(SERVER_OBJ:.o=.d) -include $(CLIENT_OBJ:.o=.d) @@ -24,15 +50,18 @@ all: $(SERVER_TARGET) $(CLIENT_TARGET) server: $(SERVER_TARGET) client: $(CLIENT_TARGET) +# Create bin directory bin: mkdir -p bin +# Link targets $(SERVER_TARGET): $(SERVER_OBJ) | bin - $(CC) $(LDFLAGS) $(SERVER_OBJ) -o $(SERVER_TARGET) + $(CC) $(SERVER_OBJ) -o $(SERVER_TARGET) $(LDFLAGS) $(CLIENT_TARGET): $(CLIENT_OBJ) | bin - $(CC) $(CLIENT_LDFLAGS) $(CLIENT_OBJ) -o $(CLIENT_TARGET) + $(CC) $(CLIENT_OBJ) -o $(CLIENT_TARGET) $(CLIENT_LDFLAGS) +# Compile rules $(SERVER_BUILD)/%.o: server/%.c mkdir -p $(dir $@) $(CC) $(CFLAGS) -c $< -o $@ @@ -41,5 +70,6 @@ $(CLIENT_BUILD)/%.o: client/%.c mkdir -p $(dir $@) $(CC) $(CLIENT_CFLAGS) -c $< -o $@ +# Clean clean: rm -rf build bin |