Show Table of Contents
2.10.4. Converting RPM Scripts
This section describes general rules for converting RPM scripts that can often be found in the
%prep, %build, %install, %check, %pre, and %post sections of a conventional spec file.
- Replace all occurrences of
%namewith%pkg_name. Most importantly, this includes adjusting the%setupmacro.- Adjust the
%setupmacro in the%prepsection 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}Note that the%setupmacro is required and that you must always use the macro with the-noption to successfully build your Software Collection.
- If you are using any of the
%_root_macros to point to the system file system hierarchy, you must use conditionals for these macros so that you can then use the spec file for building both the conventional package and the Software Collection. Edit the macros as in the following example:mkdir -p %{?scl:%_root_sysconfdir}%{?!scl:%_sysconfdir} - When building Software Collection packages that depend on other Software Collection packages, it is often important to ensure that the
scl enablefunctionality links properly or run proper binaries, and so on. One of the examples where this is needed is compiling against a Software Collection library or running an interpreted script with the interpreter in the Software Collection.Wrap the script using the%{?scl:prefix, as in the following example:%{?scl:scl enable %scl - << \EOF} set -e ruby example.rb RUBYOPT="-Ilib" ruby bar.rb # The rest of the script contents goes here. %{?scl:EOF}It is important to specifyset -ein the script so that the script behavior is consistent regardless of whether the script is executed in therpmshell or thesclenvironment. - Pay attention to any scripts that are executed during the Software Collection package installation, such as:
%pretrans,%pre,%post,%postun,%posttrans,%triggerin,%triggerun, and%triggerpostun.
If you use thescl enablefunctionality in those scripts, you are advised to start with an empty environment to avoid any unintentional collisions with the base system installation.To do so, useenv -i -before enabling the Software Collection, as in the following example:%posttrans %{?scl:env -i - scl enable %{scl} - << \EOF} %vagrant_plugin_register %{vagrant_plugin_name} %{?scl:EOF} - All hardcoded paths found in RPM scripts must be replaced with proper macros. For example, replace all occurrences of
/usr/sharewith%{_datadir}. This is needed because the$RPM_BUILD_ROOTvariable and the%{build_root}macro are not relocated by thesclmacro.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.