Safekipedia

Make (software)

Discoverer · ages 10+Adapted from Wikipedia

Make is a software tool that people use from a command line, which means they type instructions into a text window rather than clicking on pictures. It follows a set of actions that are ordered by dependencies, and these rules are written in a configuration file called a makefile. Make is most often used for build automation, which is the process of turning source code into executable code, such as a program or a library.

Make is not limited to building things. It can carry out any task that the operating system shell can perform.

Make is widely used, especially on Unix and Unix-like operating systems. Even so, many other technologies and tools exist. These include similar tools that also run actions based on dependencies, some compilers, and programs that work interactively through an integrated development environment.

The name Make first referred to the original Unix tool. Today it also describes a family of technologies, because several tools have been implemented with roughly the same features. These tools share similar makefile syntax and semantics.

Origin

Stuart Feldman created Make while working at Bell Labs. An early version was finished in April 1976, and in 2003 Feldman received the ACM Software System Award for writing it. Feldman described how the idea came after a visit from Steve Johnson, a coworker who was upset that he had wasted a morning debugging a correct program, because a file had not been rebuilt. Feldman had faced the same problem the evening before, so he decided to create a tool to fix it. His first plan was a complicated dependency analyzer, but it was simplified into Make over a single weekend. He shared this account in The Art of Unix Programming by Eric S. Raymond, published in 2003.

Makefiles were plain text files, in line with the Unix ethos, so people could read and fix them easily. Before Make, building programs on Unix mostly relied on shell scripts written for each program. Make's way of ordering tasks by their dependencies and checking which files were out of date made building more reliable and efficient. Make became widely used partly because it was included early in Unix, starting with PWB/UNIX 1.0.

Variants

Make has been implemented many times. Most versions use the same makefile format and offer the same features, though some add improvements. Sun DevPro Make appeared in 1986 with SunOS-3.2, and in December 2006 it was made open source as part of efforts to open-source Solaris. The dmake tool came with Sun Solaris Studio. It was first needed to build OpenOffice, but in 2009 its build system was rewritten to use GNU Make. Apache OpenOffice still uses a mix of build systems, while LibreOffice now uses only its newer system. BSD Make grew out of Adam de Boor's work on building targets in parallel. It is used, with different changes, in FreeBSD, NetBSD and OpenBSD. GNU Make is the standard version for Linux and macOS. It is needed to build many programs, including the GNU Compiler Collection (GCC), the Linux kernel, and Mozilla Firefox.

Other versions work in different ways. Microsoft's nmake, from Microsoft, is usually installed with Visual Studio. Embarcadero's make, from Embarcadero, can copy Microsoft's NMAKE. The Qt Project has a tool called Jom that copies nmake. Mk replaced Make in Research Unix and became the standard build tool in Plan 9. Kati is Google's replacement for GNU Make and was used in Android OS builds as of 2020. It turns makefiles into ninja files for faster builds. Snakemake is a Python-based tool for running bioinformatics workflows. POSIX sets standard basic features for Make, so simple makefiles often work across different versions.

Use

Based on a makefile, Make updates target files from source files when a source file has a newer timestamp than the target, or when the target file does not exist. For example, it can compile C files into object files and then link them into a program. It can also compile TypeScript files into JavaScript for use in a browser. Other tasks include converting an image to another format, copying a file to a content management system, and sending an e-mail about the build status.

A makefile defines targets. A target is either a file to create or a user-defined task called a phony target. If no target is named, Make updates the first target in the makefile, which is often a phony target for the most common action. Make skips a step when the target file is newer than its sources, which saves time. Sometimes this goes wrong, such as when an older copy of a source file is restored, when files come from a network filesystem whose clock is not synced, or when a source file has a future timestamp, causing needless repeated work. Make usually looks for a file named Makefile in the working directory.

Makefile

The makefile language is partly declarative programming, which means it describes the end results but not the order of the steps. A makefile can hold rules that name a target and the parts it depends on, followed by a recipe of commands. Each command line must start with a TAB character, even though a space is also whitespace. Some people, including Eric S. Raymond, see this as confusing. The tab rule came from a workaround for an early problem and was kept for backward compatibility. Makefiles can also define variables, called macros, and can include comments that start with the hash symbol (#). A long line can be split using line continuation.

Each command runs in a separate shell, and different systems use different shells, so a makefile may not work the same everywhere. Macros are usually written in all-caps, can be changed on the command-line arguments list, and can use environment variables. Their values are filled in lazily, only when they are used. Some BSD systems and GNU Make also support a command substitution operator. Rules can match files by their names, using a % symbol for any part of a name. A command can start with a minus sign to ignore errors or a plus sign to run even in "do not execute" mode.

Examples

Typing make on its own updates the first target, called "all." Typing make help lists the available targets, and typing make dist builds the files needed for sharing the program with others.

A simple makefile shows how this works. Its "all" rule is listed first, so it runs by default. It uses the computer's C compiler to turn a source file called "helloworld.c" into a program. It also has a "clean" target that removes the generated files if the user wants to start over.

Dependency tracking

A makefile is made up of dependencies, and a missing or extra one can be hard to notice. This can cause hidden bugs in the software that are difficult to find. One way to avoid this is to let the compiler keep track of changes. Another way is to use makefiles or other tools that create the dependency lists automatically, such as the Automake toolchain by the GNU Project.

Some people use meta-build tools like CMake and Meson instead.

Quiz time!

5 questions about Make (software)

Question 1 of 5

How do people use Make?

Keep exploring

This article is a child-friendly adaptation of the Wikipedia article on Make (software), available under CC BY-SA 4.0.