start page | rating of books | rating of authors | reviews | copyrights

Book HomeMac OS X for Unix GeeksSearch this book

6.2. Creating Fink Packages

You can create your own Fink packages by identifying a source archive and creating a .info file in your /sw/fink/dists/local/main/finkinfo directory.

6.2.1. Sample Program

To demonstrate how to create a package, we'll create a short C program and its associated manpage. Example 6-1 shows hellow.c and Example 6-2 shows its manpage, hellow.1.

Example 6-1. The Hello, World sample program

/*
 * hellow.c - Prints a friendly greeting.
 */

#include <stdio.h>

int main( )
{
  printf("Hello, world!\n");
  return 0;
}

Example 6-2. The manpage for hellow.c

.\" Copyright (c) 2002, O'Reilly & Associates, Inc.
.\"
.Dd April 15, 2002
.Dt HELLOW 1
.Os Mac OS X
.Sh NAME
.Nm hellow
.Nd Greeting generator
.Sh DESCRIPTION
This command prints a friendly greeting.

6.2.2. Creating and Publishing the Tarball

The Fink package system needs a tarball that can be downloaded with the curl utility, so you should put these two files into a directory, such as hellow-1.0. Then, create a tarball containing these files and that top-level directory, and put it somewhere where you can get it. In this example, the tarball is created and moved to the local Shared folder:

[localhost:~/src] bjepson% tar cvfz hellow-1.0.tar.gz hellow-1.0/
hellow-1.0/
hellow-1.0/hellow.1
hellow-1.0/hellow.c
hellow-1.0/Makefile
[localhost:~/src] bjepson% cp hellow-1.0.tar.gz /Users/Shared

The curl utility can download this file with the following URL: file:///Users/Shared/hellow-1.0.tar.gz. (We could also have put the file on a public web server or FTP server.)

6.2.3. Creating the .info File

Next, you need a .info file to tell Fink where to download the package and how to install it. Fink can use this information to download, extract, and compile the source code, and then generate and install a Debian package (.deb file). To create the file in /sw/fink/dists/local/main/finkinfo, you'll need superuser privileges (use the sudo utility to temporarily gain these privileges). Example 6-3 shows hellow-1.0.info.

Example 6-3. The hellow-1.0 info file

Package: hellow
Version: 1.0
Revision: 1
Source: file:///Users/Shared/%n-%v.tar.gz
CompileScript: make
InstallScript: mkdir -p %i/bin
 cp %n %i/bin
 mkdir -p %i/share/man/man1
 cp %n.1 %i/share/man/man1/%n.1
Description: Hello, World program
DescDetail: <<
Prints a friendly greeting to you and your friends.
<<
License: Public Domain
Maintainer: Brian Jepson <[email protected]>

The hellow-1.0.info file includes several entries, described in the following list. See the Fink Packaging Manual on http://fink.sourceforge.net/doc/packaging/ for more details.

Package
The name of the package.

Version
The package version.

Revision
The package revision number.

Source
The URL of the source distribution. You can use percent expansion in the name. (In this example, %n is the name of the package and %v is the package version.) See the Fink Packaging Manual for more percent expansions.

CompileScript
The command (or commands) needed to compile the source package. The command(s) may span multiple lines, but must begin after the colon.

InstallScript
The command (or commands) that install the compiled package. The command(s) may span multiple lines, but must begin after the colon.

Description
A short description of the package.

DescDetail
A longer description of the package, enclosed with << >>.

License
The license used by the package. See the Fink Packaging Manual for information on available licenses.

Maintainer
The name and email address of the maintainer.

6.2.4. Installing the Package

To install hellow, use the command sudo fink install hellow. This command downloads the source to a working directory, and then extracts, compiles, and packages it, generating the file /sw/fink/dists/local/main/binary-darwin-powerpc/hellow_1.0-1_darwin-powerpc.deb. After fink creates this file, it installs it using dpkg. After you've installed hellow, you can view its manpage and run the hellow command:

% man hellow

HELLOW(1)         System General Commands Manual         HELLOW(1)

NAME
     hellow - Greeting generator

DESCRIPTION
     This command prints a friendly greeting.

Mac OS                    April 15, 2002                    Mac OS
% hellow
Hello, world!

This example shows only a portion of Fink's capabilities. For example, Fink can download and apply patches to a source distribution. For more information, see the Fink Packaging Manual, which contains detailed instructions on how to build and contribute a .deb package to the Fink distribution.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.