FreeBSD Handbook : Installing applications : Porting applications : Before Starting the Port
Previous: Porting applications
Next: Quick Porting

4.3.1. Before Starting the Port

Note: Only a fraction of the overridable variables are mentioned in this document. Most (if not all) are documented at the start of the bsd.port.mk file which can be found in /usr/share/mk. This file uses a non-standard tab setting. Emacs should recognize the setting on loading the file. vi or ex can be set to using the correct value by typing `:set tabstop=4' once the file has been loaded.

You may come across code that needs modifications or conditional compilation based upon what version of UNIX it's running under. If you need to make such changes to the code for conditional compilation, make sure you make the changes as general as possible so that we can back-port code to FreeBSD 1.x systems and cross-port to other BSD systems such as 4.4BSD from CSRG, BSD/386, 386BSD and NetBSD.

The preferred way to tell 4.3BSD/Reno and newer versions of the BSD code apart is by using the `BSD' macro defined in <sys/param.h>. Hopefully that file is already included; if not, add the code:

#ifdef _HAVE_PARAM_H
#include <sys/param.h>
#endif

to the proper place in the .c file and add -D_HAVE_PARAM_H to the CFLAGS in the Makefile.

Then, you may use:

#if (defined(BSD) && (BSD >= 199103))

to detect if the code is being compiled on a 4.3 Net2 code base or newer (e.g. FreeBSD 1.x, 4.3/Reno, NetBSD 0.9, 386BSD, BSD/386 1.1 and below).

Use:

#if (defined(BSD) && (BSD >= 199306))

to detect if the code is being compiled on a 4.4 code base or newer (e.g. FreeBSD 2.x, 4.4, NetBSD 1.0, BSD/386 2.0 or above).

Use sparingly:

In the dozens of ports that have been done, there have only been one or two cases where __FreeBSD__ should have been used. Just because an earlier port screwed up and used it in the wrong place doesn't mean you should do so too.


FreeBSD Handbook : Installing applications : Porting applications : Before Starting the Port
Previous: Porting applications
Next: Quick Porting