-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
31 lines (27 loc) · 752 Bytes
/
Makefile
File metadata and controls
31 lines (27 loc) · 752 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
# Lesson 05: Pattern Rules
#
# Instead of writing a separate rule for each .o file,
# a pattern rule handles all of them:
#
# %.o: %.cpp
# $(CXX) $(CXXFLAGS) -c -o $@ $<
#
# The % is a wildcard (the "stem"). When Make needs main.o,
# it matches main against %, looks for main.cpp, and runs
# the recipe with $@ = main.o and $< = main.cpp.
#
# Now adding a new .cpp file only requires adding it to SRCS.
CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra
TARGET = main
SRCS = main.cpp vec.cpp
OBJS = $(SRCS:.cpp=.o)
$(TARGET): $(OBJS)
$(CXX) -o $@ $^
# One rule to compile them all
# Note: header deps are not tracked here — see lesson 07
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS)