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: Peter Kurpis
Subject: Re: how to have dependencies based on target?
Date: Mon, 3 Dec 2001 17:09:43 -1000 (HST)

> 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.

Tell me about it. ;-)

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

> 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.

Thanks, Paul.  Here's what I wound up doing, and it seems to work.
Sort of the same idea as you had.  A bit kludgy, and not very robust
if make is aborted, leaving a .ja file lying around.  On the other
hand, don't have dependency files to deal with.

[Please let me know if anyone has comments.  I appreciated the feedback
last week, and wanted to let you-all know what I came up with.]

> # this is a way to have a jar file generated based
> # on dependencies, as $@ and $* are not expanded if used in the dependency
> # list, and static pattern rules cannot be implicit
> #
> # for a target  x.jar , the dependencies list is generated for the subtree
> #  x , and make is recursively called to generate the target  x.ja , from
> # a set of files which may be a superset of the dependencies (because of 
> # the nature of java compilation) along with a specified set of other files,
> # after which it is then renamed to  x.jar
> #
> # note that JAR must be version 1.2+ for  uf  option
> %.jar: 
>       JAR_DEPENDENCIES="$(shell find $* -name '*.java' | sed 
> 's/\.java$$/\.class/' )" $(MAKE) $*.ja
> 
> %.ja: $(JAR_DEPENDENCIES)
>       @$(RM) $@ address@hidden
>       $(JAR) cf $@ `find $* -name \*.class`
>       for i in $(JARSUFFIXES) .dummy.; do \
>           if [ "x$$i" != "x.dummy." ]; then \
>               f=`find $* -name \*.$$i`; \
>               if [ "x$$f" != "x" ]; then \
>                   $(JAR) uf $@ $$f; \
>               fi; \
>           fi; \
>       done
>       /bin/mv $@ address@hidden 



reply via email to

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