| @@ -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 <sys/param.h> | | 1628 | #include <sys/param.h> |
1611 | #if (defined(BSD) && BSD >= 199306) | | 1629 | #if (defined(BSD) && BSD >= 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> |
1622 | Cygwin __CYGWIN__ | | 1639 | Cygwin __CYGWIN__ |
1623 | DragonFly __DragonFly__ | | 1640 | DragonFly __DragonFly__ |
1624 | FreeBSD __FreeBSD__ | | 1641 | FreeBSD __FreeBSD__ |
1625 | Haiku __HAIKU__ | | 1642 | Haiku __HAIKU__ |
1626 | Interix __INTERIX | | 1643 | Interix __INTERIX |
1627 | IRIX __sgi (TODO: get a definite source for this) | | 1644 | IRIX __sgi (TODO: get a definite source for this) |
1628 | Linux linux, __linux, __linux__ | | 1645 | Linux __linux |
1629 | Mac OS X __APPLE__ | | 1646 | Mac OS X __APPLE__ |
1630 | MirBSD __MirBSD__ (__OpenBSD__ is also defined) | | 1647 | MirBSD __MirBSD__ (__OpenBSD__ is also defined) |
1631 | Minix3 __minix | | 1648 | Minix3 __minix |
1632 | NetBSD __NetBSD__ | | 1649 | NetBSD __NetBSD__ |
1633 | OpenBSD __OpenBSD__ | | 1650 | OpenBSD __OpenBSD__ |
1634 | Solaris sun, __sun | | 1651 | Solaris sun, __sun |
| | | 1652 | Unix(-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> |
1642 | i386 i386, __i386, __i386__ | | 1660 | i386 i386, __i386, __i386__ |
1643 | MIPS __mips | | 1661 | MIPS __mips |
1644 | SPARC sparc, __sparc | | 1662 | SPARC sparc, __sparc |
1645 | </programlisting> | | 1663 | </programlisting> |
1646 | | | 1664 | |
1647 | </sect3> | | 1665 | </sect3> |