diff options
| author | Leander Scherer <leander@schererleander.de> | 2026-03-08 20:03:38 +0100 |
|---|---|---|
| committer | Leander Scherer <leander@schererleander.de> | 2026-03-08 20:03:38 +0100 |
| commit | 7bdc10ae6de645812f4e57185067f0a83ca5655f (patch) | |
| tree | 0e95f87b1e53d227448f29f0508108e764f5b716 /Makefile | |
| parent | e13162e555b1685477660971e25d0a9c7e29a7e8 (diff) | |
chore(build): update build system and development environment
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 55 |
1 files changed, 44 insertions, 11 deletions
@@ -1,22 +1,55 @@ -CC = gcc +# --- Compiler Settings --- +CC ?= gcc +PKG_CONFIG ?= pkg-config -SRC = src/main.c +# Check if raylib is available via pkg-config +HAS_RAYLIB_PC := $(shell $(PKG_CONFIG) --exists raylib && echo yes) -CFLAGS = -g -I/opt/homebrew/include -L/opt/homebrew/lib -lraylib +ifeq ($(HAS_RAYLIB_PC),yes) + RAYLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags raylib) + RAYLIB_LIBS := $(shell $(PKG_CONFIG) --libs raylib) +else + # Fallback for systems without raylib pkg-config (using local lib/ and standard flags) + RAYLIB_CFLAGS := + RAYLIB_LIBS := -Llib -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -Wl,-rpath=./lib +endif -OUT_DIR = build +# User CFLAGS/LDFLAGS can be passed from environment +CFLAGS += -Wall -Wextra -std=c99 -O2 -Iinclude $(RAYLIB_CFLAGS) +LDFLAGS += $(RAYLIB_LIBS) -lm -OUT = $(OUT_DIR)/main +# --- Project Directories --- +SRC_DIR = src +OBJ_DIR = obj +BIN_DIR = bin -all: $(OUT) +# --- Files --- +SRCS = $(wildcard $(SRC_DIR)/*.c) +OBJS = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRCS)) -$(OUT_DIR): - mkdir -p $(OUT_DIR) +# --- Output Binary --- +TARGET = $(BIN_DIR)/dungeon_game -$(OUT): $(OUT_DIR) $(SRC) - $(CC) $(CFLAGS) $(SRC) -o $(OUT) +# --- Build Rules --- +all: $(TARGET) + +$(TARGET): $(OBJS) | $(BIN_DIR) + @echo "Linking $@" + $(CC) $(OBJS) -o $@ $(LDFLAGS) + @echo "Build successful! Run with: ./$(TARGET)" + +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) + @echo "Compiling $<" + $(CC) $(CFLAGS) -c $< -o $@ + +$(BIN_DIR): + mkdir -p $(BIN_DIR) + +$(OBJ_DIR): + mkdir -p $(OBJ_DIR) clean: - rm -rf $(OUT_DIR) + @echo "Cleaning up..." + rm -rf $(OBJ_DIR) $(BIN_DIR) .PHONY: all clean |
