Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Makefiles – Building Lar | C Programming Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. C Programming Fundamentals

Lesson 28 of 50

·c

Makefiles – Building Large Projects

12 mins

Course progress56%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • `make` decides what needs rebuilding by comparing timestamps.
  • `$@` – target name; `$^` – all prerequisites; `$<` – first prerequisite.
  • `.PHONY:` declares non‑file targets to avoid name clashes.
  • Use `wildcard` and pattern rules to keep the file list dynamic.

A Makefile automates compilation, tracks dependencies, and avoids rebuilding unchanged files.

Key concepts:

  • Targets – file to be generated (myprog).
  • Prerequisites – files the target depends on (main.o utils.o).
  • Recipes – commands to run ($(CC) -o $@ $^).
  • Variables – CC, CFLAGS, LDFLAGS.
  • Phony targets – 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

Running make rebuilds only files whose source changed.

📈 Benefits

  • Incremental builds – fast iteration.
  • Centralised configuration (flags, includes).
  • Works across platforms (GNU Make, BSD make).
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from C Programming FundamentalsBrowse activities
Previous lessonHeader Files & Multiple Translation UnitsContinue to lesson 29Dynamic Data Structures – Linked ListBack to C Programming Fundamentals curriculum