|
1 | 1 | UNAME_S := $(shell uname -s) |
2 | 2 | CC = gcc |
3 | | -CFLAGS = -Wall -O2 -Iinc |
| 3 | +CFLAGS = -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -O2 -Iinc |
| 4 | + |
4 | 5 | TARGET = bloxorz |
5 | | -SOURCES = main.c src/render.c src/map.c src/box.c src/utils.c |
| 6 | +SOURCES = $(wildcard *.c src/*.c) |
6 | 7 | OBJECTS = $(SOURCES:.c=.o) |
7 | 8 |
|
| 9 | +RAYLIB_VERSION = 5.0 |
8 | 10 | RAYLIB_DIR = deps/raylib |
9 | 11 | RAYLIB_SRC = $(RAYLIB_DIR)/src |
10 | 12 | RAYLIB_LIB = $(RAYLIB_SRC)/libraylib.a |
| 13 | + |
11 | 14 | CFLAGS += -I$(RAYLIB_SRC) |
12 | 15 |
|
13 | 16 | ifeq ($(UNAME_S),Linux) |
14 | | - LDFLAGS = -L$(RAYLIB_SRC) $(RAYLIB_LIB) -lGL -lm -lpthread -ldl -lrt -lX11 |
15 | | - PKG_MANAGER = apt-get |
16 | | - INSTALL_CMD = sudo apt-get update && sudo apt-get install -y libraylib-dev |
| 17 | + LDFLAGS = -L$(RAYLIB_SRC) -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 |
| 18 | + |
| 19 | + ifneq ($(shell which apt-get 2>/dev/null),) |
| 20 | + PKG_MGR = apt-get |
| 21 | + INSTALL_CMD = sudo apt-get update && sudo apt-get install -y build-essential git libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev |
| 22 | + else ifneq ($(shell which dnf 2>/dev/null),) |
| 23 | + PKG_MGR = dnf |
| 24 | + INSTALL_CMD = sudo dnf install -y git alsa-lib-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel mesa-libGL-devel mesa-libGLU-devel |
| 25 | + else ifneq ($(shell which pacman 2>/dev/null),) |
| 26 | + PKG_MGR = pacman |
| 27 | + INSTALL_CMD = sudo pacman -S --noconfirm git base-devel alsa-lib libx11 libxrandr libxi libxcursor libxinerama mesa glu |
| 28 | + else ifneq ($(shell which zypper 2>/dev/null),) |
| 29 | + PKG_MGR = zypper |
| 30 | + INSTALL_CMD = sudo zypper install -y git alsa-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel Mesa-libGL-devel glu |
| 31 | + endif |
17 | 32 | endif |
18 | 33 |
|
19 | 34 | ifeq ($(UNAME_S),Darwin) |
20 | 35 | CC = clang |
21 | | - LDFLAGS = $(RAYLIB_LIB) -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo |
| 36 | + LDFLAGS = -L$(RAYLIB_SRC) -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo |
| 37 | + |
| 38 | + ifneq ($(shell which brew 2>/dev/null),) |
| 39 | + PKG_MGR = brew |
| 40 | + INSTALL_CMD = brew install git |
| 41 | + endif |
22 | 42 | endif |
23 | 43 |
|
24 | | -all: raylib_check $(TARGET) |
| 44 | +all: libs $(TARGET) |
25 | 45 |
|
26 | | -raylib_check: |
27 | | -ifeq ($(UNAME_S),Darwin) |
28 | | - @if [ ! -f $(RAYLIB_LIB) ]; then \ |
29 | | - echo "Raylib not found. Downloading and building locally..."; \ |
30 | | - mkdir -p deps; \ |
31 | | - if [ ! -d $(RAYLIB_DIR) ]; then \ |
32 | | - git clone --branch 5.0 https://github.com/raysan5/raylib.git $(RAYLIB_DIR); \ |
33 | | - fi; \ |
34 | | - cd $(RAYLIB_SRC) && make PLATFORM=PLATFORM_DESKTOP; \ |
35 | | - fi |
36 | | -endif |
37 | | -ifeq ($(UNAME_S),Linux) |
38 | | - @ldconfig -p | grep libraylib >/dev/null 2>&1 || ( \ |
39 | | - echo "Raylib not found. Installing via apt..."; \ |
40 | | - $(INSTALL_CMD) || ( \ |
41 | | - echo "Building raylib from source..."; \ |
42 | | - mkdir -p deps; \ |
43 | | - if [ ! -d $(RAYLIB_DIR) ]; then \ |
44 | | - wget -q https://github.com/raysan5/raylib/archive/refs/tags/5.0.tar.gz -O deps/raylib-5.0.tar.gz; \ |
45 | | - tar -xzf deps/raylib-5.0.tar.gz -C deps; \ |
46 | | - mv deps/raylib-5.0 $(RAYLIB_DIR); \ |
47 | | - fi; \ |
48 | | - cd $(RAYLIB_SRC) && make PLATFORM=PLATFORM_DESKTOP; \ |
49 | | - ) \ |
50 | | - ) |
51 | | -endif |
| 46 | +$(TARGET): $(OBJECTS) |
| 47 | + @echo "Linking $(TARGET)..." |
| 48 | + @$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS) |
| 49 | + @echo "✓ Build complete! Run with: ./$(TARGET)" |
52 | 50 |
|
53 | 51 | %.o: %.c |
54 | 52 | @echo "Compiling $<..." |
55 | 53 | @$(CC) $(CFLAGS) -c $< -o $@ |
56 | 54 |
|
57 | | -$(TARGET): $(OBJECTS) |
58 | | - @echo "Linking $(TARGET)..." |
59 | | - @$(CC) $(OBJECTS) -o $(TARGET) $(LDFLAGS) |
60 | | - @echo "✓ Build complete! Run with: ./$(TARGET)" |
| 55 | +libs: $(RAYLIB_LIB) |
| 56 | + |
| 57 | +$(RAYLIB_LIB): |
| 58 | + @echo "Checking for Raylib..." |
| 59 | + @mkdir -p deps |
| 60 | + @if [ ! -d "$(RAYLIB_DIR)" ]; then \ |
| 61 | + echo "Raylib not found. Cloning from source..."; \ |
| 62 | + git clone --depth 1 --branch $(RAYLIB_VERSION) https://github.com/raysan5/raylib.git $(RAYLIB_DIR); \ |
| 63 | + fi |
| 64 | + @echo "Building Raylib local static library..." |
| 65 | + @cd $(RAYLIB_SRC) && $(MAKE) PLATFORM=PLATFORM_DESKTOP |
| 66 | + |
| 67 | +install_deps: |
| 68 | + @echo "Detected OS: $(UNAME_S)" |
| 69 | +ifdef PKG_MGR |
| 70 | + @echo "Detected Package Manager: $(PKG_MGR)" |
| 71 | + @echo "Installing system build dependencies..." |
| 72 | + @$(INSTALL_CMD) |
| 73 | + @echo "✓ Dependencies installed." |
| 74 | +else |
| 75 | + @echo "Warning: No known package manager found. Please install git and development headers manually." |
| 76 | + @echo "Required: libasound2, libx11, libxrandr, libxi, libgl1-mesa, libglu1-mesa, libxcursor, libxinerama" |
| 77 | +endif |
61 | 78 |
|
62 | 79 | clean: |
63 | | - @echo "Cleaning..." |
| 80 | + @echo "Cleaning project files..." |
64 | 81 | @rm -f $(OBJECTS) $(TARGET) |
65 | | - @echo "✓ Clean complete!" |
| 82 | + @echo "✓ Clean complete." |
| 83 | + |
| 84 | +clean_libs: clean |
| 85 | + @echo "Removing local libs..." |
| 86 | + @rm -rf deps |
| 87 | + @echo "✓ Libraries removed." |
66 | 88 |
|
67 | | -run: $(TARGET) |
| 89 | +run: all |
68 | 90 | @./$(TARGET) |
69 | 91 |
|
70 | 92 | rebuild: clean all |
71 | 93 |
|
72 | 94 | help: |
73 | | - @echo "Build System" |
74 | | - @echo "Detected OS: $(UNAME_S)" |
| 95 | + @echo "Bloxorz Build System" |
| 96 | + @echo "--------------------" |
| 97 | + @echo "Targets:" |
| 98 | + @echo " make - Build the game (automatically builds local Raylib)" |
| 99 | + @echo " make run - Build and run the game" |
| 100 | + @echo " make install_deps - Install system development libraries (requires sudo)" |
| 101 | + @echo " make clean - Remove game object files and executable" |
| 102 | + @echo " make clean_libs - Remove game files AND the local 'deps' folder" |
| 103 | + @echo " make help - Show this help message" |
75 | 104 | @echo "" |
76 | | - @echo "Available targets:" |
77 | | - @echo " make - Build the project (auto-download raylib if missing)" |
78 | | - @echo " make run - Build and run" |
79 | | - @echo " make clean - Remove build files" |
80 | | - @echo " make rebuild - Clean and rebuild" |
81 | | - @echo " make help - Show this message" |
82 | | - |
83 | | -.PHONY: all raylib_check clean run rebuild help |
| 105 | + @echo "Configuration:" |
| 106 | + @echo " OS: $(UNAME_S)" |
| 107 | + @echo " Compiler: $(CC)" |
| 108 | + |
| 109 | +.PHONY: all libs install_deps clean clean_libs run rebuild help |
0 commit comments