Solaris/FOSS specfiles example1

Jump to: navigation, search

Writing conditional Spec files

In general, the reason for writing a conditional spec file is so that you don't have to rely on a CMS system to figure out which version of a module you want to check out. Like tke KDE4 on Solaris project, there are several hundred spec files and easily double that in support files (once all the DUDE tarfile conversions are completed) so trying to go back a rev can be rather painful. This wiki attempts to clearly document the ease in which this can be handled.


FOSS spec files care about src_ver or version
explicit plists are used to catch differences between package revisions
every decision should be based on a simple true/false decision.
we don't want to maintain too many revisions internally to the spec, just enough to go back easily if something breaks, so current, and last working (or 2) is really all we want to support. Otherwise, you have to be something of a mercurial guru to figure out how to get back the last working version.

Header, self explanatory

# SPEC file for expat library.
# Copyright 2009 Ben Taylor
# Copyright 2008 Lukas Oboril
# Copyright 2008 Adriaan de Groot
# Copyright 2008 Stefan Teleman
# This file is released under the terms of an MIT / 1-clause BSD
# license. See the file LICENSE.MIT for details.
# Expat is a GNU library for xml parsing

Package definition

src_ver is the variable that defines the package source version

# Support expat-2.0.0 and 2.0.1. 2.0.1 now default.
%define src_name        expat
#%define src_ver                2.0.0
%define src_ver         2.0.1
Name:                   %{src_name}
Version:                %{src_ver}
SUNW_Pkg:               FOSS%{name}
%define src_rev         2

Summary:                XML parser library
License:                MIT
Source:                 %{site_sourceforge}/expat/%{src_name}-%{src_ver}.tar.gz
Group:                  System/Libraries

Expat is an XML parser library written in C. It is a
stream-oriented parser in which an application registers
handlers for things the parser might find in the XML
document (like start tags).

versioning conditional defines

%define is_ver_2_0_0    %( test %{src_ver} = "2.0.0" && echo 1 || echo 0)
%define is_ver_2_0_1    %( test %{src_ver} = "2.0.1" && echo 1 || echo 0)

during development, it's possible that we could iterate through several versions. These versions will likely be important to the base-<module>.spec file, since the intention is to keep patches as history, and use the version test to manage them. Again, we really ought to keep no more than 1 working, and 2 previous versions, otherwise the clutter will become a bit difficult to deal with.

On a project like KDE4 on Solaris, there are so many working parts, being about to back rev a module quickly has really been useful.

In the case where we need to test a package minor rev greater than, equal to 1, we can do the following:

%define expat_minor_rev      %( echo %{src_ver} | cut -f3 -d\. )
%define expat_rev_ge_2_0_1   %( test ${expat_minor_rev} -ge 1 && echo 1 || echo 0)

collection of standard includes use for the KDE4 project


%use base32 = base-expat.spec
%if %has64
%use base64 = base-expat.spec


the base-expat.spec is used for both 32-bit and 64-bit building, and on occasion, you'll find that some package didn't honor the .../lib/{amd64|sparcv9} construct, and you'll use the %install area to manually clean that up.

Explicit plist

%dir %attr (0755, root, sys) /opt
%dir %attr (0755, root, sys) %{_prefix}
%defattr (-, root, bin)
%dir %attr (0755, root, bin) %{_bindir}

%dir %attr (0755, root, bin) %{_libdir}

How to use versions with explicit plists

Why use an explicit plist? As another example,ncurses-5.6. For 18 months, the plist was in place, explicitly defined. During the change to full spec, a minor change occured, rather unintentionally, and another set of libraries built which would have never been identified had a global plist been used.

Here, even a minor revision of the package generated a new minor revision of the shared library. Here we would use an explicit version test.

For a file such as an include file, we might use a %if %{expat_minor_ge_2_0_1} construct instead.

This model works good for the FOSS packages, but for the KDE4 modules, we've agreed that the library versioning will cause probably more churn in the spec files than is gained by having explicit versioning for those.

%if %{is_ver_2_0_0}

%if %{is_ver_2_0_1}

Explicit plist continued....

%dir %attr (0755, root, bin) %{_includedir}

%dir %attr (0755, root, sys) %{_datadir}
%dir %attr (0755, root, bin) %{_mandir}

%if %{has64}
%dir %attr (0755, root, bin) %{_bindir}/%{_arch64}

%dir %attr (0755, root, bin) %{_libdir}/%{_arch64}
%if %{is_ver_2_0_0}
%if %{is_ver_2_0_1}


* Tue Dec  1 2009 - [email protected]
- convrt to spec, add explicit plist
- add upgrade to version 2.0.1
* Wed Oct  1 2008 - [email protected]
- Turned back into a spec file
* Thu Jan 17 2008 - [email protected]
- Initial version

This page was last edited on 18 March 2016, at 19:17. Content is available under Creative Commons License SA 4.0 unless otherwise noted.