1️⃣ Pattern Rule?
Used to process similar rules in batches.
%.o: %.c
command
- %.o: Any .o file
- %.c: the corresponding .c file
- Pattern => Deduplication
2️⃣ Automatic Variable?
Automatically provide specific information within the build command.
| automatic variable | Meaning |
| $@ | name of current target |
| $< | first dependency (input file) |
| $^ | all of dependencies (deduplication) |
Example
CC = gcc
CFLAGS = -Wall
OBJS = main.o utils.o
all: program
program: $(OBJS)
$(CC) $(CFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f *.o program
.PHONY: clean all
- %.o: %.c → Automatically compile as .o once you have a .c file
- $@ → current target (program or main.o)
- $< → .c file
- $^ → every .o file
Example: Pattern Rule (Create .o)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.s
$(CC) $(CFLAGS) -c -o $@ $<
| %.o: %.c | every .c build to .o |
| %.o: %.s | every .s build to .o |
| $@ | current target .o |
| $< | source file name (.c or .s) |
➡️ main.c → main.o, startup.s → startup.o Automatically Processing.
'Embedded > Embedded Software' 카테고리의 다른 글
| POSIX(Portable Operating System Interface for UNIX), pthread (0) | 2025.10.21 |
|---|---|
| 2025 정기 기사 3회 - 임베디드 기사 필기 합격 (0) | 2025.09.10 |
| Makefile default grammar - default structure, using variables, cleaning files, .PHONY (0) | 2025.04.23 |
| ESP-IDF를 이용한 펌웨어 빌드(with CMake), 플래싱, 모니터링 (0) | 2025.04.19 |
| ESP32 플래시 완전 정복! esptool 실전 활용법, read_flash, write_flash (Feat : "무선 업데이트의 모든 것: OTA 프로토타입 제작기") (0) | 2025.04.15 |