Bug 59243 - Need a way to override %optflags without duplicating the whole macros file
Summary: Need a way to override %optflags without duplicating the whole macros file
Keywords:
Status: CLOSED WORKSFORME
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: rpm-build
Version: 1.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-03 19:57 UTC by Bill Crawford
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Enhancement
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-02-03 19:57:08 UTC
Embargoed:


Attachments (Terms of Use)

Description Bill Crawford 2002-02-03 19:57:04 UTC
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 17:26:31 UTC
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 18:00:52 UTC
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 18:59:04 UTC
The 1st expansion will redefine the "%optflags" object being expanded on the
fly.

Comment 4 Jeff Johnson 2002-02-05 20:26:54 UTC
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 20:52:21 UTC
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 21:48:26 UTC
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-06 00:44:47 UTC
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-06 00:59:53 UTC
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.