RPM Community Forums

Mailing List Message of <rpm-devel>

Re: Handling of rpm optflags

From: Arkadiusz Miskiewicz <arekm@pld-linux.org>
Date: Mon 05 Nov 2007 - 18:57:50 CET
Message-Id: <200711051857.50871.arekm@pld-linux.org>
On Monday 05 of November 2007, you wrote:

> I'm running into a %optflags/$RPM_OPT_FLAGS/%configure limitation - with
> the standard macros, it isn't possible to use different optflags for C++
> than for C.
>
> With recent gcc versions, there are some C++ specific flags that people may
> want in (e.g. -Weffc++ can be helpful in pointing out room for
> optimization, -fno-check-new can be useful for saving space on embedded
> systems) - those flags pased to gcc (as opposed to g++) cause an error.
>
> Non-gcc compilers are even worse, e.g. Sun Studio generates i586 code
> with -xpentium for C, and with -xtarget=pentium for C++.
>
> I see two possible fixes -- one would be leaving %optflags/$RPM_OPT_FLAGS
> as a common denominator, and adding per-language optflags (%optflags_cxx or
> so) for extra options, so e.g.
>
> %optflags -Os
> %optflags_cxx -fno-check-new

We use:
 %configure  ./configure \
        LDFLAGS="${LDFLAGS:-%rpmldflags}" \
        CFLAGS="${CFLAGS:-%rpmcflags}" \
        CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
        FFLAGS="${FFLAGS:-%rpmcflags}" \
        FCFLAGS="${FCFLAGS:-%rpmcflags}" \
        CPPFLAGS="${CPPFLAGS:-}" \
        %{?__cc:CC="%{__cc}"} \
        %{?__cxx:CXX="%{__cxx}"} \
        --host=%{_target_platform} \
        --build=%{_target_platform} \
        --prefix=%{_prefix} \
...


so 

rpmcflags
rpmcxxflags
rpmldflags

and probably should introduce rpmcppflags macro.

Where rpmcflags are defined as:

-14: rpmcflags  %(awk 'BEGIN {
        split("%{?debug:%debugcflags}%{!?debug:
%optflags}%{?debuginfocflags}",I);
        split("%{?filterout} %{?filterout_c} %{?filterout_ld}",F);
        %{filter_out}
}')

-14: rpmcxxflags        %(awk 'BEGIN {
        split("%{?debug:%debugcflags}%{!?debug:
%optflags}%{?debuginfocflags}",I);
        split("%{?filterout} %{?filterout_cxx} %{?filterout_ld}",F);
        %{filter_out}
}')

-14: rpmldflags %(awk 'BEGIN {
        split("%{?optldflags}",I);
        split("%{?filterout_ld}",F)
        %{filter_out}
}')

-14: filter_out
        for (i = 1; i in I; i++) {      A=0;
                for (f in F) {
                        if (I[i] ~ "^" F[f] "$") A=1;
                };
                if (!A) printf(I[i] FS);
        }

(filterout_XY is used to strip out some bad flags on per spec basis like:
%define            filterout_ld    -Wl,--as-needed)


-- 
Arkadiusz Mi¶kiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/
Received on Mon Nov 5 18:57:59 2007
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.