From owner-svn-doc-head@FreeBSD.ORG Sat Sep 21 15:13:47 2013 Return-Path: Delivered-To: svn-doc-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 1B6C5295; Sat, 21 Sep 2013 15:13:47 +0000 (UTC) (envelope-from eadler@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id EDBC823A4; Sat, 21 Sep 2013 15:13:46 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r8LFDk7B080133; Sat, 21 Sep 2013 15:13:46 GMT (envelope-from eadler@svn.freebsd.org) Received: (from eadler@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r8LFDkPi080130; Sat, 21 Sep 2013 15:13:46 GMT (envelope-from eadler@svn.freebsd.org) Message-Id: <201309211513.r8LFDkPi080130@svn.freebsd.org> From: Eitan Adler Date: Sat, 21 Sep 2013 15:13:46 +0000 (UTC) To: doc-committers@freebsd.org, svn-doc-all@freebsd.org, svn-doc-head@freebsd.org Subject: svn commit: r42683 - head/en_US.ISO8859-1/books/porters-handbook X-SVN-Group: doc-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-doc-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the doc tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Sep 2013 15:13:47 -0000 Author: eadler Date: Sat Sep 21 15:13:46 2013 New Revision: 42683 URL: http://svnweb.freebsd.org/changeset/doc/42683 Log: Clear up the 'Differentiating Operating Systems and OS Versions' section as it is highly unlikely that anyone will be backporting modern applications to CSRG's BSD. Modified: head/en_US.ISO8859-1/books/porters-handbook/book.xml Modified: head/en_US.ISO8859-1/books/porters-handbook/book.xml ============================================================================== --- head/en_US.ISO8859-1/books/porters-handbook/book.xml Sat Sep 21 14:48:09 2013 (r42682) +++ head/en_US.ISO8859-1/books/porters-handbook/book.xml Sat Sep 21 15:13:46 2013 (r42683) @@ -11463,112 +11463,30 @@ Reference: <http://www.freebsd.org/po Differentiating Operating Systems and OS Versions You may come across code that needs modifications or - conditional compilation based upon what version of Unix it is - 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 older - FreeBSD systems and cross-port to other BSD systems such as - 4.4BSD from CSRG, BSD/386, 386BSD, NetBSD, and OpenBSD. - - The preferred way to tell 4.3BSD/Reno (1990) and newer - versions of the BSD code apart is by using the - BSD macro defined in __FreeBSD_version and + __FreeBSD__ + macros defined in sys/param.h. - Hopefully that file is already included; if not, add the - code: + If this file is not included add the code, - #if (defined(__unix__) || defined(unix)) && !defined(USG) -#include <sys/param.h> -#endif - - to the proper place in the .c file. - We believe that every system that defines these two symbols - has sys/param.h. If you find a system - that does not, we would like to know. Please send mail to the - &a.ports;. + #include <sys/param.h> - Another way is to use the GNU Autoconf style of doing - this: + to the proper place in the .c file. - #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> + __FreeBSD__ is defined in all + versions of &os; as their major version number. For + example, in &os; 9.x, __FreeBSD__ is + defined to be 9. + + + #if __FreeBSD__ >= 9 +# if __FreeBSD_version >= 901000 + /* 9.1+ release specific code here */ +# endif #endif - - Do not forget to add -DHAVE_SYS_PARAM_H - to the CFLAGS in the - Makefile for this method. - - Once you have sys/param.h included, - 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). - - The value of the BSD macro is - 199506 for the 4.4BSD-Lite2 code base. - This is stated for informational purposes only. It should not - be used to distinguish between versions of FreeBSD based only - on 4.4-Lite versus versions that have merged in changes from - 4.4-Lite2. The __FreeBSD__ macro should be - used instead. - - Use sparingly: - - - - __FreeBSD__ is defined in all - versions of FreeBSD. Use it if the change you are making - only affects FreeBSD. Porting - gotchas like the use of sys_errlist[] - versus strerror() are Berkeley-isms, - not FreeBSD changes. - - - - In FreeBSD 2.x, __FreeBSD__ is - defined to be 2. In earlier versions, - it is 1. Later versions always bump it - to match their major version number. - - - - If you need to tell the difference between a FreeBSD - 1.x system and a FreeBSD 2.x or above system, usually the - right answer is to use the BSD macros - described above. If there actually is a FreeBSD specific - change (such as special shared library options when using - ld) then it is OK to use - __FreeBSD__ and - #if __FreeBSD__ > 1 to detect a - FreeBSD 2.x and later system. If you need more - granularity in detecting FreeBSD systems since 2.0-RELEASE - you can use the following: - - #if __FreeBSD__ >= 2 -#include <osreldate.h> -# if __FreeBSD_version >= 199504 - /* 2.0.5+ release specific code here */ -# endif -#endif - - - - In the hundreds 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 does not mean you should do so too. +