This is an old revision of the document!
The DESTDIR macro
What is it?
DESTDIR is a make environmental variable that we use in installing various parts of the FreeBSD operating system. According to its name, it sets the destination directory, where the desired components should go.
DESTDIR in src tree
We use DESTDIR for populating a jail environment. Setting DESTDIR while making an installworld will result in an individual FreeBSD userland environment, what is called a jail. We make use of jails for virtual server hosting or imprisoning processes to improve security.
DESTDIR in doc/www tree
The compiled webpages and documentations go to ${DESTDIR}/data. While mirroring the FreeBSD webpages we should set this properly in conjunction with our webserver.
DESTDIR in ports tree
So far, the DESTDIR macro in ports tree hasn't been implemented. As a SummerOfCode2006 student, GáborKövesdán is working on the implementation. According to our interpretation of DESTDIR, it should install packages into existing environments (or jails). Specifically, it means that packages should go to ${DESTDIR}/${PREFIX} and be registered under ${DESTDIR}/var/db/pkg.
For example: Installing misc/foo with DESTDIR=/bla results in a package under /bla/usr/local and it is registered under /bla/var/db/pkg, so that it be removable from the environment with pkg_delete. Of course, LOCALBASE can be overriden so using DESTDIR=/bla and LOCALBASE=/opt (or PREFIX=/opt) installs the package into /bla/opt and the package info still goes to /bla/var/db/pkg.
Unfortunately, there are ports that should be fixed to work properly with DESTDIR. DESTDIR for ports has been a desired feature a long ago, but not at the beginning, so current ports and infrastructure aren't aware of it. Modifying existing code towards a radically different direction is always difficult, we cannot avoid fixing a bunch of ports.
How to write DESTDIR-respective ports?
Always make sure that you are using the correct pathnames. Everything should be installed under ${DESTDIR}${PREFIX}, a.k.a. ${TARGETDIR}. When referencing to the final destination, always use ${TARGETDIR}. ${DOCSDIR}, ${EXAMPLESDIR}, ${DATADIR} and ${DESKTOPDIR} are okay, they are already respective to DESTDIR. ${LOCALBASE}, ${LINUXBASE} and ${X11BASE} are also full paths, so they are okay, too. If you need the relative ones of these three variables, you can use ${LOCALBASE_REL}, ${LINUXBASE_REL} and ${X11BASE_REL}. For plists, you don't have to modify anything. If the plist is good without DESTDIR set, it will probably be good for DESTDIR. For special cases, you can use %%TARGETDIR%% and %%DESTDIR%% there as well, but I don't think it will be necessary. %%LOCALBASE%%, %%LINUXBASE%% and %%X11BASE%% are unchanged there, no need to modify, but we needed to change them in Mk, since we have to look for dependencies in DESTDIR.
If you need further information feel free to contact me: MailTo(gabor@FreeBSD.org)
Known Issues
* USE_RCORDER doesn't work with DESTDIR yet. (Fixed in Perforce)
* LDCONFIG stuff fails when uninstalling from DESTDIR (Fixed in Perforce)
* There are some wird error when making pakcage with FORCE_PKG_REGISTER set (Fixed in Perforce)
* PKGINSTALLVER is set incorrectly. (Fixed in Perforce)
* MLINKS doesn't work as intended
* OPENSSLRPATH is wrong is bsd.openssl.mk
* Sometimes MD5 checksums are generated wrongly for DESTDIR. I suppose it is generated from the host system somehow, so it needs to be done chrooted as well.