Date: Sat, 21 Sep 2013 15:13:46 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> 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 Message-ID: <201309211513.r8LFDkPi080130@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <title>Differentiating Operating Systems and OS Versions</title> <para>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.</para> - - <para>The preferred way to tell 4.3BSD/Reno (1990) and newer - versions of the BSD code apart is by using the - <literal>BSD</literal> macro defined in <ulink + conditional compilation based upon what version of &os; Unix it is + running under. The preferred way to tell &os; versions apart + are the <literal>__FreeBSD_version</literal> and + <literal>__FreeBSD__</literal> + macros defined in <ulink url="http://svnweb.freebsd.org/base/head/sys/sys/param.h?view=markup">sys/param.h</ulink>. - Hopefully that file is already included; if not, add the - code:</para> + If this file is not included add the code,</para> - <programlisting>#if (defined(__unix__) || defined(unix)) && !defined(USG) -#include <sys/param.h> -#endif</programlisting> - - <para>to the proper place in the <filename>.c</filename> file. - We believe that every system that defines these two symbols - has <filename>sys/param.h</filename>. If you find a system - that does not, we would like to know. Please send mail to the - &a.ports;.</para> + <programlisting>#include <sys/param.h></programlisting> - <para>Another way is to use the GNU Autoconf style of doing - this:</para> + <para>to the proper place in the <filename>.c</filename> file.</para> - <programlisting>#ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> + <para><literal>__FreeBSD__</literal> is defined in all + versions of &os; as their major version number. For + example, in &os; 9.x, <literal>__FreeBSD__</literal> is + defined to be <literal>9</literal>.</para> + + <para> + <programlisting>#if __FreeBSD__ >= 9 +# if __FreeBSD_version >= 901000 + /* 9.1+ release specific code here */ +# endif #endif</programlisting> - - <para>Do not forget to add <literal>-DHAVE_SYS_PARAM_H</literal> - to the <makevar>CFLAGS</makevar> in the - <filename>Makefile</filename> for this method.</para> - - <para>Once you have <filename>sys/param.h</filename> included, - you may use:</para> - - <programlisting>#if (defined(BSD) && (BSD >= 199103))</programlisting> - - <para>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).</para> - - <para>Use:</para> - - <programlisting>#if (defined(BSD) && (BSD >= 199306))</programlisting> - - <para>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).</para> - - <para>The value of the <literal>BSD</literal> macro is - <literal>199506</literal> 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 <literal>__FreeBSD__</literal> macro should be - used instead.</para> - - <para>Use sparingly:</para> - - <itemizedlist> - <listitem> - <para><literal>__FreeBSD__</literal> is defined in all - versions of FreeBSD. Use it if the change you are making - <emphasis>only</emphasis> affects FreeBSD. Porting - gotchas like the use of <literal>sys_errlist[]</literal> - versus <function>strerror()</function> are Berkeley-isms, - not FreeBSD changes.</para> - </listitem> - - <listitem> - <para>In FreeBSD 2.x, <literal>__FreeBSD__</literal> is - defined to be <literal>2</literal>. In earlier versions, - it is <literal>1</literal>. Later versions always bump it - to match their major version number.</para> - </listitem> - - <listitem> - <para>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 <literal>BSD</literal> macros - described above. If there actually is a FreeBSD specific - change (such as special shared library options when using - <command>ld</command>) then it is OK to use - <literal>__FreeBSD__</literal> and - <literal>#if __FreeBSD__ > 1</literal> 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:</para> - - <programlisting>#if __FreeBSD__ >= 2 -#include <osreldate.h> -# if __FreeBSD_version >= 199504 - /* 2.0.5+ release specific code here */ -# endif -#endif</programlisting> - </listitem> - </itemizedlist> - - <para>In the hundreds of ports that have been done, there have - only been one or two cases where - <literal>__FreeBSD__</literal> 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.</para> + </para> </sect1> <sect1 id="freebsd-versions">
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201309211513.r8LFDkPi080130>