-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
87 lines (64 loc) · 2.12 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
# ==================================================================================================
# Variables
# C++ compiler name
CXX = g++
# Compiler flags
CFLAGS = -std=c++11 -O2 -g
# Debugger flags
#DFLAGS = -pg
# Warning flags
WFLAGS = -Wall -Wextra
# Source files
SRC_DIR = src
SRC = $(shell find $(SRC_DIR) -type f -name '*.cpp')
# Dependency files
DEP_DIR = deps
DEP_FILES = $(SRC:$(SRC_DIR)/%.cpp=$(DEP_DIR)/%.d)
# Object files
BUILD_DIR = build
OBJ = $(SRC:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
# Dummy warning files
WARNINGS = $(SRC:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.w)
# Executable name
EXEC = LCS_Approx_k_mis
# ==================================================================================================
# Configuration
.PHONY: all release debug
# ==================================================================================================
# Main targets
all: release
debug: DFLAGS += -ggdb
debug: $(EXEC)
release: CFLAGS += #-O3 -DNDEBUG
release: WFLAGS =
release: $(EXEC)
# ==================================================================================================
# Main rules
# Build executable from object files
$(EXEC): $(OBJ)
$(CXX) -o $@ $^ $(DFLAGS) $(LFLAGS)
# Build object file from source file
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(DEP_DIR)/%.d
@mkdir -p $(dir $@)
$(CXX) -o $@ -c $< $(CFLAGS) $(DFLAGS) $(WFLAGS)
# Create dependency files
$(DEP_DIR)/%.d: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CFLAGS) -MM -MT '$(<:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)' $< -MF $@
# ==================================================================================================
# Warnings target, output all g++ warnings without compiling
warnings: CFLAGS += -fsyntax-only
warnings: $(WARNINGS)
# Output warnings
$(BUILD_DIR)/%.w: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) -c $< $(CFLAGS) $(WFLAGS) 2> $@
# ==================================================================================================
# Clean intermediate files (not final results like executables, documentation, packages,...)
clean:
rm -rf $(BUILD_DIR)
rm -rf $(DEP_DIR)
rm -rf *~
# Clean everything
clean-all: clean
rm -rf $(EXEC)