BSD Make is the version of the make program found on BSD systems and their derivatives. It can be used to orchestrate the build of simple software projects as well as full operating systems. Use this tag for questions about the venerable art of writing and using makefiles for the BSD version of `make`.
BSD systems are shipped with their own version of the make
program sometimes renamed bsdmake
or bmake
. The versions found on FreeBSD, NetBSD and OpenBSD can have slight differences but they all share a common ancestor, PMake which name stands for parallel make.
Introduction
BSD Make is a program for creating other programs and can orchestrate the build of software projects, large and small. In some occasions, its design can fit other tasks, like the production of TeX documents. BSD Make is configured via a Makefile
, a plain text describing how a particular program can be compiled — to take the example of a small software project.
Writing a Makefile
for compiling a small program is similar to writing a shell-script for compiling that program, yet writing makefiles and shell scripts are very distinct activities. The logic of a shell script is broken down into a hierarchy procedures, while a Makefile
describe elements of a workflow, specifying goals and recipes to achieve these goals using given prerequisites. And since we are working with UNIX, goals and prerequisites are files (or nouns) and recipes are shell commands (or verbs).
Let's take a look at the following Makefile
:
program : a.o b.o c.o
cc a.o b.o c.o -o program
a.o b.o c.o : defs.h
a.o : a.c
cc -c a.c
b.o : b.c
cc -c b.c
c.o : c.c
cc -c c.c
The first paragraph specifies that the goal program
can be generated out of the prerequisites a.o
, b.o
and c.o
using the recipe cc a.o b.o c.o -o program
. Subsequent paragraphs have a similar meaning.
Main differences between makefiles and shell scripts
- BSD Make comes with meta programming facilities (macros) which are missing or cumbersome in the shell.
- Describing the workflow instead of procedures allows BSD Make to automatically parallelize the execution of independent recipes.
- Describing the workflow instead of procedure allows BSD Make to restart at the appropriate point after an interruption.
Canonical references
Beginners discovering make should start with PMake — A tutorial, the classical introduction to the art of writing makefiles, by Adam de Boor. A complete reference card is provided by the appropriate online manual page:
Also note that BSD Make is used by FreeBSD, NetBSD and OpenBSD to build the operating systems, which provides a rich gallery of advanced techniques for programming BSD Make.