-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
90 lines (72 loc) · 2.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
SRCDIR=src
# The C++ source files (but not the headers)
SRCS=$(wildcard $(SRCDIR)/*.cpp)
# The directory to store the compiled .o files.
OBJDIR=obj
# The .o files. One per cc file. Put them in the obj directory.
OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRCS))
# The flags you want to use when compiling individual objects (.o files)
# -g=generate information for debugging (used with debugging tools such as gdb
# or valgrind)
# -Wall=Give me all warnings!
# -Wextra=Give me extra warnings!
# -std=c++03=Enforce C++03 standard compliance. (You could also use C++11 if you
# want to be more up-to-date).
# -MMD=Create a .d file to store the rule for the header dependencies of each object.
CFLAGS=-std=c++17 -MMD `sdl2-config --cflags` -O3
# LDLIBS (Load Libraries)
# External libraries you are using that need to be linked.
# ``=run a shell command (command substitution)
# sdl-config=a command that generates the load libs/cflags necessary depending
# on the platform (OS/Linux/Win)
LDLIBS=`sdl2-config --libs` -lSDL2_ttf -lm
# LDFLAGS (Load/linker flags)
LDFLAGS=-no-pie
# The C++ compiler you are using.
CC=g++
# Debug flag
DEBUG ?= 1
# The directory to put the executable.
BINDIR=.
# What you run to play the game!
EXECUTABLE=cavestory
# If files named all/clean/run exist in the directory, then
# Make will not run these commands (because they will be "Up-to-Date")
# .PHONY is a special way of telling Make to run these no matter what.
.PHONY: all clean run
all: $(EXECUTABLE)
# Pastes in all of the Make rules inside of the generated .d files.
# Rules are of the format (file.o: file.cc header1.h header2.h)
# Each .d file gets generated whenever its .o file is compiled.
# Special thanks to /u/yurik for pointing this out to me!
-include $(OBJECTS:.o=.d)
# Logic for debug flag
ifeq ($(DEBUG), 1)
CFLAGS += -g
endif
# Links the objects into a "cavestory" executable.
# Also links the libs in $(LDLIBS) (SDL1.2 in our case)
# Puts the Executable in the bindir.
# re-link when an object or dependency has changed.
$(EXECUTABLE): $(OBJECTS)
@mkdir -p $(BINDIR)
$(CC) $(LDFLAGS) -o $(BINDIR)/$(EXECUTABLE) $(OBJECTS) $(LDLIBS)
# The rule for how to compile an .o (object) file from a .cc (C++ source) file
# "-c" creates a .o file
# "-o" says to create an object file (.o)
# "$@" in this case is the name of the object file (.o). MUST FOLLOW -o
# "$<" in this case is the .cc file
# Make the directory if it doesn't exist
$(OBJDIR)/%.o: %.cpp
@mkdir -p $(@D)
$(CC) -c $(CFLAGS) -o $@ $<
# Deletes all .o/.d files and the executable. This helps when you want to
# force recompilation.
clean:
rm -rf $(OBJDIR) $(BINDIR)/$(EXECUTABLE)
# Just a nice way of running the game. (Since you have to be in the bindir for
# the content to load properly)
run:
$(BINDIR)/$(EXECUTABLE)
ctags:
ctags -R $(SRCDIR)/