FreeBSD Porter's Handbook
Prev | Chapter 9 Testing your port | Next

# 9.4 `PREFIX` and `DESTDIR`

`PREFIX` determines the location where the port will install. It is usually `/usr/local`, or `/opt`. User can set `PREFIX` to anything he wants. Your port must respect this variable.

`DESTDIR`, if set by user, determines the complete alternative environment, usually a jail, or an installed system mounted elsewhere than `/`. A port will actually install into `DESTDIR`/`PREFIX`, and register with the package database in `DESTDIR`/var/db/pkg. As `DESTDIR` is handled automatically by the ports infrastructure via calling chroot(8), you do not need any modifications or any extra care to write `DESTDIR`-compliant ports.

The value of `PREFIX` will be set to `LOCALBASE` (default `/usr/local`). If `USE_LINUX_PREFIX` is set, `PREFIX` will be `LINUXBASE` (default `/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 `Makefile`s 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/$(make -V PORTNAME)

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/$(make -V PORTNAME)` 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 `Makefile`s.

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.

Prev | Home | Next
Port Tools | Up | Tinderbox

For questions about the FreeBSD ports system, e-mail <ports@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.