-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (54 loc) · 2.02 KB
/
Makefile
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
# Makefile created by Alan O'Cull using various resources off the internet
# Here is one of them:
# https://cs.colby.edu/maxwell/courses/tutorials/maketutor/
# Compilation command
CC=g++
# gcc/g++ Compilation Flags
# -g[1-3] for debugging symbols, -O[1-3] for optimization levels
# -Wall for warnings, -Werror for warnings as errors
CFLAGS= -g -O2 `sdl2-config --libs` -lSDL2main -lSDL2_mixer `sdl2-config --cflags` -L/usr/lib
# Build files should go in this directory
ODIR = build
# Save files should go in this directory
SDIR = save
# Final executable
TARGET = $(addprefix $(ODIR)/, src/Core/main)
# For modules, list any and all subfolders that need to be compiled
MODULES := Audio Map Triggers Entities Entities/AI Entities/Subclasses Entities/Boss Core Core/Input Core/UI
# Apply 'src/' to all modules/subfolders
SRC_DIR := src/ $(addprefix src/, $(MODULES))
INCLUDES := $(addprefix -I, $(SRC_DIR))
# Same as above, but utilizes build directory
BUILD_DIR := $(addprefix $(ODIR)/, $(SRC_DIR))
# Auto grab header file dependencies
DEPS := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.h))
# Grab corresponding object files that will be compiled
OBJS := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
# Each CPP file needs a corresponding object output
_OBJ := $(patsubst %.cpp, %.o, $(OBJS)) src/Core/main.o
# Objects should be outputted in build directory
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
.PHONY: all checkdirs clean run runc
all: checkdirs build # Set default functionality
runc: clean checkdirs build run
## DEFAULT BEHAVIOR
# Create necessary directories
$(BUILD_DIR):
@mkdir -p $@
# Then perform compilation
$(ODIR)/%.o: %.cpp $(SRC_DIR)
$(CC) -c -o $@ $< $(CFLAGS) $(INCLUDES)
# Finally build target / goal
build: $(OBJ)
$(CC) $^ $(CFLAGS) -o build/src/Core/main
checkdirs: $(BUILD_DIR) # Create necessary directories
@mkdir -p $(SDIR)
clean: # Delete build directory
rm -rf $(ODIR)
rm -rf $(SDIR)
run: # Run code
./$(TARGET)
debug: # Run code with gdb
gdb ./$(TARGET)
debug-mem: # Run code with valgrind
valgrind ./$(TARGET)