Sun Aug 22 16:27:50 2021 UTC ()
guide: expand section on editing the pkg-vulnerabilities file

Requested by kim@


(wiz)
diff -r1.162 -r1.163 pkgsrc/doc/guide/files/fixes.xml

cvs diff -r1.162 -r1.163 pkgsrc/doc/guide/files/fixes.xml (switch to unified diff)

--- pkgsrc/doc/guide/files/fixes.xml 2021/07/06 16:57:09 1.162
+++ pkgsrc/doc/guide/files/fixes.xml 2021/08/22 16:27:50 1.163
@@ -1,1583 +1,1618 @@ @@ -1,1583 +1,1618 @@
1<!-- $NetBSD: fixes.xml,v 1.162 2021/07/06 16:57:09 schmonz Exp $ --> 1<!-- $NetBSD: fixes.xml,v 1.163 2021/08/22 16:27:50 wiz 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
15 <sect2 id="pulling-vars-from-etc-mk.conf"> 15 <sect2 id="pulling-vars-from-etc-mk.conf">
16 <title>How to pull in user-settable variables from &mk.conf;</title> 16 <title>How to pull in user-settable variables from &mk.conf;</title>
17 17
18 <para>The pkgsrc user can configure pkgsrc by overriding several 18 <para>The pkgsrc user can configure pkgsrc by overriding several
19 variables in the file pointed to by <varname>MAKECONF</varname>, 19 variables in the file pointed to by <varname>MAKECONF</varname>,
20 which is &mk.conf; by default. When you 20 which is &mk.conf; by default. When you
21 want to use those variables in the preprocessor directives of 21 want to use those variables in the preprocessor directives of
22 &man.make.1; (for example <literal>.if</literal> or 22 &man.make.1; (for example <literal>.if</literal> or
23 <literal>.for</literal>), you need to include the file 23 <literal>.for</literal>), you need to include the file
24 <filename>../../mk/bsd.prefs.mk</filename> before, which in turn 24 <filename>../../mk/bsd.prefs.mk</filename> before, which in turn
25 loads the user preferences.</para> 25 loads the user preferences.</para>
26 26
27 <para>But note that some variables may not be completely defined 27 <para>But note that some variables may not be completely defined
28 after <filename>../../mk/bsd.prefs.mk</filename> has been 28 after <filename>../../mk/bsd.prefs.mk</filename> has been
29 included, as they may contain references to variables that are 29 included, as they may contain references to variables that are
30 not yet defined. In shell commands (the lines in 30 not yet defined. In shell commands (the lines in
31 <filename>Makefile</filename> that are indented with a tab) this 31 <filename>Makefile</filename> that are indented with a tab) this
32 is no problem, since variables are only expanded when they are 32 is no problem, since variables are only expanded when they are
33 used. But in the preprocessor directives mentioned above and in 33 used. But in the preprocessor directives mentioned above and in
34 dependency lines (of the form <literal>target: 34 dependency lines (of the form <literal>target:
35 dependencies</literal>) the variables are expanded at load 35 dependencies</literal>) the variables are expanded at load
36 time.</para> 36 time.</para>
37 37
38 <note><para>To check whether a variable can be used at load time, 38 <note><para>To check whether a variable can be used at load time,
39 run <command>pkglint -Wall</command> on your package.</para></note> 39 run <command>pkglint -Wall</command> on your package.</para></note>
40 40
41 </sect2> 41 </sect2>
42 42
43 <sect2 id="user-interaction"> 43 <sect2 id="user-interaction">
44 <title>User interaction</title> 44 <title>User interaction</title>
45 45
46 <para>Occasionally, packages require interaction from the user, 46 <para>Occasionally, packages require interaction from the user,
47 and this can be in a number of ways:</para> 47 and this can be in a number of ways:</para>
48 48
49 <itemizedlist> 49 <itemizedlist>
50 50
51 <listitem> 51 <listitem>
52 <para>When fetching the distfiles, some packages require user 52 <para>When fetching the distfiles, some packages require user
53 interaction such as entering username/password or accepting a 53 interaction such as entering username/password or accepting a
54 license on a web page.</para> 54 license on a web page.</para>
55 </listitem> 55 </listitem>
56 56
57 <listitem> 57 <listitem>
58 <para>When extracting the distfiles, some packages may ask for 58 <para>When extracting the distfiles, some packages may ask for
59 passwords.</para> 59 passwords.</para>
60 </listitem> 60 </listitem>
61 61
62 <listitem> 62 <listitem>
63 <para>help to configure the package before it is built</para> 63 <para>help to configure the package before it is built</para>
64 </listitem> 64 </listitem>
65 65
66 <listitem> 66 <listitem>
67 <para>help during the build process</para> 67 <para>help during the build process</para>
68 </listitem> 68 </listitem>
69 69
70 <listitem> 70 <listitem>
71 <para>help during the installation of a package</para> 71 <para>help during the installation of a package</para>
72 </listitem> 72 </listitem>
73 </itemizedlist> 73 </itemizedlist>
74 74
75 <para>A package can set the <varname>INTERACTIVE_STAGE</varname> 75 <para>A package can set the <varname>INTERACTIVE_STAGE</varname>
76 variable to define which stages need interaction. This should be 76 variable to define which stages need interaction. This should be
77 done in the package's <filename>Makefile</filename>, e.g.:</para> 77 done in the package's <filename>Makefile</filename>, e.g.:</para>
78 78
79<programlisting> 79<programlisting>
80INTERACTIVE_STAGE= configure install 80INTERACTIVE_STAGE= configure install
81</programlisting> 81</programlisting>
82 82
83 <para>The user can then decide to skip this package by setting the 83 <para>The user can then decide to skip this package by setting the
84 <varname>BATCH</varname> variable. Packages that require interaction 84 <varname>BATCH</varname> variable. Packages that require interaction
85 are also excluded from bulk builds.</para> 85 are also excluded from bulk builds.</para>
86 </sect2> 86 </sect2>
87 87
88 <sect2 id="handling-licenses"> 88 <sect2 id="handling-licenses">
89 <title>Handling licenses</title> 89 <title>Handling licenses</title>
90 90
91 <para>Authors of software can choose the licence under which software 91 <para>Authors of software can choose the licence under which software
92 can be copied. The Free Software Foundation has declared some 92 can be copied. The Free Software Foundation has declared some
93 licenses "Free", and the Open Source Initiative has a definition of 93 licenses "Free", and the Open Source Initiative has a definition of
94 "Open Source".</para> 94 "Open Source".</para>
95 95
96 <para>By default, pkgsrc allows packages with Free or Open Source 96 <para>By default, pkgsrc allows packages with Free or Open Source
97 licenses to be built. To allow packages with other licenses to be 97 licenses to be built. To allow packages with other licenses to be
98 built as well, the pkgsrc user needs to add these licenses to the 98 built as well, the pkgsrc user needs to add these licenses to the
99 <varname>ACCEPTABLE_LICENSES</varname> variable in &mk.conf;. Note 99 <varname>ACCEPTABLE_LICENSES</varname> variable in &mk.conf;. Note
100 that this variable only affects which packages may be 100 that this variable only affects which packages may be
101 <emphasis>built</emphasis>, while the license terms often also 101 <emphasis>built</emphasis>, while the license terms often also
102 restrict the actual use of the package and its redistribution.</para> 102 restrict the actual use of the package and its redistribution.</para>
103 103
104 <para>One might want to only install packages with a BSD license, 104 <para>One might want to only install packages with a BSD license,
105 or the GPL, and not the other. The free licenses are added to the 105 or the GPL, and not the other. The free licenses are added to the
106 default <varname>ACCEPTABLE_LICENSES</varname> variable. The pkgsrc 106 default <varname>ACCEPTABLE_LICENSES</varname> variable. The pkgsrc
107 user can override the default by setting the 107 user can override the default by setting the
108 <varname>ACCEPTABLE_LICENSES</varname> variable with "=" instead 108 <varname>ACCEPTABLE_LICENSES</varname> variable with "=" instead
109 of "+=". The licenses accepted by default are defined in the 109 of "+=". The licenses accepted by default are defined in the
110 <varname>DEFAULT_ACCEPTABLE_LICENSES</varname> variable in the file 110 <varname>DEFAULT_ACCEPTABLE_LICENSES</varname> variable in the file
111 <filename>pkgsrc/mk/license.mk</filename>.</para> 111 <filename>pkgsrc/mk/license.mk</filename>.</para>
112 112
113 <para>The license tag mechanism is intended to address 113 <para>The license tag mechanism is intended to address
114 copyright-related issues surrounding building, installing and 114 copyright-related issues surrounding building, installing and
115 using a package, and not to address redistribution issues (see 115 using a package, and not to address redistribution issues (see
116 <varname>RESTRICTED</varname> and 116 <varname>RESTRICTED</varname> and
117 <varname>NO_SRC_ON_FTP</varname>, etc.). 117 <varname>NO_SRC_ON_FTP</varname>, etc.).
118 Packages with redistribution restrictions should set these 118 Packages with redistribution restrictions should set these
119 tags.</para> 119 tags.</para>
120 120
121 <para>Denoting that a package may be copied according to a 121 <para>Denoting that a package may be copied according to a
122 particular license is done by placing the license in 122 particular license is done by placing the license in
123 <filename>pkgsrc/licenses</filename> and setting the 123 <filename>pkgsrc/licenses</filename> and setting the
124 <varname>LICENSE</varname> variable to a string identifying the 124 <varname>LICENSE</varname> variable to a string identifying the
125 license, e.g. in <filename 125 license, e.g. in <filename
126 role="pkg">graphics/xv</filename>:</para> 126 role="pkg">graphics/xv</filename>:</para>
127 127
128<programlisting> 128<programlisting>
129LICENSE= xv-license 129LICENSE= xv-license
130</programlisting> 130</programlisting>
131 131
132 <para>When trying to build, the user will get a notice that the 132 <para>When trying to build, the user will get a notice that the
133 package is covered by a license which has not been placed in the 133 package is covered by a license which has not been placed in the
134 <varname>ACCEPTABLE_LICENSES</varname> variable:</para> 134 <varname>ACCEPTABLE_LICENSES</varname> variable:</para>
135 135
136<programlisting> 136<programlisting>
137&cprompt; <userinput>make</userinput> 137&cprompt; <userinput>make</userinput>
138===> xv-3.10anb9 has an unacceptable license: xv-license. 138===> xv-3.10anb9 has an unacceptable license: xv-license.
139===> To view the license, enter "/usr/bin/make show-license". 139===> To view the license, enter "/usr/bin/make show-license".
140===> To indicate acceptance, add this line to your /etc/mk.conf: 140===> To indicate acceptance, add this line to your /etc/mk.conf:
141===> ACCEPTABLE_LICENSES+=xv-license 141===> ACCEPTABLE_LICENSES+=xv-license
142*** Error code 1 142*** Error code 1
143</programlisting> 143</programlisting>
144 144
145 <para>The license can be viewed with <command>make 145 <para>The license can be viewed with <command>make
146 show-license</command>, and if the user so chooses, the line 146 show-license</command>, and if the user so chooses, the line
147 printed above can be added to &mk.conf; to 147 printed above can be added to &mk.conf; to
148 convey to pkgsrc that it should not in the future fail because of 148 convey to pkgsrc that it should not in the future fail because of
149 that license:</para> 149 that license:</para>
150 150
151<programlisting> 151<programlisting>
152ACCEPTABLE_LICENSES+=xv-license 152ACCEPTABLE_LICENSES+=xv-license
153</programlisting> 153</programlisting>
154 154
155 <para>The use of <varname>LICENSE=shareware</varname>, 155 <para>The use of <varname>LICENSE=shareware</varname>,
156 <varname>LICENSE=no-commercial-use</varname>, and similar language 156 <varname>LICENSE=no-commercial-use</varname>, and similar language
157 is deprecated because it does not crisply refer to a particular 157 is deprecated because it does not crisply refer to a particular
158 license text. Another problem with such usage is that it does not 158 license text. Another problem with such usage is that it does not
159 enable a user to tell pkgsrc to proceed for a single package 159 enable a user to tell pkgsrc to proceed for a single package
160 without also telling pkgsrc to proceed for all packages with that 160 without also telling pkgsrc to proceed for all packages with that
161 tag.</para> 161 tag.</para>
162 162
163 <sect3 id="new-license"> 163 <sect3 id="new-license">
164 <title>Adding a package with a new license</title> 164 <title>Adding a package with a new license</title>
165 165
166 <para>When adding a package with a new license, the following steps 166 <para>When adding a package with a new license, the following steps
167 are required:</para> 167 are required:</para>
168 <orderedlist> 168 <orderedlist>
169 169
170 <listitem> 170 <listitem>
171 171
172 <para>Check whether the license qualifies as Free or Open Source by 172 <para>Check whether the license qualifies as Free or Open Source by
173 referencing <ulink 173 referencing <ulink
174 url="https://www.gnu.org/licenses/license-list.en.html">Various 174 url="https://www.gnu.org/licenses/license-list.en.html">Various
175 Licenses and Comments about Them</ulink> and <ulink 175 Licenses and Comments about Them</ulink> and <ulink
176 url="https://opensource.org/licenses/alphabetical">Licenses by Name | 176 url="https://opensource.org/licenses/alphabetical">Licenses by Name |
177 Open Source Initiative</ulink>. If this is the case, the filename in 177 Open Source Initiative</ulink>. If this is the case, the filename in
178 <filename>pkgsrc/licenses/</filename> does not need the 178 <filename>pkgsrc/licenses/</filename> does not need the
179 <filename>-license</filename> suffix, and the license name should be 179 <filename>-license</filename> suffix, and the license name should be
180 added to:</para> 180 added to:</para>
181 181
182 <itemizedlist> 182 <itemizedlist>
183 183
184 <listitem><para>DEFAULT_ACCEPTABLE_LICENSES in 184 <listitem><para>DEFAULT_ACCEPTABLE_LICENSES in
185 <filename>pkgsrc/mk/license.mk</filename></para></listitem> 185 <filename>pkgsrc/mk/license.mk</filename></para></listitem>
186 186
187 <listitem><para>default_acceptable_licenses in 187 <listitem><para>default_acceptable_licenses in
188 <filename>pkgsrc/pkgtools/pkg_install/files/lib/license.c</filename></para></listitem> 188 <filename>pkgsrc/pkgtools/pkg_install/files/lib/license.c</filename></para></listitem>
189 189
190 </itemizedlist> 190 </itemizedlist>
191 </listitem> 191 </listitem>
192 192
193 <listitem><para>The license text should be added to 193 <listitem><para>The license text should be added to
194 <filename>pkgsrc/licenses</filename> for displaying. A list of known 194 <filename>pkgsrc/licenses</filename> for displaying. A list of known
195 licenses can be seen in this directory.</para></listitem> 195 licenses can be seen in this directory.</para></listitem>
196 196
197 </orderedlist> 197 </orderedlist>
198 </sect3> 198 </sect3>
199 199
200 <sect3 id="change-license"> 200 <sect3 id="change-license">
201 <title>Change to the license</title> 201 <title>Change to the license</title>
202 202
203 <para>When the license changes (in a way other than formatting), 203 <para>When the license changes (in a way other than formatting),
204 make sure that the new license has a different name (e.g., 204 make sure that the new license has a different name (e.g.,
205 append the version number if it exists, or the date). Just 205 append the version number if it exists, or the date). Just
206 because a user told pkgsrc to build programs under a previous 206 because a user told pkgsrc to build programs under a previous
207 version of a license does not mean that pkgsrc should build 207 version of a license does not mean that pkgsrc should build
208 programs under the new licenses. The higher-level point is that 208 programs under the new licenses. The higher-level point is that
209 pkgsrc does not evaluate licenses for reasonableness; the only 209 pkgsrc does not evaluate licenses for reasonableness; the only
210 test is a mechanistic test of whether a particular text has been 210 test is a mechanistic test of whether a particular text has been
211 approved by either of two bodies (FSF or OSI).</para> 211 approved by either of two bodies (FSF or OSI).</para>
212 </sect3> 212 </sect3>
213 </sect2> 213 </sect2>
214 214
215 <sect2 id="restricted-packages"> 215 <sect2 id="restricted-packages">
216 <title>Restricted packages</title> 216 <title>Restricted packages</title>
217 217
218 <para>Some licenses restrict how software may be re-distributed. 218 <para>Some licenses restrict how software may be re-distributed.
219 By declaring the restrictions, package tools can 219 By declaring the restrictions, package tools can
220 automatically refrain from e.g. placing binary packages on FTP 220 automatically refrain from e.g. placing binary packages on FTP
221 sites.</para> 221 sites.</para>
222 222
223 <para>There are four possible restrictions, which are 223 <para>There are four possible restrictions, which are
224 the cross product of sources (distfiles) and binaries not being 224 the cross product of sources (distfiles) and binaries not being
225 placed on FTP sites and CD-ROMs. Because this is rarely the exact 225 placed on FTP sites and CD-ROMs. Because this is rarely the exact
226 language in any license, and because non-Free licenses tend to be 226 language in any license, and because non-Free licenses tend to be
227 different from each other, pkgsrc adopts a definition of FTP and 227 different from each other, pkgsrc adopts a definition of FTP and
228 CD-ROM. 228 CD-ROM.
229 229
230 "FTP" means making the source or binary file available over the 230 "FTP" means making the source or binary file available over the
231 Internet at no charge. 231 Internet at no charge.
232 232
233 "CD-ROM" means making the source or binary available on some kind of 233 "CD-ROM" means making the source or binary available on some kind of
234 media, together with other source and binary packages, which is sold 234 media, together with other source and binary packages, which is sold
235 for a distribution charge. 235 for a distribution charge.
236 </para> 236 </para>
237 237
238 <para>In order to encode these restrictions, the package system 238 <para>In order to encode these restrictions, the package system
239 defines five make variables that can be set to note these 239 defines five make variables that can be set to note these
240 restrictions:</para> 240 restrictions:</para>
241 241
242 <itemizedlist> 242 <itemizedlist>
243 <listitem> 243 <listitem>
244 <para><varname>RESTRICTED</varname></para> 244 <para><varname>RESTRICTED</varname></para>
245 245
246 <para>This variable should be set whenever a restriction 246 <para>This variable should be set whenever a restriction
247 exists (regardless of its kind). Set this variable to a 247 exists (regardless of its kind). Set this variable to a
248 string containing the reason for the restriction. It should 248 string containing the reason for the restriction. It should
249 be understood that those wanting to understand the restriction 249 be understood that those wanting to understand the restriction
250 will have to read the license, and perhaps seek advice of 250 will have to read the license, and perhaps seek advice of
251 counsel.</para> 251 counsel.</para>
252 </listitem> 252 </listitem>
253 253
254 <listitem> 254 <listitem>
255 <para><varname>NO_BIN_ON_CDROM</varname></para> 255 <para><varname>NO_BIN_ON_CDROM</varname></para>
256 256
257 <para>Binaries may not be placed on CD-ROM containing other 257 <para>Binaries may not be placed on CD-ROM containing other
258 binary packages, for which a distribution charge may be made. 258 binary packages, for which a distribution charge may be made.
259 In this case, set this variable to 259 In this case, set this variable to
260 <varname>${RESTRICTED}</varname>.</para> 260 <varname>${RESTRICTED}</varname>.</para>
261 </listitem> 261 </listitem>
262 262
263 <listitem> 263 <listitem>
264 <para><varname>NO_BIN_ON_FTP</varname></para> 264 <para><varname>NO_BIN_ON_FTP</varname></para>
265 265
266 <para>Binaries may not made available on the Internet without 266 <para>Binaries may not made available on the Internet without
267 charge. In this case, set this variable to 267 charge. In this case, set this variable to
268 <varname>${RESTRICTED}</varname>. If this variable is set, 268 <varname>${RESTRICTED}</varname>. If this variable is set,
269 binary packages will not be included on ftp.NetBSD.org.</para> 269 binary packages will not be included on ftp.NetBSD.org.</para>
270 </listitem> 270 </listitem>
271 271
272 <listitem> 272 <listitem>
273 <para><varname>NO_SRC_ON_CDROM</varname></para> 273 <para><varname>NO_SRC_ON_CDROM</varname></para>
274 274
275 <para>Distfiles may not be placed on CD-ROM, together with 275 <para>Distfiles may not be placed on CD-ROM, together with
276 other distfiles, for which a fee may be charged. In this 276 other distfiles, for which a fee may be charged. In this
277 case, set this variable to <varname>${RESTRICTED}</varname>. 277 case, set this variable to <varname>${RESTRICTED}</varname>.
278 </para> 278 </para>
279 </listitem> 279 </listitem>
280 280
281 <listitem> 281 <listitem>
282 <para><varname>NO_SRC_ON_FTP</varname></para> 282 <para><varname>NO_SRC_ON_FTP</varname></para>
283 283
284 <para>Distfiles may not made available via FTP at no charge. 284 <para>Distfiles may not made available via FTP at no charge.
285 In this case, set this variable to 285 In this case, set this variable to
286 <varname>${RESTRICTED}</varname>. If this variable is set, 286 <varname>${RESTRICTED}</varname>. If this variable is set,
287 the distfile(s) will not be mirrored on ftp.NetBSD.org.</para> 287 the distfile(s) will not be mirrored on ftp.NetBSD.org.</para>
288 </listitem> 288 </listitem>
289 </itemizedlist> 289 </itemizedlist>
290 290
291 <para>Please note that packages will be removed from pkgsrc when the 291 <para>Please note that packages will be removed from pkgsrc when the
292 distfiles are not distributable and cannot be obtained for a period 292 distfiles are not distributable and cannot be obtained for a period
293 of one full quarter branch. Packages with manual/interactive fetch 293 of one full quarter branch. Packages with manual/interactive fetch
294 must have a maintainer and it is his/her responsibility to ensure 294 must have a maintainer and it is his/her responsibility to ensure
295 this.</para> 295 this.</para>
296 </sect2> 296 </sect2>
297 297
298 298
299 <sect2 id="dependencies"> 299 <sect2 id="dependencies">
300 <title>Handling dependencies</title> 300 <title>Handling dependencies</title>
301 301
302 <para>Your package may depend on some other package being present, 302 <para>Your package may depend on some other package being present,
303 and there are various ways of expressing this dependency. 303 and there are various ways of expressing this dependency.
304 pkgsrc supports the <varname>DEPENDS</varname>, 304 pkgsrc supports the <varname>DEPENDS</varname>,
305 <varname>BUILD_DEPENDS</varname>, 305 <varname>BUILD_DEPENDS</varname>,
306 <varname>TOOL_DEPENDS</varname>, and 306 <varname>TOOL_DEPENDS</varname>, and
307 <varname>TEST_DEPENDS</varname> definitions, the 307 <varname>TEST_DEPENDS</varname> definitions, the
308 <varname>USE_TOOLS</varname> definition, as well as dependencies 308 <varname>USE_TOOLS</varname> definition, as well as dependencies
309 via <filename>buildlink3.mk</filename>, which is the preferred way 309 via <filename>buildlink3.mk</filename>, which is the preferred way
310 to handle dependencies, and which uses the variables named above. 310 to handle dependencies, and which uses the variables named above.
311 See <xref linkend="buildlink"/> for more information.</para> 311 See <xref linkend="buildlink"/> for more information.</para>
312 312
313 <para>The basic difference is that the <varname>DEPENDS</varname> 313 <para>The basic difference is that the <varname>DEPENDS</varname>
314 definition registers that pre-requisite in the binary package so it 314 definition registers that pre-requisite in the binary package so it
315 will be pulled in when the binary package is later installed, whilst 315 will be pulled in when the binary package is later installed, whilst
316 the <varname>BUILD_DEPENDS</varname>, <varname>TOOL_DEPENDS</varname>, 316 the <varname>BUILD_DEPENDS</varname>, <varname>TOOL_DEPENDS</varname>,
317 and <varname>TEST_DEPENDS</varname> definitions do not, marking a 317 and <varname>TEST_DEPENDS</varname> definitions do not, marking a
318 dependency that is only needed for building or testing the resulting 318 dependency that is only needed for building or testing the resulting
319 package. See also <xref linkend="creating"/> for more information.</para> 319 package. See also <xref linkend="creating"/> for more information.</para>
320 320
321 <para>This means that if you only need a package present whilst 321 <para>This means that if you only need a package present whilst
322 you are building or testing, it should be noted as a 322 you are building or testing, it should be noted as a
323 <varname>TOOL_DEPENDS</varname>, 323 <varname>TOOL_DEPENDS</varname>,
324 <varname>BUILD_DEPENDS</varname>, or 324 <varname>BUILD_DEPENDS</varname>, or
325 <varname>TEST_DEPENDS</varname>. When cross-compiling, 325 <varname>TEST_DEPENDS</varname>. When cross-compiling,
326 <varname>TOOL_DEPENDS</varname> are <emphasis>native</emphasis> 326 <varname>TOOL_DEPENDS</varname> are <emphasis>native</emphasis>
327 packages, i.e. packages for the architecture where the package 327 packages, i.e. packages for the architecture where the package
328 is built; 328 is built;
329 <varname>BUILD_DEPENDS</varname> are <emphasis>target</emphasis> 329 <varname>BUILD_DEPENDS</varname> are <emphasis>target</emphasis>
330 packages, i.e., packages for the architecture for which the package 330 packages, i.e., packages for the architecture for which the package
331 is built.</para> 331 is built.</para>
332 332
333 <para>The format for a <varname>DEPENDS</varname>, 333 <para>The format for a <varname>DEPENDS</varname>,
334 <varname>BUILD_DEPENDS</varname>, <varname>TOOL_DEPENDS</varname>, 334 <varname>BUILD_DEPENDS</varname>, <varname>TOOL_DEPENDS</varname>,
335 and <varname>TEST_DEPENDS</varname> definition is:</para> 335 and <varname>TEST_DEPENDS</varname> definition is:</para>
336 336
337<programlisting> 337<programlisting>
338&lt;pre-req-package-name&gt;:../../&lt;category&gt;/&lt;pre-req-package&gt; 338&lt;pre-req-package-name&gt;:../../&lt;category&gt;/&lt;pre-req-package&gt;
339</programlisting> 339</programlisting>
340 340
341 <para>Please note that the <quote>pre-req-package-name</quote> 341 <para>Please note that the <quote>pre-req-package-name</quote>
342 may include any of the wildcard version numbers recognized by 342 may include any of the wildcard version numbers recognized by
343 &man.pkg.info.1;.</para> 343 &man.pkg.info.1;.</para>
344 344
345 <orderedlist> 345 <orderedlist>
346 <listitem> 346 <listitem>
347 <para>If your package needs another package's binaries or 347 <para>If your package needs another package's binaries or
348 libraries to build and run, and if that package has a 348 libraries to build and run, and if that package has a
349 <filename>buildlink3.mk</filename> file available, use it:</para> 349 <filename>buildlink3.mk</filename> file available, use it:</para>
350 350
351<programlisting> 351<programlisting>
352.include "../../graphics/jpeg/buildlink3.mk" 352.include "../../graphics/jpeg/buildlink3.mk"
353</programlisting> 353</programlisting>
354 </listitem> 354 </listitem>
355 355
356 <listitem> 356 <listitem>
357 <para>If your package needs another package's binaries or 357 <para>If your package needs another package's binaries or
358 libraries only for building, and if that package has a 358 libraries only for building, and if that package has a
359 <filename>buildlink3.mk</filename> file available, use it:</para> 359 <filename>buildlink3.mk</filename> file available, use it:</para>
360 360
361<programlisting> 361<programlisting>
362.include "../../graphics/jpeg/buildlink3.mk" 362.include "../../graphics/jpeg/buildlink3.mk"
363</programlisting> 363</programlisting>
364 <para>but set 364 <para>but set
365 <varname>BUILDLINK_DEPMETHOD.<replaceable>jpeg</replaceable>?=build</varname> 365 <varname>BUILDLINK_DEPMETHOD.<replaceable>jpeg</replaceable>?=build</varname>
366 to make it a build dependency only. This case is rather 366 to make it a build dependency only. This case is rather
367 rare.</para> 367 rare.</para>
368 </listitem> 368 </listitem>
369 369
370 <listitem> 370 <listitem>
371 <para>If your package needs binaries from another package to build, 371 <para>If your package needs binaries from another package to build,
372 use the <varname>TOOL_DEPENDS</varname> definition:</para> 372 use the <varname>TOOL_DEPENDS</varname> definition:</para>
373 373
374<programlisting> 374<programlisting>
375TOOL_DEPENDS+= itstool-[0-9]*:../../textproc/itstool 375TOOL_DEPENDS+= itstool-[0-9]*:../../textproc/itstool
376</programlisting> 376</programlisting>
377 </listitem> 377 </listitem>
378 378
379 <listitem> 379 <listitem>
380 <para>If your package needs static libraries to link against, header 380 <para>If your package needs static libraries to link against, header
381 files to include, etc. from another package to build, 381 files to include, etc. from another package to build,
382 use the <varname>BUILD_DEPENDS</varname> definition.</para> 382 use the <varname>BUILD_DEPENDS</varname> definition.</para>
383 383
384<!-- 384<!--
385<programlisting> 385<programlisting>
386BUILD_DEPENDS+= TODO: find a good example 386BUILD_DEPENDS+= TODO: find a good example
387</programlisting> --> 387</programlisting> -->
388 </listitem> 388 </listitem>
389 389
390 <listitem> 390 <listitem>
391 <para>If your package needs a library with which to link and 391 <para>If your package needs a library with which to link and
392 there is no <filename>buildlink3.mk</filename> file 392 there is no <filename>buildlink3.mk</filename> file
393 available, create one. Using 393 available, create one. Using
394 <varname>DEPENDS</varname> won't be sufficient because the 394 <varname>DEPENDS</varname> won't be sufficient because the
395 include files and libraries will be hidden from the compiler.</para> 395 include files and libraries will be hidden from the compiler.</para>
396 </listitem> 396 </listitem>
397 397
398 <listitem> 398 <listitem>
399 <para>If your package needs some executable to be able to run 399 <para>If your package needs some executable to be able to run
400 correctly and if there's no 400 correctly and if there's no
401 <filename>buildlink3.mk</filename> file, this is specified 401 <filename>buildlink3.mk</filename> file, this is specified
402 using the <varname>DEPENDS</varname> variable. The 402 using the <varname>DEPENDS</varname> variable. The
403 <filename role="pkg">print/lyx</filename> package needs to 403 <filename role="pkg">print/lyx</filename> package needs to
404 be able to execute the latex binary from the tex-latex-bin package 404 be able to execute the latex binary from the tex-latex-bin package
405 when it runs, and that is specified:</para> 405 when it runs, and that is specified:</para>
406 406
407<programlisting> 407<programlisting>
408DEPENDS+= tex-latex-bin-[0-9]*:../../print/tex-latex-bin 408DEPENDS+= tex-latex-bin-[0-9]*:../../print/tex-latex-bin
409</programlisting> 409</programlisting>
410 </listitem> 410 </listitem>
411 <listitem> 411 <listitem>
412 <para>If your package includes a test suite that has extra 412 <para>If your package includes a test suite that has extra
413 dependencies only required for this purpose (frequently this 413 dependencies only required for this purpose (frequently this
414 can be run as a <quote>make test</quote> target), use the 414 can be run as a <quote>make test</quote> target), use the
415 <varname>TEST_DEPENDS</varname> variable.</para> 415 <varname>TEST_DEPENDS</varname> variable.</para>
416 </listitem> 416 </listitem>
417 <listitem> 417 <listitem>
418 <para>You can use wildcards in package dependencies. Note that 418 <para>You can use wildcards in package dependencies. Note that
419 such wildcard dependencies are retained when creating binary 419 such wildcard dependencies are retained when creating binary
420 packages. The dependency is checked when installing the binary 420 packages. The dependency is checked when installing the binary
421 package and any package which matches the pattern will be 421 package and any package which matches the pattern will be
422 used. Wildcard dependencies should be used with care.</para> 422 used. Wildcard dependencies should be used with care.</para>
423 423
424 <para>The <quote>-[0-9]*</quote> should be used instead of 424 <para>The <quote>-[0-9]*</quote> should be used instead of
425 <quote>-*</quote> to avoid potentially ambiguous matches 425 <quote>-*</quote> to avoid potentially ambiguous matches
426 such as <quote>tk-postgresql</quote> matching a 426 such as <quote>tk-postgresql</quote> matching a
427 <quote>tk-*</quote> <varname>DEPENDS</varname>.</para> 427 <quote>tk-*</quote> <varname>DEPENDS</varname>.</para>
428 428
429 <para>Wildcards can also be used to specify that a package 429 <para>Wildcards can also be used to specify that a package
430 will only build against a certain minimum version of a 430 will only build against a certain minimum version of a
431 pre-requisite:</para> 431 pre-requisite:</para>
432 432
433<programlisting> 433<programlisting>
434DEPENDS+= ImageMagick>=6.0:../../graphics/ImageMagick 434DEPENDS+= ImageMagick>=6.0:../../graphics/ImageMagick
435</programlisting> 435</programlisting>
436 436
437 <para>This means that the package will build using version 6.0 437 <para>This means that the package will build using version 6.0
438 of ImageMagick or newer. Such a dependency may be warranted 438 of ImageMagick or newer. Such a dependency may be warranted
439 if, for example, the command line options of an executable 439 if, for example, the command line options of an executable
440 have changed.</para> 440 have changed.</para>
441 441
442 <para>If you need to depend on minimum versions of libraries, 442 <para>If you need to depend on minimum versions of libraries,
443 set 443 set
444 <varname>BUILDLINK_API_DEPENDS.<replaceable>pkg</replaceable></varname> 444 <varname>BUILDLINK_API_DEPENDS.<replaceable>pkg</replaceable></varname>
445 to the appropriate pattern before including its 445 to the appropriate pattern before including its
446 <filename>buildlink3.mk</filename> file, e.g.</para> 446 <filename>buildlink3.mk</filename> file, e.g.</para>
447 447
448<programlisting> 448<programlisting>
449BUILDLINK_API_DEPENDS.jpeg+= jpeg>=9.0 449BUILDLINK_API_DEPENDS.jpeg+= jpeg>=9.0
450.include "../../graphics/jpeg/buildlink3.mk" 450.include "../../graphics/jpeg/buildlink3.mk"
451</programlisting> 451</programlisting>
452 452
453 <para>For security fixes, please update the package 453 <para>For security fixes, please update the package
454 vulnerabilities file. See <xref 454 vulnerabilities file. See <xref
455 linkend="security-handling"/> for more 455 linkend="security-handling"/> for more
456 information.</para> 456 information.</para>
457 </listitem> 457 </listitem>
458 </orderedlist> 458 </orderedlist>
459 459
460 <para>If your package needs files from another package to build, 460 <para>If your package needs files from another package to build,
461 add the relevant distribution files to 461 add the relevant distribution files to
462 <varname>DISTFILES</varname>, so they will be extracted 462 <varname>DISTFILES</varname>, so they will be extracted
463 automatically. See the <filename 463 automatically. See the <filename
464 role="pkg">print/ghostscript</filename> package for an example. 464 role="pkg">print/ghostscript</filename> package for an example.
465 (It relies on the jpeg sources being present in source form 465 (It relies on the jpeg sources being present in source form
466 during the build.)</para> 466 during the build.)</para>
467 </sect2> 467 </sect2>
468 468
469 469
470 <sect2 id="conflicts"> 470 <sect2 id="conflicts">
471 <title>Handling conflicts with other packages</title> 471 <title>Handling conflicts with other packages</title>
472 472
473 <para>Your package may conflict with other packages a user might 473 <para>Your package may conflict with other packages a user might
474 already have installed on his system, e.g. if your package 474 already have installed on his system, e.g. if your package
475 installs the same set of files as another package in the pkgsrc 475 installs the same set of files as another package in the pkgsrc
476 tree or has the same <varname>PKGNAME</varname>.</para> 476 tree or has the same <varname>PKGNAME</varname>.</para>
477 477
478 <para>For example, <filename role="pkg">x11/libXaw3d</filename> 478 <para>For example, <filename role="pkg">x11/libXaw3d</filename>
479 and <filename role="pkg">x11/Xaw-Xpm</filename> 479 and <filename role="pkg">x11/Xaw-Xpm</filename>
480 install the same shared library, thus you set in 480 install the same shared library, thus you set in
481 <filename>pkgsrc/x11/libXaw3d/Makefile</filename>:</para> 481 <filename>pkgsrc/x11/libXaw3d/Makefile</filename>:</para>
482 482
483 <programlisting> 483 <programlisting>
484CONFLICTS= Xaw-Xpm-[0-9]* 484CONFLICTS= Xaw-Xpm-[0-9]*
485 </programlisting> 485 </programlisting>
486 486
487 <para>and in <filename>pkgsrc/x11/Xaw-Xpm/Makefile</filename>:</para> 487 <para>and in <filename>pkgsrc/x11/Xaw-Xpm/Makefile</filename>:</para>
488 488
489 <programlisting> 489 <programlisting>
490CONFLICTS= libXaw3d-[0-9]* 490CONFLICTS= libXaw3d-[0-9]*
491 </programlisting> 491 </programlisting>
492 492
493 <para>&man.pkg.add.1 is able to detect attempts to install packages 493 <para>&man.pkg.add.1 is able to detect attempts to install packages
494 that conflict with existing packages and abort. However, in many 494 that conflict with existing packages and abort. However, in many
495 situations this is too late in the process. Binary package managers 495 situations this is too late in the process. Binary package managers
496 will not know about the conflict until they attempt to install the 496 will not know about the conflict until they attempt to install the
497 package after already downloading it and all its dependencies. 497 package after already downloading it and all its dependencies.
498 Users may also waste time building a package and its dependencies 498 Users may also waste time building a package and its dependencies
499 only to find out at the end that it conflicts with another package 499 only to find out at the end that it conflicts with another package
500 they have installed.</para> 500 they have installed.</para>
501 501
502 <para>To avoid these issues <varname>CONFLICTS</varname> entries 502 <para>To avoid these issues <varname>CONFLICTS</varname> entries
503 should be added in all cases where it is known that packages conflict 503 should be added in all cases where it is known that packages conflict
504 with each other. These <varname>CONFLICTS</varname> entries are 504 with each other. These <varname>CONFLICTS</varname> entries are
505 exported in &man.pkg.summary.5 files and consumed by binary package 505 exported in &man.pkg.summary.5 files and consumed by binary package
506 managers to inform users that packages cannot be installed onto 506 managers to inform users that packages cannot be installed onto
507 the target system.</para> 507 the target system.</para>
508 </sect2> 508 </sect2>
509 509
510 510
511 <sect2 id="not-building-packages"> 511 <sect2 id="not-building-packages">
512 <title>Packages that cannot or should not be built</title> 512 <title>Packages that cannot or should not be built</title>
513 513
514 <para>There are several reasons why a package might be 514 <para>There are several reasons why a package might be
515 instructed to not build under certain circumstances. If the 515 instructed to not build under certain circumstances. If the
516 package builds and runs on most platforms, the exceptions 516 package builds and runs on most platforms, the exceptions
517 should be noted with <varname>BROKEN_ON_PLATFORM</varname>. If 517 should be noted with <varname>BROKEN_ON_PLATFORM</varname>. If
518 the package builds and runs on a small handful of platforms, 518 the package builds and runs on a small handful of platforms,
519 set <varname>BROKEN_EXCEPT_ON_PLATFORM</varname> instead. 519 set <varname>BROKEN_EXCEPT_ON_PLATFORM</varname> instead.
520 Both <varname>BROKEN_ON_PLATFORM</varname> and 520 Both <varname>BROKEN_ON_PLATFORM</varname> and
521 <varname>BROKEN_EXCEPT_ON_PLATFORM</varname> are OS triples 521 <varname>BROKEN_EXCEPT_ON_PLATFORM</varname> are OS triples
522 (OS-version-platform) that can use glob-style 522 (OS-version-platform) that can use glob-style
523 wildcards.</para> 523 wildcards.</para>
524 <para>If a package is not appropriate for some platforms (as 524 <para>If a package is not appropriate for some platforms (as
525 opposed to merely broken), a different set of variables should be 525 opposed to merely broken), a different set of variables should be
526 used as this affects failure reporting and statistics. 526 used as this affects failure reporting and statistics.
527 If the package is appropriate for most platforms, the exceptions 527 If the package is appropriate for most platforms, the exceptions
528 should be noted with <varname>NOT_FOR_PLATFORM</varname>. If 528 should be noted with <varname>NOT_FOR_PLATFORM</varname>. If
529 the package is appropriate for only a small handful of platforms 529 the package is appropriate for only a small handful of platforms
530 (often exactly one), set <varname>ONLY_FOR_PLATFORM</varname> instead. 530 (often exactly one), set <varname>ONLY_FOR_PLATFORM</varname> instead.
531 Both <varname>ONLY_FOR_PLATFORM</varname> and 531 Both <varname>ONLY_FOR_PLATFORM</varname> and
532 <varname>NOT_FOR_PLATFORM</varname> are OS triples 532 <varname>NOT_FOR_PLATFORM</varname> are OS triples
533 (OS-version-platform) that can use glob-style 533 (OS-version-platform) that can use glob-style
534 wildcards.</para> 534 wildcards.</para>
535 <para>Some packages are tightly bound to a specific version of an 535 <para>Some packages are tightly bound to a specific version of an
536 operating system, e.g. LKMs or <filename 536 operating system, e.g. LKMs or <filename
537 role="pkg">sysutils/lsof</filename>. Such binary packages are not 537 role="pkg">sysutils/lsof</filename>. Such binary packages are not
538 backwards compatible with other versions of the OS, and should be 538 backwards compatible with other versions of the OS, and should be
539 uploaded to a version specific directory on the FTP server. Mark 539 uploaded to a version specific directory on the FTP server. Mark
540 these packages by setting <varname>OSVERSION_SPECIFIC</varname> to 540 these packages by setting <varname>OSVERSION_SPECIFIC</varname> to
541 <quote>yes</quote>. This variable is not currently used by any of 541 <quote>yes</quote>. This variable is not currently used by any of
542 the package system internals, but may be used in the 542 the package system internals, but may be used in the
543 future.</para> 543 future.</para>
544 <para>If the package should be skipped (for example, because it 544 <para>If the package should be skipped (for example, because it
545 provides functionality already provided by the system), set 545 provides functionality already provided by the system), set
546 <varname>PKG_SKIP_REASON</varname> to a descriptive message. If 546 <varname>PKG_SKIP_REASON</varname> to a descriptive message. If
547 the package should fail because some preconditions are not met, 547 the package should fail because some preconditions are not met,
548 set <varname>PKG_FAIL_REASON</varname> to a descriptive 548 set <varname>PKG_FAIL_REASON</varname> to a descriptive
549 message.</para> 549 message.</para>
550 </sect2> 550 </sect2>
551 551
552 552
553 <sect2 id="undeletable-packages"> 553 <sect2 id="undeletable-packages">
554 <title>Packages which should not be deleted, once installed</title> 554 <title>Packages which should not be deleted, once installed</title>
555 555
556 <para>To ensure that a package may not be deleted, once it has been 556 <para>To ensure that a package may not be deleted, once it has been
557 installed, the <varname>PKG_PRESERVE</varname> definition should 557 installed, the <varname>PKG_PRESERVE</varname> definition should
558 be set in the package Makefile. This will be carried into any 558 be set in the package Makefile. This will be carried into any
559 binary package that is made from this pkgsrc entry. A 559 binary package that is made from this pkgsrc entry. A
560 <quote>preserved</quote> package will 560 <quote>preserved</quote> package will
561 not be deleted using &man.pkg.delete.1; unless the 561 not be deleted using &man.pkg.delete.1; unless the
562 <quote>-f</quote> option is used.</para> 562 <quote>-f</quote> option is used.</para>
563 </sect2> 563 </sect2>
564 564
565 565
566 <sect2 id="security-handling"> 566 <sect2 id="security-handling">
567 <title>Handling packages with security problems</title> 567 <title>Handling packages with security problems</title>
568 568
569 <para>When a vulnerability is found, this should be noted in 569 <para>When a vulnerability is found, this should be noted in
570 <filename>localsrc/security/advisories/pkg-vulnerabilities</filename>, 570 <filename>localsrc/security/advisories/pkg-vulnerabilities</filename>.
571 and after committing that file, ask pkgsrc-security@NetBSD.org to 571 Entries in that file consist of three parts:</para>
 572 <itemizedlist>
 573 <listitem><para>package version pattern</para></listitem>
 574 <listitem><para>type of vulnerability (please cut'n'paste an existing one where possible)</para></listitem>
 575 <listitem><para>URL providing additional information about the issue</para></listitem>
 576 </itemizedlist>
 577
 578 <para>For the package version pattern please always use `&lt;' to
 579 mark an upper bound (not `&lt;='!). This will avoid possible
 580 problems due unrelated <varname>PKGREVISION</varname> bumps not
 581 related to security fixes. Lower bounds can be added too, using
 582 '&gt;' or '&gt;='. For example,
 583 <quote><literal>foo&gt;'=1&lt;1.2</literal></quote> would mark
 584 versions 1.0 (included) to 1.2 (excluded) of
 585 <quote><literal>foo</literal></quote> as affected by the security
 586 issue.</para>
 587
 588 <para>Entries should always be added at the bottom of the file.</para>
 589
 590 <para>When fixing packages, please modify the upper bound of the
 591 corresponding entry. To continue the previous example, if a fix
 592 was backported to version 1.1nb2, change the previous pattern to
 593 <quote><literal>foo&gt;'=1&lt;1.1nb2</literal></quote>.</para>
 594
 595 <para>To locally test a package version pattern against a
 596 <varname>PKGNAME</varname> you can use the <command>pkg_admin
 597 pmatch</command> command.</para>
 598
 599 <para>The URL should be as permanent as possible and provide as
 600 much information about the issue as possible. CVE entries are
 601 preferred.</para>
 602
 603 <para>After committing that file, ask pkgsrc-security@NetBSD.org to
