-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
35 lines (28 loc) · 826 Bytes
/
Makefile
File metadata and controls
35 lines (28 loc) · 826 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
# Lesson 13: Out-of-Source Builds
#
# All build artifacts (.o, .d, executable) go into build/
# instead of polluting the source tree. This keeps the
# project directory clean and makes `clean` trivial (rm -rf build/).
#
# Key technique: BUILDDIR prefix on all output paths.
# The pattern rule creates subdirectories as needed with
# @mkdir -p $(@D)
# $(@D) = the directory part of the target path
CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra -Iinclude -MMD -MP
BUILDDIR = build
TARGET = $(BUILDDIR)/app
SRCS = src/main.cpp src/point.cpp
OBJS = $(SRCS:%.cpp=$(BUILDDIR)/%.o)
DEPS = $(OBJS:.o=.d)
.PHONY: all clean
all: $(TARGET)
$(TARGET): $(OBJS)
@mkdir -p $(@D)
$(CXX) -o $@ $^
$(BUILDDIR)/%.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
rm -rf $(BUILDDIR)
-include $(DEPS)