-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
38 lines (32 loc) · 1014 Bytes
/
Makefile
File metadata and controls
38 lines (32 loc) · 1014 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
# Lesson 07: Automatic Header Dependencies
#
# Problem: in lesson 06, header dependencies were manual.
# If you change config.hpp but the Makefile doesn't list it
# as a prerequisite, Make won't recompile. Bugs ensue.
#
# Solution: the compiler can generate dependency files (.d)
# that list every header a .cpp includes.
#
# -MMD generates a .d file alongside the .o file
# -MP adds phony targets for each header (avoids errors
# when headers are deleted/renamed)
#
# The -include directive loads all .d files silently.
# On first build, no .d files exist — that's fine, the
# pattern rule compiles everything anyway.
CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra -Iinclude -MMD -MP
TARGET = main
SRCS = main.cpp store.cpp
OBJS = $(SRCS:.cpp=.o)
DEPS = $(OBJS:.o=.d)
VPATH = src
$(TARGET): $(OBJS)
$(CXX) -o $@ $^
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS) $(DEPS)
# Pull in auto-generated dependency rules
-include $(DEPS)