-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
executable file
·71 lines (59 loc) · 2.04 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
CCX=g++
IDIR=include
CPPFLAGS_RELEASE=-I$(IDIR) -O2 -ffast-math
CPPFLAGS_DEBUG=-I$(IDIR) -O0 -g
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LDFLAGS=-framework OpenGL -lm -lglfw -lglew
else
LDFLAGS=-lm -lglfw -lGLEW -lGL
endif
# Final binary
BIN = raw-physics
# Put all auto generated stuff to this build dir.
BUILD_DIR=./bin
BUILD_DIR_DEBUG = $(BUILD_DIR)/debug
BUILD_DIR_RELEASE = $(BUILD_DIR)/release
# List of all .cpp source files.
CPP = $(wildcard src/*.cpp) $(wildcard src/examples/*.cpp) $(wildcard src/render/*.cpp) \
$(wildcard src/physics/*.cpp) $(wildcard src/vendor/*.cpp)
# All .o files go to build dir.
RELEASE_OBJ = $(CPP:%.cpp=$(BUILD_DIR_RELEASE)/%.o)
DEBUG_OBJ = $(CPP:%.cpp=$(BUILD_DIR_DEBUG)/%.o)
# Gcc/Clang will create these .d files containing dependencies.
RELEASE_DEP = $(RELEASE_OBJ:%.o=%.d)
DEBUG_DEP = $(DEBUG_OBJ:%.o=%.d)
# Default target named after the binary.
release : $(BUILD_DIR_RELEASE)/$(BIN)
debug : $(BUILD_DIR_DEBUG)/$(BIN)
# Actual target of the binary - depends on all .o files.
$(BUILD_DIR_RELEASE)/$(BIN) : $(RELEASE_OBJ)
# Create build directories - same structure as sources.
mkdir -p $(@D)
# Just link all the object files.
$(CCX) $(CPPFLAGS_RELEASE) $^ $(LDFLAGS) -o $@
$(BUILD_DIR_DEBUG)/$(BIN) : $(DEBUG_OBJ)
# Create build directories - same structure as sources.
mkdir -p $(@D)
# Just link all the object files.
$(CCX) $(CPPFLAGS_DEBUG) $^ $(LDFLAGS) -o $@
# Include all .d files
-include $(RELEASE_DEP)
-include $(DEBUG_DEP)
# Build target for every single object file.
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
$(BUILD_DIR_RELEASE)/%.o : %.cpp
mkdir -p $(@D)
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(CCX) $(CPPFLAGS_RELEASE) -MMD -c $< -o $@
$(BUILD_DIR_DEBUG)/%.o : %.cpp
mkdir -p $(@D)
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(CCX) $(CPPFLAGS_DEBUG) -MMD -c $< -o $@
.PHONY : clean
clean :
# This should remove all generated files.
-rm -r $(BUILD_DIR)