PREFIX 變數會決定該 port 所會安裝的位置。預設是 /usr/local , 但是使用者可以設定程自訂的路徑,像是 /opt 。 必須遵循此變數的值。

若使用者有設定 DESTDIR 變數, 那麼它會採用所設定的環境,通常可能是 jail 環境或者是並非掛載於 / 上的系統。 通常 port 會裝在 DESTDIR/PREFIX 底下, 並且會紀錄在 DESTDIR/var/db/pkg 內的套件資料庫。 由於事實上 DESTDIR 會由 ports 架構透過 chroot(8) 來自動處理,所以您不需去作相關修改或刻意維護 DESTDIR 相容的 ports。

PREFIX 會設為 LOCALBASE (預設為 /usr/local)。 若有設定 USE_LINUX_PREFIX, 那麼 PREFIX 則為 LINUXBASE ( 預設為 /compat/linux)。

Avoiding hard-coded /usr/local paths in the source makes the port much more flexible and able to cater to the needs of other sites. Often, this can be accomplished by replacing occurrences of /usr/local in the port's various Makefiles with ${PREFIX}. This variable is automatically passed down to every stage of the build and install processes.

Make sure the application is not installing things in /usr/local instead of PREFIX. A quick test for such hard-coded paths is:

% make clean; make package PREFIX=/var/tmp/`make -V PORTNAME`

If anything is installed outside of PREFIX, the package creation process will complain that it cannot find the files.

In addition, it is worth checking the same with the stage directory support (see 節 6.1, “Staging”):

% make stage && make check-plist && make stage-qa && make package

These tests will not find hard-coded paths inside the port's files, nor will it verify that LOCALBASE is being used to correctly refer to files from other ports. The temporarily-installed port in /var/tmp/`make -V PORTNAME` must be tested for proper operation to make sure there are no problems with paths.

PREFIX must not be set explicitly in a port's Makefile. Users installing the port may have set PREFIX to a custom location, and the port must respect that setting.

Refer to programs and files from other ports with the variables mentioned above, not explicit pathnames. For instance, if the port requires a macro PAGER to have the full pathname of less, do not use a literal path of /usr/local/bin/less. Instead, use ${LOCALBASE}:


The path with LOCALBASE is more likely to still work if the system administrator has moved the whole /usr/local tree somewhere else.


All these tests are done automatically when running poudriere testport or poudriere bulk -t. It is highly recommended that every ports contributor install it, and tests all his ports with it. See 節 9.5, “Poudriere for more information.

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

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

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