Sat May 21 11:30:57 2022 UTC ()
State of the art on OS testing macros


(nia)
diff -r1.173 -r1.174 pkgsrc/doc/guide/files/fixes.xml

cvs diff -r1.173 -r1.174 pkgsrc/doc/guide/files/fixes.xml (expand / switch to unified diff)

--- pkgsrc/doc/guide/files/fixes.xml 2022/05/21 11:24:28 1.173
+++ pkgsrc/doc/guide/files/fixes.xml 2022/05/21 11:30:57 1.174
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1<!-- $NetBSD: fixes.xml,v 1.173 2022/05/21 11:24:28 nia Exp $ --> 1<!-- $NetBSD: fixes.xml,v 1.174 2022/05/21 11:30:57 nia Exp $ -->
2 2
3<chapter id="fixes"> <?dbhtml filename="fixes.html"?> 3<chapter id="fixes"> <?dbhtml filename="fixes.html"?>
4<title>Making your package work</title> 4<title>Making your package work</title>
5 5
6<sect1 id="general-operation"> 6<sect1 id="general-operation">
7 <title>General operation</title> 7 <title>General operation</title>
8 8
9 <para>One appealing feature of pkgsrc is that it runs on many 9 <para>One appealing feature of pkgsrc is that it runs on many
10 different platforms. As a result, it is important to ensure, 10 different platforms. As a result, it is important to ensure,
11 where possible, that packages in pkgsrc are portable. This 11 where possible, that packages in pkgsrc are portable. This
12 chapter mentions some particular details you should pay 12 chapter mentions some particular details you should pay
13 attention to while working on pkgsrc.</para> 13 attention to while working on pkgsrc.</para>
14 14
@@ -1593,55 +1593,73 @@ pre-configure: @@ -1593,55 +1593,73 @@ pre-configure:
1593 <varname>__i386__</varname> and <varname>__NetBSD__</varname> 1593 <varname>__i386__</varname> and <varname>__NetBSD__</varname>
1594 are all defined, you know that you are using NetBSD on an i386 1594 are all defined, you know that you are using NetBSD on an i386
1595 compatible CPU, and your compiler is GCC.</para> 1595 compatible CPU, and your compiler is GCC.</para>
1596 1596
1597 <para>The list of the following macros for hardware and 1597 <para>The list of the following macros for hardware and
1598 operating system depends on the compiler that is used. For 1598 operating system depends on the compiler that is used. For
1599 example, if you want to conditionally compile code on Solaris, 1599 example, if you want to conditionally compile code on Solaris,
1600 don't use <varname>__sun__</varname>, as the SunPro compiler 1600 don't use <varname>__sun__</varname>, as the SunPro compiler
1601 does not define it. Use <varname>__sun</varname> instead.</para> 1601 does not define it. Use <varname>__sun</varname> instead.</para>
1602 1602
1603<sect3 id="fixes.build.cpp.os"> 1603<sect3 id="fixes.build.cpp.os">
1604<title>C preprocessor macros to identify the operating system</title> 1604<title>C preprocessor macros to identify the operating system</title>
1605 1605
 1606 <para>To distinguish between specific NetBSD versions,
 1607 you should use the following code.</para>
 1608
 1609<programlisting>
 1610#ifdef __NetBSD__
 1611#include <sys/param.h>
 1612#if __NetBSD_Prereq__(9,99,17)
 1613/* use a newer feature */
 1614#else
 1615/* older code */
 1616#endif
 1617#endif
 1618
 1619#ifndef _WIN32
 1620/* Unix-like specific code */
 1621#endif
 1622</programlisting>
 1623
1606 <para>To distinguish between 4.4 BSD-derived systems and the 1624 <para>To distinguish between 4.4 BSD-derived systems and the
1607 rest of the world, you should use the following code.</para> 1625 rest of the world, you should use the following code.</para>
1608 1626
1609<programlisting> 1627<programlisting>
1610#include &lt;sys/param.h&gt; 1628#include &lt;sys/param.h&gt;
1611#if (defined(BSD) &amp;&amp; BSD &gt;= 199306) 1629#if (defined(BSD) &amp;&amp; BSD &gt;= 199306)
1612/* BSD-specific code goes here */ 1630/* BSD-specific code goes here */
1613#else 1631#else
1614/* non-BSD-specific code goes here */ 1632/* non-BSD-specific code goes here */
1615#endif 1633#endif
1616</programlisting> 1634</programlisting>
1617 1635
1618 <para>If this distinction is not fine enough, you can also test 1636 <para>You can also test for the following macros:</para>
1619 for the following macros.</para> 
1620 1637
1621<programlisting> 1638<programlisting>
1622Cygwin __CYGWIN__ 1639Cygwin __CYGWIN__
1623DragonFly __DragonFly__ 1640DragonFly __DragonFly__
1624FreeBSD __FreeBSD__ 1641FreeBSD __FreeBSD__
1625Haiku __HAIKU__ 1642Haiku __HAIKU__
1626Interix __INTERIX 1643Interix __INTERIX
1627IRIX __sgi (TODO: get a definite source for this) 1644IRIX __sgi (TODO: get a definite source for this)
1628Linux linux, __linux, __linux__ 1645Linux __linux
1629Mac OS X __APPLE__ 1646Mac OS X __APPLE__
1630MirBSD __MirBSD__ (__OpenBSD__ is also defined) 1647MirBSD __MirBSD__ (__OpenBSD__ is also defined)
1631Minix3 __minix 1648Minix3 __minix
1632NetBSD __NetBSD__ 1649NetBSD __NetBSD__
1633OpenBSD __OpenBSD__ 1650OpenBSD __OpenBSD__
1634Solaris sun, __sun 1651Solaris sun, __sun
 1652Unix(-like) __unix
1635</programlisting> 1653</programlisting>
1636 1654
1637</sect3> 1655</sect3>
1638<sect3 id="fixes.build.cpp.arch"> 1656<sect3 id="fixes.build.cpp.arch">
1639<title>C preprocessor macros to identify the hardware architecture</title> 1657<title>C preprocessor macros to identify the hardware architecture</title>
1640 1658
1641<programlisting> 1659<programlisting>
1642i386 i386, __i386, __i386__ 1660i386 i386, __i386, __i386__
1643MIPS __mips 1661MIPS __mips
1644SPARC sparc, __sparc 1662SPARC sparc, __sparc
1645</programlisting> 1663</programlisting>
1646 1664
1647</sect3> 1665</sect3>