572 update the file on ftp.NetBSD.org.</para> 604 update the file on ftp.NetBSD.org.</para>
573 605
574 <para>After fixing the vulnerability by a patch, its 606 <para>After fixing the vulnerability by a patch, its
575 <varname>PKGREVISION</varname> should be increased (this is of 607 <varname>PKGREVISION</varname> should be increased (this is of
576 course not necessary if the problem is fixed by using a newer 608 course not necessary if the problem is fixed by using a newer
577 release of the software), and the pattern in the 609 release of the software), and the pattern in the
578 pkg-vulnerabilities file must be updated.</para> 610 pkg-vulnerabilities file must be updated.</para>
579 611
580 <para>Also, if the fix should be applied to the stable pkgsrc 612 <para>Also, if the fix should be applied to the stable pkgsrc
581 branch, be sure to submit a pullup request!</para> 613 branch, be sure to submit a pullup request!</para>
582 614
583 <para>Binary packages already on ftp.NetBSD.org will be handled 615 <para>Binary packages already on ftp.NetBSD.org will be handled
584 semi-automatically by a weekly cron job.</para> 616 semi-automatically by a weekly cron job.</para>
 617
 618 <para>In case a security issue is disputed, please contact
 619 pkgsrc-security@NetBSD.org.</para>
