Building IPS Spec Files

by:
Michal Pryc (michal.pryc [At sun.com)
Luis de Bethencourt (luis.debethencourt [At sun.com)

Menu:
1. Information
2. Introduction
3. Writing
4. Example
5. Summary
6. Task

1. Information

This exercise will teach you:
1. What is an spec file and how it is formed
2. How to write the spec file
3. How to check the spec file builds correctly

2. Introduction to spec files

The spec file is at the heart of the package. It contains information required to build the package, instructions on how to build it and it dictates exactly what files are a part of the package, and where they should be installed.
With this many responsibilities, the spec file format can be a bit complex. However, it's broken into several sections, most of them being shell scripts, making it easier to handle. All told, there are seven sections:
1. preamble
2. prep
3. build
4. install
5. clean
6. files
7. changelog

2.1 the preamble section

The preamble contains information that will be displayed when users request information about the package. This would include a description of the package's function, the version number of the software, and so on. Also contained in the preamble are lines identifying sources, patches, and more.

2.2 the prep section

The prep section is where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the prep section. Usually, this boils down to unpacking the sources.

2.3 the build section

The build section is used to perform whatever commands are required to actually compile the sources. This section usually consists of a single make command, but it can be more complex if the building process needs it.

2.4 the install section

The install section is used to perform the commands required to actually install the software. Usually a make install is enough.

2.5 the clean section

The clean section is a script that cleans things up after the build.

2.6 the files

The files section is a list of files and where this files must go, this will be the package and this section is very important. A number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information.

2.7 the changelog

The changelog section is a log of all the changes made in the package and information about this changes.

3. Writing the spec file

Get the empty spec file template

Download example content tar ball and untar: spec_file.tar.bz2
$ cd download_directory
$ bzcat spec_file.tar.bz2 | tar xvf -

Write the spec file (from the empty template) using your favorite editor, in this example vim.

$ vim my_packages/SUNWempty.spec
You will see the sections explained above. Writing a spec file can be as simple as filling those sections. But since this is your first one, close vim and let's give you an example...

4. Example

Open example spec file

$ vim my_packages/SUNWnano.spec

Sections:
1. preamble
2. prep
3. build
4. install
5. clean
6. files
7. changelog

4.1 the preamble section

%include Solaris.inc
Name: SUNWnano
License: GPL
Version: 2.0.7
Summary: GNU nano is a free replacement for Pico, the default Pine editor.
Source: http://www.nano-editor.org/dist/v2.0/nano-%{version}.tar.gz
SUNW_Copyright: %{name}.copyright
URL: http://www.nano-editor.org
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%include default-depend.inc

%description
GNU nano is a small and friendly text editor. It aims to emulate the
Pico text editor while also offering a few enhancements.


We define name, license, version, url and description that will appear when the package is searched or package information triggered. The IPS build system will download the tarball defined in source, and will build from it. Notice the SUNWnano.copyright file in the copyright directory. Packages won't build if there is no copyright file for them.

4.2 the prep section

%prep
%setup -q


Shell comand to setup the build directory.

4.3 the build section

%build
./configure --enable-all --prefix=%{_prefix} --exec-prefix=%{_prefix}
make


Thanks to autotools, configure and make check the dependencies in the system and prepare the build for install.

4.4 the install section

%install
rm -rf %{buildroot}
make DESTDIR="%{buildroot}" install
rm -rf %{buildroot}%{_datadir}/info


Any previous builds are removed. Package is built and installed in the buildroot with make install. The files that don't need to be installed are removed from the buildroot.

4.5 the clean section

Nothing needs to be cleaned for this package.

4.6 the files

%files
%defattr (-, root, bin)
%dir %attr (0755, root, bin) %{_bindir}
%{_bindir}/*
%dir %attr(0755, root, bin) %{_mandir}
%dir %attr(0755, root, bin) %{_mandir}/*
%{_mandir}/*/*
%dir %attr (0755, root, sys) %{_datadir}/nano
%{_datadir}/nano/*


Here in this very important section, the files are listed, and their and locations are defined.

4.7 the changelog

%changelog
* Mon May 12 2008 - luis.debethencourt@sun.com
- Initial version


Since we just created the package the changelog just lists the current date and that this is the initial version.

5. Summary

In this page, you have learned the format of an IPS spec file, how it works and how to write one looking at an example spec file.

Did you saw how easy it was?
Go write yours now! :)

6. Task

Your task is to create working spec file
1. Get the SFE packages from HERE
2. Unpack
3. The SFEnano.spec is broken (sections %build and %files), your task is to change those, so actually you will get the working SFEnano.spec file
4. The working solution of the SFEnano.spec can be found HERE, please don't go the easy way and try to fix broken spec file before checking the working solution :-)