# Building the toolset from source

The djbwares toolset is known to build, run, and work on FreeBSD 10, PC-BSD 10, NetBSD 10, Debian Linux version 12, and OpenBSD version 5.9. It should similarly build, run, and work on any modern BSD and on any modern Linux flavour.

The source is structured as a slashpackage-style package.

It requires redo, `install`, `xmlto`, the host operating system's equivalent of Debian's `build-essential` tools (whatever thay may be), and a POSIX-conformant operating system (with the standard utilities present) to build.

It builds with the g++ and clang++ compilers. The build system attempts to autodetect the available compiler, as well as various operating-system-dependant features. The way that it autodetects features was in some of Daniel J. Bernstein's original softwares: a short test program that references the desired features, and a header that defines a preprocessor macro according to whether the build system can successfully compile and link the test program. (People who absolutely must can override the compiler autodetection with an environment variable.)

## Building the toolset itself

To just build the toolset from source, without packaging the binaries:

> `package/compile`

This gives you:

- binaries in `command/`, which you can just add to your `PATH` environment variable or symbolically link to;
- manual pages in `manual/`, which you can just add to your `MANPATH` environment variable or symbolically link to;
- C language headers in `header/`;
- link libraries in `library/`; and
- the Guide in `guide/`.

The build process updates files in these directories atomically. It doesn't create part-written executables or other files at their final names. So you can run things straight out of these directories whilst rebuilding.

## Cleaning the build area

To clean the build run

> `package/clean`

or just `rm -r build/`

To clean the build, packaging, and built files run

> `package/distclean`

or just `rm -r build/ command/ manual/ header/ library/ guide/`

## Packaging the binaries

To build installable binary packages on FreeBSD, TrueOS, NetBSD, or OpenBSD run

>     package/bsd/prepare && bsd/rules clean build binary

On FreeBSD and TrueOS this requires pkg version 1.2 or later in order to avoid segmentation faults and other bugs. So ensure that pkg is up to that version in your ports tree.

To build the binary packages on Debian Linux run

>     package/debian/prepare && dpkg-buildpackage -b -uc