-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
47 lines (36 loc) · 1006 Bytes
/
Copy pathMakefile
File metadata and controls
47 lines (36 loc) · 1006 Bytes
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
# Paths
SRC_DIR := src
INCLUDE_DIR := include
BUILD_DIR := build
BIN_DIR := $(BUILD_DIR)/bin
BIN_NAME := exec
BIN_PATH := $(BIN_DIR)/$(BIN_NAME)
# Compiler flags
CXX ?= g++
CXXFLAGS += --std=c++20 -Wall -Wextra -Wpedantic -g
CXX_DEB_FLAGS = -DDEBUG
CXX_REL_FLAGS = -O2
INCLUDES = -I $(INCLUDE_DIR)
LIBRARIES =
# Find all source files (any *.cpp under $(SRC_DIR)).
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
SOURCES += $(wildcard $(SRC_DIR)/**/*.cpp)
# Generate object names from source files.
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
# Generate dependency file names for header dependencies.
DEPENDS = $(OBJECTS:.o=.d)
# Phony targets
.PHONY: _default build run clean
_default: build
build: $(BIN_PATH)
run: build
@$(BIN_PATH)
clean:
$(RM) -r $(BUILD_DIR)
$(BIN_PATH): $(OBJECTS)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBRARIES) -o $@ $^
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -o $@ -c $<
-include $(DEPENDS)