章 6. Special Considerations

內容目錄
6.1. Staging
6.2. Bundled Libraries
6.3. 共用函式庫
6.4. Ports with Distribution Restrictions or Legal Concerns
6.5. Building Mechanisms
6.6. 使用 GNU Autotools
6.7. 使用 GNU gettext
6.8. 使用 Perl
6.9. 使用 X11
6.10. 使用 GNOME
6.11. GNOME 元件
6.12. 使用 Qt
6.13. 使用 KDE
6.14. 使用 Java
6.15. 網路應用程式, Apache 和 PHP
6.16. 使用 Python
6.17. 使用 Tcl/Tk
6.18. 使用 Emacs
6.19. 使用 Ruby
6.20. 使用 SDL
6.21. 使用 wxWidgets
6.22. 使用 Lua
6.23. 使用 iconv
6.24. 使用 Xfce
6.25. 使用 Mozilla
6.26. 使用 Databases
6.27. Starting and Stopping Services (rc Scripts)
6.28. Adding Users and Groups
6.29. Ports That Rely on Kernel Sources

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

6.1. Staging

bsd.port.mk 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 節 9.4, “PREFIX 以及 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:

NO_MTREE=	yes

提示:

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.

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

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

The source path ${PREFIX}/lib/libfoo.so.42 looks fine but could, in fact, be incorrect. Absolute paths can point to a wrong location, like when a remote file system has been mounted with NFS under a non-root mount point. Relative paths are less fragile, and often much shorter.

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

本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/

若有 FreeBSD 方面疑問,請先閱讀 FreeBSD 相關文件,如不能解決的話,再洽詢 <questions@FreeBSD.org>。

關於本文件的問題,請洽詢 <doc@FreeBSD.org>。