Questions tagged [bsdmake]

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

  1. BSD Make comes with meta programming facilities (macros) which are missing or cumbersome in the shell.
  2. Describing the workflow instead of procedures allows BSD Make to automatically parallelize the execution of independent recipes.
  3. 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.

See also

22 questions
15
votes
5 answers

Merits of bmake

Apart from the fact that bmake is an BSD equivalent of GNU make, I could not clearly understand it's advantages over GNU make. Can anyone help me? I was able to find only one resource that was bit helpful. More help or pointers are appreciated.
prabhu
  • 919
  • 2
  • 12
  • 28
11
votes
1 answer

Catchall target with BSD's make

In a BSD Makefile, is it possible to define a catch-all target? I'm looking for the GNU equivalent of: %: @echo caught target $@ I was hoping that the preprocessor possesses enough magic to define a target on the fly, but couldn't figure out…
mavam
  • 12,242
  • 10
  • 53
  • 87
8
votes
2 answers

How to conditionally assign value to a variable in a Makefile (BSD + GNU)?

I have a (from my point of view) rather complicated Makefile. That is mostly because I wanted colors there and other unnecessary things. Anyway, might I jump right into my question: Apart from Linux I newly support *BSD, thus I need to check for the…
Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52
7
votes
1 answer

make & gmake compatible if else statement

Is there any type of if/else statement compatible with GNU make and Berkley make (freeBSD)? GNU MAKE: ifeq ($(BUILD_TYPE), debug) berkley make: .ifdef (BUILD_TYPE)
abrahab
  • 2,430
  • 9
  • 39
  • 64
5
votes
1 answer

Remove a flag from CFLAGS in FreeBSD makefile

In a GNU makefile, it is possible to use filter-out to remove a flag from CFLAG like this : CFLAGS:=$(filter-out -flag,$(CFLAGS)) However, I can't make it work with a FreeBSD makefile. Is filter-out supported by FreeBSD ? Otherwise, what can I do…
poloDD
  • 71
  • 6
4
votes
2 answers

GNU make equivalent to BSD make's $(var:Q)?

BSD make has a :Q variable expansion modifier, documented in the FreeBSD make man page as follows: :Q Quotes every shell meta-character in the variable, so that it can be passed safely through recursive invocations of make. If variable var…
Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
4
votes
2 answers

How to programmatically define targets in GNU Make?

I am not aware of any way to define programatically targets in GNU Make. How is this possible? Sometimes one can go away with alternate methods. The ability to define programatically targets in Makefiles is however a very important to write and…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
3
votes
1 answer

old Makefile for building library no longer works under FreeBSD

I haven't been doing a lot of C programming lately, but recently I revisited an old project and found the old Makefile to build a library under FreeBSD no longer works. Here's a much simplified version of the Makefile that used to work: TEST =…
varro
  • 2,382
  • 2
  • 16
  • 24
2
votes
1 answer

What does :C colon-C mean in FreeBSD make?

My company uses FreeBSD, and therefore FreeBSD's flavor of make. A few of our in-house ports include something like this (where BRANCH is something that came from an SVN URL, either 'trunk' or a branch name like 'branches/1.2.3'). PORTVERSION= …
josaphatv
  • 633
  • 4
  • 19
2
votes
1 answer

Automatically create .OBJDIR subdirectories

OS: FreeBSD 11.0-RELEASE I have the following directory structure: /xxx/obj/ /xxx/src/deep.cpp /xxx/flat.cpp /xxx/makefile The content of makefile is as follows: flat.out: flat.o deep.out: src/deep.o I have no problem building flat: /xxx $ make…
Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
2
votes
1 answer

How to define subroutines in a Makefile

I am working on a Makefile which has a¹ receipt producing some file using M4. It uses some complex shell constructions to compute macro values which have to be passed to M4. How can I organize code to avoid redundant declarations displayed in the…
Tim Enghel
  • 215
  • 2
  • 12
1
vote
1 answer

How to force an error in BSD make

Is there a way to force an error in a BSD makefile without using a target? I'm looking for something like .if ...some condition... error bad configuration .endif This question is like "How to force an error in a gnumake file", but is for BSD…
Mr Fooz
  • 109,094
  • 6
  • 73
  • 101
1
vote
2 answers

GNU Make: chdir make process itself

Is it possible to use a makefile that directs the make process itself to chdir? I want to write a makefile that expects to be executed from the build directory. Suppose I have a project directory structure that looks like this project/ ├──…
Greg Nisbet
  • 6,710
  • 3
  • 25
  • 65
1
vote
1 answer

How to prepare Debian packages of software built with `bmake`

I am porting some software to Debian/Jessie which uses bmake, the version of make usually found on BSDs, as build system. So the installation procedure is ./configure bmake all bmake install Aside from the use of bmake instead of make, it is…
Tim Enghel
  • 215
  • 2
  • 12
0
votes
1 answer

Linker not finding symbols which should be present

Recently I took it upon myself to see if I could get devd from the FreeBSD project to build and run on OpenBSD. In doing so, I found that the application itself was not fairly large, so it was not too much work to go through and find what I needed…
1
2