-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
51 lines (39 loc) · 1.68 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
# Directory vars
SRC_DIR = src
OBJ_DIR = obj
EXE_NAME = Gaming.out
# OBJS specifies which files to compile as part of the project
# The second var tells make to turn all the file extentions into .o
# It takes the pattern %.cpp with % being anything in the src folder
# and turns it into %.o in the obj folder
GAME_SRC = $(wildcard $(SRC_DIR)/*.cpp)
GAME_HEADERS = $(GAME_SRC:$(SRC_DIR)/%.cpp=$(SRC_DIR)/%.h)
GAME_OBJS = $(GAME_SRC:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
# Guarding incase there is no directory for the objs directory
dir_guard=@mkdir -p $(@D)
# The compiler we're using
CC = g++
# Specifies the additional compilation options we're using
CXX_FLAGS = -Wall -std=c++11
DEBUG_FLAGS = -g
# Specifies the libraries we're linking against
LINKER_FLAGS = -lsfml-graphics -lsfml-window -lsfml-system
# This is the target that compiles our executable
# The ^ variable is all the dependencies, and the @ variable is the target
$(EXE_NAME) : $(GAME_OBJS)
$(CC) $^ $(CXX_FLAGS) $(LINKER_FLAGS) -o $@
# Target for release, with no additional debug information
# TODO: Maybe package the game in a folder with all the assets needed?
release : $(GAME_OBJS)
$(CC) $^ $(CXX_FLAGS) $(LINKER_FLAGS) -o $(EXE_NAME)
$(OBJ_DIR)/main.o: $(SRC_DIR)/main.cpp
$(dir_guard)
$(CC) $^ $(CXX_FLAGS) $(DEBUG_FLAGS) -c -o $@
# Here we're gonna override the default make rule for turning cpp files into object files
# Because we need to make sure the obj files are compiled using the correct version
# $< is the first prerequisite, so it doesn't compile with the .h file
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h
$(dir_guard)
$(CC) $< $(CXX_FLAGS) $(DEBUG_FLAGS) -c -o $@
clean:
rm $(EXE_NAME) $(GAME_OBJS) $(COAL_OBJS)