PREFIX 變數會決定該 port 所會安裝的位置, 通常是 /usr/local 或 /opt 。 使用者可以藉由設定 PREFIX 決定要裝在哪邊, 而你所維護的 port 必須遵循該規則。
若使用者有設定 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 the hard-coding of /usr/local or /usr/X11R6 anywhere in the source will make the port much more flexible and able to cater to the needs of other sites. For X ports that use imake, this is automatic; otherwise, this can often be done by simply replacing the occurrences of /usr/local (or /usr/X11R6 for X ports that do not use imake) in the various Makefiles in the port to read ${PREFIX}, as this variable is automatically passed down to every stage of the build and install processes.
Make sure your application is not installing things in /usr/local instead of PREFIX. A quick test for this is to do this is:
# make clean; make package PREFIX=/var/tmp/port-name
If anything is installed outside of PREFIX, the package creation process will complain that it cannot find the files.
This does not test for the existence of internal references, or correct use of LOCALBASE for references to files from other ports. Testing the installation in /var/tmp/port-name to do that while you have it installed would do that.
The variable PREFIX can be reassigned in your Makefile or in the user's environment. However, it is strongly discouraged for individual ports to set this variable explicitly in the Makefiles.
Also, refer to programs/files from other ports with the variables mentioned above, not explicit pathnames. For instance, if your port requires a macro PAGER to be the full pathname of less, use the compiler flag:
-DPAGER=\"${LOCALBASE}/bin/less\"instead of -DPAGER=\"/usr/local/bin/less\". This way it will have a better chance of working if the system administrator has moved the whole /usr/local tree somewhere else.