585 </sect2> 620 </sect2>
586 621
587 622
588 <sect2 id="bumping-pkgrevision"> 623 <sect2 id="bumping-pkgrevision">
589 <title>How to handle incrementing versions when fixing an existing package</title> 624 <title>How to handle incrementing versions when fixing an existing package</title>
590 625
591 <para>When making fixes to an existing package it can be useful 626 <para>When making fixes to an existing package it can be useful
592 to change the version number in <varname>PKGNAME</varname>. To 627 to change the version number in <varname>PKGNAME</varname>. To
593 avoid conflicting with future versions by the original author, a 628 avoid conflicting with future versions by the original author, a
594 <quote>nb1</quote>, <quote>nb2</quote>, ... suffix can be used 629 <quote>nb1</quote>, <quote>nb2</quote>, ... suffix can be used
595 on package versions by setting <varname>PKGREVISION=1</varname> 630 on package versions by setting <varname>PKGREVISION=1</varname>
596 (2, ...). The <quote>nb</quote> is treated like a 631 (2, ...). The <quote>nb</quote> is treated like a
597 <quote>.</quote> by the package tools. e.g.</para> 632 <quote>.</quote> by the package tools. e.g.</para>
598 633
599<programlisting> 634<programlisting>
600DISTNAME= foo-17.42 635DISTNAME= foo-17.42
601PKGREVISION= 9 636PKGREVISION= 9
602</programlisting> 637</programlisting>
603 638
604 <para>will result in a <varname>PKGNAME</varname> of 639 <para>will result in a <varname>PKGNAME</varname> of
605 <quote>foo-17.42nb9</quote>. If you want to use the original 640 <quote>foo-17.42nb9</quote>. If you want to use the original
606 value of <varname>PKGNAME</varname> without the <quote>nbX</quote> 641 value of <varname>PKGNAME</varname> without the <quote>nbX</quote>
607 suffix, e.g. for setting <varname>DIST_SUBDIR</varname>, use 642 suffix, e.g. for setting <varname>DIST_SUBDIR</varname>, use
608 <varname>PKGNAME_NOREV</varname>.</para> 643 <varname>PKGNAME_NOREV</varname>.</para>
609 644
610 <para>When a new release of the package is released, the 645 <para>When a new release of the package is released, the
611 <varname>PKGREVISION</varname> should be removed, e.g. on a new 646 <varname>PKGREVISION</varname> should be removed, e.g. on a new
612 minor release of the above package, things should be like:</para> 647 minor release of the above package, things should be like:</para>
613 648
614<programlisting> 649<programlisting>
615DISTNAME= foo-17.43 650DISTNAME= foo-17.43
616</programlisting> 651</programlisting>
617 652
618 <para><varname>PKGREVISION</varname> should be incremented for any 653 <para><varname>PKGREVISION</varname> should be incremented for any
619 non-trivial change in the resulting binary package. Without a 654 non-trivial change in the resulting binary package. Without a
620 <varname>PKGREVISION</varname> bump, someone with the previous 655 <varname>PKGREVISION</varname> bump, someone with the previous
621 version installed has no way of knowing that their package is out 656 version installed has no way of knowing that their package is out
622 of date. Thus, changes without increasing 657 of date. Thus, changes without increasing
623 <varname>PKGREVISION</varname> are essentially labeled "this is so 658 <varname>PKGREVISION</varname> are essentially labeled "this is so
624 trivial that no reasonable person would want to upgrade", and this 659 trivial that no reasonable person would want to upgrade", and this
625 is the rough test for when increasing 660 is the rough test for when increasing
626 <varname>PKGREVISION</varname> is appropriate. Examples of 661 <varname>PKGREVISION</varname> is appropriate. Examples of
627 changes that do not merit increasing 662 changes that do not merit increasing
628 <varname>PKGREVISION</varname> are:</para> 663 <varname>PKGREVISION</varname> are:</para>
629 664
630 <itemizedlist> 665 <itemizedlist>
631 666
632 <listitem><para>Changing <varname>HOMEPAGE</varname>, 667 <listitem><para>Changing <varname>HOMEPAGE</varname>,
633 <varname>MAINTAINER</varname>, <varname>OWNER</varname>, or 668 <varname>MAINTAINER</varname>, <varname>OWNER</varname>, or
634 comments in Makefile.</para></listitem> 669 comments in Makefile.</para></listitem>
635 670
636 <listitem><para>Changing build variables if the resulting binary 671 <listitem><para>Changing build variables if the resulting binary
637 package is the same.</para></listitem> 672 package is the same.</para></listitem>
638 673
639 <listitem><para>Changing 674 <listitem><para>Changing
640 <filename>DESCR</filename>.</para></listitem> 675 <filename>DESCR</filename>.</para></listitem>
641 676
642 <listitem><para>Adding <varname>PKG_OPTIONS</varname> if the 677 <listitem><para>Adding <varname>PKG_OPTIONS</varname> if the
643 default options don't change.</para></listitem> 678 default options don't change.</para></listitem>
644 679
645 </itemizedlist> 680 </itemizedlist>
646 681
647 <para>Examples of changes that do merit an increase to 682 <para>Examples of changes that do merit an increase to
648 <varname>PKGREVISION</varname> include:</para> 683 <varname>PKGREVISION</varname> include:</para>
649 684
650 <itemizedlist> 685 <itemizedlist>
651 686
652 <listitem><para>Security fixes</para></listitem> 687 <listitem><para>Security fixes</para></listitem>
653 688
654 <listitem><para>Changes or additions to a patch 689 <listitem><para>Changes or additions to a patch
655 file</para></listitem> 690 file</para></listitem>
656 691
657 <listitem><para>Changes to the 692 <listitem><para>Changes to the
658 <filename>PLIST</filename></para></listitem> 693 <filename>PLIST</filename></para></listitem>
659 694
660 <listitem><para>A dependency is changed or 695 <listitem><para>A dependency is changed or
661 renamed.</para></listitem> 696 renamed.</para></listitem>
662 697
663 </itemizedlist> 698 </itemizedlist>
664 699
665 <para>PKGREVISION must also be incremented when dependencies have ABI 700 <para>PKGREVISION must also be incremented when dependencies have ABI
666 changes.</para> 701 changes.</para>
667 </sect2> 702 </sect2>
668 703
669<sect2 id="fixes.subst"> 704<sect2 id="fixes.subst">
670<title>Substituting variable text in the package files (the SUBST framework)</title> 705<title>Substituting variable text in the package files (the SUBST framework)</title>
671 706
672<para>When you want to replace the same text in multiple files, or 707<para>When you want to replace the same text in multiple files, or
673multiple times in the same file, it is cumbersome to maintain a patch 708multiple times in the same file, it is cumbersome to maintain a patch
674file for this. This is where the SUBST framework steps in. It provides an 709file for this. This is where the SUBST framework steps in. It provides an
675easy-to-use interface for replacing text in files. It just needs the 710easy-to-use interface for replacing text in files. It just needs the
676following information:</para> 711following information:</para>
677 712
678<itemizedlist> 713<itemizedlist>
679 714
680<listitem><para>In which phase of the package build cycle should the 715<listitem><para>In which phase of the package build cycle should the
681replacement happen?</para></listitem> 716replacement happen?</para></listitem>
682 717
683<listitem><para>In which files should the replacement 718<listitem><para>In which files should the replacement
684happen?</para></listitem> 719happen?</para></listitem>
685 720
686<listitem><para>Which text should be replaced with 721<listitem><para>Which text should be replaced with
687what?</para></listitem> 722what?</para></listitem>
688 723
689</itemizedlist> 724</itemizedlist>
690 725
691<para>This information is encoded in a block of <varname>SUBST</varname> 726<para>This information is encoded in a block of <varname>SUBST</varname>
692variables. A minimal example is:</para> 727variables. A minimal example is:</para>
693 728
694<programlisting> 729<programlisting>
695SUBST_CLASSES+= paths 730SUBST_CLASSES+= paths
696SUBST_STAGE.paths= pre-configure 731SUBST_STAGE.paths= pre-configure
697SUBST_FILES.paths= src/*.c 732SUBST_FILES.paths= src/*.c
698SUBST_SED.paths= -e 's,/usr/local,${PREFIX},g' 733SUBST_SED.paths= -e 's,/usr/local,${PREFIX},g'
699</programlisting> 734</programlisting>
700 735
701<para>Translated into English, it means: In the pre-configure stage (that 736<para>Translated into English, it means: In the pre-configure stage (that
702is, after applying the patches from the patches/ directory and before 737is, after applying the patches from the patches/ directory and before
703running the configure script and the portability check), replace the text 738running the configure script and the portability check), replace the text
704<literal>/usr/local</literal> with the content of the variable 739<literal>/usr/local</literal> with the content of the variable
705<varname>PREFIX</varname>.</para> 740<varname>PREFIX</varname>.</para>
706 741
707<para>Each SUBST block starts by appending an identifier to 742<para>Each SUBST block starts by appending an identifier to
708<varname>SUBST_CLASSES</varname> (note the <literal>+=</literal>). This 743<varname>SUBST_CLASSES</varname> (note the <literal>+=</literal>). This
709identifier can be chosen freely by the package. If there should ever be 744identifier can be chosen freely by the package. If there should ever be
710duplicate identifiers, the pkgsrc infrastructure will catch this and fail 745duplicate identifiers, the pkgsrc infrastructure will catch this and fail
711early, so don't worry about name collisions.</para> 746early, so don't worry about name collisions.</para>
712 747
713<para>Except for <varname>SUBST_CLASSES</varname>, all variables in a 748<para>Except for <varname>SUBST_CLASSES</varname>, all variables in a
714SUBST block are parameterized using this identifier. In the remainder of 749SUBST block are parameterized using this identifier. In the remainder of
715this section, these parameterized variables are written as 750this section, these parameterized variables are written as
716<varname>SUBST_STAGE.*</varname>.</para> 751<varname>SUBST_STAGE.*</varname>.</para>
717 752
718<programlisting> 753<programlisting>
719SUBST_CLASSES+= paths 754SUBST_CLASSES+= paths
720SUBST_STAGE.paths= pre-configure 755SUBST_STAGE.paths= pre-configure
721SUBST_MESSAGE.paths= Fixing absolute paths. 756SUBST_MESSAGE.paths= Fixing absolute paths.
722SUBST_FILES.paths= src/*.c 757SUBST_FILES.paths= src/*.c
723SUBST_FILES.paths+= scripts/*.sh 758SUBST_FILES.paths+= scripts/*.sh
724SUBST_SED.paths= -e 's,"/usr/local,"${PREFIX},g' 759SUBST_SED.paths= -e 's,"/usr/local,"${PREFIX},g'
725SUBST_SED.paths+= -e 's,"/var/log,"${VARBASE}/log,g' 760SUBST_SED.paths+= -e 's,"/var/log,"${VARBASE}/log,g'
726SUBST_VARS.paths= LOCALBASE PREFIX PKGVERSION 761SUBST_VARS.paths= LOCALBASE PREFIX PKGVERSION
727</programlisting> 762</programlisting>
728 763
729<para>To get a complete picture about the SUBST substitutions, run 764<para>To get a complete picture about the SUBST substitutions, run
730<command>bmake show-all-subst</command>. If something doesn't work as 765<command>bmake show-all-subst</command>. If something doesn't work as
731expected, run pkglint on the package, which detects several typical 766expected, run pkglint on the package, which detects several typical
732mistakes surrounding the SUBST blocks. For any questions that might 767mistakes surrounding the SUBST blocks. For any questions that might
733remain after this, have a look at 768remain after this, have a look at
734<filename>mk/subst.mk</filename>.</para> 769<filename>mk/subst.mk</filename>.</para>
735 770
736<sect3 id="fixes.subst.when"> 771<sect3 id="fixes.subst.when">
737<title>Choosing the time where the substitutions happen</title> 772<title>Choosing the time where the substitutions happen</title>
738 773
739<para>The <varname>SUBST_STAGE.*</varname> is one of 774<para>The <varname>SUBST_STAGE.*</varname> is one of
740{pre,do,post}-{extract,patch,configure,build,test,install}. Of these, 775{pre,do,post}-{extract,patch,configure,build,test,install}. Of these,
741<literal>pre-configure</literal> is used most often, by far. The most 776<literal>pre-configure</literal> is used most often, by far. The most
742popular stages are, in chronological order:</para> 777popular stages are, in chronological order:</para>
743 778
744<variablelist> 779<variablelist>
745 780
746<varlistentry><term><literal>post-extract</literal></term> 781<varlistentry><term><literal>post-extract</literal></term>
747<listitem><para>The substitutions are applied immediately after the 782<listitem><para>The substitutions are applied immediately after the
748distfiles are extracted. Running <command>bmake extract</command> on the 783distfiles are extracted. Running <command>bmake extract</command> on the
749package will leave no traces of the original files.</para> 784package will leave no traces of the original files.</para>
750 785
751<para>When the substitution applies to files for which there is also a 786<para>When the substitution applies to files for which there is also a
752patch in the <filename>patches/</filename> directory, this means that the 787patch in the <filename>patches/</filename> directory, this means that the
753patches will be computed based on the result of the substitution. When 788patches will be computed based on the result of the substitution. When
754these patches are sent to the upstream maintainer later, to be fixed in 789these patches are sent to the upstream maintainer later, to be fixed in
755the upstream package, these patches may no longer match what the upstream 790the upstream package, these patches may no longer match what the upstream
756author is used to. Because of this, <literal>pre-configure</literal> is 791author is used to. Because of this, <literal>pre-configure</literal> is
757often a better choice.</para></listitem></varlistentry> 792often a better choice.</para></listitem></varlistentry>
758 793
759<varlistentry><term><literal>pre-configure</literal></term> 794<varlistentry><term><literal>pre-configure</literal></term>
760<listitem><para>The substitutions are applied after the patches from the 795<listitem><para>The substitutions are applied after the patches from the
761<filename>patches/</filename> directory. This makes it possible to run 796<filename>patches/</filename> directory. This makes it possible to run
762<command>bmake patch</command> on the package, after which the patches 797<command>bmake patch</command> on the package, after which the patches
763can be edited using the tools pkgvi and mkpatches from the <filename 798can be edited using the tools pkgvi and mkpatches from the <filename
764role="pkg">pkgtools/pkgdiff</filename> package.</para> 799role="pkg">pkgtools/pkgdiff</filename> package.</para>
765 800
766<para>When updating the patches, it is helpful to explicitly separate the 801<para>When updating the patches, it is helpful to explicitly separate the
767<command>bmake patch</command> from the <command>bmake 802<command>bmake patch</command> from the <command>bmake
768configure</command>, and to only edit the patches between these commands. 803configure</command>, and to only edit the patches between these commands.
769Otherwise the substitutions from the SUBST block will end up in the patch 804Otherwise the substitutions from the SUBST block will end up in the patch
770file. When this happens in really obvious ways, pkglint will complain 805file. When this happens in really obvious ways, pkglint will complain
771about patches that contain a hard-coded <literal>/usr/pkg</literal> 806about patches that contain a hard-coded <literal>/usr/pkg</literal>
772instead of the correct and intended <literal>@PREFIX@</literal>, but it 807instead of the correct and intended <literal>@PREFIX@</literal>, but it
773can only detect these really obvious 808can only detect these really obvious
774cases.</para></listitem></varlistentry> 809cases.</para></listitem></varlistentry>
775 810
776<varlistentry><term><literal>do-configure</literal></term> 811<varlistentry><term><literal>do-configure</literal></term>
777<listitem><para>This stage should only be used if the package defines a 812<listitem><para>This stage should only be used if the package defines a
778<literal>pre-configure</literal> action itself, and the substitution must 813<literal>pre-configure</literal> action itself, and the substitution must
779happen after that. Typical examples are packages that use the 814happen after that. Typical examples are packages that use the
780<literal>pre-configure</literal> stage to regenerate the GNU configure 815<literal>pre-configure</literal> stage to regenerate the GNU configure
781script from 816script from
782<filename>configure.ac</filename>.</para></listitem></varlistentry> 817<filename>configure.ac</filename>.</para></listitem></varlistentry>
783 818
784<varlistentry><term><literal>post-configure</literal></term> 819<varlistentry><term><literal>post-configure</literal></term>
785<listitem><para>This stage is used to fix up any mistakes by the 820<listitem><para>This stage is used to fix up any mistakes by the
786configure stage.</para></listitem></varlistentry> 821configure stage.</para></listitem></varlistentry>
787 822
788<varlistentry><term><literal>pre-build</literal></term> 823<varlistentry><term><literal>pre-build</literal></term>
789<listitem><para>This stage should only be used for substitutions that are 824<listitem><para>This stage should only be used for substitutions that are
790clearly related to building the package, not for fixing the 825clearly related to building the package, not for fixing the
791configuration. Substitutions for pathnames (such as replacing 826configuration. Substitutions for pathnames (such as replacing
792<filename>/usr/local</filename> with <literal>${PREFIX}</literal>) or 827<filename>/usr/local</filename> with <literal>${PREFIX}</literal>) or
793user names (such as replacing <literal>@MY_USER@</literal> with the 828user names (such as replacing <literal>@MY_USER@</literal> with the
794actual username) belong in pre-configure or post-configure 829actual username) belong in pre-configure or post-configure
795instead.</para></listitem></varlistentry> 830instead.</para></listitem></varlistentry>
796 831
797<varlistentry><term><literal>post-build</literal></term> 832<varlistentry><term><literal>post-build</literal></term>
798<listitem><para>Just as with pre-build, this stage should only be used 833<listitem><para>Just as with pre-build, this stage should only be used
799for substitutions that are clearly related to building the package, not 834for substitutions that are clearly related to building the package, not
800for fixing the configuration. Substitutions for pathnames (such as 835for fixing the configuration. Substitutions for pathnames (such as
801replacing <filename>/usr/local</filename> with 836replacing <filename>/usr/local</filename> with
802<literal>${PREFIX}</literal>) or user names (such as replacing 837<literal>${PREFIX}</literal>) or user names (such as replacing
803<literal>@MY_USER@</literal> with the actual username) belong in 838<literal>@MY_USER@</literal> with the actual username) belong in
804pre-configure or post-configure instead.</para> 839pre-configure or post-configure instead.</para>
805 840
806<para>A typical use is to update pkg-config files to include the rpath 841<para>A typical use is to update pkg-config files to include the rpath
807compiler options.</para></listitem></varlistentry> 842compiler options.</para></listitem></varlistentry>
808 843
809<varlistentry><term><literal>pre-install</literal></term> 844<varlistentry><term><literal>pre-install</literal></term>
810<listitem><para>In general, the install phase should be as simple as 845<listitem><para>In general, the install phase should be as simple as
811possible. As with the pre-build and post-build stages, it should not be 846possible. As with the pre-build and post-build stages, it should not be
812used to fix pathnames or user names, these belong in pre-configure 847used to fix pathnames or user names, these belong in pre-configure
813instead. There are only few legitimate use cases for applying 848instead. There are only few legitimate use cases for applying
814substitutions in this stage.</para></listitem></varlistentry> 849substitutions in this stage.</para></listitem></varlistentry>
815 850
816</variablelist> 851</variablelist>
817 852
818</sect3> 853</sect3>
819 854
820<sect3 id="fixes.subst.where"> 855<sect3 id="fixes.subst.where">
821<title>Choosing the files where the substitutions happen</title> 856<title>Choosing the files where the substitutions happen</title>
822 857
823<para>The <varname>SUBST_FILES.*</varname> variable contains a list of 858<para>The <varname>SUBST_FILES.*</varname> variable contains a list of
824filename patterns. These patterns are relative to 859filename patterns. These patterns are relative to
825<varname>WRKSRC</varname> since that is where most substitutions happen. 860<varname>WRKSRC</varname> since that is where most substitutions happen.
826A typical example is:</para> 861A typical example is:</para>
827 862
828<programlisting> 863<programlisting>
829SUBST_FILES.path= Makefile */Makefile */*/Makefile *.[ch] 864SUBST_FILES.path= Makefile */Makefile */*/Makefile *.[ch]
830</programlisting> 865</programlisting>
831 866
832 867
833<para>The above patterns, especially the last, are quite broad. The SUBST 868<para>The above patterns, especially the last, are quite broad. The SUBST
834implementation checks that each filename pattern that is mentioned here 869implementation checks that each filename pattern that is mentioned here
835has an effect. For example, if none of the 870has an effect. For example, if none of the
836<filename>*/*/Makefile</filename> files contains the patterns to be found 871<filename>*/*/Makefile</filename> files contains the patterns to be found
837and substituted, that filename pattern is redundant and should be left 872and substituted, that filename pattern is redundant and should be left
838out. By default, the SUBST framework will complain with an error message. 873out. By default, the SUBST framework will complain with an error message.
839If the text to be substituted occurs in some of the files from a single 874If the text to be substituted occurs in some of the files from a single
840pattern, but not in all of them, that is totally ok, and the SUBST 875pattern, but not in all of them, that is totally ok, and the SUBST
841framework will only print an INFO message for those files.</para> 876framework will only print an INFO message for those files.</para>
842 877
843<para>If there is a good reason for having redundant filename patterns, 878<para>If there is a good reason for having redundant filename patterns,
844set <varname>SUBST_NOOP_OK.*</varname> to <literal>yes</literal>.</para> 879set <varname>SUBST_NOOP_OK.*</varname> to <literal>yes</literal>.</para>
845 880
846<para>Another popular way of choosing the files for the substitutions is 881<para>Another popular way of choosing the files for the substitutions is
847via a shell command, like this:</para> 882via a shell command, like this:</para>
848 883
849<programlisting> 884<programlisting>
850C_FILES_CMD= cd ${WRKSRC} &amp;&amp; ${FIND} . -name '*.c' 885C_FILES_CMD= cd ${WRKSRC} &amp;&amp; ${FIND} . -name '*.c'
851SUBST_FILES.path= ${C_FILES_CMD:sh} 886SUBST_FILES.path= ${C_FILES_CMD:sh}
852</programlisting> 887</programlisting>
853 888
854<para>The variable name <varname>C_FILES_CMD</varname> in this example is 889<para>The variable name <varname>C_FILES_CMD</varname> in this example is
855freely chosen and independent of the SUBST framework.</para> 890freely chosen and independent of the SUBST framework.</para>
856 891
857<para>In this variant, the <varname>SUBST_FILES.*</varname> variable 892<para>In this variant, the <varname>SUBST_FILES.*</varname> variable
858lists each file individually. Thereby chances are higher that there are 893lists each file individually. Thereby chances are higher that there are
859filename patterns in which no substitution happens. Since the SUBST 894filename patterns in which no substitution happens. Since the SUBST
860framework cannot know whether the filename patterns in 895framework cannot know whether the filename patterns in
861<varname>SUBST_FILES.*</varname> have been explicitly listed in the 896<varname>SUBST_FILES.*</varname> have been explicitly listed in the
862Makefile (where any redundant filename pattern would be suspicious) or 897Makefile (where any redundant filename pattern would be suspicious) or
863been generated by a shell command (in which redundant filename patterns 898been generated by a shell command (in which redundant filename patterns
864are more likely and to be expected), it will complain about these 899are more likely and to be expected), it will complain about these
865redundant filename patterns. Therefore, SUBST blocks that use a shell 900redundant filename patterns. Therefore, SUBST blocks that use a shell
866command to generate the list of filename patterns often need to set 901command to generate the list of filename patterns often need to set
867<varname>SUBST_NOOP_OK.*</varname> to <literal>yes</literal>.</para> 902<varname>SUBST_NOOP_OK.*</varname> to <literal>yes</literal>.</para>
868 903
869</sect3> 904</sect3>
870 905
871<sect3 id="fixes.subst.what"> 906<sect3 id="fixes.subst.what">
872<title>Choosing what to substitute</title> 907<title>Choosing what to substitute</title>
873 908
874<para>In most cases, the substitutions are given using one or more 909<para>In most cases, the substitutions are given using one or more
875&man.sed.1; commands, like this:</para> 910&man.sed.1; commands, like this:</para>
876 911
877<programlisting> 912<programlisting>
878SUBST_SED.path= -e 's|/usr/local|${PREFIX}|g' 913SUBST_SED.path= -e 's|/usr/local|${PREFIX}|g'
879</programlisting> 914</programlisting>
880 915
881<para>Each of the sed commands needs to be preceded by the 916<para>Each of the sed commands needs to be preceded by the
882<literal>-e</literal> option and should be specified on a line of its 917<literal>-e</literal> option and should be specified on a line of its
883own, to avoid hiding short sed commands at the end of a line.</para> 918own, to avoid hiding short sed commands at the end of a line.</para>
884 919
885<para>Since the sed commands often contain shell metacharacters as the 920<para>Since the sed commands often contain shell metacharacters as the
886separator (the <literal>|</literal> in the above example), it is common 921separator (the <literal>|</literal> in the above example), it is common
887to enclose them in single quotes.</para> 922to enclose them in single quotes.</para>
888 923
889<para>A common substitution is to replace placeholders of the form 924<para>A common substitution is to replace placeholders of the form
890<literal>@VARNAME@</literal> with their pkgsrc counterpart variable 925<literal>@VARNAME@</literal> with their pkgsrc counterpart variable
891<literal>${VARNAME}</literal>. A typical example is:</para> 926<literal>${VARNAME}</literal>. A typical example is:</para>
892 927
893<programlisting> 928<programlisting>
894SUBST_VARS.path= PREFIX 929SUBST_VARS.path= PREFIX
895</programlisting> 930</programlisting>
896 931
897<para>This type of substitutions is typically done by the GNU configure 932<para>This type of substitutions is typically done by the GNU configure
898scripts during the do-configure stage, but in some cases these need to be 933scripts during the do-configure stage, but in some cases these need to be
899overridden. The same pattern is also used when a package defines patches 934overridden. The same pattern is also used when a package defines patches
900that replace previously hard-coded paths like 935that replace previously hard-coded paths like
901<literal>/usr/local</literal> with a <literal>@PREFIX@</literal> 936<literal>/usr/local</literal> with a <literal>@PREFIX@</literal>
902placeholder first, which then gets substituted by the actual 937placeholder first, which then gets substituted by the actual
903<literal>${PREFIX}</literal> in the pre-configure stage. In many of these 938<literal>${PREFIX}</literal> in the pre-configure stage. In many of these
904cases, it works equally well to just use the SUBST framework to directly 939cases, it works equally well to just use the SUBST framework to directly
905replace <literal>/usr/local</literal> with <literal>${PREFIX}</literal>, 940replace <literal>/usr/local</literal> with <literal>${PREFIX}</literal>,
906thereby omitting the intermediate patch file.</para> 941thereby omitting the intermediate patch file.</para>
907 942
908<para>If the above is not flexible enough, it is possible to not use sed 943<para>If the above is not flexible enough, it is possible to not use sed
909at all for the substitution but to specify an entirely different command, 944at all for the substitution but to specify an entirely different command,
910like this:</para> 945like this:</para>
911 946
912<programlisting> 947<programlisting>
913SUBST_FILTER_CMD.path= LC_ALL=C ${TR} -d '\r' 948SUBST_FILTER_CMD.path= LC_ALL=C ${TR} -d '\r'
914</programlisting> 949</programlisting>
915 950
916<para>This is used for the few remaining packages in which the 951<para>This is used for the few remaining packages in which the
917distributed files use Windows-style line endings that need to be 952distributed files use Windows-style line endings that need to be
918converted to UNIX-style line endings.</para> 953converted to UNIX-style line endings.</para>
919 954
920</sect3> 955</sect3>
921 956
922<sect3 id="fixes.subst.other"> 957<sect3 id="fixes.subst.other">
923<title>Other SUBST variables</title> 958<title>Other SUBST variables</title>
924 959
925<para>When a SUBST block is applied during a package build, a message is 960<para>When a SUBST block is applied during a package build, a message is
926logged. The default message is fine for most purposes but can be 961logged. The default message is fine for most purposes but can be
927overridden by setting <literal>SUBST_MESSAGE.*</literal> to an individual 962overridden by setting <literal>SUBST_MESSAGE.*</literal> to an individual
928message.</para> 963message.</para>
929 964
930</sect3> 965</sect3>
931 966
932</sect2> 967</sect2>
933 968
934</sect1> 969</sect1>
935 970
936<sect1 id="fixes.fetch"> 971<sect1 id="fixes.fetch">
937 <title>The <emphasis>fetch</emphasis> phase</title> 972 <title>The <emphasis>fetch</emphasis> phase</title>
938 973
939 <sect2 id="no-plain-download"> 974 <sect2 id="no-plain-download">
940 <title>Packages whose distfiles aren't available for plain downloading</title> 975 <title>Packages whose distfiles aren't available for plain downloading</title>
941 976
942 <para>If you need to download from a dynamic URL you can set 977 <para>If you need to download from a dynamic URL you can set
943 <varname>DYNAMIC_MASTER_SITES</varname> and a <command>make 978 <varname>DYNAMIC_MASTER_SITES</varname> and a <command>make
944 fetch</command> will call <filename>files/getsite.sh</filename> 979 fetch</command> will call <filename>files/getsite.sh</filename>
945 with the name of each file to download as an argument, expecting 980 with the name of each file to download as an argument, expecting
946 it to output the URL of the directory from which to download 981 it to output the URL of the directory from which to download
947 it. <filename role="pkg">graphics/ns-cult3d</filename> is an 982 it. <filename role="pkg">graphics/ns-cult3d</filename> is an
948 example of this usage.</para> 983 example of this usage.</para>
949 984
950 <para>If the download can't be automated, because the user must 985 <para>If the download can't be automated, because the user must
951 submit personal information to apply for a password, or must pay 986 submit personal information to apply for a password, or must pay
952 for the source, or whatever, you can set 987 for the source, or whatever, you can set
953 <varname>FETCH_MESSAGE</varname> to a list of lines that are 988 <varname>FETCH_MESSAGE</varname> to a list of lines that are
954 displayed to the user before aborting the build. Example:</para> 989 displayed to the user before aborting the build. Example:</para>
955 990
956<programlisting> 991<programlisting>
957FETCH_MESSAGE= "Please download the files" 992FETCH_MESSAGE= "Please download the files"
958FETCH_MESSAGE+= " "${DISTFILES:Q} 993FETCH_MESSAGE+= " "${DISTFILES:Q}
959FETCH_MESSAGE+= "manually from "${MASTER_SITES:Q}"." 994FETCH_MESSAGE+= "manually from "${MASTER_SITES:Q}"."
960</programlisting> 995</programlisting>
961 996
962 </sect2> 997 </sect2>
963 998
964 999
965 <sect2 id="modified-distfiles-same-name"> 1000 <sect2 id="modified-distfiles-same-name">
966 <title>How to handle modified distfiles with the 'old' name</title> 1001 <title>How to handle modified distfiles with the 'old' name</title>
967 1002
968 <para>Sometimes authors of a software package make some 1003 <para>Sometimes authors of a software package make some
969 modifications after the software was released, and they put up a 1004 modifications after the software was released, and they put up a
970 new distfile without changing the package's version number. If a 1005 new distfile without changing the package's version number. If a
971 package is already in pkgsrc at that time, the checksum will 1006 package is already in pkgsrc at that time, the checksum will
972 no longer match. The contents of the new distfile should be 1007 no longer match. The contents of the new distfile should be
973 compared against the old one before changing anything, to make 1008 compared against the old one before changing anything, to make
974 sure the distfile was really updated on purpose, and that 1009 sure the distfile was really updated on purpose, and that
975 no trojan horse or so crept in. 1010 no trojan horse or so crept in.
976 Please mention that the distfiles were compared and what was found 1011 Please mention that the distfiles were compared and what was found
977 in your commit message.</para> 1012 in your commit message.</para>
978 <para>Then, the correct way to work around this is to set 1013 <para>Then, the correct way to work around this is to set
979 <varname>DIST_SUBDIR</varname> to a unique directory name, usually 1014 <varname>DIST_SUBDIR</varname> to a unique directory name, usually
980 based on <varname>PKGNAME_NOREV</varname> (but take care with 1015 based on <varname>PKGNAME_NOREV</varname> (but take care with
981 python or ruby packages, where <varname>PKGNAME</varname> includes 1016 python or ruby packages, where <varname>PKGNAME</varname> includes
982 a variable prefix). All <varname>DISTFILES</varname> and 1017 a variable prefix). All <varname>DISTFILES</varname> and
983 <varname>PATCHFILES</varname> for this package will be put in that 1018 <varname>PATCHFILES</varname> for this package will be put in that
984 subdirectory of the local distfiles directory. (See <xref 1019 subdirectory of the local distfiles directory. (See <xref
985 linkend="bumping-pkgrevision"/> for more details.) In case this 1020 linkend="bumping-pkgrevision"/> for more details.) In case this
986 happens more often, <varname>PKGNAME</varname> can be used (thus 1021 happens more often, <varname>PKGNAME</varname> can be used (thus
987 including the <filename>nbX</filename> suffix) or a date stamp can 1022 including the <filename>nbX</filename> suffix) or a date stamp can
988 be appended, like 1023 be appended, like
989 <varname>${PKGNAME_NOREV}-YYYYMMDD</varname>.</para> 1024 <varname>${PKGNAME_NOREV}-YYYYMMDD</varname>.</para>
990 1025
991 <para><varname>DIST_SUBDIR</varname> is also used when a distfile's 1026 <para><varname>DIST_SUBDIR</varname> is also used when a distfile's
992 name does not contain a version and the distfile is apt to change. In 1027 name does not contain a version and the distfile is apt to change. In
993 cases where the likelihood of this is very small, 1028 cases where the likelihood of this is very small,
994 <varname>DIST_SUBDIR</varname> might not be required. Additionally, 1029 <varname>DIST_SUBDIR</varname> might not be required. Additionally,
995 <varname>DIST_SUBDIR</varname> must not be removed unless the 1030 <varname>DIST_SUBDIR</varname> must not be removed unless the
996 distfile name changes, even if a package is being moved or 1031 distfile name changes, even if a package is being moved or
997 renamed.</para> 1032 renamed.</para>
998 1033
999 <para>Do not forget regenerating the <filename>distinfo</filename> file 1034 <para>Do not forget regenerating the <filename>distinfo</filename> file
1000 after that, since it contains the <varname>DIST_SUBDIR</varname> 1035 after that, since it contains the <varname>DIST_SUBDIR</varname>
1001 path in the filenames. 1036 path in the filenames.
1002 Also, increase the PKGREVISION if the installed package is different. 1037 Also, increase the PKGREVISION if the installed package is different.
1003 Furthermore, a mail to the package's authors seems appropriate 1038 Furthermore, a mail to the package's authors seems appropriate
1004 telling them that changing distfiles after releases without 1039 telling them that changing distfiles after releases without
1005 changing the file names is not good practice.</para> 1040 changing the file names is not good practice.</para>
1006 </sect2> 1041 </sect2>
1007 1042
1008 <sect2 id="build.fetch.github"> 1043 <sect2 id="build.fetch.github">
1009 <title>Packages hosted on github.com</title> 1044 <title>Packages hosted on github.com</title>
1010 1045
1011 <para>Helper methods exist for packages hosted on github.com which 1046 <para>Helper methods exist for packages hosted on github.com which
1012 will often have distfile names that clash with other packages, for 1047 will often have distfile names that clash with other packages, for
1013 example <filename>1.0.tar.gz</filename>. Use one of the three recipes 1048 example <filename>1.0.tar.gz</filename>. Use one of the three recipes
1014 from below:</para> 1049 from below:</para>
1015 1050
1016 <sect3 id="build.fetch.github.tag"> 1051 <sect3 id="build.fetch.github.tag">
1017 <title>Fetch based on a tagged release</title> 1052 <title>Fetch based on a tagged release</title>
1018 1053
1019 <para>If your distfile URL looks similar to 1054 <para>If your distfile URL looks similar to
1020 <literal>https://github.com/username/example/archive/v1.0.zip</literal>, 1055 <literal>https://github.com/username/example/archive/v1.0.zip</literal>,
1021 then you are packaging a tagged release.</para> 1056 then you are packaging a tagged release.</para>
1022 1057
1023<programlisting> 1058<programlisting>
1024DISTNAME= example-1.0 1059DISTNAME= example-1.0
1025MASTER_SITES= ${MASTER_SITE_GITHUB:=username/} 1060MASTER_SITES= ${MASTER_SITE_GITHUB:=username/}
1026#GITHUB_PROJECT= example # can be omitted if same as DISTNAME 1061#GITHUB_PROJECT= example # can be omitted if same as DISTNAME
1027GITHUB_TAG= v${PKGVERSION_NOREV} 1062GITHUB_TAG= v${PKGVERSION_NOREV}
1028EXTRACT_SUFX= .zip 1063EXTRACT_SUFX= .zip
1029</programlisting> 1064</programlisting>
1030 1065
1031 </sect3> 1066 </sect3>
1032 1067
1033 <sect3 id="build.fetch.github.commit.prerelease"> 1068 <sect3 id="build.fetch.github.commit.prerelease">
1034 <title>Fetch based on a specific commit before the first release</title> 1069 <title>Fetch based on a specific commit before the first release</title>
1035 1070
1036 <para>If your distfile looks similar to 1071 <para>If your distfile looks similar to
1037 <literal>https://github.com/username/example/archive/988881adc9fc3655077dc2d4d757d480b5ea0e11</literal> and is from a commit before the first 1072 <literal>https://github.com/username/example/archive/988881adc9fc3655077dc2d4d757d480b5ea0e11</literal> and is from a commit before the first
1038 release, then set the package version to 0.0.0.N, where N is the number 1073 release, then set the package version to 0.0.0.N, where N is the number
1039 of commits to the repository, and set GITHUB_TAG to the commit hash. 1074 of commits to the repository, and set GITHUB_TAG to the commit hash.
1040 This will (almost) ensure that the first tagged release will have a 1075 This will (almost) ensure that the first tagged release will have a
1041 version greater than this one so that package upgrades will function 1076 version greater than this one so that package upgrades will function
1042 properly.</para> 1077 properly.</para>
1043 1078
1044<programlisting> 1079<programlisting>
1045DISTNAME= example-0.0.0.347 1080DISTNAME= example-0.0.0.347
1046MASTER_SITES= ${MASTER_SITE_GITHUB:=username/} 1081MASTER_SITES= ${MASTER_SITE_GITHUB:=username/}
1047#GITHUB_PROJECT= example # can be omitted if same as DISTNAME 1082#GITHUB_PROJECT= example # can be omitted if same as DISTNAME
1048GITHUB_TAG= 988881adc9fc3655077dc2d4d757d480b5ea0e11 1083GITHUB_TAG= 988881adc9fc3655077dc2d4d757d480b5ea0e11
1049</programlisting> 1084</programlisting>
1050 </sect3> 1085 </sect3>
1051 1086
1052 <sect3 id="build.fetch.github.commit.postrelease"> 1087 <sect3 id="build.fetch.github.commit.postrelease">
1053 <title>Fetch based on a specific commit after a release</title> 1088 <title>Fetch based on a specific commit after a release</title>
1054 1089
1055 <para>If your distfile looks similar to 1090 <para>If your distfile looks similar to
1056 <literal>https://github.com/username/example/archive/988881adc9fc3655077dc2d4d757d480b5ea0e11</literal> and is from a commit after a release, 1091 <literal>https://github.com/username/example/archive/988881adc9fc3655077dc2d4d757d480b5ea0e11</literal> and is from a commit after a release,
1057 then include the last release version and the commit count since that 1092 then include the last release version and the commit count since that
1058 release in the package version and set GITHUB_TAG to the commit hash. 1093 release in the package version and set GITHUB_TAG to the commit hash.
1059 The latest release and commit count are shown in the output of 1094 The latest release and commit count are shown in the output of
1060 "git describe --tags": 1095 "git describe --tags":
1061 </para> 1096 </para>
1062 1097
1063<screen> 1098<screen>
1064# git clone https://github.com/username/example 1099# git clone https://github.com/username/example
1065# cd example 1100# cd example
1066# git describe --tags 1101# git describe --tags
10671.2.3-5-g988881a 11021.2.3-5-g988881a
1068</screen> 1103</screen>
1069 1104
1070<programlisting> 1105<programlisting>
1071DISTNAME= example-1.2.3.5 1106DISTNAME= example-1.2.3.5
1072MASTER_SITES= ${MASTER_SITE_GITHUB:=username/} 1107MASTER_SITES= ${MASTER_SITE_GITHUB:=username/}
1073#GITHUB_PROJECT= example # can be omitted if same as DISTNAME 1108#GITHUB_PROJECT= example # can be omitted if same as DISTNAME
1074GITHUB_TAG= 988881adc9fc3655077dc2d4d757d480b5ea0e11 1109GITHUB_TAG= 988881adc9fc3655077dc2d4d757d480b5ea0e11
1075</programlisting> 1110</programlisting>
1076 </sect3> 1111 </sect3>
1077 1112
1078 <sect3 id="build.fetch.github.release"> 1113 <sect3 id="build.fetch.github.release">
1079 <title>Fetch based on release</title> 1114 <title>Fetch based on release</title>
1080 1115
1081 <para>If your distfile URL looks similar to 1116 <para>If your distfile URL looks similar to
1082 <literal>https://github.com/username/example/releases/download/rel-1.6/offensive-1.6.zip</literal>, 1117 <literal>https://github.com/username/example/releases/download/rel-1.6/offensive-1.6.zip</literal>,
1083 then you are packaging a release.</para> 1118 then you are packaging a release.</para>
1084 1119
1085<programlisting> 1120<programlisting>
1086DISTNAME= offensive-1.6 1121DISTNAME= offensive-1.6
1087PKGNAME= ${DISTNAME:S/offensive/proper/} 1122PKGNAME= ${DISTNAME:S/offensive/proper/}
1088MASTER_SITES= ${MASTER_SITE_GITHUB:=username/} 1123MASTER_SITES= ${MASTER_SITE_GITHUB:=username/}
1089GITHUB_PROJECT= example 1124GITHUB_PROJECT= example
1090GITHUB_RELEASE= rel-${PKGVERSION_NOREV} # usually just set this to ${DISTNAME} 1125GITHUB_RELEASE= rel-${PKGVERSION_NOREV} # usually just set this to ${DISTNAME}
1091EXTRACT_SUFX= .zip 1126EXTRACT_SUFX= .zip
1092</programlisting> 1127</programlisting>
1093 </sect3> 1128 </sect3>
1094 </sect2> 1129 </sect2>
1095</sect1> 1130</sect1>
1096 1131
1097 1132
1098<sect1 id="fixes.configure"> 1133<sect1 id="fixes.configure">
1099 <title>The <emphasis>configure</emphasis> phase</title> 1134 <title>The <emphasis>configure</emphasis> phase</title>
1100 1135
1101 <sect2 id="fixes.libtool"> 1136 <sect2 id="fixes.libtool">
1102 <title>Shared libraries - libtool</title> 1137 <title>Shared libraries - libtool</title>
1103 1138
1104 <para>pkgsrc supports many different machines, with different 1139 <para>pkgsrc supports many different machines, with different
1105 object formats like a.out and ELF, and varying abilities to do 1140 object formats like a.out and ELF, and varying abilities to do
1106 shared library and dynamic loading at all. To accompany this, 1141 shared library and dynamic loading at all. To accompany this,
1107 varying commands and options have to be passed to the 1142 varying commands and options have to be passed to the
1108 compiler, linker, etc. to get the Right Thing, which can be 1143 compiler, linker, etc. to get the Right Thing, which can be
1109 pretty annoying especially if you don't have all the machines 1144 pretty annoying especially if you don't have all the machines
1110 at your hand to test things. The 1145 at your hand to test things. The
1111 <filename role="pkg">devel/libtool</filename> pkg 1146 <filename role="pkg">devel/libtool</filename> pkg
1112 can help here, as it just <quote>knows</quote> how to build 1147 can help here, as it just <quote>knows</quote> how to build
1113 both static and dynamic libraries from a set of source files, 1148 both static and dynamic libraries from a set of source files,
1114 thus being platform-independent.</para> 1149 thus being platform-independent.</para>
1115 1150
1116 <para>Here's how to use libtool in a package in seven simple 1151 <para>Here's how to use libtool in a package in seven simple
1117 steps:</para> 1152 steps:</para>
1118 1153
1119 <orderedlist> 1154 <orderedlist>
1120 <listitem> 1155 <listitem>
1121 <para>Add <varname>USE_LIBTOOL=yes</varname> to the package 1156 <para>Add <varname>USE_LIBTOOL=yes</varname> to the package
1122 Makefile.</para> 1157 Makefile.</para>
1123 </listitem> 1158 </listitem>
1124 1159
1125 <listitem> 1160 <listitem>
1126 <para>For library objects, use <quote>${LIBTOOL} --mode=compile 1161 <para>For library objects, use <quote>${LIBTOOL} --mode=compile
1127 ${CC}</quote> in place of <quote>${CC}</quote>. You could even 1162 ${CC}</quote> in place of <quote>${CC}</quote>. You could even
1128 add it to the definition of <varname>CC</varname>, if only 1163 add it to the definition of <varname>CC</varname>, if only
1129 libraries are being built in a given Makefile. This one command 1164 libraries are being built in a given Makefile. This one command
1130 will build both PIC and non-PIC library objects, so you need not 1165 will build both PIC and non-PIC library objects, so you need not
1131 have separate shared and non-shared library rules.</para> 1166 have separate shared and non-shared library rules.</para>
1132 </listitem> 1167 </listitem>
1133 1168
1134 <listitem> 1169 <listitem>
1135 <para>For the linking of the library, remove any 1170 <para>For the linking of the library, remove any
1136 <quote>ar</quote>, <quote>ranlib</quote>, and <quote>ld 1171 <quote>ar</quote>, <quote>ranlib</quote>, and <quote>ld
1137 -Bshareable</quote> commands, and instead use:</para> 1172 -Bshareable</quote> commands, and instead use:</para>
1138 1173
1139<programlisting> 1174<programlisting>
1140${LIBTOOL} --mode=link \ 1175${LIBTOOL} --mode=link \
1141 ${CC} -o ${.TARGET:.a=.la} \ 1176 ${CC} -o ${.TARGET:.a=.la} \
1142 ${OBJS:.o=.lo} \ 1177 ${OBJS:.o=.lo} \
1143 -rpath ${PREFIX}/lib \ 1178 -rpath ${PREFIX}/lib \
1144 -version-info major:minor 1179 -version-info major:minor
1145</programlisting> 1180</programlisting>
1146 1181
1147 <para>Note that the library is changed to have a 1182 <para>Note that the library is changed to have a
1148 <filename>.la</filename> extension, and the objects are 1183 <filename>.la</filename> extension, and the objects are
1149 changed to have a <filename>.lo</filename> 1184 changed to have a <filename>.lo</filename>
1150 extension. Change <varname>OBJS</varname> as 1185 extension. Change <varname>OBJS</varname> as
1151 necessary. This automatically creates all of the 1186 necessary. This automatically creates all of the
1152 <filename>.a</filename>, 1187 <filename>.a</filename>,
1153 <filename>.so.major.minor</filename>, and ELF symlinks (if 1188 <filename>.so.major.minor</filename>, and ELF symlinks (if
1154 necessary) in the build directory. Be sure to include 1189 necessary) in the build directory. Be sure to include
1155 <quote>-version-info</quote>, especially when major and 1190 <quote>-version-info</quote>, especially when major and
1156 minor are zero, as libtool will otherwise strip off the 1191 minor are zero, as libtool will otherwise strip off the
1157 shared library version.</para> 1192 shared library version.</para>
1158 1193
1159 <para>From the libtool manual:</para> 1194 <para>From the libtool manual:</para>
1160 1195
1161<programlisting> 1196<programlisting>
1162So, libtool library versions are described by three integers: 1197So, libtool library versions are described by three integers:
1163 1198
1164CURRENT 1199CURRENT
1165The most recent interface number that this library implements. 1200The most recent interface number that this library implements.
1166 1201
1167REVISION 1202REVISION
1168The implementation number of the CURRENT interface. 1203The implementation number of the CURRENT interface.
1169 1204
1170AGE 1205AGE
1171The difference between the newest and oldest interfaces that 1206The difference between the newest and oldest interfaces that
1172this library implements. In other words, the library implements 1207this library implements. In other words, the library implements
1173all the interface numbers in the range from number `CURRENT - 1208all the interface numbers in the range from number `CURRENT -
1174AGE' to `CURRENT'. 1209AGE' to `CURRENT'.
1175 1210
1176If two libraries have identical CURRENT and AGE numbers, then the 1211If two libraries have identical CURRENT and AGE numbers, then the
1177dynamic linker chooses the library with the greater REVISION number. 1212dynamic linker chooses the library with the greater REVISION number.
1178</programlisting> 1213</programlisting>
1179 1214
1180 <para>The <quote>-release</quote> option will produce 1215 <para>The <quote>-release</quote> option will produce
1181 different results for a.out and ELF (excluding symlinks) 1216 different results for a.out and ELF (excluding symlinks)
1182 in only one case. An ELF library of the form 1217 in only one case. An ELF library of the form
1183 <quote>libfoo-release.so.<emphasis>x</emphasis>.<emphasis>y</emphasis></quote> 1218 <quote>libfoo-release.so.<emphasis>x</emphasis>.<emphasis>y</emphasis></quote>
1184 will have a symlink of 1219 will have a symlink of
1185 <quote>libfoo.so.<emphasis>x</emphasis>.<emphasis>y</emphasis></quote> 1220 <quote>libfoo.so.<emphasis>x</emphasis>.<emphasis>y</emphasis></quote>
1186 on an a.out platform. This is handled 1221 on an a.out platform. This is handled
1187 automatically.</para> 1222 automatically.</para>
1188 1223
1189 <para>The <quote>-rpath argument</quote> is the install 1224 <para>The <quote>-rpath argument</quote> is the install
1190 directory of the library being built.</para> 1225 directory of the library being built.</para>
1191 1226
1192 <para>In the <filename>PLIST</filename>, include only the 1227 <para>In the <filename>PLIST</filename>, include only the
1193 <filename>.la</filename> file, the other files will be 1228 <filename>.la</filename> file, the other files will be
1194 added automatically.</para> 1229 added automatically.</para>
1195 </listitem> 1230 </listitem>
1196 1231
1197 <listitem> 1232 <listitem>
1198 <para>When linking shared object (<filename>.so</filename>) 1233 <para>When linking shared object (<filename>.so</filename>)
1199 files, i.e. files that are loaded via &man.dlopen.3;, NOT 1234 files, i.e. files that are loaded via &man.dlopen.3;, NOT
1200 shared libraries, use <quote>-module 1235 shared libraries, use <quote>-module
1201 -avoid-version</quote> to prevent them getting version 1236 -avoid-version</quote> to prevent them getting version
1202 tacked on.</para> 1237 tacked on.</para>
1203 1238
1204 <para>The <filename>PLIST</filename> file gets the 1239 <para>The <filename>PLIST</filename> file gets the
1205 <filename>foo.so</filename> entry.</para> 1240 <filename>foo.so</filename> entry.</para>
1206 </listitem> 1241 </listitem>
1207 1242
1208 <listitem> 1243 <listitem>
1209 <para>When linking programs that depend on these libraries 1244 <para>When linking programs that depend on these libraries
1210 <emphasis>before</emphasis> they are installed, preface 1245 <emphasis>before</emphasis> they are installed, preface
1211 the &man.cc.1; or &man.ld.1; line with <quote>${LIBTOOL} 1246 the &man.cc.1; or &man.ld.1; line with <quote>${LIBTOOL}
1212 --mode=link</quote>, and it will find the correct 1247 --mode=link</quote>, and it will find the correct
1213 libraries (static or shared), but please be aware that 1248 libraries (static or shared), but please be aware that
1214 libtool will not allow you to specify a relative path in 1249 libtool will not allow you to specify a relative path in
1215 -L (such as <quote>-L../somelib</quote>), because it 1250 -L (such as <quote>-L../somelib</quote>), because it
1216 expects you to change that argument to be the 1251 expects you to change that argument to be the
1217 <filename>.la</filename> file. e.g.</para> 1252 <filename>.la</filename> file. e.g.</para>
1218 1253
1219<programlisting> 1254<programlisting>
1220${LIBTOOL} --mode=link ${CC} -o someprog -L../somelib -lsomelib 1255${LIBTOOL} --mode=link ${CC} -o someprog -L../somelib -lsomelib
1221</programlisting> 1256</programlisting>
1222 1257
1223 <para>should be changed to:</para> 1258 <para>should be changed to:</para>
1224 1259
1225<programlisting> 1260<programlisting>
1226${LIBTOOL} --mode=link ${CC} -o <replaceable>someprog</replaceable> <replaceable>../somelib/somelib.la</replaceable> 1261${LIBTOOL} --mode=link ${CC} -o <replaceable>someprog</replaceable> <replaceable>../somelib/somelib.la</replaceable>
1227</programlisting> 1262</programlisting>
1228 1263
1229 <para>and it will do the right thing with the libraries.</para> 1264 <para>and it will do the right thing with the libraries.</para>
1230 </listitem> 1265 </listitem>
1231 1266
1232 <listitem> 1267 <listitem>
1233 <para>When installing libraries, preface the &man.install.1; 1268 <para>When installing libraries, preface the &man.install.1;
1234 or &man.cp.1; command with <quote>${LIBTOOL} 1269 or &man.cp.1; command with <quote>${LIBTOOL}
1235 --mode=install</quote>, and change the library name to 1270 --mode=install</quote>, and change the library name to
1236 <filename>.la</filename>. e.g.</para> 1271 <filename>.la</filename>. e.g.</para>
1237 1272
1238<programlisting> 1273<programlisting>
1239${LIBTOOL} --mode=install ${BSD_INSTALL_LIB} ${SOMELIB:.a=.la} ${PREFIX}/lib 1274${LIBTOOL} --mode=install ${BSD_INSTALL_LIB} ${SOMELIB:.a=.la} ${PREFIX}/lib
1240</programlisting> 1275</programlisting>
1241 1276
1242 <para>This will install the static <filename>.a</filename>, 1277 <para>This will install the static <filename>.a</filename>,
1243 shared library, any needed symlinks, and run 1278 shared library, any needed symlinks, and run
1244 &man.ldconfig.8;.</para> 1279 &man.ldconfig.8;.</para>
1245 </listitem> 1280 </listitem>
1246 1281
1247 <listitem> 1282 <listitem>
1248 <para>In your <filename>PLIST</filename>, include only 1283 <para>In your <filename>PLIST</filename>, include only
1249 the <filename>.la</filename> 1284 the <filename>.la</filename>
1250 file (this is a change from previous behaviour).</para> 1285 file (this is a change from previous behaviour).</para>
1251 </listitem> 1286 </listitem>
1252 </orderedlist> 1287 </orderedlist>
1253 </sect2> 1288 </sect2>
1254 1289
1255 1290
1256 <sect2 id="using-libtool"> 1291 <sect2 id="using-libtool">
1257 <title>Using libtool on GNU packages that already support libtool</title> 1292 <title>Using libtool on GNU packages that already support libtool</title>
1258 1293
1259 <para>Add <varname>USE_LIBTOOL=yes</varname> to the 1294 <para>Add <varname>USE_LIBTOOL=yes</varname> to the
1260 package Makefile. This will override the package's own libtool 1295 package Makefile. This will override the package's own libtool
1261 in most cases. For older libtool using packages, libtool is 1296 in most cases. For older libtool using packages, libtool is
1262 made by ltconfig script during the do-configure step; you can 1297 made by ltconfig script during the do-configure step; you can
1263 check the libtool script location by doing <command>make 1298 check the libtool script location by doing <command>make
1264 configure; find work*/ -name libtool</command>.</para> 1299 configure; find work*/ -name libtool</command>.</para>
1265 1300
1266 <para><varname>LIBTOOL_OVERRIDE</varname> specifies which libtool 1301 <para><varname>LIBTOOL_OVERRIDE</varname> specifies which libtool
1267 scripts, relative to <varname>WRKSRC</varname>, to override. By 1302 scripts, relative to <varname>WRKSRC</varname>, to override. By
1268 default, it is set to <quote>libtool */libtool 1303 default, it is set to <quote>libtool */libtool
1269 */*/libtool</quote>. If this does not match the location of the 1304 */*/libtool</quote>. If this does not match the location of the
1270 package's libtool script(s), set it as appropriate.</para> 1305 package's libtool script(s), set it as appropriate.</para>
1271 1306
1272 <para>If you do not need <filename>*.a</filename> static 1307 <para>If you do not need <filename>*.a</filename> static
1273 libraries built and installed, then use 1308 libraries built and installed, then use
1274 <varname>SHLIBTOOL_OVERRIDE</varname> instead.</para> 1309 <varname>SHLIBTOOL_OVERRIDE</varname> instead.</para>
1275 1310
1276 <para>If your package makes use of the platform-independent library 1311 <para>If your package makes use of the platform-independent library
1277 for loading dynamic shared objects, that comes with libtool 1312 for loading dynamic shared objects, that comes with libtool
1278 (libltdl), you should include devel/libltdl/buildlink3.mk.</para> 1313 (libltdl), you should include devel/libltdl/buildlink3.mk.</para>
1279 1314
1280 <para>Some packages use libtool incorrectly so that the package 1315 <para>Some packages use libtool incorrectly so that the package
1281 may not work or build in some circumstances. Some of the more 1316 may not work or build in some circumstances. Some of the more
1282 common errors are:</para> 1317 common errors are:</para>
1283 1318
1284 <itemizedlist> 1319 <itemizedlist>
1285 <listitem> 1320 <listitem>
1286 <para>The inclusion of a shared object (-module) as a dependent library in an 1321 <para>The inclusion of a shared object (-module) as a dependent library in an
1287 executable or library. This in itself isn't a problem if one of two things 1322 executable or library. This in itself isn't a problem if one of two things
1288 has been done:</para> 1323 has been done:</para>
1289 1324
1290 <orderedlist> 1325 <orderedlist>
1291 <listitem> 1326 <listitem>
1292 <para>The shared object is named correctly, i.e. 1327 <para>The shared object is named correctly, i.e.
1293 <filename>libfoo.la</filename>, not 1328 <filename>libfoo.la</filename>, not
1294 <filename>foo.la</filename></para> 1329 <filename>foo.la</filename></para>
1295 </listitem> 1330 </listitem>
1296 1331
1297 <listitem> 1332 <listitem>
1298 <para>The -dlopen option is used when linking an executable.</para> 1333 <para>The -dlopen option is used when linking an executable.</para>
1299 </listitem> 1334 </listitem>
1300 </orderedlist> 1335 </orderedlist>
1301 </listitem> 1336 </listitem>
1302 1337
1303 <listitem> 1338 <listitem>
1304 <para>The use of libltdl without the correct calls to initialisation routines. 1339 <para>The use of libltdl without the correct calls to initialisation routines.
1305 The function lt_dlinit() should be called and the macro 1340 The function lt_dlinit() should be called and the macro
1306 <varname>LTDL_SET_PRELOADED_SYMBOLS</varname> included in 1341 <varname>LTDL_SET_PRELOADED_SYMBOLS</varname> included in
1307 executables.</para> 1342 executables.</para>
1308 </listitem> 1343 </listitem>
1309 </itemizedlist> 1344 </itemizedlist>
1310 </sect2> 1345 </sect2>
1311 1346
1312 1347
1313 <sect2 id="autoconf-automake"> 1348 <sect2 id="autoconf-automake">
1314 <title>GNU Autoconf/Automake</title> 1349 <title>GNU Autoconf/Automake</title>
1315 1350
1316 <para>If a package needs GNU autoconf or automake to be executed 1351 <para>If a package needs GNU autoconf or automake to be executed
1317 to regenerate the configure script and Makefile.in makefile 1352 to regenerate the configure script and Makefile.in makefile
1318 templates, then they should be executed in a pre-configure 1353 templates, then they should be executed in a pre-configure
1319 target.</para> 1354 target.</para>
1320 1355
1321 <para>For packages that need only autoconf:</para> 1356 <para>For packages that need only autoconf:</para>
1322 1357
1323<programlisting> 1358<programlisting>
1324AUTOCONF_REQD= 2.50 # if default version is not good enough 1359AUTOCONF_REQD= 2.50 # if default version is not good enough
1325USE_TOOLS+= autoconf # use "autoconf213" for autoconf-2.13 1360USE_TOOLS+= autoconf # use "autoconf213" for autoconf-2.13
1326... 1361...
1327 1362
1328pre-configure: 1363pre-configure:
1329 cd ${WRKSRC} &amp;&amp; autoconf 1364 cd ${WRKSRC} &amp;&amp; autoconf
1330 1365
1331... 1366...
1332</programlisting> 1367</programlisting>
1333 1368
1334 <para>and for packages that need automake and autoconf:</para> 1369 <para>and for packages that need automake and autoconf:</para>
1335 1370
1336<programlisting> 1371<programlisting>
1337AUTOMAKE_REQD= 1.7.1 # if default version is not good enough 1372AUTOMAKE_REQD= 1.7.1 # if default version is not good enough
1338USE_TOOLS+= automake # use "automake14" for automake-1.4 1373USE_TOOLS+= automake # use "automake14" for automake-1.4
1339... 1374...
1340 1375
1341pre-configure: 1376pre-configure:
1342 set -e; cd ${WRKSRC}; \ 1377 set -e; cd ${WRKSRC}; \
1343 aclocal; autoheader; automake -a --foreign -i; autoconf 1378 aclocal; autoheader; automake -a --foreign -i; autoconf
1344 1379
1345... 1380...
1346</programlisting> 1381</programlisting>
1347 1382
1348 <para>Packages which use GNU Automake will almost certainly 1383 <para>Packages which use GNU Automake will almost certainly
1349 require GNU Make.</para> 1384 require GNU Make.</para>
1350 1385
1351 <para>There are times when the configure process makes 1386 <para>There are times when the configure process makes
1352 additional changes to the generated files, which then causes 1387 additional changes to the generated files, which then causes
1353 the build process to try to re-execute the automake sequence. 1388 the build process to try to re-execute the automake sequence.
1354 This is prevented by touching various files in the configure 1389 This is prevented by touching various files in the configure
1355 stage. If this causes problems with your package you can set 1390 stage. If this causes problems with your package you can set
1356 <varname>AUTOMAKE_OVERRIDE=NO</varname> in the package 1391 <varname>AUTOMAKE_OVERRIDE=NO</varname> in the package
1357 Makefile.</para> 1392 Makefile.</para>
1358 </sect2> 1393 </sect2>
1359</sect1> 1394</sect1>
1360 1395
1361<sect1 id="programming-languages"> 1396<sect1 id="programming-languages">
1362 <title>Programming languages</title> 1397 <title>Programming languages</title>
1363 1398
1364 <sect2 id="basic-programming-languages"> 1399 <sect2 id="basic-programming-languages">
1365 <title>C, C++, and Fortran</title> 1400 <title>C, C++, and Fortran</title>
1366 1401
1367 <para>Compilers for the C, C++, and Fortran languages comes with 1402 <para>Compilers for the C, C++, and Fortran languages comes with
1368 the NetBSD base system. By default, pkgsrc assumes that a package 1403 the NetBSD base system. By default, pkgsrc assumes that a package
1369 is written in C and will hide all other compilers (via the wrapper 1404 is written in C and will hide all other compilers (via the wrapper
1370 framework, see <xref linkend="buildlink" />).</para> 1405 framework, see <xref linkend="buildlink" />).</para>
1371 1406
1372 <para>To declare which language's compiler a package needs, set 1407 <para>To declare which language's compiler a package needs, set
1373 the <varname>USE_LANGUAGES</varname> variable. Allowed values 1408 the <varname>USE_LANGUAGES</varname> variable. Allowed values
1374 currently are <quote>c</quote>, <quote>c++</quote>, and 1409 currently are <quote>c</quote>, <quote>c++</quote>, and
1375 <quote>fortran</quote> (and any combination). The default is 1410 <quote>fortran</quote> (and any combination). The default is
1376 <quote>c</quote>. Packages using GNU configure scripts, even if 1411 <quote>c</quote>. Packages using GNU configure scripts, even if
1377 written in C++, usually need a C compiler for the configure 1412 written in C++, usually need a C compiler for the configure
1378 phase.</para> 1413 phase.</para>
1379 </sect2> 1414 </sect2>
1380 1415
1381 <sect2 id="java-programming-language"> 1416 <sect2 id="java-programming-language">
1382 <title>Java</title> 1417 <title>Java</title>
1383 1418
1384 <para>If a program is written in Java, use the Java framework in 1419 <para>If a program is written in Java, use the Java framework in
1385 pkgsrc. The package must include 1420 pkgsrc. The package must include
1386 <filename>../../mk/java-vm.mk</filename>. This Makefile fragment 1421 <filename>../../mk/java-vm.mk</filename>. This Makefile fragment
1387 provides the following variables:</para> 1422 provides the following variables:</para>
1388 1423
1389 <itemizedlist> 1424 <itemizedlist>
1390 <listitem><para><varname>USE_JAVA</varname> defines if a build 1425 <listitem><para><varname>USE_JAVA</varname> defines if a build
1391 dependency on the JDK is added. If 1426 dependency on the JDK is added. If
1392 <varname>USE_JAVA</varname> is set to <quote>run</quote>, then 1427 <varname>USE_JAVA</varname> is set to <quote>run</quote>, then
1393 there is only a runtime dependency on the JDK. The default is 1428 there is only a runtime dependency on the JDK. The default is
1394 <quote>yes</quote>, which also adds a build dependency on the 1429 <quote>yes</quote>, which also adds a build dependency on the
1395 JDK.</para></listitem> 1430 JDK.</para></listitem>
1396 1431
1397 <listitem><para>Set <varname>USE_JAVA2</varname> to declare that 1432 <listitem><para>Set <varname>USE_JAVA2</varname> to declare that
1398 a package needs a Java2 implementation. The supported values 1433 a package needs a Java2 implementation. The supported values
1399 are <quote>yes</quote>, <quote>1.4</quote>, and 1434 are <quote>yes</quote>, <quote>1.4</quote>, and
1400 <quote>1.5</quote>. <quote>yes</quote> accepts any Java2 1435 <quote>1.5</quote>. <quote>yes</quote> accepts any Java2
1401 implementation, <quote>1.4</quote> insists on versions 1.4 or 1436 implementation, <quote>1.4</quote> insists on versions 1.4 or
1402 above, and <quote>1.5</quote> only accepts versions 1.5 or 1437 above, and <quote>1.5</quote> only accepts versions 1.5 or
1403 above. This variable is not set by default.</para></listitem> 1438 above. This variable is not set by default.</para></listitem>
1404 1439
1405 <listitem><para><varname>PKG_JAVA_HOME</varname> is 1440 <listitem><para><varname>PKG_JAVA_HOME</varname> is
1406 automatically set to the runtime location of the used Java 1441 automatically set to the runtime location of the used Java
1407 implementation dependency. It may be used to set 1442 implementation dependency. It may be used to set
1408 <varname>JAVA_HOME</varname> to a good value if the program 1443 <varname>JAVA_HOME</varname> to a good value if the program
1409 needs this variable to be defined. 1444 needs this variable to be defined.
1410 </para></listitem> 1445 </para></listitem>
1411 <!-- XXX: describe PKG_JVM_DEFAULT and PKG_JVMS_ACCEPTED, but 1446 <!-- XXX: describe PKG_JVM_DEFAULT and PKG_JVMS_ACCEPTED, but
1412 not here --> 1447 not here -->
1413 </itemizedlist> 1448 </itemizedlist>
1414 </sect2> 1449 </sect2>
1415 1450
1416 <sect2 id="go-programming-language"> 1451 <sect2 id="go-programming-language">
1417 <title>Go</title> 1452 <title>Go</title>
1418 1453
1419 <para>If a program is written in Go and has any dependencies on 1454 <para>If a program is written in Go and has any dependencies on
1420 other Go modules, have the package include 1455 other Go modules, have the package include
1421 <filename>../../lang/go/go-module.mk</filename>.</para> 1456 <filename>../../lang/go/go-module.mk</filename>.</para>
1422 1457
1423 1458
1424 <orderedlist> 1459 <orderedlist>
1425 <listitem><para>Generate a list of those dependencies with 1460 <listitem><para>Generate a list of those dependencies with
1426 <command>make clean && make patch && make show-go-modules > 1461 <command>make clean && make patch && make show-go-modules >
1427 go-modules.mk</command>.</para></listitem> 1462 go-modules.mk</command>.</para></listitem>
1428 1463
1429 <listitem><para>Prepend <programlisting>.include 1464 <listitem><para>Prepend <programlisting>.include
1430 "go-modules.mk"</programlisting> to any other 1465 "go-modules.mk"</programlisting> to any other
1431 <programlisting>.include</programlisting>s.</para></listitem> 1466 <programlisting>.include</programlisting>s.</para></listitem>
1432 1467
1433 <listitem><para>Incorporate these modules in 1468 <listitem><para>Incorporate these modules in
1434 <filename>distinfo</filename> with <command>make 1469 <filename>distinfo</filename> with <command>make
1435 makesum</command>.</para></listitem> 1470 makesum</command>.</para></listitem>
1436 </orderedlist> 1471 </orderedlist>
1437 </sect2> 1472 </sect2>
1438 1473
1439 <sect2 id="perl-scripts"> 1474 <sect2 id="perl-scripts">
1440 <title>Packages containing Perl scripts</title> 1475 <title>Packages containing Perl scripts</title>
1441 1476
1442 <para>If your package contains interpreted Perl scripts, add 1477 <para>If your package contains interpreted Perl scripts, add
1443 <quote>perl</quote> to the <varname>USE_TOOLS</varname> variable 1478 <quote>perl</quote> to the <varname>USE_TOOLS</varname> variable
1444 and set <varname>REPLACE_PERL</varname> to ensure that the proper 1479 and set <varname>REPLACE_PERL</varname> to ensure that the proper
1445 interpreter path is set. <varname>REPLACE_PERL</varname> should 1480 interpreter path is set. <varname>REPLACE_PERL</varname> should
1446 contain a list of scripts, relative to <varname>WRKSRC</varname>, 1481 contain a list of scripts, relative to <varname>WRKSRC</varname>,
1447 that you want adjusted. Every occurrence of 1482 that you want adjusted. Every occurrence of
1448 <filename>*/bin/perl</filename> in a she-bang line will be 1483 <filename>*/bin/perl</filename> in a she-bang line will be
1449 replaced with the full path to the perl executable.</para> 1484 replaced with the full path to the perl executable.</para>
1450 1485
1451 <para>If a particular version of perl is needed, set the 1486 <para>If a particular version of perl is needed, set the
1452 <varname>PERL5_REQD</varname> variable to the version number. The 1487 <varname>PERL5_REQD</varname> variable to the version number. The
1453 default is <quote>5.0</quote>.</para> 1488 default is <quote>5.0</quote>.</para>
1454 1489
1455 <para>See <xref linkend="perl-modules" /> for information 1490 <para>See <xref linkend="perl-modules" /> for information
1456 about handling perl modules.</para> 1491 about handling perl modules.</para>
1457 </sect2> 1492 </sect2>
1458 1493
1459 <sect2 id="shell-scripts"> 1494 <sect2 id="shell-scripts">
1460 <title>Packages containing shell scripts</title> 1495 <title>Packages containing shell scripts</title>
1461 1496
1462 <para><varname>REPLACE_SH</varname>, 1497 <para><varname>REPLACE_SH</varname>,
1463 <varname>REPLACE_BASH</varname>, <varname>REPLACE_CSH</varname>, 1498 <varname>REPLACE_BASH</varname>, <varname>REPLACE_CSH</varname>,
1464 and <varname>REPLACE_KSH</varname> can be used to replace shell 1499 and <varname>REPLACE_KSH</varname> can be used to replace shell
1465 hash bangs in files. Please use the appropriate one, preferring 1500 hash bangs in files. Please use the appropriate one, preferring
1466 <varname>REPLACE_SH</varname> in case this shell is sufficient. 1501 <varname>REPLACE_SH</varname> in case this shell is sufficient.
1467 Each should contain a list of scripts, relative to 1502 Each should contain a list of scripts, relative to
1468 <varname>WRKSRC</varname>, that you want adjusted. Every 1503 <varname>WRKSRC</varname>, that you want adjusted. Every
1469 occurrence of the matching shell in a she-bang line will be 1504 occurrence of the matching shell in a she-bang line will be
1470 replaced with the full path to the shell executable. 1505 replaced with the full path to the shell executable.
1471 When using <varname>REPLACE_BASH</varname>, don't forget to add 1506 When using <varname>REPLACE_BASH</varname>, don't forget to add
1472 <filename>bash</filename> to <varname>USE_TOOLS</varname>.</para> 1507 <filename>bash</filename> to <varname>USE_TOOLS</varname>.</para>
1473 </sect2> 1508 </sect2>
1474 1509
1475 <sect2 id="other-programming-languages"> 1510 <sect2 id="other-programming-languages">
1476 <title>Other programming languages</title> 1511 <title>Other programming languages</title>
1477 1512
1478 <para>Currently, there is no special handling for other languages 1513 <para>Currently, there is no special handling for other languages
1479 in pkgsrc. If a compiler package provides a 1514 in pkgsrc. If a compiler package provides a
1480 <filename>buildlink3.mk</filename> file, include that, otherwise 1515 <filename>buildlink3.mk</filename> file, include that, otherwise
1481 just add a (build) dependency on the appropriate compiler 1516 just add a (build) dependency on the appropriate compiler
1482 package.</para> 1517 package.</para>
1483 </sect2> 1518 </sect2>
1484</sect1> 1519</sect1>
1485 1520
1486<sect1 id="fixes.build"> 1521<sect1 id="fixes.build">
1487 <title>The <emphasis>build</emphasis> phase</title> 1522 <title>The <emphasis>build</emphasis> phase</title>
1488 1523
1489 <para>The most common failures when building a package are that 1524 <para>The most common failures when building a package are that
1490 some platforms do not provide certain header files, functions or 1525 some platforms do not provide certain header files, functions or
1491 libraries, or they provide the functions in a library that the 1526 libraries, or they provide the functions in a library that the
1492 original package author didn't know. To work around this, you 1527 original package author didn't know. To work around this, you
1493 can rewrite the source code in most cases so that it does not 1528 can rewrite the source code in most cases so that it does not
1494 use the missing functions or provides a replacement function.</para> 1529 use the missing functions or provides a replacement function.</para>
1495 1530
1496<sect2 id="fixes.build.cpp"> 1531<sect2 id="fixes.build.cpp">
1497<title>Compiling C and C++ code conditionally</title> 1532<title>Compiling C and C++ code conditionally</title>
1498 1533
1499 <para>If a package already comes with a GNU configure script, the 1534 <para>If a package already comes with a GNU configure script, the
1500 preferred way to fix the build failure is to change the 1535 preferred way to fix the build failure is to change the
1501 configure script, not the code. In the other cases, you can 1536 configure script, not the code. In the other cases, you can
1502 utilize the C preprocessor, which defines certain macros 1537 utilize the C preprocessor, which defines certain macros
1503 depending on the operating system and hardware architecture it 1538 depending on the operating system and hardware architecture it
1504 compiles for. These macros can be queried using for example 1539 compiles for. These macros can be queried using for example
1505 <varname>#if defined(__i386)</varname>. Almost every operating 1540 <varname>#if defined(__i386)</varname>. Almost every operating
1506 system, hardware architecture and compiler has its own macro. 1541 system, hardware architecture and compiler has its own macro.
1507 For example, if the macros <varname>__GNUC__</varname>, 1542 For example, if the macros <varname>__GNUC__</varname>,
1508 <varname>__i386__</varname> and <varname>__NetBSD__</varname> 1543 <varname>__i386__</varname> and <varname>__NetBSD__</varname>
1509 are all defined, you know that you are using NetBSD on an i386 1544 are all defined, you know that you are using NetBSD on an i386
1510 compatible CPU, and your compiler is GCC.</para> 1545 compatible CPU, and your compiler is GCC.</para>
1511 1546
1512 <para>The list of the following macros for hardware and 1547 <para>The list of the following macros for hardware and
1513 operating system depends on the compiler that is used. For 1548 operating system depends on the compiler that is used. For
1514 example, if you want to conditionally compile code on Solaris, 1549 example, if you want to conditionally compile code on Solaris,
1515 don't use <varname>__sun__</varname>, as the SunPro compiler 1550 don't use <varname>__sun__</varname>, as the SunPro compiler
1516 does not define it. Use <varname>__sun</varname> instead.</para> 1551 does not define it. Use <varname>__sun</varname> instead.</para>
1517 1552
1518<sect3 id="fixes.build.cpp.os"> 1553<sect3 id="fixes.build.cpp.os">
1519<title>C preprocessor macros to identify the operating system</title> 1554<title>C preprocessor macros to identify the operating system</title>
1520 1555
1521 <para>To distinguish between 4.4 BSD-derived systems and the 1556 <para>To distinguish between 4.4 BSD-derived systems and the
1522 rest of the world, you should use the following code.</para> 1557 rest of the world, you should use the following code.</para>
1523 1558
1524<programlisting> 1559<programlisting>
1525#include &lt;sys/param.h&gt; 1560#include &lt;sys/param.h&gt;
1526#if (defined(BSD) &amp;&amp; BSD &gt;= 199306) 1561#if (defined(BSD) &amp;&amp; BSD &gt;= 199306)
1527/* BSD-specific code goes here */ 1562/* BSD-specific code goes here */
1528#else 1563#else
1529/* non-BSD-specific code goes here */ 1564/* non-BSD-specific code goes here */
1530#endif 1565#endif
1531</programlisting> 1566</programlisting>
1532 1567
1533 <para>If this distinction is not fine enough, you can also test 1568 <para>If this distinction is not fine enough, you can also test
1534 for the following macros.</para> 1569 for the following macros.</para>
1535 1570
1536<programlisting> 1571<programlisting>
1537Cygwin __CYGWIN__ 1572Cygwin __CYGWIN__
1538DragonFly __DragonFly__ 1573DragonFly __DragonFly__
1539FreeBSD __FreeBSD__ 1574FreeBSD __FreeBSD__
1540Haiku __HAIKU__ 1575Haiku __HAIKU__
1541Interix __INTERIX 1576Interix __INTERIX
1542IRIX __sgi (TODO: get a definite source for this) 1577IRIX __sgi (TODO: get a definite source for this)
1543Linux linux, __linux, __linux__ 1578Linux linux, __linux, __linux__
1544Mac OS X __APPLE__ 1579Mac OS X __APPLE__
1545MirBSD __MirBSD__ (__OpenBSD__ is also defined) 1580MirBSD __MirBSD__ (__OpenBSD__ is also defined)
1546Minix3 __minix 1581Minix3 __minix
1547NetBSD __NetBSD__ 1582NetBSD __NetBSD__
1548OpenBSD __OpenBSD__ 1583OpenBSD __OpenBSD__
1549Solaris sun, __sun 1584Solaris sun, __sun
1550</programlisting> 1585</programlisting>
1551 1586
1552</sect3> 1587</sect3>
1553<sect3 id="fixes.build.cpp.arch"> 1588<sect3 id="fixes.build.cpp.arch">
1554<title>C preprocessor macros to identify the hardware architecture</title> 1589<title>C preprocessor macros to identify the hardware architecture</title>
1555 1590
1556<programlisting> 1591<programlisting>
1557i386 i386, __i386, __i386__ 1592i386 i386, __i386, __i386__
1558MIPS __mips 1593MIPS __mips
1559SPARC sparc, __sparc 1594SPARC sparc, __sparc
1560</programlisting> 1595</programlisting>
1561 1596
1562</sect3> 1597</sect3>
1563<sect3 id="fixes.build.cpp.compiler"> 1598<sect3 id="fixes.build.cpp.compiler">
1564<title>C preprocessor macros to identify the compiler</title> 1599<title>C preprocessor macros to identify the compiler</title>
1565 1600
1566<programlisting> 1601<programlisting>
1567GCC __GNUC__ (major version), __GNUC_MINOR__ 1602GCC __GNUC__ (major version), __GNUC_MINOR__
1568MIPSpro _COMPILER_VERSION (0x741 for MIPSpro 7.41) 1603MIPSpro _COMPILER_VERSION (0x741 for MIPSpro 7.41)
1569SunPro __SUNPRO_C (0x570 for Sun C 5.7) 1604SunPro __SUNPRO_C (0x570 for Sun C 5.7)
1570SunPro C++ __SUNPRO_CC (0x580 for Sun C++ 5.8) 1605SunPro C++ __SUNPRO_CC (0x580 for Sun C++ 5.8)
1571</programlisting> 1606</programlisting>
1572 1607
1573</sect3> 1608</sect3>
1574</sect2> 1609</sect2>
1575<sect2 id="compiler-bugs"> 1610<sect2 id="compiler-bugs">
1576<title>How to handle compiler bugs</title> 1611<title>How to handle compiler bugs</title>
1577 1612
1578 <para>Some source files trigger bugs in the compiler, based on 1613 <para>Some source files trigger bugs in the compiler, based on
1579 combinations of compiler version and architecture and almost 1614 combinations of compiler version and architecture and almost
1580 always relation to optimisation being enabled. Common symptoms 1615 always relation to optimisation being enabled. Common symptoms
1581 are gcc internal errors or never finishing compiling a 1616 are gcc internal errors or never finishing compiling a
1582 file.</para> 1617 file.</para>
1583 1618