From Fedora Project Wiki

Revision as of 16:47, 22 April 2009 by Toshio (talk | contribs) (Wording changes from scop)

Add a paragraph with instructions for adding compiler flags in common circumstances


Compiler flags

Current

Compilers used to build packages should honor the applicable compiler flags set in the system rpm configuration. As of Aug 2006, this means in practice $RPM_OPT_FLAGS/%{optflags} for C, C++, and Fortran compilers. Honoring means that the contents of that variable is used as the basis of the flags actually used by the compiler during the package build. Adding to and overriding or filtering parts of these flags is permitted if there's a good reason to do so; the rationale for doing so should be reviewed and documented in the specfile especially in the override and filter cases.

Addition

Most C, C++, and Fortran programs will pick up the correct compiler flags if you use a macro that automatically sets them to build the package, such as %configure or %cmake (If you're unsure whether a macro sets the flags, install redhat-rpm-config and the package that provides the macro in /etc/rpm/*. Then run "rpm -E %somemacro"). If there are no such macros that would apply to your package, the de facto standard is that C compiler flags are picked up via the CFLAGS make variable, C++ Compiler flags via the CXXFLAGS variable, and Fortran flags via FFLAGS. So, you could have something like this in your spec file:

make CFLAGS="%{optflags}" all

If the build still does not pick up the proper compiler flags, you will have to look in the configure script or Makefiles to diagnose what's going on.