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 %name with %pkg_name. Most importantly, this includes adjusting the %setup macro.
    • Adjust 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}
      Note that the %setup macro is required and that you must always use the macro with the -n option 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 enable functionality 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 specify set -e in the script so that the script behavior is consistent regardless of whether the script is executed in the rpm shell or the scl environment.
  • 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 the scl enable functionality 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, use env -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/share with %{_datadir}. This is needed because the $RPM_BUILD_ROOT variable and the %{build_root} macro are not relocated by the scl macro.