Lesson 28 of 50
cMakefiles – Building Large Projects
12 mins
Course progress56%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 28 of 50
c12 mins
Keep these ideas in mind as you work through the lesson.
A Makefile automates compilation, tracks dependencies, and avoids rebuilding unchanged files.
Key concepts:
myprog).main.o utils.o).$(CC) -o $@ $^).CC, CFLAGS, LDFLAGS.clean, all.Example (expanded):
CC = gcc
CFLAGS = -Wall -Wextra -O2 -Iinclude
LDFLAGS =
SRCS = $(wildcard src/*.c)
OBJS = $(SRCS:.c=.o)
.PHONY: all clean run
all: myprog
myprog: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
run: myprog
./myprog
clean:
rm -f $(OBJS) myprog
make rebuilds only files whose source changed.