help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU Make 3.79, consolidating dependancy lines


From: Ian Wilson
Subject: Re: GNU Make 3.79, consolidating dependancy lines
Date: Mon, 17 May 2004 13:28:50 +0000 (UTC)
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007

Ian Wilson wrote:

< Q: how best to reduce redundancy in the dependancy lines. >

I have something like ...
--------------------------------------------------------------------
%.obj : %.src
    compile $<

fooprog_objs = foo_main.obj foo_mangle.obj foo_other.obj funky_lib.obj
barprog.objs = bar_part1.obj bar_part2.obj funky_lib.obj wow_lib.obj
bazprog.objs = bazmain.obj bazio.obj
quxprog.objs = qux.obj morequx.obj wow_lib.obj
# I also wish I knew a way to avoid so much ".obj" clutter above

fooprog.prg : ${fooprog.objs}
    link -o $@ ${fooprog.objs}

barprog.prg : ${barprog.objs}
    link -o $@ ${barprog.objs}

bazprog.prg : ${bazprog.objs}
    link -o $@ ${bazprog.objs}

quxprog.prg : ${quxprog.objs}
    link -o $@ ${quxprog.objs}
--------------------------------------------------------------------
Lets say the above works.

Is there any way of merging the dependancy & command lines into some meta dependancy expression?
<anything>.prg : ${${<anything>}.objs}
    link -o $@ ${${<anything>}.objs}

Karl Berry wrote:
>>    quxprog.objs = qux.obj morequx.obj wow_lib.obj
>>    # I also wish I knew a way to avoid so much ".obj" clutter above
>>
>> Don't know if you'll think it's an improvement, but here's one way:
>> quxprog.objs = $(addsuffix .obj, qux morequx wow_lib)

Definitely an improvement because, in reality, my list of objects is much much longer than in my contrived example.


Tristran Van Berkhom wrote:
>> Actualy I use this form:
>>
>> %.prg:
>>     link -o $@ $^
>>
>> While dependancies have already been sorted out using wildcards and
>> subst/patsubst et al.

Which gave me the clue how to abstract out the common command line from about a hundred dependancy lines.


I have incorporated ideas from both responses to achieve my objectives of avoiding repetition in rules and keeping the dependencies brief:

-------------------------------------------------------------
fooprog.prg : $(addsuffix .obj, \
              foo_main foo_mangle foo_other funky_lib)
barprog.prg : $(addsuffix .obj, \
              bar_part1 bar_part2 funky_lib wow_lib)
bazprog.prg : $(addsuffix .obj, bazmain bazio)
quxprog.prg : $(addsuffix .obj, qux morequx wow_lib)

%.prg :
        link -o $@ $^

%.obj : %.src
        compile $<
-------------------------------------------------------------

Thanks Tristran, Karl,
Ian.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]