Solaris/FOSS specfiles example1

From KDE Community Wiki
Revision as of 20:41, 3 December 2009 by 216.207.70.250 (talk) (minor fixups)

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.

Philosophy

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.

Header, self explanatory

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

Package definition

src_ver is the variable that defines the package source version

  1. Support expat-2.0.0 and 2.0.1. 2.0.1 now default.

%define src_name expat

  1. %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 Url: http://expat.sf.net/ Group: System/Libraries

%description 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. 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 %include foss-paths.inc

%include base-foss-header.inc

%include foss-common32.inc %use base32 = base-expat.spec %if %has64 %include foss-common64.inc %use base64 = base-expat.spec %endif

%include base-foss-common.inc

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

%dir %attr (0755, root, bin) %{_libdir} %{_libdir}/libexpat.so %{_libdir}/libexpat.so.1

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}

%if %{is_ver_2_0_0} %{_libdir}/libexpat.so.1.5.0 %endif %if %{is_ver_2_0_1} %{_libdir}/libexpat.so.1.5.2 %endif

Explicit plist continued....

%dir %attr (0755, root, bin) %{_includedir} %{_includedir}/expat.h %{_includedir}/expat_external.h

%dir %attr (0755, root, sys) %{_datadir} %dir %attr (0755, root, bin) %{_mandir} %{_mandir}/man1/xmlwf.1

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

%dir %attr (0755, root, bin) %{_libdir}/%{_arch64} %{_libdir}/%{_arch64}/libexpat.so %{_libdir}/%{_arch64}/libexpat.so.1 %if %{is_ver_2_0_0} %{_libdir}/%{_arch64}/libexpat.so.1.5.0 %endif %if %{is_ver_2_0_1} %{_libdir}/%{_arch64}/libexpat.so.1.5.2 %endif

%endif

%changelog

- convert to full spec (No DUDE files), explicit plist - add upgrade to version 2.0.1

- Turned back into a spec file

- Initial version