| 1 |
<?xml version="1.0" encoding="iso-8859-1"?> |
| 2 |
<!-- |
| 3 |
The FreeBSD Documentation Project |
| 4 |
|
| 5 |
$FreeBSD$ |
| 6 |
--> |
| 7 |
|
| 8 |
<chapter xmlns="http://docbook.org/ns/docbook" |
| 9 |
xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0" |
| 10 |
xml:id="porting-dads"> |
| 11 |
|
| 12 |
<title>Dos and Don'ts</title> |
| 13 |
|
| 14 |
<sect1 xml:id="dads-intro"> |
| 15 |
<title>Introduction</title> |
| 16 |
|
| 17 |
<para>Here is a list of common dos and don'ts that are encountered |
| 18 |
during the porting process. Check the port against this list, |
| 19 |
but also check ports in the <link |
| 20 |
xlink:href="https://bugs.FreeBSD.org/search/">PR |
| 21 |
database</link> that others have submitted. Submit any |
| 22 |
comments on ports as described in <link |
| 23 |
xlink:href="&url.articles.contributing;/contrib-how.html#CONTRIB-GENERAL">Bug |
| 24 |
Reports and General Commentary</link>. Checking ports in the |
| 25 |
PR database will both make it faster for us to commit them, and |
| 26 |
prove that you know what you are doing.</para> |
| 27 |
</sect1> |
| 28 |
|
| 29 |
<sect1 xml:id="porting-wrkdir"> |
| 30 |
<title><varname>WRKDIR</varname></title> |
| 31 |
|
| 32 |
<para>Do not write anything to files outside |
| 33 |
<varname>WRKDIR</varname>. <varname>WRKDIR</varname> is the |
| 34 |
only place that is guaranteed to be writable during the port |
| 35 |
build (see <link |
| 36 |
xlink:href="&url.books.handbook;/ports-using.html#PORTS-CD"> |
| 37 |
installing ports from a CDROM</link> for an example of |
| 38 |
building ports from a read-only tree). The |
| 39 |
<filename>pkg-<replaceable>*</replaceable></filename> files can |
| 40 |
be modified by <link linkend="pkg-names">redefining a |
| 41 |
variable</link> rather than overwriting the file.</para> |
| 42 |
</sect1> |
| 43 |
|
| 44 |
<sect1 xml:id="porting-wrkdirprefix"> |
| 45 |
<title><varname>WRKDIRPREFIX</varname></title> |
| 46 |
|
| 47 |
<para>Make sure the port honors <varname>WRKDIRPREFIX</varname>. |
| 48 |
Most ports do not have to worry about this. In particular, when |
| 49 |
referring to a <varname>WRKDIR</varname> of another |
| 50 |
port, note that the correct location is |
| 51 |
<filename>WRKDIRPREFIXPORTSDIR/<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> |
| 52 |
not |
| 53 |
<filename>PORTSDIR/<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> |
| 54 |
or |
| 55 |
<filename>.CURDIR/../../<replaceable>subdir</replaceable>/<replaceable>name</replaceable>/work</filename> |
| 56 |
or some such.</para> |
| 57 |
|
| 58 |
<para>Also, if defining <varname>WRKDIR</varname>, |
| 59 |
make sure to prepend |
| 60 |
<literal>${WRKDIRPREFIX}${.CURDIR}</literal> in |
| 61 |
the front.</para> |
| 62 |
</sect1> |
| 63 |
|
| 64 |
<sect1 xml:id="porting-versions"> |
| 65 |
<title>Differentiating Operating Systems and OS Versions</title> |
| 66 |
|
| 67 |
<para>Some code needs modifications or |
| 68 |
conditional compilation based upon what version of &os; Unix it |
| 69 |
is running under. The preferred way to tell &os; versions apart |
| 70 |
are the <literal>__FreeBSD_version</literal> and |
| 71 |
<literal>__FreeBSD__</literal> macros defined in <link |
| 72 |
xlink:href="http://svnweb.freebsd.org/base/head/sys/sys/param.h?view=markup">sys/param.h</link>. |
| 73 |
If this file is not included add the code,</para> |
| 74 |
|
| 75 |
<programlisting>#include <sys/param.h></programlisting> |
| 76 |
|
| 77 |
<para>to the proper place in the <filename>.c</filename> |
| 78 |
file.</para> |
| 79 |
|
| 80 |
<para><literal>__FreeBSD__</literal> is defined in all versions |
| 81 |
of &os; as their major version number. For example, in &os; |
| 82 |
9.x, <literal>__FreeBSD__</literal> is defined to be |
| 83 |
<literal>9</literal>.</para> |
| 84 |
|
| 85 |
<programlisting>#if __FreeBSD__ >= 9 |
| 86 |
# if __FreeBSD_version >= 901000 |
| 87 |
/* 9.1+ release specific code here */ |
| 88 |
# endif |
| 89 |
#endif</programlisting> |
| 90 |
|
| 91 |
<para>A complete list of <literal>__FreeBSD_version</literal> |
| 92 |
values is available in <xref linkend="versions"/>.</para> |
| 93 |
</sect1> |
| 94 |
|
| 95 |
<sect1 xml:id="dads-after-port-mk"> |
| 96 |
<title>Writing Something After |
| 97 |
<filename>bsd.port.mk</filename></title> |
| 98 |
|
| 99 |
<para>Do not write anything after the |
| 100 |
<literal>.include <bsd.port.mk></literal> line. It |
| 101 |
usually can be avoided by including |
| 102 |
<filename>bsd.port.pre.mk</filename> somewhere in the middle of |
| 103 |
the <filename>Makefile</filename> and |
| 104 |
<filename>bsd.port.post.mk</filename> at the end.</para> |
| 105 |
|
| 106 |
<important> |
| 107 |
<para>Include either the |
| 108 |
<filename>bsd.port.pre.mk</filename>/<filename>bsd.port.post.mk</filename> |
| 109 |
pair or <filename>bsd.port.mk</filename> only; do not mix |
| 110 |
these two usages.</para> |
| 111 |
</important> |
| 112 |
|
| 113 |
<para><filename>bsd.port.pre.mk</filename> only defines a few |
| 114 |
variables, which can be used in tests in the |
| 115 |
<filename>Makefile</filename>, |
| 116 |
<filename>bsd.port.post.mk</filename> defines the rest.</para> |
| 117 |
|
| 118 |
<para>Here are some important variables defined in |
| 119 |
<filename>bsd.port.pre.mk</filename> (this is not the complete |
| 120 |
list, please read <filename>bsd.port.mk</filename> for the |
| 121 |
complete list).</para> |
| 122 |
|
| 123 |
<informaltable frame="none" pgwide="0"> |
| 124 |
<tgroup cols="2"> |
| 125 |
<thead> |
| 126 |
<row> |
| 127 |
<entry>Variable</entry> |
| 128 |
<entry>Description</entry> |
| 129 |
</row> |
| 130 |
</thead> |
| 131 |
|
| 132 |
<tbody> |
| 133 |
<row> |
| 134 |
<entry><varname>ARCH</varname></entry> |
| 135 |
<entry>The architecture as returned by |
| 136 |
<command>uname -m</command> (for example, |
| 137 |
<literal>i386</literal>)</entry> |
| 138 |
</row> |
| 139 |
|
| 140 |
<row> |
| 141 |
<entry><varname>OPSYS</varname></entry> |
| 142 |
<entry>The operating system type, as returned by |
| 143 |
<command>uname -s</command> (for example, |
| 144 |
<literal>FreeBSD</literal>)</entry> |
| 145 |
</row> |
| 146 |
|
| 147 |
<row> |
| 148 |
<entry><varname>OSREL</varname></entry> |
| 149 |
<entry>The release version of the operating system |
| 150 |
(for example, <literal>2.1.5</literal> or |
| 151 |
<literal>2.2.7</literal>)</entry> |
| 152 |
</row> |
| 153 |
|
| 154 |
<row> |
| 155 |
<entry><varname>OSVERSION</varname></entry> |
| 156 |
<entry>The numeric version of the operating system; the |
| 157 |
same as <link |
| 158 |
linkend="versions"><literal>__FreeBSD_version</literal></link>.</entry> |
| 159 |
</row> |
| 160 |
|
| 161 |
<row> |
| 162 |
<entry><varname>LOCALBASE</varname></entry> |
| 163 |
<entry>The base of the <quote>local</quote> tree (for |
| 164 |
example, <literal>/usr/local</literal>)</entry> |
| 165 |
</row> |
| 166 |
|
| 167 |
<row> |
| 168 |
<entry><varname>PREFIX</varname></entry> |
| 169 |
|
| 170 |
<entry>Where the port installs itself (see |
| 171 |
<link linkend="porting-prefix">more on |
| 172 |
<varname>PREFIX</varname></link>).</entry> |
| 173 |
</row> |
| 174 |
</tbody> |
| 175 |
</tgroup> |
| 176 |
</informaltable> |
| 177 |
|
| 178 |
<note> |
| 179 |
<para>When <varname>MASTERDIR</varname> is needed, always define |
| 180 |
it before including |
| 181 |
<filename>bsd.port.pre.mk</filename>.</para> |
| 182 |
</note> |
| 183 |
|
| 184 |
<para>Here are some examples of things that can be added after |
| 185 |
<filename>bsd.port.pre.mk</filename>:</para> |
| 186 |
|
| 187 |
<programlisting># no need to compile lang/perl5 if perl5 is already in system |
| 188 |
.if ${OSVERSION} > 300003 |
| 189 |
BROKEN= perl is in system |
| 190 |
.endif</programlisting> |
| 191 |
|
| 192 |
<para>Always use tab instead of spaces after |
| 193 |
<literal>BROKEN=</literal>.</para> |
| 194 |
</sect1> |
| 195 |
|
| 196 |
<sect1 xml:id="dads-sh-exec"> |
| 197 |
<title>Use the <function>exec</function> Statement in Wrapper |
| 198 |
Scripts</title> |
| 199 |
|
| 200 |
<para>If the port installs a shell script whose purpose is to |
| 201 |
launch another program, and if launching that program is the |
| 202 |
last action performed by the script, make sure to launch the |
| 203 |
program using the <function>exec</function> statement, for |
| 204 |
instance:</para> |
| 205 |
|
| 206 |
<programlisting>#!/bin/sh |
| 207 |
exec %%LOCALBASE%%/bin/java -jar %%DATADIR%%/foo.jar "$@"</programlisting> |
| 208 |
|
| 209 |
<para>The <function>exec</function> statement replaces the shell |
| 210 |
process with the specified program. If |
| 211 |
<function>exec</function> is omitted, the shell process remains |
| 212 |
in memory while the program is executing, and needlessly |
| 213 |
consumes system resources.</para> |
| 214 |
</sect1> |
| 215 |
|
| 216 |
<sect1 xml:id="dads-rational"> |
| 217 |
<title>Do Things Rationally</title> |
| 218 |
|
| 219 |
<para>The <filename>Makefile</filename> should do things in a |
| 220 |
simple and reasonable manner. Making it a couple of lines |
| 221 |
shorter or more readable is always better. Examples include |
| 222 |
using a make <literal>.if</literal> construct instead of a shell |
| 223 |
<literal>if</literal> construct, not redefining |
| 224 |
<buildtarget>do-extract</buildtarget> if redefining |
| 225 |
<varname>EXTRACT*</varname> is enough, and using |
| 226 |
<varname>GNU_CONFIGURE</varname> instead of |
| 227 |
<literal>CONFIGURE_ARGS |
| 228 |
+= --prefix=${PREFIX}</literal>.</para> |
| 229 |
|
| 230 |
<para>If a lot of new code is needed to do something, there may |
| 231 |
already be an implementation of it in |
| 232 |
<filename>bsd.port.mk</filename>. While hard to read, there are |
| 233 |
a great many seemingly-hard problems for which |
| 234 |
<filename>bsd.port.mk</filename> already provides a shorthand |
| 235 |
solution.</para> |
| 236 |
</sect1> |
| 237 |
|
| 238 |
<sect1 xml:id="dads-cc"> |
| 239 |
<title>Respect Both <varname>CC</varname> and |
| 240 |
<varname>CXX</varname></title> |
| 241 |
|
| 242 |
<para>The port must respect both <varname>CC</varname> and |
| 243 |
<varname>CXX</varname>. What we mean by this is that |
| 244 |
the port must not set the values of these variables absolutely, |
| 245 |
overriding existing values; instead, it may append whatever |
| 246 |
values it needs to the existing values. This is so that build |
| 247 |
options that affect all ports can be set globally.</para> |
| 248 |
|
| 249 |
<para>If the port does not respect these variables, |
| 250 |
please add |
| 251 |
<literal>NO_PACKAGE=ignores either cc or cxx</literal> to the |
| 252 |
<filename>Makefile</filename>.</para> |
| 253 |
|
| 254 |
<para>Here is an example of a <filename>Makefile</filename> |
| 255 |
respecting both <varname>CC</varname> and |
| 256 |
<varname>CXX</varname>. Note the <literal>?=</literal>:</para> |
| 257 |
|
| 258 |
<programlisting>CC?= gcc</programlisting> |
| 259 |
|
| 260 |
<programlisting>CXX?= g++</programlisting> |
| 261 |
|
| 262 |
<para>Here is an example which respects neither |
| 263 |
<varname>CC</varname> nor <varname>CXX</varname>:</para> |
| 264 |
|
| 265 |
<programlisting>CC= gcc</programlisting> |
| 266 |
|
| 267 |
<programlisting>CXX= g++</programlisting> |
| 268 |
|
| 269 |
<para>Both <varname>CC</varname> and <varname>CXX</varname> |
| 270 |
can be defined on &os; systems in |
| 271 |
<filename>/etc/make.conf</filename>. The first example defines |
| 272 |
a value if it was not previously set in |
| 273 |
<filename>/etc/make.conf</filename>, preserving any system-wide |
| 274 |
definitions. The second example clobbers anything previously |
| 275 |
defined.</para> |
| 276 |
</sect1> |
| 277 |
|
| 278 |
<sect1 xml:id="dads-cflags"> |
| 279 |
<title>Respect <varname>CFLAGS</varname></title> |
| 280 |
|
| 281 |
<para>The port must respect <varname>CFLAGS</varname>. |
| 282 |
What we mean by this is that the port must not set |
| 283 |
the value of this variable absolutely, overriding the existing |
| 284 |
value. Instead, it may append whatever values it needs to the |
| 285 |
existing value. This is so that build options that affect all |
| 286 |
ports can be set globally.</para> |
| 287 |
|
| 288 |
<para>If it does not, please add |
| 289 |
<literal>NO_PACKAGE=ignores cflags</literal> to the |
| 290 |
<filename>Makefile</filename>.</para> |
| 291 |
|
| 292 |
<para>Here is an example of a <filename>Makefile</filename> |
| 293 |
respecting <varname>CFLAGS</varname>. Note the |
| 294 |
<literal>+=</literal>:</para> |
| 295 |
|
| 296 |
<programlisting>CFLAGS+= -Wall -Werror</programlisting> |
| 297 |
|
| 298 |
<para>Here is an example which does not respect |
| 299 |
<varname>CFLAGS</varname>:</para> |
| 300 |
|
| 301 |
<programlisting>CFLAGS= -Wall -Werror</programlisting> |
| 302 |
|
| 303 |
<para><varname>CFLAGS</varname> is defined on |
| 304 |
&os; systems in <filename>/etc/make.conf</filename>. The first |
| 305 |
example appends additional flags to |
| 306 |
<varname>CFLAGS</varname>, preserving any system-wide |
| 307 |
definitions. The second example clobbers anything previously |
| 308 |
defined.</para> |
| 309 |
|
| 310 |
<para>Remove optimization flags from the third party |
| 311 |
<filename>Makefile</filename>s. The system |
| 312 |
<varname>CFLAGS</varname> contains system-wide optimization |
| 313 |
flags. An example from an unmodified |
| 314 |
<filename>Makefile</filename>:</para> |
| 315 |
|
| 316 |
<programlisting>CFLAGS= -O3 -funroll-loops -DHAVE_SOUND</programlisting> |
| 317 |
|
| 318 |
<para>Using system optimization flags, the |
| 319 |
<filename>Makefile</filename> would look similar to this |
| 320 |
example:</para> |
| 321 |
|
| 322 |
<programlisting>CFLAGS+= -DHAVE_SOUND</programlisting> |
| 323 |
</sect1> |
| 324 |
|
| 325 |
<sect1 xml:id="dads-verbose-logs"> |
| 326 |
<title>Verbose Build Logs</title> |
| 327 |
|
| 328 |
<para>Make the port build system display all commands executed |
| 329 |
during the build stage. Complete build logs are crucial to |
| 330 |
debugging port problems.</para> |
| 331 |
|
| 332 |
<para>Non-informative build log example (bad):</para> |
| 333 |
|
| 334 |
<programlisting> CC source1.o |
| 335 |
CC source2.o |
| 336 |
CCLD someprogram</programlisting> |
| 337 |
|
| 338 |
<para>Verbose build log example (good):</para> |
| 339 |
|
| 340 |
<programlisting>cc -O2 -pipe -I/usr/local/include -c -o source1.o source1.c |
| 341 |
cc -O2 -pipe -I/usr/local/include -c -o source2.o source2.c |
| 342 |
cc -o someprogram source1.o source2.o -L/usr/local/lib -lsomelib</programlisting> |
| 343 |
|
| 344 |
<para>Some build systems such as <application>CMake</application>, |
| 345 |
<application>ninja</application>, and <application>GNU |
| 346 |
configure</application> are set up for verbose logging by |
| 347 |
the ports framework. In other cases, ports might need |
| 348 |
individial tweaks.</para> |
| 349 |
</sect1> |
| 350 |
|
| 351 |
<sect1 xml:id="dads-feedback"> |
| 352 |
<title>Feedback</title> |
| 353 |
|
| 354 |
<para>Do send applicable changes and patches to the upstream |
| 355 |
maintainer for inclusion in the next release of the code. |
| 356 |
This makes updating to the next release that much easier.</para> |
| 357 |
</sect1> |
| 358 |
|
| 359 |
<sect1 xml:id="dads-readme"> |
| 360 |
<title><filename>README.html</filename></title> |
| 361 |
|
| 362 |
<para><filename>README.html</filename> is not part of the port, |
| 363 |
but generated by <command>make readme</command>. Do not |
| 364 |
include this file in patches or commits.</para> |
| 365 |
|
| 366 |
<note> |
| 367 |
<para>If <command>make readme</command> fails, make sure that |
| 368 |
the default value of <varname>ECHO_MSG</varname> has not |
| 369 |
been modified by the port.</para> |
| 370 |
</note> |
| 371 |
</sect1> |
| 372 |
|
| 373 |
<sect1 xml:id="dads-arch-neutral"> |
| 374 |
<title>Marking a Port as Architecture Neutral</title> |
| 375 |
|
| 376 |
<para>Ports that do not have any architecture-dependent files |
| 377 |
or requirements are identified by setting |
| 378 |
<literal>NO_ARCH=yes</literal>.</para> |
| 379 |
</sect1> |
| 380 |
|
| 381 |
<sect1 xml:id="dads-noinstall"> |
| 382 |
<title>Marking a Port Not Installable with |
| 383 |
<varname>BROKEN</varname>, <varname>FORBIDDEN</varname>, or |
| 384 |
<varname>IGNORE</varname></title> |
| 385 |
|
| 386 |
<para>In certain cases, users must be prevented from installing |
| 387 |
a port. There are several variables that can be used in a |
| 388 |
port's <filename>Makefile</filename> to tell the user that the |
| 389 |
port cannot be installed. The value of |
| 390 |
these make variables will be the |
| 391 |
reason that is shown to users for why the port refuses to |
| 392 |
install itself. Please use the correct make |
| 393 |
variable. Each variable conveys radically different |
| 394 |
meanings, both to users and to automated systems that depend on |
| 395 |
<filename>Makefile</filename>s, such as |
| 396 |
<link linkend="build-cluster">the ports build cluster</link>, |
| 397 |
<link linkend="freshports">FreshPorts</link>, and |
| 398 |
<link linkend="portsmon">portsmon</link>.</para> |
| 399 |
|
| 400 |
<sect2 xml:id="dads-noinstall-variables"> |
| 401 |
<title>Variables</title> |
| 402 |
|
| 403 |
<itemizedlist> |
| 404 |
<listitem> |
| 405 |
<para><varname>BROKEN</varname> is reserved for ports that |
| 406 |
currently do not compile, install, deinstall, or run |
| 407 |
correctly. Use it for ports where the problem |
| 408 |
is believed to be temporary.</para> |
| 409 |
|
| 410 |
<para>If instructed, the build cluster will still attempt |
| 411 |
to try to build them to see if the underlying problem has |
| 412 |
been resolved. (However, in general, the cluster is run |
| 413 |
without this.)</para> |
| 414 |
|
| 415 |
<para>For instance, use <varname>BROKEN</varname> when a |
| 416 |
port:</para> |
| 417 |
|
| 418 |
<itemizedlist> |
| 419 |
<listitem> |
| 420 |
<para>does not compile</para> |
| 421 |
</listitem> |
| 422 |
|
| 423 |
<listitem> |
| 424 |
<para>fails its configuration or installation |
| 425 |
process</para> |
| 426 |
</listitem> |
| 427 |
|
| 428 |
<listitem> |
| 429 |
<para>installs files outside of |
| 430 |
<filename>${PREFIX}</filename></para> |
| 431 |
</listitem> |
| 432 |
|
| 433 |
<listitem> |
| 434 |
<para>does not remove all its files cleanly upon |
| 435 |
deinstall (however, it may be acceptable, and |
| 436 |
desirable, for the port to leave user-modified files |
| 437 |
behind)</para> |
| 438 |
</listitem> |
| 439 |
|
| 440 |
<listitem> |
| 441 |
<para>has runtime issues on systems where it is |
| 442 |
supposed to run fine.</para> |
| 443 |
</listitem> |
| 444 |
</itemizedlist> |
| 445 |
</listitem> |
| 446 |
|
| 447 |
<listitem> |
| 448 |
<para><varname>FORBIDDEN</varname> is used for ports that |
| 449 |
contain a security vulnerability or induce grave concern |
| 450 |
regarding the security of a &os; system with a given port |
| 451 |
installed (for example, a reputably insecure program or a |
| 452 |
program that provides easily exploitable services). Mark |
| 453 |
ports as <varname>FORBIDDEN</varname> as soon as a |
| 454 |
particular piece of software has a vulnerability and there |
| 455 |
is no released upgrade. Ideally upgrade ports as soon as |
| 456 |
possible when a security vulnerability is discovered so as |
| 457 |
to reduce the number of vulnerable &os; hosts (we like |
| 458 |
being known for being secure), however sometimes there is |
| 459 |
a noticeable time gap between disclosure of a |
| 460 |
vulnerability and an updated release of the vulnerable |
| 461 |
software. Do not mark a port <varname>FORBIDDEN</varname> |
| 462 |
for any reason other than security.</para> |
| 463 |
</listitem> |
| 464 |
|
| 465 |
<listitem> |
| 466 |
<para><varname>IGNORE</varname> is reserved for ports that |
| 467 |
must not be built for some other reason. Use it |
| 468 |
for ports where the problem is believed to be |
| 469 |
structural. The build cluster will not, under any |
| 470 |
circumstances, build ports marked as |
| 471 |
<varname>IGNORE</varname>. For instance, use |
| 472 |
<varname>IGNORE</varname> when a port:</para> |
| 473 |
|
| 474 |
<itemizedlist> |
| 475 |
<listitem> |
| 476 |
<para>does not work on the installed version of |
| 477 |
&os;</para> |
| 478 |
</listitem> |
| 479 |
|
| 480 |
<listitem> |
| 481 |
<para>has a distfile which may not be automatically |
| 482 |
fetched due to licensing restrictions</para> |
| 483 |
</listitem> |
| 484 |
|
| 485 |
<listitem> |
| 486 |
<para>does not work with some other currently |
| 487 |
installed port (for instance, the port depends on |
| 488 |
<package role="port">www/apache20</package> but |
| 489 |
<package role="port">www/apache22</package> is |
| 490 |
installed)</para> |
| 491 |
</listitem> |
| 492 |
</itemizedlist> |
| 493 |
|
| 494 |
<note> |
| 495 |
<para>If a port would conflict with a currently |
| 496 |
installed port (for example, if they install a file in |
| 497 |
the same place that performs a different function), |
| 498 |
<link linkend="conflicts">use |
| 499 |
<varname>CONFLICTS</varname> instead</link>. |
| 500 |
<varname>CONFLICTS</varname> will set |
| 501 |
<varname>IGNORE</varname> by itself.</para> |
| 502 |
</note> |
| 503 |
</listitem> |
| 504 |
|
| 505 |
<listitem> |
| 506 |
<para>To mark a port as <varname>IGNORE</varname>d |
| 507 |
only on certain architectures, there are two other |
| 508 |
convenience variables that will automatically set |
| 509 |
<varname>IGNORE</varname>: |
| 510 |
<varname>ONLY_FOR_ARCHS</varname> and |
| 511 |
<varname>NOT_FOR_ARCHS</varname>. Examples:</para> |
| 512 |
|
| 513 |
<programlisting>ONLY_FOR_ARCHS= i386 amd64</programlisting> |
| 514 |
|
| 515 |
<programlisting>NOT_FOR_ARCHS= ia64 sparc64</programlisting> |
| 516 |
|
| 517 |
<para>A custom <varname>IGNORE</varname> message can be |
| 518 |
set using <varname>ONLY_FOR_ARCHS_REASON</varname> and |
| 519 |
<varname>NOT_FOR_ARCHS_REASON</varname>. Per |
| 520 |
architecture entries are possible with |
| 521 |
<varname>ONLY_FOR_ARCHS_REASON_<replaceable>ARCH</replaceable></varname> |
| 522 |
and |
| 523 |
<varname>NOT_FOR_ARCHS_REASON_<replaceable>ARCH</replaceable></varname>.</para> |
| 524 |
</listitem> |
| 525 |
|
| 526 |
<listitem> |
| 527 |
<para>If a port fetches i386 binaries and installs them, |
| 528 |
set <varname>IA32_BINARY_PORT</varname>. If this variable |
| 529 |
is set, <filename>/usr/lib32</filename> must be present |
| 530 |
for IA32 versions of libraries and the kernel must support |
| 531 |
IA32 compatibility. If one of these two |
| 532 |
dependencies is not satisfied, <varname>IGNORE</varname> |
| 533 |
will be set automatically.</para> |
| 534 |
</listitem> |
| 535 |
</itemizedlist> |
| 536 |
</sect2> |
| 537 |
|
| 538 |
<sect2 xml:id="dads-noinstall-notes"> |
| 539 |
<title>Implementation Notes</title> |
| 540 |
|
| 541 |
<para>Do not quote the values of <varname>BROKEN</varname>, |
| 542 |
<varname>IGNORE</varname>, and related variables. Due to the |
| 543 |
way the information is shown to the user, the wording of |
| 544 |
messages for each variable differ:</para> |
| 545 |
|
| 546 |
<programlisting>BROKEN= fails to link with base -lcrypto</programlisting> |
| 547 |
|
| 548 |
<programlisting>IGNORE= unsupported on recent versions</programlisting> |
| 549 |
|
| 550 |
<para>resulting in this output from |
| 551 |
<command>make describe</command>:</para> |
| 552 |
|
| 553 |
<programlisting>===> foobar-0.1 is marked as broken: fails to link with base -lcrypto.</programlisting> |
| 554 |
|
| 555 |
<programlisting>===> foobar-0.1 is unsupported on recent versions.</programlisting> |
| 556 |
</sect2> |
| 557 |
</sect1> |
| 558 |
|
| 559 |
<sect1 xml:id="dads-deprecated"> |
| 560 |
<title>Marking a Port for Removal with |
| 561 |
<varname>DEPRECATED</varname> or |
| 562 |
<varname>EXPIRATION_DATE</varname></title> |
| 563 |
|
| 564 |
<para>Do remember that <varname>BROKEN</varname> and |
| 565 |
<varname>FORBIDDEN</varname> are to be used as a temporary |
| 566 |
resort if a port is not working. Permanently broken ports |
| 567 |
will be removed from the tree entirely.</para> |
| 568 |
|
| 569 |
<para>When it makes sense to do so, users can be warned about |
| 570 |
a pending port removal with <varname>DEPRECATED</varname> and |
| 571 |
<varname>EXPIRATION_DATE</varname>. The former is a |
| 572 |
string stating why the port is scheduled for removal; the latter |
| 573 |
is a string in ISO 8601 format (YYYY-MM-DD). Both will be shown |
| 574 |
to the user.</para> |
| 575 |
|
| 576 |
<para>It is possible to set <varname>DEPRECATED</varname> |
| 577 |
without an <varname>EXPIRATION_DATE</varname> (for instance, |
| 578 |
recommending a newer version of the port), but the converse |
| 579 |
does not make any sense.</para> |
| 580 |
|
| 581 |
<para>There is no set policy on how much notice to give. |
| 582 |
Current practice seems to be one month for security-related |
| 583 |
issues and two months for build issues. This also gives any |
| 584 |
interested committers a little time to fix the problems.</para> |
| 585 |
</sect1> |
| 586 |
|
| 587 |
<sect1 xml:id="dads-dot-error"> |
| 588 |
<title>Avoid Use of the <literal>.error</literal> |
| 589 |
Construct</title> |
| 590 |
|
| 591 |
<para>The correct way for a <filename>Makefile</filename> to |
| 592 |
signal that the port cannot be installed due to some external |
| 593 |
factor (for instance, the user has specified an illegal |
| 594 |
combination of build options) is to set a non-blank value to |
| 595 |
<varname>IGNORE</varname>. This value will be formatted and |
| 596 |
shown to the user by <command>make install</command>.</para> |
| 597 |
|
| 598 |
<para>It is a common mistake to use <literal>.error</literal> |
| 599 |
for this purpose. The problem with this is that many automated |
| 600 |
tools that work with the ports tree will fail in this situation. |
| 601 |
The most common occurrence of this is seen when trying to build |
| 602 |
<filename>/usr/ports/INDEX</filename> (see |
| 603 |
<xref linkend="make-describe"/>). However, even more trivial |
| 604 |
commands such as <command>make maintainer</command> also fail in |
| 605 |
this scenario. This is not acceptable.</para> |
| 606 |
|
| 607 |
<example xml:id="dot-error-breaks-index"> |
| 608 |
<title>How to Avoid Using <literal>.error</literal></title> |
| 609 |
|
| 610 |
<para>The first of the |
| 611 |
next two <filename>Makefile</filename> snippets will cause |
| 612 |
<command>make index</command> to fail, while the second one |
| 613 |
will not:</para> |
| 614 |
|
| 615 |
<programlisting>.error "option is not supported"</programlisting> |
| 616 |
|
| 617 |
<programlisting>IGNORE=option is not supported</programlisting> |
| 618 |
</example> |
| 619 |
</sect1> |
| 620 |
|
| 621 |
<sect1 xml:id="dads-sysctl"> |
| 622 |
<title>Usage of <filename>sysctl</filename></title> |
| 623 |
|
| 624 |
<para>The usage of <filename>sysctl</filename> is discouraged |
| 625 |
except in targets. This is because the evaluation of any |
| 626 |
<literal>makevar</literal>s, such as used during |
| 627 |
<command>make index</command>, then has to run the command, |
| 628 |
further slowing down that process.</para> |
| 629 |
|
| 630 |
<para>Only use &man.sysctl.8; through |
| 631 |
<varname>SYSCTL</varname>, as it contains the fully |
| 632 |
qualified path and can be overridden, if one has such a |
| 633 |
special need.</para> |
| 634 |
</sect1> |
| 635 |
|
| 636 |
<sect1 xml:id="dads-rerolling-distfiles"> |
| 637 |
<title>Rerolling Distfiles</title> |
| 638 |
|
| 639 |
<para>Sometimes the authors of software change the content of |
| 640 |
released distfiles without changing the file's name. |
| 641 |
Verify that the changes are official and have been performed |
| 642 |
by the author. It has happened in the past that the distfile |
| 643 |
was silently altered on the download servers with the intent to |
| 644 |
cause harm or compromise end user security.</para> |
| 645 |
|
| 646 |
<para>Put the old distfile aside, download the new one, unpack |
| 647 |
them and compare the content with &man.diff.1;. If there is |
| 648 |
nothing suspicious, update |
| 649 |
<filename>distinfo</filename>. Be sure to summarize the |
| 650 |
differences in the PR or commit log, so that other people know |
| 651 |
that nothing bad has |
| 652 |
happened.</para> |
| 653 |
|
| 654 |
<para>Contact the authors of the software |
| 655 |
and confirm the changes with them.</para> |
| 656 |
</sect1> |
| 657 |
|
| 658 |
<sect1 xml:id="dads-use-posix-standards"> |
| 659 |
<title>Use <acronym>POSIX</acronym> Standards</title> |
| 660 |
|
| 661 |
<para>&os; ports generally expect <acronym>POSIX</acronym> |
| 662 |
compliance. Some software and build systems make assumptions |
| 663 |
based on a particular operating system or environment that can |
| 664 |
cause problems when used in a port.</para> |
| 665 |
|
| 666 |
<para>Do not use <filename>/proc</filename> if there are any |
| 667 |
other ways of getting the information. For example, |
| 668 |
<function>setprogname(argv[0])</function> in |
| 669 |
<function>main()</function> and then &man.getprogname.3; |
| 670 |
to know the executable name.</para> |
| 671 |
|
| 672 |
<para>Do not rely on behavior that is undocumented by |
| 673 |
<acronym>POSIX</acronym>.</para> |
| 674 |
|
| 675 |
<para>Do not record timestamps in the critical path of the |
| 676 |
application if it also works without. Getting timestamps may be |
| 677 |
slow, depending on the accuracy of timestamps in the |
| 678 |
<acronym>OS</acronym>. If timestamps are really needed, |
| 679 |
determine how precise they have to be and use an |
| 680 |
<acronym>API</acronym> which is documented to just deliver the |
| 681 |
needed precision.</para> |
| 682 |
|
| 683 |
<para>A number of simple syscalls (for example |
| 684 |
&man.gettimeofday.2;, &man.getpid.2;) are much faster on &linux; |
| 685 |
than on any other operating system due to caching and the |
| 686 |
vsyscall performance optimizations. Do not rely on them being |
| 687 |
cheap in performance-critical applications. In general, try |
| 688 |
hard to avoid syscalls if possible.</para> |
| 689 |
|
| 690 |
<para>Do not rely on &linux;-specific socket behavior. In |
| 691 |
particular, default socket buffer sizes are different (call |
| 692 |
&man.setsockopt.2; with <literal>SO_SNDBUF</literal> and |
| 693 |
<literal>SO_RCVBUF</literal>, and while &linux;'s &man.send.2; |
| 694 |
blocks when the socket buffer is full, &os;'s will fail and |
| 695 |
set <literal>ENOBUFS</literal> in errno.</para> |
| 696 |
|
| 697 |
<para>If relying on non-standard behavior is required, |
| 698 |
encapsulate it properly into a generic <acronym>API</acronym>, |
| 699 |
do a check for the behavior in the configure stage, and stop |
| 700 |
if it is missing.</para> |
| 701 |
|
| 702 |
<para>Check the |
| 703 |
<link xlink:href="http://www.freebsd.org/cgi/man.cgi">man |
| 704 |
pages</link> to see if the function used is a |
| 705 |
<acronym>POSIX</acronym> interface (in the |
| 706 |
<quote>STANDARDS</quote> section of the man page).</para> |
| 707 |
|
| 708 |
<para>Do not assume that <filename>/bin/sh</filename> is |
| 709 |
<application>bash</application>. Ensure that a command line |
| 710 |
passed to &man.system.3; will work with a |
| 711 |
<acronym>POSIX</acronym> compliant shell.</para> |
| 712 |
|
| 713 |
<para>A list of common <application>bash</application>isms is |
| 714 |
available <link |
| 715 |
xlink:href="https://wiki.ubuntu.com/DashAsBinSh">here</link>.</para> |
| 716 |
|
| 717 |
<para>Check that headers are included in the |
| 718 |
<acronym>POSIX</acronym> or man page recommended way. For |
| 719 |
example, <filename>sys/types.h</filename> is often forgotten, |
| 720 |
which is not as much of a problem for &linux; as it is for |
| 721 |
&os;.</para> |
| 722 |
</sect1> |
| 723 |
|
| 724 |
<sect1 xml:id="dads-misc"> |
| 725 |
<title>Miscellanea</title> |
| 726 |
|
| 727 |
<para>Always double-check <filename>pkg-descr</filename> and |
| 728 |
<filename>pkg-plist</filename>. |
| 729 |
If reviewing a port and a better wording can be achieved, |
| 730 |
do so.</para> |
| 731 |
|
| 732 |
<para>Do not copy more copies of the GNU General Public License |
| 733 |
into our system, please.</para> |
| 734 |
|
| 735 |
<para>Please be careful to note any legal issues! Do not let us |
| 736 |
illegally distribute software!</para> |
| 737 |
</sect1> |
| 738 |
</chapter> |