-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
66 lines (58 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
CXX = g++
WARNINGS = -Wfatal-errors -Wall -Wextra -Wpedantic -Wconversion -Wshadow
CXX_FLAGS = -g -std=c++17
# Final binary
BIN = qtboy
# Put all auto generated stuff to this build dir.
BUILD_DIR = build
# Change variables and commands based on OS
ifdef OS
RM = del /Q
RM_DIR = RMDIR $(BUILD_DIR) /S /Q
FixPath = $(subst /,\,$1)
OS = windows
# Windows can't overwrite directories with mkdir
MKDIR = if not exist $(BUILD_DIR) mkdir
LIBS = -lmingw32
else
ifeq ($(shell uname), Linux)
RM = rm -f
RM_DIR = rm -r -f $(BUILD_DIR)
FixPath = $1
OS = linux
MKDIR = mkdir -p
LIBS =
endif
endif
# List of all .cpp source files.
CPP = $(wildcard src/*.cpp)
# All .o files go to build dir.
OBJ = $(CPP:src/%.cpp=$(BUILD_DIR)/%.o)
# Gcc/Clang will create these .d files containing dependencies.
DEP = $(OBJ:%.o=%.d)
# Shows where to find the header files
INCLUDE = -Iinclude
# Libraries to link
LIBRARY =
LINKER =
# Target of the binary - depends on all .o files.
$(BIN) : $(OBJ)
# Create build directories - same structure as sources.
$(MKDIR) $(BUILD_DIR)
# Just link all the object files.
$(CXX) $(CXX_FLAGS) $^ $(LIBRARY) $(LINKER) -o $@
# Include all .d files
-include $(DEP)
# Build target for every single object file.
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
$(BUILD_DIR)/%.o : src/%.cpp
$(MKDIR) $(BUILD_DIR)
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(CXX) $(CXX_FLAGS) $(INCLUDE) -MMD -c $< -o $@
.PHONY : clean
clean :
# This should remove all generated files.
$(RM) $(call FixPath,$(OBJ)) $(call FixPath,$(DEP))
$(RM_DIR)