From Fedora Project Wiki

Package-specific RPM Macros For Build Flags

Summary

Create _pkg_extra_***flags macros to make it easier for packages to add to the default list of compiler flags.

This is a follow up to the: https://fedoraproject.org/wiki/Changes/RPMMacrosForBuildFlags

Owner


Current status


Change Owner status updates:

  • The PR to the 'redhat-rpm-config' package was accepted as this commit:
  • And built as this BODHI update, which is now present in Rawhide.
  • I tested the change is present in Rawhide buildroot and can be used properly.
  • (PR) to the Fedora Packaging Guidelines merged

This Change is now FULLY COMPLETE.

If you encounter any bugs regarding the behavior, please reach out to me so I can investigate.

Detailed Description

The macros file in the redhat-rpm-config package contains a list of default compiler flags for packages to use when compiling C, C++, and Fortran packages. This change will add new macros to the redhat-rpm-config package, which will make it easier for packages to add their own compiler flags.

The proposed macros for adding new flags are:

   %_pkg_extra_cflags
   %_pkg_extra_cxxflags
   %_pkg_extra_fflags
   %_pkg_extra_ldflags

These will be added to %{build_cflags}, %{build_cxxflags}, %{build_fflags}, and %{build_ldflags} existing macros respectively, to allow packages to add their own flags to the default list: e.g.

   %build_cflags %{optflags} %{_pkg_extra_cflags}

Note:
This is a followup for the previously accepted change:
https://fedoraproject.org/wiki/Changes/RPMMacrosForBuildFlags
that was implemented as:
https://src.fedoraproject.org/rpms/redhat-rpm-config/c/198872?branch=rawhide
but later changed to:
https://src.fedoraproject.org/rpms/redhat-rpm-config/c/e0e097?branch=rawhide

My goal is to re-implement the original solution, which would create the _pkg_extra_***flags macros, to grant the package maintainers an elegant, clean and simple way to make the per-package adjustments to the build flags.

Currently, this is done by editing the CFLAGS etc. environmental variables directly and re-exporting them. That sometimes cause issues that could be avoided by using macro instead.

Also, when set by macro, the flags adjustment will be present in every %set_build_flags call, not just in-between of the manual adjustment and the end of the RPMbuild phase (%build, %install, %check, etc.).


Feedback

Benefit to Fedora

  • It will provide a standard way to add to the list of default compiler flags.
  • It will make it easier to determine which packages add compiler flags by doing a simple grep of the spec files.


Scope

  • Proposal owners:
    • Proposal owners will update the redhat-rpm-config package and add the new macros.
    • Proposal owners will test the changes to ensure that the correct flags are still being used.
  • Other developers:
    • Other developers may, but are not required to, update their packages to use the new macros.


  • Trademark approval: N/A (not needed for this Change)
  • Alignment with the Fedora Strategy:

Upgrade/compatibility impact

None.


Early Testing (Optional)

How To Test

  • This can be tested by inspecting the value of the %{build_cflags}, %{build_cxxflags}, %{build_fflags}, and %{build_ldflags} macros and ensuring they are the same before and after the change.
  • This can be tested by modifying some of the new macros in a spec file and ensuring that the changes appear in the appropriate macro mentioned above.


User Experience

This is a change for developers and will have no impact to the user experience.


Dependencies

A PR must be approved and merged to the redhat-rpm-config package. [ DONE ]
A PR must be approved and merged to the Fedora Packaging Guidelines. [ DONE ]



Contingency Plan

  • Contingency mechanism: Change owner will revert the update to redhat-rpm-config package.
  • Contingency deadline: Beta freeze
  • Blocks release? No


Documentation

Was put into the buildflags.md file as a part of this commit.


Release Notes

None.