aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clangd2
-rw-r--r--.gitignore29
-rw-r--r--Makefile55
-rw-r--r--flake.lock27
-rw-r--r--flake.nix88
5 files changed, 182 insertions, 19 deletions
diff --git a/.clangd b/.clangd
new file mode 100644
index 0000000..ca21cc7
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,2 @@
+CompileFlags:
+ Add: [-Iinclude, -I../include, -std=c99, -Wall, -Wextra]
diff --git a/.gitignore b/.gitignore
index c6127b3..0754ec2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,12 +2,15 @@
*.d
# Object files
+obj/
*.o
*.ko
*.obj
*.elf
# Linker output
+bin/
+result
*.ilk
*.map
*.exp
@@ -17,16 +20,16 @@
*.pch
# Libraries
-*.lib
-*.a
-*.la
-*.lo
+# *.lib
+# *.a
+# *.la
+# *.lo
# Shared objects (inc. Windows DLLs)
-*.dll
-*.so
-*.so.*
-*.dylib
+# *.dll
+# *.so
+# *.so.*
+# *.dylib
# Executables
*.exe
@@ -42,6 +45,16 @@
*.idb
*.pdb
+# Nix / Dev environment
+.direnv/
+.envrc
+
+# Editor-specific
+.vscode/
+.idea/
+*.swp
+*~
+
# Kernel Module Compile Results
*.mod*
*.cmd
diff --git a/Makefile b/Makefile
index 714e0f9..f1983d9 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..5380f9a
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1772773019,
+ "narHash": "sha256-E1bxHxNKfDoQUuvriG71+f+s/NT0qWkImXsYZNFFfCs=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "aca4d95fce4914b3892661bcb80b8087293536c6",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..81a7b13
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,88 @@
+{
+ description = "Raylib C/C++ Dev Environment";
+
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
+ };
+
+ outputs =
+ { self, nixpkgs }:
+ let
+ supportedSystems = [
+ "x86_64-linux"
+ "aarch64-linux"
+ "x86_64-darwin"
+ "aarch64-darwin"
+ ];
+
+ forEachSystem = nixpkgs.lib.genAttrs supportedSystems;
+ in
+ {
+ packages = forEachSystem (system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ in
+ {
+ default = pkgs.stdenv.mkDerivation {
+ pname = "raylib-shooter";
+ version = "0.1.0";
+ src = ./.;
+
+ nativeBuildInputs = with pkgs; [
+ pkg-config
+ gnumake
+ ];
+
+ buildInputs = with pkgs; [
+ raylib
+ ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
+ libGL
+ libX11
+ libXrandr
+ libXi
+ libXcursor
+ libXinerama
+ ];
+
+ buildPhase = ''
+ make
+ '';
+
+ installPhase = ''
+ mkdir -p $out/bin
+ cp bin/dungeon_game $out/bin/raylib-shooter
+ '';
+ };
+ });
+
+ apps = forEachSystem (system: {
+ default = {
+ type = "app";
+ program = "${self.packages.${system}.default}/bin/raylib-shooter";
+ };
+ });
+
+ devShells = forEachSystem (
+ system:
+ let
+ pkgs = nixpkgs.legacyPackages.${system};
+ in
+ {
+ default = pkgs.mkShell {
+ inputsFrom = [ self.packages.${system}.default ];
+ packages = with pkgs; [
+ gcc
+ clang-tools
+ gdb
+ tiled
+ zsh
+ ];
+ shellHook = ''
+ export SHELL=${pkgs.zsh}/bin/zsh
+ echo "Raylib dev shell loaded."
+ '';
+ };
+ }
+ );
+ };
+}