GNU Make

GNU Make

GNU Make is an incredibly popular development utility that orchestrates the compilation of software projects. Make is often used to manage the GCC suite of compilers but can be used for any development or software packaging task.

Use GNU Make with Incredibuild

What is GNU Make?

GNU Make is an incredibly popular development utility that orchestrates the compilation of software projects. Make is often used to manage the GCC suite of compilers but can be used for any development or software packaging task.

 

Since building large C/C++ programs usually involves multiple steps, a tool like Make is needed to ensure all source files are compiled and linked. Make also lets the developer control how ancillary files like documentation, man pages, systemd profiles, init scripts, and configuration templates are packaged and installed.

 

Make is not limited to languages like C/C++. Web developers can use GNU Make to do repetitive tasks like minify CSS and JS, and system administrators can automate maintenance tasks.

 

Additionally, end-users can use Make to compile and install software without being programmers or experts on the software they are installing.

 

* Learn more about what is GCC

Try it now
What is GNU Make?

What can it do, and how does it work?

GNU Make processes a Makefile, a text file that provides instructions for building the software project. It iterates through the instructions and determines the rules specified and the target output to generate.

 

A Makefile rule is a named group of commands that work together to create output file(s) called a target—usually a library or executable. If the target already exists and the source hasn’t been updated, make is smart enough to skip unnecessary build steps to reduce compile time.

CMake vs Make

Learn More

History of GNU Make

Make was initially developed by Stuart Feldman in April of 1976, but GNU released its free software version of the tool in the late 1980s. Version 3.56 is still available (via diffs) from the GNU FTP server, dating back to September 23, 1989.

 

The latest version is 4.3, released January 19, 2020.

How to Download / Install GNU Make

If you’re on Linux, the make program is probably already installed. If not, you can install it with the following commands:

 

  • Debian/Ubuntu – apt install make
  • Fedora/RHEL – yum install make
  • Arch/Manjaro – pacman -S make

 

While this will install the make program, you may find it helpful to install the development tools that come with your distribution to get the most out of make. To do this, run:

 

  • Debian/Ubuntu – apt install build-essential
  • Fedora/RHEL – yum groupinstall ‘Development Tools’
  • Arch/Manjaro – pacman -S base-devel

 

On Windows, you can either install and use MinGW (Minimalist GNU for Windows) or enable Windows Subsystem for Linux (WSL) and install the Linux distribution of your choice. Then run the appropriate commands above based on your selection.

GNU Make Examples

Makefiles are the primary way you instruct GNU Make to build your software project. Let’s examine a simple Makefile.

 

# Define our compiler as GCC

CC=gcc

# The main rule and targets

hello: hello.c hellolib.c

$(CC) -o hello hello.c hellolib.c

 

# A rule to clean binaries

clean:

rm -f hello

 

In this simple project, we first define a variable called CC. While not necessary, this lets us specify the compiler to use for the entire project. If we wanted to change it later, we would only have to alter one line. Make allows you to define as many variables as you wish and use them in your rules, reducing typing and refactoring effort.

 

The first rule in the file, named “hello”, becomes the default rule and is processed when you run the “make” command. The files involved are listed so make can optimize their build order and selection, and the following line, preceded by a TAB, lists the command(s) to run to create the target. Note the use of the previously defined variable CC.

 

Finally, we define a clean rule, invoked via the “make clean” command, which removes the binary generated to perform a clean build when necessary. The clean rule is not required but is handy to have, especially if you generate multiple binaries.

 

You could add to this example by including an install rule. Many instructions for common software packages tell you to run “make install”. Doing so simply triggers the install rule, which commonly includes commands that copy the compiled binaries to their necessary locations.

 

Many newcomers to GNU Make encounter syntax issues with their Makefiles. It is important to indent your build commands in a rule with a single tab. Spaces will not work and cause make to execute your Makefile incorrectly.

Features and Advantages

GNU Make is a valuable tool for compiling software projects, especially those in the GNU/Linux landscape. Its simple Makefile syntax and intelligent processing of target files make it an excellent choice for development.

 

Make has a variety of convenient command-line line arguments that let you make quick alterations to the execution of your Makefile, including the -j switch, which enables parallel operations for faster performance.

 

A key feature of GNU Make is that it is entirely free software licensed under GPL (General Public License) version 3.

GNU Make and Incredibuild

While Make allows you to specify how many simultaneous processes should run via the -j switch, you are still limited to one machine. Incredibuild integrates with GNU Make and turbocharges development from compilations to testing and release automation, consistently delivering better products to market radically faster. Incredibuild Virtualized Distributed Processing™ technology harvests idle CPU across your network and the cloud, emulates just what you need from your local environment on remote machines, and seamlessly turns every machine into a supercomputer with hundreds of cores.

icon

Bottom line

GNU Make is a cornerstone of the GNU/Linux ecosystem. It’s nearly impossible to find a program on most Linux systems that Make didn’t help build. Make is a well-constructed utility that automates even the most complex software builds—including the Linux kernel.

Get Free License

More Build systems

  • MSBuild

  • CMake

  • Make

  • Ninja

  • WAF

  • Qmake

  • QBS

  • Jom

  • Scons

  • Jam / Bjam / jamPlus