-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
151 lines (136 loc) · 5.13 KB
/
Copy pathmakefile
File metadata and controls
151 lines (136 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Makefile for C++ OOP Project (Optimized & Recursive)
# Directories
SRC_DIR := src
OBJ_DIR := build
BIN_DIR := bin
INCLUDE_DIR := include
DATA_DIR := data
CONFIG_DIR := config
RAYLIB_DIR := third_party/raylib
# Compiler settings
CXX := g++
PKG_CONFIG := pkg-config
RAYLIB_VERSION ?= 5.5
CXXFLAGS := -Wall -Wextra -std=c++17 -I $(INCLUDE_DIR) -I $(SRC_DIR)
LDFLAGS :=
ifeq ($(OS),Windows_NT)
CXX := C:/msys64/ucrt64/bin/g++.exe
PKG_CONFIG := C:/msys64/ucrt64/bin/pkg-config.exe
RAYLIB_CFLAGS := $(shell "$(PKG_CONFIG)" --cflags raylib 2>NUL)
RAYLIB_LIBS := $(shell "$(PKG_CONFIG)" --libs raylib 2>NUL)
CXXFLAGS += $(RAYLIB_CFLAGS)
LDFLAGS += $(RAYLIB_LIBS) -lopengl32 -lgdi32 -lwinmm
TARGET := bin/game.exe
RUN_CMD := .\bin\game.exe
else
RAYLIB_CFLAGS := $(shell $(PKG_CONFIG) --cflags raylib 2>/dev/null)
RAYLIB_LIBS := $(shell $(PKG_CONFIG) --libs raylib 2>/dev/null)
CXXFLAGS += $(RAYLIB_CFLAGS)
LDFLAGS += $(RAYLIB_LIBS) -lpthread -lm -ldl
TARGET := bin/game
RUN_CMD := ./bin/game
endif
# 1. Recursive Source Finding
rwildcard = $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
SRCS := $(call rwildcard,$(SRC_DIR)/,*.cpp)
# 2. Dynamic Object Mapping
OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRCS))
# Main targets
all: check-raylib directories $(TARGET)
check-raylib:
@$(PKG_CONFIG) --exists raylib || (echo "raylib belum terpasang. Jalankan 'make download' di WSL/Linux terlebih dahulu."; exit 1)
download:
ifeq ($(OS),Windows_NT)
@echo "Target download ini untuk WSL/Linux. Untuk MSYS2 Windows, jalankan: pacman -S --needed mingw-w64-ucrt-x86_64-raylib pkgconf"
else
@set -e; \
if command -v pacman >/dev/null 2>&1; then \
echo "Detected Arch Linux / pacman-based system"; \
sudo pacman -Syu; \
sudo pacman -S --needed base-devel cmake git alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama pkg-config; \
if pacman -Q raylib >/dev/null 2>&1; then \
echo "raylib sudah terinstall via pacman"; \
else \
echo "Installing raylib from AUR using yay/paru..."; \
if command -v yay >/dev/null 2>&1; then \
yay -S --needed raylib; \
elif command -v paru >/dev/null 2>&1; then \
paru -S --needed raylib; \
else \
echo "yay atau paru tidak ditemukan. Install manual: yay -S raylib atau paru -S raylib"; \
exit 1; \
fi; \
fi; \
elif command -v apt-get >/dev/null 2>&1; then \
echo "Detected Debian/Ubuntu-based system"; \
sudo apt-get update; \
sudo apt-get install -y build-essential pkg-config git cmake libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev; \
if apt-cache show libraylib-dev >/dev/null 2>&1; then \
sudo apt-get install -y libraylib-dev; \
else \
mkdir -p third_party; \
if [ ! -d "$(RAYLIB_DIR)/.git" ]; then \
rm -rf "$(RAYLIB_DIR)"; \
git clone --depth 1 --branch "$(RAYLIB_VERSION)" https://github.com/raysan5/raylib.git "$(RAYLIB_DIR)"; \
fi; \
cmake -S "$(RAYLIB_DIR)" -B "$(RAYLIB_DIR)/build" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release; \
cmake --build "$(RAYLIB_DIR)/build"; \
sudo cmake --install "$(RAYLIB_DIR)/build"; \
sudo ldconfig; \
fi; \
elif command -v dnf >/dev/null 2>&1; then \
echo "Detected Fedora/RHEL-based system"; \
sudo dnf groupinstall -y "Development Tools"; \
sudo dnf install -y cmake git alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel pkg-config; \
mkdir -p third_party; \
if [ ! -d "$(RAYLIB_DIR)/.git" ]; then \
rm -rf "$(RAYLIB_DIR)"; \
git clone --depth 1 --branch "$(RAYLIB_VERSION)" https://github.com/raysan5/raylib.git "$(RAYLIB_DIR)"; \
fi; \
cmake -S "$(RAYLIB_DIR)" -B "$(RAYLIB_DIR)/build" -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release; \
cmake --build "$(RAYLIB_DIR)/build"; \
sudo cmake --install "$(RAYLIB_DIR)/build"; \
sudo ldconfig; \
else \
echo "Distro Linux tidak terdeteksi. Install raylib secara manual atau lapor maintainer."; \
exit 1; \
fi; \
echo "raylib siap dipakai. Jalankan: make run"
endif
# Create necessary root directories
directories:
ifeq ($(OS),Windows_NT)
@if not exist "$(OBJ_DIR)" mkdir "$(OBJ_DIR)"
@if not exist "$(BIN_DIR)" mkdir "$(BIN_DIR)"
@if not exist "$(DATA_DIR)" mkdir "$(DATA_DIR)"
@if not exist "$(CONFIG_DIR)" mkdir "$(CONFIG_DIR)"
else
@mkdir -p $(OBJ_DIR) $(BIN_DIR) $(DATA_DIR) $(CONFIG_DIR)
endif
# Link object files to create executable
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
@echo "Build successful! Executable is at $(TARGET)"
# Compile source files into object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
ifeq ($(OS),Windows_NT)
@if not exist "$(dir $@)" mkdir "$(dir $@)"
else
@mkdir -p $(dir $@)
endif
$(CXX) $(CXXFLAGS) -c $< -o $@
# Run the game
run: all
$(RUN_CMD)
# Clean up generated files
clean:
ifeq ($(OS),Windows_NT)
@if exist "$(OBJ_DIR)" rmdir /s /q "$(OBJ_DIR)"
@if exist "$(BIN_DIR)" rmdir /s /q "$(BIN_DIR)"
else
rm -rf $(OBJ_DIR) $(BIN_DIR)
endif
@echo "Cleaned up $(OBJ_DIR) and $(BIN_DIR)"
# Rebuild everything from scratch
rebuild: clean all
.PHONY: all check-raylib download clean rebuild run directories