The GNU `make` utility and Makefiles

The 'make' method serves as a recipe for your code. It makes compilation easier and cleaner. Here, we'll see how to use 'make' through Makefiles.

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

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

A simple Makefile for our prime number program above 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