-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
62 lines (50 loc) · 1.6 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
CXX=g++
CXXFLAGS= -fopenmp -I. -Wall -Wextra -g -ggdb -O2
# https://stackoverflow.com/questions/714100/os-detecting-makefile
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
CXXFLAGS += -no-pie
endif
ifeq ($(UNAME), Darwin)
CXXFLAGS += -std=c++11
endif
# https://stackoverflow.com/questions/2394609/makefile-header-dependencies
BUILD_DIR = ./build
CPP = $(wildcard canvas/*.cpp) \
$(wildcard geometry/*.cpp) \
$(wildcard lighting/*.cpp) \
$(wildcard lighting/patterns/*.cpp) \
$(wildcard scene/*.cpp) \
$(wildcard math/*.cpp)
OBJ = $(CPP:%.cpp=$(BUILD_DIR)/%.o)
DEP = $(OBJ:%.o=%.d)
T_CPP = $(wildcard tests/unit/*.cpp)
T_OBJ = $(T_CPP:%.cpp=$(BUILD_DIR)/%.o)
T_DEP = $(T_OBJ:%.o=%.d)
.PHONY : lib
test : $(BUILD_DIR)/bin/test
render : $(BUILD_DIR)/bin/render
# Actual target of the binary - depends on all .o files.
$(BUILD_DIR)/bin/test : build/tests/tests.o $(OBJ) $(T_OBJ) $(CXX_FLAGS)
# Create build directories - same structure as sources.
mkdir -p $(@D)
# Just link all the object files.
$(CXX) $(CXXFLAGS) $^ -o $@
$(BUILD_DIR)/bin/render : build/tests/render.o $(OBJ) $(CXX_FLAGS)
mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $^ -o $@
# Build target for every single object file.
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
$(BUILD_DIR)/%.o : %.cpp
mkdir -p $(@D)
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(CXX) $(CXXFLAGS) -MMD -c $< -o $@
# Include all .d files
-include $(DEP)
.PHONY : clean
clean :
# This should remove all generated files.
-rm -rf $(BUILD_DIR)/ $(OBJ) $(DEP)
-rm -rf $(BUILD_DIR)/bin