-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
120 lines (94 loc) · 2.96 KB
/
Makefile
File metadata and controls
120 lines (94 loc) · 2.96 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
# Makefile for DOOMED Game Project
# C++ Game with OpenGL/GLUT
# Compiler and flags
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2
# Platform detection
UNAME_S := $(shell uname -s)
# Platform-specific settings
ifeq ($(UNAME_S),Darwin) # macOS
INCLUDES = -I/opt/homebrew/include -I/usr/local/include
LIBS = -framework OpenGL -framework GLUT
LIBDIRS = -L/opt/homebrew/lib -L/usr/local/lib
endif
ifeq ($(UNAME_S),Linux)
INCLUDES = -I/usr/include
LIBS = -lGL -lglut -lGLU -lalut -lopenal -lpthread
LIBDIRS = -L/usr/lib -L/usr/local/lib
endif
# Directories
SRCDIR = classes
OBJDIR = obj
BINDIR = bin
# Target executable
TARGET = $(BINDIR)/doomed
# Source files
SOURCES = $(wildcard $(SRCDIR)/*.cpp)
OBJECTS = $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
OBJECTS := $(OBJECTS:$(SRCDIR)/%.mm=$(OBJDIR)/%.o)
# Header dependencies
HEADERS = $(wildcard $(SRCDIR)/*.hpp $(SRCDIR)/*.h)
# Create directories if they don't exist
$(shell mkdir -p $(OBJDIR) $(BINDIR))
# Default target
all: $(TARGET)
# Link the executable
$(TARGET): $(OBJECTS)
@echo "Linking $(TARGET)..."
$(CXX) $(OBJECTS) -o $@ $(LIBDIRS) $(LIBS)
@echo "Build successful! Executable: $(TARGET)"
# Compile C++ source files
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(HEADERS)
@echo "Compiling $<..."
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Main source file (if it exists in root directory)
main.o: main.cpp $(HEADERS)
$(CXX) $(CXXFLAGS) $(INCLUDES) -c main.cpp -o main.o
# If main.cpp is in root directory
ifneq (,$(wildcard main.cpp))
$(TARGET): main.o $(OBJECTS)
@echo "Linking $(TARGET) with main.cpp..."
$(CXX) main.o $(OBJECTS) -o $@ $(LIBDIRS) $(LIBS)
endif
# Clean build files
clean:
@echo "Cleaning build files..."
rm -rf $(OBJDIR) $(BINDIR) main.o
@echo "Clean complete."
# Clean and rebuild
rebuild: clean all
# Run the game
run: $(TARGET)
./$(TARGET)
# Install dependencies (macOS with Homebrew)
install-deps-mac:
@echo "Installing dependencies for macOS..."
brew install glfw3 freeglut
# Install dependencies (Ubuntu/Debian)
install-deps-linux:
@echo "Installing dependencies for Linux..."
sudo apt-get update
sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev libopenal-dev libalut-dev
# Debug build
debug: CXXFLAGS += -g -DDEBUG
debug: $(TARGET)
# Release build
release: CXXFLAGS += -O3 -DNDEBUG
release: $(TARGET)
# Show help
help:
@echo "Available targets:"
@echo " all - Build the game (default)"
@echo " clean - Remove build files"
@echo " rebuild - Clean and build"
@echo " run - Build and run the game"
@echo " debug - Build with debug symbols"
@echo " release - Build optimized release version"
@echo " install-deps-mac - Install dependencies on macOS"
@echo " install-deps-linux - Install dependencies on Linux"
@echo " help - Show this help message"
# Phony targets
.PHONY: all clean rebuild run debug release help install-deps-mac install-deps-linux
# Print variables for debugging
print-%:
@echo $* = $($*)