Chapter 6. Special Considerations

Table of Contents
6.1. Staging
6.2. Shared Libraries
6.3. Ports with Distribution Restrictions
6.4. Building Mechanisms
6.5. Using GNU Autotools
6.6. Using GNU gettext
6.7. Using Perl
6.8. Using X11
6.9. Using GNOME
6.10. Using Qt
6.11. Using KDE
6.12. Using Java
6.13. Web Applications, Apache and PHP
6.14. Using Python
6.15. Using Tcl/Tk
6.16. Using Emacs
6.17. Using Ruby
6.18. Using SDL
6.19. Using wxWidgets
6.20. Using Lua
6.21. Using iconv
6.22. Using Xfce
6.23. Using Mozilla
6.24. Using Databases
6.25. Starting and Stopping Services (rc Scripts)
6.26. Adding Users and Groups
6.27. Ports That Rely on Kernel Sources

There are some more things you have to take into account when you create a port. This section explains the most common of those.

6.1. Staging

bsd.port.mk expects ports to work with a so-called stage directory. This means that a port should not install files directly to the regular destination directories (that is, under PREFIX, for example) but instead into a separate directory from which the package is then built. In many cases, this does not require root privileges, therefore it enables building packages as an unprivileged user. With staging, the package is first built, installed into the stage directory, referenced as STAGEDIR, packaged, and then installed from the package. Automake tools refers to this concept as DESTDIR, but in FreeBSD, DESTDIR has a different meaning (see Section 9.4, “PREFIX and DESTDIR).

When a port still requires system-wide privileges in order to run the package target, the following line has to be added to its Makefile:

NEED_ROOT= yes

For meta ports, add the following line, otherwise they would needlessly extract the mtree(8), the basic directory layout of the package, to the stage directory, and will be counted as orphans. Meta ports are the ports that do not install files themselves but depend on other ports, hence this distinction.

NO_MTREE= yes

To enable staging for a port, the STAGEDIR variable has to prepended before the uses of PREFIX, ETCDIR, DATADIR, EXAMPLESDIR, MANPREFIX, DOCSDIR, etc. at the pre-install, do-install, and post-install targets (see the examples through the book). Directories should be created as part of the post-install target. Try to avoid using absolute paths whenever possible.

When creating a symlink, STAGEDIR should be prepended to the target path only. For example:

${LN} -sf libfoo.so.42 ${STAGEDIR}${PREFIX}/lib/libfoo.so

Note that the source path, ${PREFIX}/lib/libfoo.so.42, while looks fine, could be in fact incorrect, since absolute paths can potentially point to a wrong location, e.g. when remote filesystem is mounted via NFS under a non-root mount point. Relative paths are less fragile, and often much shorter.

For ports that install kernel modules, the STAGEDIR variable has to be prepended to their default destination, /boot/modules. Then the pre-install target may be used to take care of the creation of this directory:

pre-install: ${MKDIR} ${STAGEDIR}/boot/modules

Furthermore, one should pay attention to disallow running kldxref(8) on install. This can be usually disabled via defining the NO_XREF variable and adding it to MAKE_ENV in the port's Makefile.

MAKE_ENV+= KMODDIR=/boot/modules NO_XREF=yes

Instead, the hints files for the kernel loader should be only generated when the package is installed or deinstalled. This can be achieved by invoking kldxref(8) in the pkg-plist file.

@unexec kldxref /boot/modules @exec kldxref /boot/modules

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.