-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
100 lines (70 loc) · 2.02 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
88
89
90
91
92
93
94
95
96
97
98
99
100
# -------------- Settings --------------------------
# Main directories
SOURCE_DIR := src
BUILD_DIR := build
OBJS_DIR := $(BUILD_DIR)/objs
DEPS_DIR := $(BUILD_DIR)/deps
# Binary target file
TARGET := cernyj87
# Compiler and linker settings
CXX := g++
LD := g++
CXXFLAGS := -g -Wall -Wextra -pedantic -std=c++17
LDFLAGS := -lstdc++fs -lssl -lcrypto
# Additional variables
SOURCES := $(wildcard $(SOURCE_DIR)/*.cpp)
HEADERS := $(wildcard $(SOURCE_DIR)/*.h)
OBJS := $(patsubst %,$(OBJS_DIR)/%.o,$(notdir $(basename $(SOURCES))))
DEPS := $(patsubst %,$(DEPS_DIR)/%.d,$(notdir $(basename $(SOURCES))))
# -------------- Entry points ----------------------
# Main entry
all: compile doc
# Help with targets
.PHONY: help
help:
@echo Available targets: all, compile, clean, doc, tests, linecount
# Main build
.PHONY: compile
compile: $(TARGET)
# Build and run tests
.PHONY: tests
tests: tests_compile
./$(TARGET)
.PHONY: tests_compile
tests_compile: CXXFLAGS += -DIS_TESTS
tests_compile: compile;
# Clean
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf $(TARGET)
rm -rf doc
# Run target
.PHONY: run
run:
./$(TARGET)
# -------------- Building and linking --------------
# Link all together to make final target
$(TARGET): $(OBJS)
$(LD) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
# Make .o and .d file for every .cpp file
$(OBJS_DIR)/%.o: $(SOURCE_DIR)/%.cpp $(OBJS_DIR) $(DEPS_DIR)
$(CXX) $(CXXFLAGS) -MMD -MF $(DEPS_DIR)/$(basename $(@F)).d -c $< -o $@
# Add rules for every .cpp file based on .d
-include $(DEPS)
# Create directories if not present
$(OBJS_DIR):
mkdir -p $@
$(DEPS_DIR):
mkdir -p $@
# -------------- Documentation ---------------------
# Create doxygen documentation and index.html redirection
.PHONY: doc
doc: doc/index.html
doc/index.html: Doxyfile assets/docs_files/* $(SOURCES) $(HEADERS)
@doxygen ./Doxyfile
@echo '<meta http-equiv="REFRESH" content="0;URL=html/index.html">' > doc/index.html
# -------------- Utils -----------------------------
.PHONY: linecount
linecount:
wc -l $(SOURCES) $(HEADERS) Makefile