help-make
[Top][All Lists]
Advanced

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

Re: how to have dependencies based on target?


From: Paul D. Smith
Subject: Re: how to have dependencies based on target?
Date: Tue, 27 Nov 2001 16:48:22 -0500

%% address@hidden (Peter Kurpis) writes:

  pk> I would like to build a java jar file  x.jar  based on changes to
  pk> any  .class  files in subtree  x .  I tried the rule

  pk> %.jar: $(shell find $* -name \*.java | sed 's/\.java$$/.class/')

You can't do that.

  pk> But it seems that $@ and $* are not expanded on the target line

Exactly.  See the GNU make manual, section "How Make Reads a Makefile".

  pk> Is this correct behavior, or am I doing something wrong?

It's correct.

  pk> How can I get this to work -- it seems such a basic thing?

Heh.  Well, basic for Java, maybe.  Not at all basic for any traditional
use of make.  The people who designed the Java build environment
obviously had little knowledge of make, or else they just didn't care.

But, the short answer is Java and make simply don't work well together.

Make wants to build a single target from a list of prerequisites, then
build the next one, and the next, etc.

Java wants you to give it all the files at once, and it generates a lot
of output files.  That's not a paradigm that make supports well.


The only way to get this to work is via auto-re-exec.  See the GNU make
manual, section "How Makefiles Are Remade".

Something like this:

  JARFILES = foo.jar bar.jar baz.jar

  %.jar:
        @$(RM) $@
        $(JAR) cf $@ $^

  all: $(JARFILES)

  include $(JARFILES:.jar=.dep)

  %.dep:
        find $* -name \*.java -print \
          | sed 's/\(.*\)\.java$$/$*.jar $*.dep: \1.class/' \
          > $@

I just wrote that off the top of my head so I'm not sure the quoting,
etc. is correct, but hopefully you get the idea.

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



reply via email to

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