When a Linux application is made up of more than a few source files, compiling and linking the files by manually typing the gcc command can get tiresome. Also, you don’t want to compile every file whenever you change something in a single source file. These situations are where the GNU make utility comes to your rescue.

The make utility works by reading and interpreting a makefile — a text file that describes which files are required to build a particular program as well as how to compile and link the files to build the program. Whenever you change one or more files, make determines which files to recompile — and it issues the appropriate commands for compiling those files and rebuilding the program.

By default, GNU make looks for a makefile that has one of the following names, in the order shown:

  • GNUmakefile

  • makefile

  • Makefile

In Unix systems, using Makefile as the name of the makefile is customary because it appears near the beginning of directory listings, where uppercase names appear before lowercase names.

When you download software from the Internet, you usually find a Makefile, together with the source files. To build the software, you only have to type make at the shell prompt and make takes care of all the steps necessary to build the software.

If your makefile doesn’t have a standard name (such as Makefile), you have to use the -f option with make to specify the makefile name. If your makefile is called myprogram.mak, for example, you have to run make using the following command line:

make -f myprogram.mak