oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Managing Packages on Panther with DarwinPorts
Pages: 1, 2, 3

Creating the Portfile

Once the tarball has been placed in file:///Users/Shared/greet/src/, you need to create a file named Portfile in /Users/ernierothman/darwinports/dports/games/greet. A portfile lists the attributes of the package needed by DarwinPorts, for example, name, version, maintainer(s), where to download the package and how to install it. DarwinPorts uses this information to download, extract, and compile the source code. Information on patchfiles, special configure or compilation flags, and/or installation or post installation configuration instructions could be included in a portfile.

The following portfile can be used in the 'greet' example.

# $Id: $
PortSystem 1.0
name		greet
version		1.0
categories	games
description	"Twist on hello program"
long_description "Twist on hello program.  \
				  Prints: Greetings,\

master_sites	file:///Users/Shared/greet/src
homepage		file:///Users/Shared/greet
distname	${portname}-${portversion}
platforms	darwin
checksums	md5 732bf0585410cbebe6de7f57c8de88d8
configure {}

set instprog	"/usr/bin/install -m 755"
set instman	"/usr/bin/install -m 644"
destroot	{ 
    system "${instprog} -d ${destroot}${prefix}/bin"
	system "${instprog} -d ${destroot}${prefix}/man/man6"
	system "${instprog}  \
	  ${worksrcpath}/greet ${destroot}${prefix}/bin"
	system "${instprog}  \
	  ${worksrcpath}/*.6 ${destroot}${prefix}/man/man6" }

This Portfile file includes several entries, described in the following list.

# $Id: $
All Portfiles begin with this string, which is a commented out RCS Id tag.
Portsystem 1.0
This second line is the Portsystem version declaration.
The package name.
The package version.
Used for organization of packages into categories, e.g., mail, editors, games, etc.
Email addresses of folks maintaining the port.
One line description of the package.
More detailed description of the package.
The URL of the source distribution.
The URL of the software's web site.
Name of the distribution, e.g., greet-1.0. (Note: portname gets the value of name and portversion gets the value of version.)
Specifies the platform on which the port is to be built.
This command will verify the md5 checksum. (Required.)
The brackets are left empty if there is no autoconf configure script to run, as in this simple example. If there is a configure script, the argument -prefix=${prefix} is passed to it by DarwinPorts. After the configure{} line in the above Portfile, there are installation instructions to ensure that the program and its man page get installed into the correct directory.

The variables instprog and instman, are used to specify exactly which commands are to be used to install the binary and man page, respectively. The destroot key is included to specify exactly what the system should do when the destroot option is used with the port command.

For additional details on portfiles, see Michael A. Maibaum's DarwinPorts User Guide, a sample portfile in /Users/ernierothman/darwinports/base/doc/exampleport, and the portfile man page for more details.

Building and Installing Port

Once the Portfile file is ready, you can build the port. This involves a sequence of port commands, each invoked with the -v (verbose) and -d (debug) options. Begin this process by changing to the the directory which contains Portfile and enter the following command to verify the md5 checksum of the tarball: port -d -v checksum

Figure 6. The required port checksum command.

Since no explicit port name was provided in the preceding command, DarwinPorts obtains from any Portfile in the current directory the information that is needed to download and verify the md5 checksum of the source file. The source tarball file greet-1.0.tar.gz is downloaded into /opt/local/var/db/dports/distfiles/greet, and a work directory is created in /Users/ernierothman/darwinports/dports/games/greet/.

Next, extract the source by entering the following command

port -d -v extract

Figure 7. Extracting the source code.

This command unpacks greet-1.0.tar.gz, creating the /Users/ernierothman/darwinports/dports/games/greet/work/greet-1.0 directory.

Once the source code has been unpacked, you can build the package with the following command:

port -d -v build

Figure 8. Building the application.

If the build goes well, you can test the installation by first installing the port in the destroot directory:

port -d -v destroot

This produces a large number of warning messages, but in the end, if all goes well, you will have installed both the binary greet and the man page greet.6 in the /Users/ernierothman/darwinports/dports/games/greet/work/destroot/opt/local directory. After you've tested the binary and man page in this destroot directory, you can install the greet port system-wide, that is, in /opt/local

To do this enter the following command:

sudo port -d -v install

You can check that greet has actually been installed properly by entering the 'port installed' command, and by trying to run greet and viewing its man page.

Figure 9. Installing greet system-wide and verifying its installation.

Finally, you should enter the portindex command from /Users/ernierothman/darwinport/dport so that your DarwinPorts installation is completely aware of the newly installed greet port. Once you've done this, you can uninstall greet as you would uninstall any other port. That is, you could uninstall greet with the following command:

sudo port uninstall greet

This example shows only a small portion of DarwinPorts' capabilities. For more information, see the sources noted earlier, which contain detailed instructions on how to build and contribute a package to the DarwinPorts distribution.

Final Thoughts

DarwinPorts, along with Fink, provide Mac OS X users with the means to easily install and maintain an enormous number of open source applications. Fink has many more ported applications and is more mature than DarwinPorts. On the other hand, you may find some specific applications missing in Fink, but included in DarwinPorts. Fortunately, Fink and DarwinPorts can co-exist on the same system. Both projects seem to be under active development and improvement. Moreover, there is increasing cooperation among the Fink, DarwinPorts, and Gentoo Linux projects via the Metapkg Alliance. These efforts have made thousands of open source packages available to Mac OS X users, and have made package management on Mac OS X quite painless.

Ernest E. Rothman is a Professor of Mathematics at Salve Regina University (SRU) in Newport, Rhode Island and coauthor of Mac OS X Tiger For Unix Geeks.

Return to the Mac DevCenter