Back to concepts

Makefiles

Understand the file that tells `make` how to build a project and run other project tasks.

A makefile is a text file that tells make what work it can perform. It most often describes how to compile and link a program, but it can also define other project tasks.

A simple makefile organizes that information as rules; makefiles may also contain variable definitions, directives, and comments. In this example, make hello uses the rule to build hello from hello.c.

A makefile with one build rule
1hello: hello.c2 cc -o hello hello.c

A makefile is the generic kind of input file. Makefile is one conventional filename for it; makefile discovery determines which file GNU Make reads.

See it in context

Follow the lessons that apply this concept, then inspect the repository at the exact commit behind each explanation.

GNU Make manual: An Introduction to Makefiles