Apple's native format for packaging and distributing software is PackageMaker. Packages created with PackageMaker have a .pkg extension. When a user double-clicks on a package, the Installer application ( /Applications/Utilities ) is invoked and the installation process begins. These packages are bundles that contain all of the items the Installer needs. You can also use PackageMaker to create metapackages for installing multiple packages. Metapackages contain meta-information , files, and libraries associated with a given application. Packages can also contain multiple versions of an application; typically, both Mac OS X and Classic versions. PackageMaker documentation is available in the Help Viewer accessible from PackageMaker's Help option in the menu bar. The basic components of a package are:
12.1.1 Setting up the DirectoryTo demonstrate how to create a package, we'll create a short C program and its associated manpage . Example 12-1 shows hellow.c , and Example 12-2 shows its manpage, hellow.1 . Example 12-1. The Hello, World sample program/* * hellow.c - Prints a friendly greeting. */ #include <stdio.h> int main( ) { printf("Hello, world!\n"); return 0; } Example 12-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. PackageMaker expects you to set up the files using a directory structure that mirrors your intended installation. So, if you plan to install hellow into /usr/bin , and hellow.1 into /usr/share/man/man1 , you must create the appropriate subdirectories under your working directory. However, you can use a makefile to create and populate those subdirectories, so to begin with, your hellow directory looks like this: $ find hellow hellow hellow/hellow.1 hellow/hellow.c hellow/Makefile Suppose that your hellow project resides in ~/src/hellow . To keep things organized, you can create a subdirectory called stage that contains the installation directory. In that case, you'd place the hellow binary in ~/src/hellow/stage/bin and the hellow.1 manpage in ~/src/hellow/stage/share/man/man1 . The makefile shown in Example 12-3 compiles hellow.c , creates the stage directory and its subdirectories, and copies the distribution files into those directories when you run the command make prep . Example 12-3. Makefile for hellowhellow: cc -o hellow hellow.c prep: hellow mkdir -p -m 755 stage/bin mkdir -p -m 755 stage/share/man/man1 cp hellow stage/bin/ cp hellow.1 stage/share/man/man1/ To get started, you need only hellow.c , hellow.1 , and makefile . When you run the command make prep , it compiles the program and copies the files to their locations in the stage directory. After running make prep , the hellow directory will look like this: $ find hellow hellow hellow/hellow hellow/hellow.1 hellow/hellow.c hellow/Makefile hellow/stage hellow/stage/bin hellow/stage/bin/hellow hellow/stage/share hellow/stage/share/man hellow/stage/share/man/man1 hellow/stage/share/man/man1/hellow.1 Now you're ready to launch PackageMaker and bundle up the application. 12.1.2 Creating the PackageRun PackageMaker and set the options as appropriate for your package. Figure 12-1 through Figure 12-5 show the settings for the hellow sample. The options are as follows :
Figure 12-1. PackageMaker's Description tab
Figure 12-2. PackageMaker's Files tab
Figure 12-3. PackageMaker's Resources tab
Figure 12-4. PackageMaker's Info tab
Figure 12-5. PackageMaker's Version tabAfter filling in the package settings, select File Create Package to create the .pkg file. To install it, double-click on the file and install as you would any other Mac OS X package. When you quit PackageMaker, you'll be prompted to save the PackageMaker session with its currently filled in values as a .pmsp document. If you subsequently double-click your .pmsp document, PackageMaker will open with the values that were saved in the .pmsp file. |