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.
This commit is contained in:
Eitan Adler 2013-09-21 15:13:46 +00:00
parent 3fb2953044
commit c890716679
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/head/; revision=42683

View file

@ -11463,112 +11463,30 @@ Reference: <http://www.freebsd.org/ports/portaudit/74a9541d-5d6c-11d8-80e3-00
<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)) &amp;&amp; !defined(USG)
#include &lt;sys/param.h&gt;
<programlisting>#include &lt;sys/param.h&gt;</programlisting>
<para>to the proper place in the <filename>.c</filename> file.</para>
<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__ &gt;= 9
# if __FreeBSD_version &gt;= 901000
/* 9.1+ release specific code here */
# endif
#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>
<para>Another way is to use the GNU Autoconf style of doing
this:</para>
<programlisting>#ifdef HAVE_SYS_PARAM_H
#include &lt;sys/param.h&gt;
#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) &amp;&amp; (BSD &gt;= 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) &amp;&amp; (BSD &gt;= 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__ &gt; 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__ &gt;= 2
#include &lt;osreldate.h&gt;
# if __FreeBSD_version &gt;= 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">