-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
28 lines (23 loc) · 691 Bytes
/
Makefile
File metadata and controls
28 lines (23 loc) · 691 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
# Lesson 04: Automatic Variables
#
# Make provides special variables inside recipes:
# $@ — the target filename
# $< — the first prerequisite
# $^ — all prerequisites (space-separated, deduplicated)
# $* — the stem matched by a pattern rule (lesson 05)
#
# These eliminate repetition: the recipe doesn't hardcode filenames.
CXX = g++
CXXFLAGS = -std=c++20 -Wall -Wextra
TARGET = main
OBJS = main.o calc.o
$(TARGET): $(OBJS)
$(CXX) -o $@ $^
# $@ is main.o, $< is main.cpp (first prerequisite)
main.o: main.cpp calc.hpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
calc.o: calc.cpp calc.hpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJS)