-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
48 lines (40 loc) · 1.34 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
########## COMMON VARIABLES ##########
CXX = g++
CFLAGS = -Wall
MODULE_NAME = comet
BUILD_DIR = bin
SOURCE_FILES = \
$(wildcard comet/*.cpp) \
$(wildcard comet/lights/*.cpp) \
$(wildcard comet/materials/*.cpp) \
$(wildcard comet/primitives/*.cpp) \
$(wildcard comet/textures/*.cpp) \
$(wildcard comet/utils/*.cpp)
OBJECT_FILES = $(patsubst %,$(BUILD_DIR)/%, $(notdir $(SOURCE_FILES:.cpp=.o)))
########## BUILD ##########
$(BUILD_DIR)/$(MODULE_NAME): $(OBJECT_FILES)
$(CXX) -o $@ $^
# Using the vpath directive to fetch the right
# source file to build the right object file.
vpath %.cpp $(dir $(SOURCE_FILES))
# Since the timestamps on directories change whenever a file is
# added, removed, or renamed, we certainly don’t want to rebuild all
# the targets whenever the build directory’s timestamp changes.
# One way to manage this is with order-only prerequisites:
# make the directory an order-only prerequisite on all the targets
$(BUILD_DIR)/%.o: %.cpp | $(BUILD_DIR)
$(CXX) $(CFLAGS) -I. -c $< -o $@
# This is an order-only prerequisite for
# the creation of the build directory before
# the generation of the object files
$(BUILD_DIR):
@mkdir -p "$(BUILD_DIR)"
########## HELP ##########
.PHONY: help
help:
@echo "SOURCE_FILES: $(SOURCE_FILES)"
########## CLEAN ##########
.PHONY: clean
clean:
@echo "Removing the build folder..."
rm -rf bin