FreeBSD Handbook : Installing Applications: The Ports collection : How Does the Ports Collection Work?
Previous: Why Have a Ports Collection?
Next: Getting a FreeBSD Port

4.2. How Does the Ports Collection Work?

Programs are typically distributed on the Internet as a tarball consisting of a Makefile and the source code for the program and usually some instructions (which are unfortunately not always as instructive as they could be), with perhaps a configuration script.

The standard scenario is that you FTP down the tarball, extract it somewhere, glance through the instructions, make any changes that seem necessary, run the configure script to set things up and use the standard `make' program to compile and install the program from the source.

FreeBSD ports still use the tarball mechanism, but use a skeleton to hold the "knowledge" of how to get the program working on FreeBSD, rather than expecting the user to be able to work it out. They also supply their own customised Makefile, so that almost every port can be built in the same way.

If you look at a port skeleton (either on your FreeBSD system or the FTP site) and expect to find all sorts of pointy-headed rocket science lurking there, you may be disappointed by the one or two rather unexciting-looking files and directories you find there. (We will discuss in a minute how to go about Getting a port).

``How on earth can this do anything?'' I hear you cry. ``There is no source code there!''

Fear not, gentle reader, all will become clear (hopefully). Let's see what happens if we try and install a port. I have chosen `ElectricFence', a useful tool for developers, as the skeleton is more straightforward than most.

Note if you are trying this at home, you will need to be root.

 # cd /usr/ports/devel/ElectricFence
# make install
>> Checksum OK for ElectricFence-2.0.5.tar.gz.
===>  Extracting for ElectricFence-2.0.5
===>  Patching for ElectricFence-2.0.5
===>  Applying FreeBSD patches for ElectricFence-2.0.5
===>  Configuring for ElectricFence-2.0.5
===>  Building for ElectricFence-2.0.5
[lots of compiler output...]
===>  Installing for ElectricFence-2.0.5
===>  Warning: your umask is "0002".
      If this is not desired, set it to an appropriate value
      and install this port again by ``make reinstall''.
install -c -o bin -g bin -m 444 /usr/ports/devel/ElectricFence/work/ElectricFence-2.0.5/libefence.a /usr/local/lib
install -c -o bin -g bin -m 444 /usr/ports/devel/ElectricFence/work/ElectricFence-2.0.5/libefence.3 /usr/local/man/man3
===>   Compressing manual pages for ElectricFence-2.0.5
===>  Registering installation for ElectricFence-2.0.5

To avoid confusing the issue, I have completely removed the build output.

If you tried this yourself, you may well have got something like this at the start:-

# make install
>> ElectricFence-2.0.5.tar.gz doesn't seem to exist on this system.
>> Attempting to fetch from ftp://ftp.doc.ic.ac.uk/Mirrors/sunsite.unc.edu/pub/Linux/devel/lang/c/.

The `make' program has noticed that you did not have a local copy of the source code and tried to FTP it down so it could get the job done. I already had the source handy in my example, so it did not need to fetch it.

Let's go through this and see what the `make' program was doing.

  1. Locate the source code tarball. If it is not available locally, try to grab it from an FTP site.
  2. Run a checksum test on the tarball to make sure it has not been tampered with, accidentally truncated, downloaded in ASCII mode, struck by neutrinos while in transit, etc.
  3. Extract the tarball into a temporary work directory.
  4. Apply any patches needed to get the source to compile and run under FreeBSD.
  5. Run any configuration script required by the build process and correctly answer any questions it asks.
  6. (Finally!) Compile the code.
  7. Install the program executable and other supporting files, man pages, etc. under the /usr/local hierarchy, where they will not get mixed up with system programs. This also makes sure that all the ports you install will go in the same place, instead of being flung all over your system.
  8. Register the installation in a database. This means that, if you do not like the program, you can cleanly remove all traces of it from your system.

Scroll up to the make output and see if you can match these steps to it. And if you were not impressed before, you should be by now!


FreeBSD Handbook : Installing Applications: The Ports collection : How Does the Ports Collection Work?
Previous: Why Have a Ports Collection?
Next: Getting a FreeBSD Port