Chapter 7. Notes on fixes for packages

7.1. CPP defines

To port an application to NetBSD, it's usually necessary for the compiler to be able to judge the system on which it's compiling, and we use definitions so that the C pre-processor can do this.

The really impatient should just note that a number of the FreeBSD ports (which are called packages in the NetBSD world) rely on the CPP definition __FreeBSD__. This should be used sparingly, for FreeBSD-specific features, but unfortunately this is not always the case. A number also rely on the fact that the CPU type is an Intel-based CPU with little-endian byte order.

To test whether you are working on a 4.4 BSD-derived system, you should use the BSD definition, which is defined in <sys/param.h> on said systems.

        #include <sys/param.h>
  
and then you can surround the BSD-specific parts of your port using the conditional:
	#if (defined(BSD) && BSD >= 199306)
	...
	#endif
  

Please use the __NetBSD__ definition sparingly - it should only apply to features of NetBSD that are not present in other 4.4-lite derived BSDs.

You should also avoid defining __FreeBSD__=1 and then simply using the FreeBSD port, if only from an aesthetic viewpoint.