bmake

Introduction

In the past when building large software projects, I've had to ensure that GNU make (if not my own patched version of it), was installed and had developed a set of macros to greatly simplify delveloping complex build trees.

My main development machine for the last several years, runs 4.4BSD (NetBSD to be precise), and the BSD source tree is an excellent example of managing a large software project. In following NetBSD's -current delevlopment, I learned to use the new BSD Makefiles and make(1), I'll refer to it as bmake from here on. Since then all my new projects and many of my old ones use bmake. Since bmake.tar.gz uses GNU's autoconf and is quite portable, I've skipped the effort of making the rest of my distribution support GNU make.

It may be insteresting to note that much of my tree uses the same simple Makefile, it is:

# a totally generic makefile suits 90% of projects

PROG=	${.CURDIR:T}

SRCS=	$(PROG).c

.include "prog.mk"

macros

The example Makefile above, perhaps suggests why I like bmake(1). The important magic is in the line:
.include "prog.mk";
Makefiles for libraries inlcude lib.mk btw. Anyway, apart from reading a bunch of rules from the system macros (/usr/share/mk/* by default) it reads "../Makefile.inc" thus provinding a hook for much magic. My Makefile.inc files typically look for Makefile.${MACHINE}.inc as well. Note that I used to use the bsd.*.mk macros (intended for building /usr/src), but attempts to get simple portability improvments committed into these, usually failed, so the only viable solution is to maintain a parallel set.

obj

Another cool feature of bmake(1) is that if the directory obj exists in the same directory as the Makefile, then bmake will chdir into it before doing anything else. This helps keep the build tree clean, and if the obj directories are symlinks off to a separate file system, eg.
/usr/src/bin/cat/obj -> /usr/obj/bin/cat
then suddenly building for multiple architectures is very easy. Since I typically export my tree via NFS and want to gather the binaries into my configs tree, I use the following:

/usr/local/obj -> src/obj.${MACHINE}
and then I set:

BSDSRCDIR=`cd /usr/local/src; /bin/pwd`
BSDOBJDIR=/usr/local/obj
Note: You must set BSDSRCDIR with the same value that /bin/pwd produces as otherwise obj.mk will do the wrong thing.

MACHINE and MACHINE_ARCH

The variables MACHINE and MACHINE_ARCH are built into bmake. The script bmake/machine.sh is used to set it it from the output of uname(1).

bootstraping bmake

This is about all I ever need to do on a new machine:
$ mkdir /tmp/bmake
$ cd /tmp/bmake
$ /usr/local/src/sjg/bmake/configure
$ make -f makefile.boot
# make -f makefile.boot install
Note that bmake/mk contains copies of bsd.*.mk too which should only be installed on non-4.4BSD systems. The install step above will only install them if bsd.own.mk does not exists in the target directory.

Building in the source directory

If you wish to build bmake in the src dir, you must still use an absolute pathname for configure to ensure that the srcdir macros in makefile.boot are correctly set.

$ `pwd`/configure
$ make -f makefile.boot
# make -f makefile.boot install

AIX

The differences in VPATH handling in various make utilities is one of the prime motives for compiling GNU make or bmake on a system. Because of the way AIX's make(1) handles VPATH, bootstraping bmake is a bit more painful than usual.

Bootstraping bmake in /usr/local/src/sjg/bmake should not present any difficulties though I've not tried it. In anycase the following does work (the need for the sed(1) command suggests a bug in make(1)).

$ mkdir /tmp/bmake
$ cd /tmp/bmake
$ /usr/local/src/sjg/bmake/configure
$ make -f makefile.boot depend MKDEP_OPTS=-N
$ sed 's,/usr/local/src.*/\([^/]*\.c\),\1,' .depend >> makefile.boot
$ cd lst.lib
$ sed 's,/usr/local/src.*/\([^/]*\.c\),\1,' .depend >> makefile.boot
$ make -f makefile.boot
# make -f makefile.boot install
Note: AIX.sys.mk is still probably full of errors, updates appreciated.


$Id: bmake.html,v 1.10 1999/04/29 00:29:16 sjg Exp $
Copyright © 1997 QUICK.COM.AU