Skip to content

Commit 898188e

Browse files
committed
meow
1 parent 3c09ee0 commit 898188e

1 file changed

Lines changed: 76 additions & 50 deletions

File tree

Makefile

Lines changed: 76 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,109 @@
11
UNAME_S := $(shell uname -s)
22
CC = gcc
3-
CFLAGS = -Wall -O2 -Iinc
3+
CFLAGS = -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -O2 -Iinc
4+
45
TARGET = bloxorz
5-
SOURCES = main.c src/render.c src/map.c src/box.c src/utils.c
6+
SOURCES = $(wildcard *.c src/*.c)
67
OBJECTS = $(SOURCES:.c=.o)
78

9+
RAYLIB_VERSION = 5.0
810
RAYLIB_DIR = deps/raylib
911
RAYLIB_SRC = $(RAYLIB_DIR)/src
1012
RAYLIB_LIB = $(RAYLIB_SRC)/libraylib.a
13+
1114
CFLAGS += -I$(RAYLIB_SRC)
1215

1316
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
1732
endif
1833

1934
ifeq ($(UNAME_S),Darwin)
2035
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
2242
endif
2343

24-
all: raylib_check $(TARGET)
44+
all: libs $(TARGET)
2545

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)"
5250

5351
%.o: %.c
5452
@echo "Compiling $<..."
5553
@$(CC) $(CFLAGS) -c $< -o $@
5654

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
6178

6279
clean:
63-
@echo "Cleaning..."
80+
@echo "Cleaning project files..."
6481
@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."
6688

67-
run: $(TARGET)
89+
run: all
6890
@./$(TARGET)
6991

7092
rebuild: clean all
7193

7294
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"
75104
@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

Comments
 (0)