2.3. Converting a Conventional Spec File

The following steps show how to convert a conventional spec file into a Software Collection spec file so that the Software Collection spec file that you can use in both the conventional package and the Software Collection.

Procedure 2.1. Converting a Conventional Spec File into a Software Collection Spec File

  1. Add the %scl_package macro to the spec file. Place the macro in front of the spec file preamble as follows:
    %{?scl:%scl_package package_name}
  2. You are advised to define the %pkg_name macro in the spec file in case the package is not built for the Software Collection:
    %{!?scl:%global pkg_name %{name}}
    Consequently, you can use the %pkg_name macro to define the original name of the package wherever it is needed in the spec file that you can then use for building both the conventional package and the Software Collection.
  3. Change the Name tag in the spec file preamble as follows:
    Name: %{?scl_prefix}package_name
  4. To check that all essential Software Collection's packages are dependencies of the main meta package, add the following macro after the BuildRequires or Requires tags in the spec file:
    %{?scl:Requires: %scl_runtime}
  5. Edit the %setup macro in the %prep section of the spec file so that the macro can deal with a different package name in the Software Collection environment:
    %setup -q -n %{pkg_name}-%{version}

Example of the Converted Spec File

To see what the diff file comparing a conventional spec file with a converted spec file looks like, see the following example:
--- a/less.spec
+++ b/less.spec
@@ -1,10 +1,13 @@
+%{?scl:%scl_package less}
+%{!?scl:%global pkg_name %{name}}
 Summary: A text file browser similar to more, but better
-Name: less
+Name: %{?scl_prefix}less
 Version: 444
 Release: 7%{?dist}
 License: GPLv3+
 Group: Applications/Text
-Source: http://www.greenwoodsoftware.com/less/%{name}-%{version}.tar.gz
+Source: http://www.greenwoodsoftware.com/less/%{pkg_name}-%{version}.tar.gz
 Source1: lesspipe.sh
 Source2: less.sh
 Source3: less.csh
@@ -19,6 +22,7 @@ URL: http://www.greenwoodsoftware.com/less/
 Requires: groff
 BuildRequires: ncurses-devel
 BuildRequires: autoconf automake libtool
+%{?scl:Requires: %scl_runtime}
 The less utility is a text file browser that resembles more, but has
@@ -31,7 +35,7 @@ You should install less because it is a basic utility for viewing text
 files, and you'll use it frequently.
-%setup -q
+%setup -q -n %{pkg_name}-%{version}
 %patch1 -p1 -b .Foption
 %patch2 -p1 -b .search
 %patch4 -p1 -b .time
-mkdir -p $RPM_BUILD_ROOT/etc/profile.d
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
 install -p -c -m 755 %{SOURCE1} $RPM_BUILD_ROOT/%{_bindir}
-install -p -c -m 644 %{SOURCE2} $RPM_BUILD_ROOT/etc/profile.d
-install -p -c -m 644 %{SOURCE3} $RPM_BUILD_ROOT/etc/profile.d
-ls -la $RPM_BUILD_ROOT/etc/profile.d
+install -p -c -m 644 %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
+install -p -c -m 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/profile.d
+ls -la $RPM_BUILD_ROOT%{_sysconfdir}/profile.d