-->

Previous | Table of Contents | Next

Page 132

11.3.6. The Missing Spec File Sections

Our sample spec file is somewhat simplistic and it's missing two sections that might be used in more complex situations. We'll go over each one briefly here. More complete information on these sections will be given at various points in the book.

11.3.6.1. The Install/Uninstall Scripts

One missing section to our spec file is the section that would define one or more of four possible scripts. The scripts are executed at various times when a package is installed or erased.

The scripts can be executed at the following points:

We'll see how these scripts are used in Chapter 20.

11.3.6.2. The %clean Section

The other missing section has the rather descriptive title %clean. This section can be used to clean up any files that are not part of the application's normal build area. For example, if the application creates a directory structure in /tmp as part of its build, it will not be removed. By adding a sh script to the %clean section, such situations can be handled gracefully, right after the binary package is created.

11.4. Starting the Build

Now it's time to begin the build. First, we change directory into the directory holding cdplayer's spec file:


# cd /usr/src/redhat/SPECS

#

Next, we start the build with an rpm -b command:


# rpm -ba cdplayer-1.0.spec

The a following the -b option directs RPM to perform all phases of the build process. Sometimes it is necessary to stop at various phases during the initial build to resolve problems that crop up while writing the spec file. In these cases, other letters can be used after the -b in order to stop the build at the desired phase. For this example, however, we will continue through the entire build process.

Page 133

In this example, the only other argument to the build command is the name of the package's spec file. This can be wildcarded to build more than one package, but in our example, we'll stick with one.

Let's look at RPM's output during the build:


* Package: cdplayer

+ umask 022

+ echo Excuting: %prep

Excuting: %prep

+ cd /usr/src/redhat/BUILD

+ cd /usr/src/redhat/BUILD

+ rm -rf cdplayer-1.0

+ gzip -dc /usr/src/redhat/SOURCES/cdplayer-1.0.tgz

+ tar -xvvf -

drwxrwxr-x root/users        0 Aug  4 22:30 1996 cdplayer-1.0/

-rw-r--r-- root/users    17982 Nov 10 01:10 1995 cdplayer-1.0/COPYING

-rw-r--r-- root/users      627 Nov 10 01:10 1995 cdplayer-1.0/ChangeLog

-rw-r--r-- root/users      482 Nov 10 01:11 1995 cdplayer-1.0/INSTALL

.

.

.

-rw-r--r-- root/users     2720 Nov 10 01:10 1995 cdplayer-1.0/struct.h

-rw-r--r-- root/users      730 Nov 10 01:10 1995 cdplayer-1.0/vol.c

-rw-r--r-- root/users     2806 Nov 10 01:10 1995 cdplayer-1.0/volume.c

-rw-r--r-- root/users     1515 Nov 10 01:10 1995 cdplayer-1.0/volume.h

+ [ 0 -ne 0 ]

+ cd cdplayer-1.0

+ cd /usr/src/redhat/BUILD/cdplayer-1.0 + chown -R root.root .

+ chmod -R a+rX,g-w,o-w .

+ exit 0

The output continues, but let's stop here for a moment and discuss what has happened so far.

At the start of the output, RPM displays the package name (cdplayer), sets the umask, and starts executing the %prep section. Thanks to the %setup macro, RPM then changes directory into the build area, removes any existing old sources, and extracts the sources from the original compressed tar file. Although each file is listed as it is extracted, we've omitted most of the files listed to save space.

The %setup macro continues by changing directory into cdplayer's top-level source directory and setting the file ownership and permissions properly. As you can see, it does quite a bit of work for you.

Let's take a look at the output from the %build section next:


+ umask 022

+ echo Excuting: %build

Excuting: %build

+ cd /usr/src/redhat/BUILD

+ cd cdplayer-1.0

+ make

gcc -Wall -O2 -c -I/usr/include/ncurses cdp.c

gcc -Wall -O2 -c -I/usr/include/ncurses color.c

gcc -Wall -O2 -c -I/usr/include/ncurses display.c



Page 134


gcc -Wall -O2 -c -I/usr/include/ncurses misc.c

gcc -Wall -O2 -c -I/usr/include/ncurses volume.c

volume.c: In function `mix_set_volume':

volume.c:67: warning: implicit declaration of function `ioctl'

gcc -Wall -O2 -c -I/usr/include/ncurses hardware.c

gcc -Wall -O2 -c -I/usr/include/ncurses database.c

gcc -Wall -O2 -c -I/usr/include/ncurses getline.c

gcc -o cdp cdp.o color.o display.o misc.o volume.o hardware.o database.o

getline.o -I/usr/include/ncurses -L/usr/lib -lncurses

groff -Tascii -man cdp.1 | compress >cdp.1.Z

+ exit 0

There are no surprises here. After setting the umask and changing directory into cdplayer's top-level directory, RPM issues the make command we put into the spec file. The rest of the output comes from make as it actually builds the software. Next comes the %install section:


+ umask 022

+ echo Excuting: %install

Excuting: %install

+ cd /usr/src/redhat/BUILD

+ cd cdplayer-1.0

+ make install

chmod 755 cdp

chmod 644 cdp.1.Z

cp cdp /usr/local/bin

ln -s /usr/local/bin/cdp /usr/local/bin/cdplay

cp cdp.1 /usr/local/man/man1

+ exit 0

Just as in the previous sections, RPM again sets the umask and changes directory into the proper directory. It then executes cdplayer's install target, installing the newly built software on the build system. Those of you who carefully studied the spec file might have noticed that the README file is not part of the install section. It's not a problem, as we see here:


+ umask 022

+ echo Excuting: special doc

Excuting: special doc

+ cd /usr/src/redhat/BUILD

+ cd cdplayer-1.0

+ DOCDIR=//usr/doc/cdplayer-1.0-1

+ rm -rf //usr/doc/cdplayer-1.0-1

+ mkdir -p //usr/doc/cdplayer-1.0-1

+ cp -ar README //usr/doc/cdplayer-1.0-1

+ exit 0

After the customary umask and cd commands, RPM constructs the path that will be used for cdplayer's documentation directory. It then cleans out any preexisting directory and copies the README file into it. The cdplayer app is now installed on the build system. The only thing left to do is to create the actual package files and perform some housekeeping. The binary package file is created first:


Binary Packaging: cdplayer-1.0-1

Finding dependencies...

Requires (2): libc.so.5 libncurses.so.2.0



Previous | Table of Contents | Next