The GNU make Utility and Makefiles

Learn how to use the make utility that uses Makefile to make compilation of your program easier and cleaner.

The make utility

There is a UNIX tool called make that’s commonly used to compile C programs that are made up of several files, and (sometimes) involve several compilation steps. There’s a lot of power in the make tool, but what we want to introduce here is a simple use of it, which lets us avoid having to remember a long, complicated compile command (e.g., in line 1 of the output from the prime number program we saw in the previous lesson).

The make utility uses a special plain-text file that we write and that has to reside in the same directory as our program and has to be called Makefile. We can think of a Makefile as a recipe for making our program (i.e. linking and compiling).

The Makefile file

A simple Makefile for our prime number program from the previous lesson might look like this:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy