# Dependencies

Free and open source software is highly modular, and MacPorts ports often require that other ports be installed beforehand; these prerequisites for a given port are called a port's dependencies.

The three keywords used when specifying dependencies in a Portfile are related to port install phases, and they refer to what are called library, build, and run dependencies. Though all of them install dependencies before a given port is installed, specifying dependencies with the correct keyword is important for proper port upgrade and uninstall behavior. For example, you may not uninstall a port that is a library dependency for another port, though you may remove one that is a build dependency; likewise, upgrading a port will upgrade its library and build dependencies also, but not its run dependencies.

depends_lib
depends_lib-append
depends_lib-delete

  The list of dependencies to check before phases `configure`, `build`, `destroot`, `install`, and `package`. Library dependencies are needed both at build time (for headers and libraries to link against) and at run time.

depends_build
depends_build-append
depends_build-delete

  The list of dependencies to check before phases `configure`, `build`, `destroot`, `install`, and `package`. Build dependencies are needed when software is compiled, but not needed at all once the software is compiled and installed.

depends_run
depends_run-append
depends_run-delete

  The list of dependencies to check before phases `destroot`, `install`, and `package`. Run dependencies are needed when the software is run, but not to compile it.

## Port and File Dependencies

There are two types of dependencies: port dependencies and file dependencies. Port dependencies can be satisfied by reference to a port (the MacPorts registry is queried), or by reference to a file (whether provided by a port or not). The most commonly-used type of dependencies in Portfiles are port dependencies, because dependencies should be provided by MacPorts ported software whenever possible, and usually only one port can provide the needed libraries and files.

But when satisfying a dependency with vendor-supplied software is preferred for special reasons, or when it is possible for more than one port to satisfy a dependency, then file dependencies may be used. An example of the former is with X11 —Apple's is widely preferred; an example of the latter is with "-devel" named ports —these ports provide identical files (though only one can be activated at a time).

Port dependencies, the preferred type, are specified as shown in these examples:

    depends_lib         port:rrdtool port:apache2

    depends_build       port:libtool

    depends_run         port:apache2 port:php5

File dependencies may be of three types: `bin` for programs, `lib` for libraries, and `path` for any installed file. File dependencies are specifed in the form: <type>:<filename>:<port>. <filename> is relative to `${prefix}`.

Note that the <port> specified is only installed if the specified library, binary, or file is not found. See the examples below:

    depends_lib         lib:libX11.6:xorg

    depends_build       bin:glibtool:libtool

    depends_run         path:lib/libltdl.a:libtool

When using lib dependencies, only the library name is specified —not its extension. (e.g. ".dylib" ".so", etc.)