From 2b1d7ee7b29947938d0d08842ec4e5b15997b584 Mon Sep 17 00:00:00 2001 From: rillig Date: Thu, 3 Nov 2005 02:51:45 +0000 Subject: Rewrote the section about CPP defines, as NetBSD is not the only target platform of pkgsrc. It now lists some commonly known predefined macros for operating systems, CPUs and compilers. --- doc/guide/files/fixes.xml | 82 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 24 deletions(-) (limited to 'doc') diff --git a/doc/guide/files/fixes.xml b/doc/guide/files/fixes.xml index 3fc7716fef6..662d5ee9f7b 100644 --- a/doc/guide/files/fixes.xml +++ b/doc/guide/files/fixes.xml @@ -1,7 +1,7 @@ - + - Notes on fixes for packages + Making your package work General operation @@ -804,40 +804,74 @@ - - Building considerations + + Building the package 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. - - - 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. - + Sometimes you need to compile different code depending on + the target platform. The C preprocessor has a set of predefined + macros that can be queried by using #ifdef FOO + or #if defined(FOO). Among these macros are + usually ones that describe the target CPU and operating system. + Depending of which of the macros are defined, you can write code + that uses features unique to a specific platform. The best way to + handle these differences is to use the GNU autotools (automake, + autoconf, etc.) to check for specific features (like the existence + of a header file, a function or a library). + + If that is not possible you can use the predefined macros + below to configure your code to the platform it runs on. Almost + every operating system, hardware architecture and compiler has its + own macro. For example, if the macros __GNUC__, + __i386__ and __NetBSD__ are + all defined, you know that you are using NetBSD on an Intel CPU, + and your compiler is GCC. + + + CPP defines for operating systems + + To distinguish between 4.4 BSD-derived systems and the + rest of the world, you should use the following code. + + + #if (defined(BSD) && BSD >= 199306) + /* your BSD-specific code goes here */ + #else + /* non-BSD-specific code */ + #endif +]]> + + If this distinction is not fine enough, you can also use + the following defines. - ]]> + FreeBSD __FreeBSD__ + Linux linux, __linux, __linux__ + NetBSD __NetBSD__ + OpenBSD __OpenBSD__ + Solaris sun, __sun (GCC and SunPro), __sun__ (only GCC) - and then you can surround the BSD-specific parts of your - package's C/C++ code using this conditional: + + CPP defines for CPUs - = 199306) - ... - #endif]]> + i386 i386, __i386, __i386__ + MIPS __mips + SPARC sparc, __sparc - Please use the __NetBSD__ definition sparingly - it - should only apply to features of &os; that are not present in other - 4.4-lite-derived BSDs. + + CPP defines for compilers + + + GCC __GNUC__ (major version), __GNUC_MINOR__ + + + -- cgit v1.2.3