Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

make: computed & automatic variables in dependencies

4 views
Skip to first unread message

ssad...@my-deja.com

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Hello all,

I am having a problem with gnu make that I can't work out how to solve
with gnu make 3.79 and NT.

I define multiple sets of java classes:

LIB1_CLASSES=foo1.class
LIB2_CLASSES=foo2.class

And jar files into which they should go:

JAR_FILES=LIB1.jar LIB2.jar

now I want to make a single rule that determines for each jar whether
it must be rebuilt:

$(JAR_FILES): $($*_CLASSES)
jar -tvf $@ $($*_CLASSES)

The $($*_CLASSES) gets the right classes variable for the target being
made. Unfortunately, $* does not work in a dependency list - and I
find that the second one (in the command) works but the first doesn't.
As an alternative, I try using %. Eg,

$(JAR_FILES): %.jar: $(%_CLASSES)
jar -tvf $@ $($*_CLASSES)

But while % works generally in the dependency list, it fails when I try
to compute a variable from it.

Does anyone know how I could achieve what I want - either a solution to
the above or another approach to take?

Thanks for any suggestions!

Simon Sadedin.


Sent via Deja.com http://www.deja.com/
Before you buy.

Paul D. Smith

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to ssad...@my-deja.com
%% ssad...@my-deja.com writes:

s> LIB1_CLASSES=foo1.class
s> LIB2_CLASSES=foo2.class

s> JAR_FILES=LIB1.jar LIB2.jar

s> now I want to make a single rule that determines for each jar whether
s> it must be rebuilt:

s> $(JAR_FILES): $($*_CLASSES)
s> jar -tvf $@ $($*_CLASSES)

You can't do this in make. Automatic variables are _ONLY_ valid within
the context of the command script, not the target or prerequisite lists.

s> As an alternative, I try using %. Eg,

s> $(JAR_FILES): %.jar: $(%_CLASSES)
s> jar -tvf $@ $($*_CLASSES)

s> But while % works generally in the dependency list, it fails when I try
s> to compute a variable from it.

Right. The command line must be expanded for variables _before_ the %'s
are replaced, the way make works.

s> Does anyone know how I could achieve what I want - either a solution to
s> the above or another approach to take?

The only way to do things like this now is via constructed makefiles.
You can create a makefile containing the dependencies you want, then
include them in your makefile. Due to GNU make's auto-re-exec feature,
they will be automatically kept up-to-date for you.

For example:

LIB1_CLASSES=foo1.class
LIB2_CLASSES=foo2.class

JAR_FILES=LIB1.jar LIB2.jar

$(JAR_FILES):
jar -tvf $@ $($*_CLASSES)

include jar_deps.mk

jar_deps.mk: Makefile
rm -f $@
for f in $(JAR_FILES:%.jar=); do \
echo "$$f.jar: \$$($$f_CLASSES)" >> $@; \
done

I didn't test this so the quoting might not be exact, but the
jar_deps.mk file should look like this after make builds it:

LIB1.jar: $(LIB1_CLASSES)
LIB2.jar: $(LIB2_CLASSES)

etc.

There is a feature I'm working on which will make this easier, but for
now this is the best you can do.

--
-------------------------------------------------------------------------------
Paul D. Smith <psm...@gnu.org> Find some GNU make tips at:
http://www.gnu.org http://www.ultranet.com/~pauld/gmake/
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist

ssad...@my-deja.com

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
<snip>

> The only way to do things like this now is via constructed makefiles.
> You can create a makefile containing the dependencies you want, then
> include them in your makefile. Due to GNU make's auto-re-exec
feature,
> they will be automatically kept up-to-date for you.
>

Thanks for your excellent & detailed response - you've given me what I
needed to know, and I can probably work with your suggestion. My main
challenge is how to make it cross-platform
(yes, it has to work on windblows:-( )

>
> There is a feature I'm working on which will make this easier, but for
> now this is the best you can do.

Understanding that even answering my message is slowing it down :-),
any idea on the time frame/release it would appear in?

Cheers & thanks,

Paul D. Smith

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
%% ssad...@my-deja.com writes:

s> Thanks for your excellent & detailed response - you've given me what I
s> needed to know, and I can probably work with your suggestion. My main
s> challenge is how to make it cross-platform
s> (yes, it has to work on windblows:-( )

Hmm. Doesn't GNU make on windows support auto-re-exec? I thought it
did.

--
-------------------------------------------------------------------------------
Paul D. Smith <psm...@baynetworks.com> Network Management Development


"Please remain calm...I may be mad, but I am a professional." --Mad Scientist

-------------------------------------------------------------------------------
These are my opinions---Nortel Networks takes no responsibility for them.

Paul D. Smith

unread,
Jun 8, 2000, 3:00:00 AM6/8/00
to
%% ssad...@my-deja.com writes:

>> There is a feature I'm working on which will make this easier, but for
>> now this is the best you can do.

s> Understanding that even answering my message is slowing it down :-),
s> any idea on the time frame/release it would appear in?

Oops, forgot this one :)

I have no idea on the timeframe. Not within the next 3 months or so,
for sure.

My plan is to make this the next major feature, in the next version
3.80.

ssad...@my-deja.com

unread,
Jun 9, 2000, 3:00:00 AM6/9/00
to
In article <p5ln0fo...@nortelnetworks.com>,

psm...@baynetworks.com wrote:
> %% ssad...@my-deja.com writes:
>
> s> Thanks for your excellent & detailed response - you've given me
what I
> s> needed to know, and I can probably work with your suggestion.
My main
> s> challenge is how to make it cross-platform
> s> (yes, it has to work on windblows:-( )
>
> Hmm. Doesn't GNU make on windows support auto-re-exec? I thought it
> did.

Actually I was referring to the "for" loop in your example. I can
probably get away with installing a real shell on the nt box - make has
some nice features to support that.

Cheers,

Simon.

Paul D. Smith

unread,
Jun 9, 2000, 3:00:00 AM6/9/00
to
%% ssad...@my-deja.com writes:

s> My main challenge is how to make it cross-platform (yes, it has to
s> work on windblows:-( )

>> Hmm. Doesn't GNU make on windows support auto-re-exec? I thought it
>> did.

s> Actually I was referring to the "for" loop in your example.

Hmm... doesn't command.com have any loop capabilities? I thought you
could loop in DOS batch files. You can use make functions to munge the
contents to exactly what you want, then the loop is very simple.

s> I can probably get away with installing a real shell on the nt box

That's definitely the best way to go, though :)

0 new messages