Bug 59243 - Need a way to override %optflags without duplicating the whole macros file
Need a way to override %optflags without duplicating the whole macros file
Status: CLOSED WORKSFORME
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm-build (Show other bugs)
1.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: Jeff Johnson
: FutureFeature
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-02-03 14:57 EST by Bill Crawford
Modified: 2008-05-01 11:38 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-02-03 14:57:08 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Bill Crawford 2002-02-03 14:57:04 EST
Description of Problem:
The arch-specific macros files specify %optflags and then use it in the various
build-related macros.  Unfortunately this arrangement means it is impossible to
override the %optflags without duplicating most of the contents of the
arch-specific macros file.  While I don't mind having to know about what's in
those files, I would rather not have to do this, as it means I need to rebuild
my .rpmmacros-%{_target} every time there is a minor change in e.g. the
%configure macro ... and all I want to do is override the compile flags (to add
-W -Wall to my personal builds, as it happens, but I assume there are other
applications :o)

I can fix this (sort of) by changing the %optflags definitions in the macros
files to include another macro and define that in my personal rpmmacros ... but
there's still a "what order do I include these files in" problem.  So it's not
really a solution.

Is it possible to have some of the expansion done later, or perhaps change some
of the macro definitions to "unless this is already defined ..." ?
Comment 1 Jeff Johnson 2002-02-05 12:26:31 EST
How about defining the macro on the command line:
    --define 'optflags %{expand:%%global optflags %{optflags} -W -Wall}'

This will append "-W -Wall" to the current value on 1st expansion of %optflags.

And, to eliminate unnecssary typing, you can add your own rpmbuild
extension to rpm by adding to /etc/popt

    rpmb		alias --Wall <glop above>
    rpmbuild	alias --Wall <glop above>

(Note: two entries to guarantee match on argv[0])

to be used as

    rpmbuild -ba --Wall <specfile>

HTH (untested, reopen this bug if  the above doesn't work)
Comment 2 Bill Crawford 2002-02-05 13:00:52 EST
Thanks, I'll try that when I get home.

One question though: you said "first expansion" ... optflags is expanded
multiple times and then redefined (once in rpmrc, once in macros, once in
%{arch}-redhat-linux/macros).
Comment 3 Jeff Johnson 2002-02-05 13:59:04 EST
The 1st expansion will redefine the "%optflags" object being expanded on the
fly.
Comment 4 Jeff Johnson 2002-02-05 15:26:54 EST
The other piece that may be missing is that CLI macros
are always added after everything else, 1st expansion
appends -W -Wall, and away we go.
Comment 5 Bill Crawford 2002-02-05 15:52:21 EST
Won't that mean it's added after e.g. %configure etc. get expanded (with the
value of optargs from the macros file)?

I'll go try it anyway.  On my way home now.
Comment 6 Bill Crawford 2002-02-05 16:48:26 EST
OK, that works -- thanks.  Apologies for questioning you; I spent a while
experimenting last night and it looked as though expansion was being done fairly
early on in the process.  A couple of things that didn't work were:

 defining %optflags in .rpmmacros
 defining %optflags in .rpmmacros-%{target} and modifying .rpmrc to look at that

The only thing that worked was to define %optflags and then paste the rest of
/usr/lib/rpm/%{target}/macros in after it, hence my assumption that expansion
was always immediate.

Interestingly so did putting "optflags: i386 -W -Wall -O2 -march=i386 -mcpu=686"
in .rpmrc, as long as I put it *after* the "include: /usr/lib/rpm/rpmrc" (I'd
tried something similar earlier and it failed because I'd put it at the start of
.rpmrc, before the include).

However the header and region stuff sounds even more hairy than the macro and
command line stuff, so I'll leave you to it.  Thanks for your help.
Comment 7 Jeff Johnson 2002-02-05 19:44:47 EST
Yeah %optflags is broke ATM, only the side effect of the
	optflags: yadda yadda
in the ageless and decrepit rpmrc line works. 

One of these years I'll succeed in eliminating rpmrc configuration, sigh.
Comment 8 Bill Crawford 2002-02-05 19:59:53 EST
What might work (but would probably break any kind of backward compatability)
would be to process the command line first, then the target-specific macro file,
then the general one, *then* rpmrc; and make the *first* definition stick, not
the last one.  Kinda like ssh config file works.

(I know it's not going to happen, just speculating).

Note You need to log in before you can comment on or make changes to this bug.