Chapter 6. Special Considerations

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

This section explains the most common things to consider when creating a port.

6.1. Staging expects ports to work with a stage directory. This means that a port must 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, making it possible to build packages as an unprivileged user. With staging, the port is built and installed into the stage directory, STAGEDIR. A package is created from the stage directory and then installed on the system. Automake tools refer to this concept as DESTDIR, but in FreeBSD, DESTDIR has a different meaning (see Section 10.4, “PREFIX and DESTDIR).


No port really needs to be root. It can mostly be avoided by using USES=uidfix. If the port still runs commands like chown(8), chgrp(1), or forces owner or group with install(1) then use USES=fakeroot to fake those calls. Some patching of the port's Makefiles will be needed.

Meta ports, or ports that do not install files themselves but only depend on other ports, must avoid needlessly extracting the mtree(8) to the stage directory. This is the basic directory layout of the package, and these empty directories will be seen as orphans. To prevent mtree(8) extraction, add this line:



Metaports should use USES=metaport. It sets up defaults for ports that do not fetch, build, or install anything.

Staging is enabled by prepending STAGEDIR to paths used in the pre-install, do-install, and post-install targets (see the examples through the book). Typically, this includes PREFIX, ETCDIR, DATADIR, EXAMPLESDIR, MANPREFIX, DOCSDIR, and so on. Directories should be created as part of the post-install target. Avoid using absolute paths whenever possible.


Ports that install kernel modules must prepend STAGEDIR to their destination, by default /boot/modules.

6.1.1. Handling Symbolic Links

When creating a symlink, there are two cases, either the source and target are both within ${PREFIX}. In that case, use ${RLN}. In the other case, if one or both of the paths are outside of ${PREFIX} use ${LN} -s and only prepend ${STAGEDIR} to the target's path.

Example 6.1. Inside ${PREFIX}, Create Relative Symbolic Links

${RLN} uses install(1)'s relative symbolic feature which frees the porter of computing the relative path.


Will generate:

% ls -lF ${STAGEDIR}${PREFIX}/lib
  lrwxr-xr-x  1 nobody  nobody    181 Aug  3 11:27 ->
  -rwxr-xr-x  1 nobody  nobody     15 Aug  3 11:24*

When used with paths not in the same directory:

${RLN} ${STAGEDIR}${PREFIX}/libexec/foo/bar ${STAGEDIR}${PREFIX}/bin/bar

Will automatically generate the relative symbolic links:

% ls -lF ${STAGEDIR}${PREFIX}/bin
  lrwxr-xr-x  1 nobody  nobody    181 Aug  3 11:27 bar@ -> ../libexec/foo/bar

Example 6.2. Outside ${PREFIX}, Create Absolute Symbolic Links

When creating a symbolic link outside of ${PREFIX}, the source must not contain ${STAGEDIR}, the target, however, must:

${LN} -sf /var/cache/${PORTNAME} ${STAGEDIR}${PREFIX}/share/${PORTNAME}

Will generate:

% ls -lF ${STAGEDIRDIR}${PREFIX}/share
  lrwxr-xr-x  1 nobody  nobody    181 Aug  3 11:27 foo@ -> /var/cache/foo

All FreeBSD documents are available for download at

Questions that are not answered by the documentation may be sent to <>.
Send questions about this document to <>.