MacPorts installs software on top of the
operating system, providing newer versions of pre-installed packages or software that is not included in macOS. This is in contrast to other package management systems, such as
APT and
DNF, that are part of the operating system. For this reason, MacPorts is sometimes known as an overlay distribution. Other examples include Fink and
Homebrew. In contrast to the FreeBSD Ports Collection, which installs its software in /usr/local, MacPorts stores its data in /opt/local by default, although this can be modified when compiling MacPorts from source. The reason given for this change is that other packaging systems could overwrite what MacPorts has installed, or vice versa. A dedicated directory helps to overcome this problem. Fink follows a similar approach, installing its data into /sw by default.
Binary archives Buildbots are used to build ports in advance so that users do not have to compile the package locally. The result of this is known as a binary archive, and it helps to reduce the time required for installation. Similar to Homebrew, MacPorts takes the approach of having different builders for different operating system versions and architectures. However, sometimes it might be necessary to build from source locally if the binaries fail to build or the port's license does not allow binary distribution. If a binary could not be built, this would be noted on the MacPorts website for that individual port and the maintainer would be alerted. It is also possible to view recent buildbot events on a dedicated activity page. Binary archives are created locally whenever a user builds a port from source. They can also be manually created by running sudo port archive
packagename. This is similar to how the
AUR use
shell scripts known as a PKGBUILD, or how Homebrew use
ruby scripts as a formula. The portfiles are complete TCL programs with access to the TCL
interpreter. They make use of simple
key value pair options to define attributes. For example, this is the portfile for
Hashcat: These include the following:
Fetch First, MacPorts retrieves and downloads all the relevant files for the port from
upstream. These are known as distfiles. In the case of hashcat, these files are retrieved from
GitHub. They are removed, along with temporary build files, when the installation is complete.
Checksum Checksums are always defined within the portfile, since they are different for different files. The checksums of the downloaded files are compared to those in the portfile to see whether they match. In the above portfile, Hashcat does not require any changes to the code for the installation to work. Hence, there are no patch files required. When patches are required, the patch file would be stored with the portfile, and it would be referenced like the following (from
wget): patchfiles prefix.patch
Configure The project's
configure script is run to prepare for the build process. Part of this involves determining whether the required
libraries are present. For ports that do not have a configure script, this stage (as well as others when required) can be disabled. Since the configure stage is not referenced in the Portfile, hashcat is using the default configure setup as defined by MacPorts. This involves running the configure script via ./configure.
Build The instructions in the portfile are then used to
build the port. The commands that are executed can vary for different
languages. The portfile for hashcat shows that it should be treated as a
Makefile project. It will therefore be built by running make.
Test Some ports define a test to verify that the build has succeeded. This is an optional phase that is only run if the user executes port test
packagename. It is therefore not executed when installing a port. test.run yes test.target check test.env DYLD_LIBRARY_PATH=${worksrcpath}/magick/.libs
Destroot The destroot stage is the first step in moving the built files into the correct location. MacPorts takes the approach of first staging the installation into an intermediate location (destroot) before placing the files in their correct positions (install). One advantage of this is that it makes it easy to record what files were created, allowing them to be cleanly uninstalled. For hashcat, this is done by running make install, where one of the arguments (DESTDIR) specifies where to temporarily store the files. Note that in the majority of scenarios, only the stages below occur on the user's machine. This is because
binaries for the ports are pre-built so that they do not need to be built from source locally.
Install The destrooted files are archived safely. Since these files have not been activated yet, this allows for multiple different versions of the same port to be archived without interfering with each other.
Activate When activating a port, the files in the destroot directory are moved to their correct location. This makes them accessible to the user, completing the installation process. == Development ==