Introduction to Ports


You now know about packages and the tools FreeBSD provides for interacting with them. Ports offer another way for you to install software in FreeBSD. You use ports to compile software directly from the source code in an automated procedure that controls and safeguards the installation process as it allows you to grab the source directly from each program's distribution site.

As convenient as packages are, the traditional "UNIX way" of installing new software has always been to compile it yourself. The administrator finds the distribution site (using either HTTP or FTP, or in an earlier era, a tool such as Gopher or Archie), downloads the source code bundled up in a .tar.gz or .tgz (or .tbz) file, and unpacks it into some temporary directory. After reading the various README files for special instructions, the administrator usually runs a configure script that examines the system to check for a variety of function calls (these calls vary from platform to platform within the UNIX world) and generates an appropriate compilation script based on what calls are available for the program to use. The next step is to compile the software by running makean encapsulated compiler-management tool that reads its build targets and the necessary steps from a file called Makefile within the main source directory. After a (hopefully) clean compile, the administrator must then find the new, freshly baked executable and manually copy it into the publicly accessible location for binaries (/usr/local/bin, for example). In the best-case scenario, however, there is an "install" target in the makefile, so typing make install copies the proper files into (if he's lucky) the correct location.

This installation operation is (or rather, was) very inexact; sometimes it worked, sometimes it didn't. In the vast majority of cases it worked "sort of." Software distributed in source form usually worked fine on systems similar to the one the author was using; but trying to compile it on another platform usually resulted in at least a few minor disagreements about installation locations under the best of circumstances, or complete failures to compile in other cases. Maintenance was impossible, performance was unpredictable, and the reputation of UNIX for being arcane and difficult to use only grew stronger.

Enter the FreeBSD ports. Ports provide a way for you to compile software directly from the source in a regimented, structured, automated procedure that ensures the safety and integrity of the software you're installing while allowing you to grab the source directly from each program's distribution site (or a backup location, such as the central FreeBSD server, if the initial source fails). This means you can stay on top of the very latest developments in a piece of software without having to wait for a precompiled binary package that might not run on a heavily customized system.

Port installation also allows thousands of different pieces of software to install all their components into the proper locations in the FreeBSD filesystem without the developers even having to consider explicitly supporting FreeBSD's system structure. This is accomplished through a widespread system of port maintainers, volunteers in the FreeBSD user community who keep track of changes in their assigned ports and maintain scripts that patch a program's build and installation procedures to operate correctly with FreeBSD. When a developer updates his software, the port maintainer tries compiling it on FreeBSD and then makes whatever changes are necessary to the code patches and installation scripts that make it work smoothly with FreeBSD. A port, then, is simply these scripts and patches in a bundle, sitting in a particular spot on your FreeBSD machine, with a customized makefile that enables you to install the software simply by typing make install. No downloading; no configuring; no patching; no tweaking; no copying. All that work has been done for you.

FreeBSD's port system has been so successful it has been adopted by various other systems, particularly OpenBSD and NetBSD, and has inspired similar systems on Gentoo Linux and Mac OS X/Darwin. Its success can be attributed to two things: Its ability to keep UNIX administrators happy who prefer to compile their own software (either through security awareness or machismo), and its ability to provide the simplicity of version tracking and maintenance that the package system boasts. It's truly the best of both worlds.

The FreeBSD Ports Tree

The ports collection lives in /usr/ports. Go into that directory now and take a look around. What you see should resemble Listing 16.4. You'll notice that every category you saw in the Sysinstall program is here as a directory. (The list may not be 100% accurate for you because categories are reorganized on a fairly regular basis.)

Listing 16.4. Directories in /usr/ports

# ls -sF /usr/ports/ total 7422     2 .cvsignore         4 deskutils/         4 net-mgmt/    34 CHANGES           38 devel/             2 news/     2 COPYRIGHT          2 distfiles/         2 palm/  6768 INDEX-6            2 dns/               2 picobsd/     4 KNOBS              6 editors/           2 polish/    32 LEGAL              4 emulators/         2 portuguese/   106 MOVED              2 finance/           8 print/     6 Makefile           2 french/            2 russian/     2 Mk/                2 ftp/               2 science/     2 README            16 games/            12 security/     4 README.html        2 german/            2 shells/     2 Templates/        14 graphics/         14 sysutils/     2 Tools/             2 hebrew/           20 textproc/    86 UPDATING           2 hungarian/         2 ukrainian/     2 accessibility/     4 irc/               2 vietnamese/     2 arabic/           10 japanese/         24 www/     4 archivers/         4 java/              6 x11/     2 astro/             2 korean/            2 x11-clocks/    14 audio/             6 lang/              2 x11-fm/     2 benchmarks/       14 mail/              2 x11-fonts/     2 biology/           6 math/              2 x11-servers/     2 cad/               2 mbone/             6 x11-themes/     4 chinese/          12 misc/              6 x11-toolkits/     4 comms/             6 multimedia/        4 x11-wm/     2 converters/       22 net/    10 databases/         2 net-im/

Note

The contents of /usr/ports are by their nature independent of the branched development structure of the FreeBSD operating system. A newly released copy of the system will come with a snapshot of the ports created at the time the system was released, but it immediately becomes obsolete as soon as the ports within it are revised as new versions of the ported software come out. If you synchronize your ports tree to the central repository (as we will discuss later), it's always to whatever is current at the time you synchronize. There isn't a fixed state for the ports tree attached to each release as there is with the packages. Therefore, these sample directory listings are almost certain to differ somewhat from what is in your system. This also means that if you're trying to maintain multiple FreeBSD systems with identical software loadouts, you should avoid the ports system and use packages instead.


The first few directories (the ones beginning with capital letters, taking advantage of the UNIX convention of alphabetizing capital and lowercase initial letters separately, in accordance with the ASCII character set) are structural elements of the ports system, adjuncts that make the system work. You'll also find informative text files there, such as MOVED, which provides an up-to-date listing of recently moved or removed ports (including explanations for each of these changes). The rest of the directories are categories of ports.

Look inside one and you'll see as many as hundreds of different port directories, as demonstrated in the very partial Listing 16.5.

Listing 16.5. Some of the Ports Within a Category (Directory)

# ls -sF /usr/ports/audio/ total 1206  2 HVSC-Update/                       2 mp32ogg/  2 Maaate/                            2 mp3_check/ 16 Makefile                           2 mp3asm/  2 abcde/                             2 mp3blaster/  2 abcmidi/                           2 mp3burn/  2 abcselect/                         2 mp3butler/  2 ac3dec/                            2 mp3c/  2 adpcm/                             2 mp3check/  2 adplay/                            2 mp3ck/  2 afsp/                              2 mp3encode/

Note

Even though ports are sorted into categories by their intended functionality, their names aren't allowed to clasha port in audio can't have the same name as a port in sysutils even though they're in different directories. This is because once your ports are installed, they're all stored in a single flat database (/var/db/pkg) with no category divisions. The categories are only there in /usr/ports for your convenience in finding ports by type.


Browsing the ports in this way is less than efficient, especially in the larger categories (in this example, /usr/ports/audio contains 596 ports at the time of this writing). What if you know the name of a port you want to install, but you don't know what category it's in? You can use the locate command to find the port by name:

# locate uudeview /usr/ports/converters/uudeview


However, until the locate database has been initially built (which might take a week after you first install FreeBSD), the command won't work. Use the /usr/libexec/locate.updatedb command to build the database manually so you can make use of locate.

Anatomy of a FreeBSD Port

Inside each port directory are a few files, totaling no more than a few kilobytes, that completely define all the tweaks and modifications that need to be made to a freshly downloaded bundle of source code for it to compile and install cleanly on FreeBSD. These files are detailed in Table 16.2 (an incomplete listingsome ports have additional files).

Table 16.2. Files in a Port Directory

File

Purpose

Makefile

Contains certain variables used in the build process as well as contact information for the maintainer.

README.html

Contains the "short description" (or comment) for the port in HTML format.

distinfo

An MD5 checksum used for verifying the authenticity of the downloaded tarball.

files/

runme.sh

patch-aa

patch.ab

Patches that are applied to the source after it has been unpacked and support files that are FreeBSD specific; these vary greatly from port to port.

pkg-comment

The "short description" for the port.

pkg-descr

The "long description" for the port, which usually includes the URL of the developer's distribution site.

pkg-plist

The "packing list," which lists all the files to be installed as well as keywords telling the port system what to do when the port is deinstalled (for example, removing directories and unchanged files).


Makefile is the file that has the critical elements for building, configuring, installing, and maintaining a port. Listing 16.6 shows you what's typically inside Makefile.

Listing 16.6. A Typical Port Makefile

# New ports collection makefile for:    amp # Date created:         Jun 23 1997 # Whom:                 Vanilla I. Shu <vanilla@MinJe.com.TW> # # $FreeBSD: ports/audio/amp/Makefile,v 1.16 2005/04/17 15:19:40 novel Exp $ # PORTNAME=       amp PORTVERSION=    0.7.6 PORTEPOCH=      1 CATEGORIES=     audio MASTER_SITES=   http://www-users.cs.umn.edu/~wburdick/ftp/ MAINTAINER=     delphus@gmail.com COMMENT=        Another mp3 player GNU_CONFIGURE=  yes USE_GMAKE=      yes MAN1=           amp.1 PLIST_FILES=    bin/amp do-install:         @ ${INSTALL_PROGRAM} ${WRKSRC}/amp ${PREFIX}/bin         @ ${INSTALL_MAN} ${WRKSRC}/amp.1 ${PREFIX}/man/man1 .include <bsd.port.mk>

The list of shell-style variables tells you what you need to know about where the source for the port comes from, what version the makefile thinks is current, and how to reach the maintainer. The MAINTAINER is a volunteer, usually unaffiliated with whoever develops the actual software but a contributing member of the FreeBSD community, whose job is to make sure the port compiles and installs cleanly and that the most recent version of the software is reflected in the port.

Most makefiles contain targets, such as clean, install, and all. Not all the makefiles in the ports have these targets explicitly defined, but what they do have is an included central makefile (bsd.port.mk, which lives in the /usr/ports/Mk directory along with other included files). This file is what contains the standardized build targets. The individual makefiles in each port serve as overrides or augmentations (much in the same way /etc/rc.conf relates to /etc/defaults/rc.conf), setting the necessary variables for the build and defining additional targets that will be used in the automated compile process.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net