# Makefile for java libraries
# by Alexandre Oliva <oliva@dcc.unicamp.br>
# $Id: Makefile,v 1.2 1998/04/13 05:39:34 oliva Exp $

# You may want to change the location of these programs

AWK     = awk
JAVAC	= javac
JAVADOC	= javadoc -author -version

# DOCDIR specifies where the documentation should be stored
DOCDIR= $(ROOTDIR)/docs/
# ROOTDIR should be maintained by the dependency manager

all:

CLASSPATH=$(ROOTDIR)
SETCLASSPATH=CLASSPATH=$(CLASSPATH)$${CLASSPATH+:$$CLASSPATH}

.SUFFIXES: .class .java

.java.class:
	$(SETCLASSPATH) $(JAVAC) -d $(ROOTDIR) $< 

.PHONY: all doc depend clean distclean maintclean
.PHONY: norec.all rec.depend norec.depend
.PHONY: norec.clean norec.distclean norec.maintclean

norec.all:

all: norec.all
	ls -1 */Makefile 2>/dev/null | while read f; do \
	  (cd `dirname $$f`; $(MAKE) $@); \
	done

doc:
	if [ ! -d $(DOCDIR) ]; then mkdir $(DOCDIR); fi
	$(SETCLASSPATH) $(JAVADOC) -d $(DOCDIR) ` \
	    cd $(ROOTDIR) && \
	    find . -name \*.java -print | sed 's%^\\./%%' | \
	    while read f; do echo \`dirname $$f\`; done | uniq | \
	    sed s%/%.%g`

depend:
	@ case $(ROOTDIR) in \
	   .) rootdir=..;; \
	   *) rootdir=../$(ROOTDIR);; \
	  esac; \
	  find * -type d -prune ! -name CVS ! -name RCS ! -name SCCS -print | \
	  while read f; do \
	    if [ ! -f $$f/Makefile ]; then \
	      { $(AWK) 'noprint == 0 { print; } \
	                /^# $(DEPLINE)/ { noprint = 1; }' <Makefile; \
	        echo; echo ROOTDIR=$$rootdir; echo; \
	        echo "norec.all: depend"; \
	        echo "	if [ ! -f Makefile.new ]; then $$(MAKE); fi"; \
	      } >$$f/Makefile.new && \
	      mv $$f/Makefile.new $$f/Makefile || exec false; \
	    fi; \
	    (cd $$f && $(MAKE) ROOTDIR=$$rootdir depend) || exec false; \
	  done
	$(MAKE) norec.depend

norec.depend:
	rm -f Makefile.new
	@ \
	{ $(AWK) 'noprint == 0 { print; } \
	          /^# $(DEPLINE)/ { noprint = 1; }' <Makefile; \
	  echo; echo ROOTDIR=$(ROOTDIR); echo; \
	  ls -1 *.java 2>/dev/null | \
	  while read f; do \
	    echo Computing dependencies for $$f... >&2; \
	    $(SETCLASSPATH) $(JAVAC) -verbose $$f 2>&1 | \
	    $(AWK) ' \
	      /^\[parsed / && classname == "" { \
	        classname = substr($$2, 1, length($$2)-5) ".class"; \
	        print "CLASSES += " classname; \
	        print classname ": " $$2; \
	        next; \
	      } \
	      /^\[parsed / { \
	        print classname ": " $$2; \
	        next; \
	      } \
	      /^\[loaded [^ $$]*\.class / && index($$2, "$(ROOTDIR)/") == 1 { \
	        print classname ": " \
	          substr($$2, 1, length($$2)-6) ".java"; \
	        next; \
	      } \
	      /^\[wrote / && $$2 == classname "]" { \
		next; \
	      } \
	      /^\[wrote / { \
		cls = substr($$2, 1, length($$2)-1); \
	        print "CLASSES += " cls | "sed 's/\\\\\\\\$$/\\\\$$\\\\$$/g'"; \
		print cls ": " classname | "sed 's/\\\\\\\\$$/\\\\$$\\\\$$/g'"; \
		print "	rm -f " classname " && $$(MAKE) " classname; \
	        next; \
	      } \
	      /^\[.*\]$$/ { next; } \
	      { print | "cat >&2"; } \
	    '; \
	  done; \
	  echo; echo "norec.all: $$(CLASSES)"; \
	} >Makefile.new
	mv Makefile Makefile.bak
	mv Makefile.new Makefile

norec.clean:
	rm -f *~ '#'* core Makefile.bak Makefile.new

clean: norec.clean
	ls -1 */Makefile 2>/dev/null | while read f; do \
	  (cd `dirname $$f`; $(MAKE) $@); \
	done

norec.distclean: norec.clean
	rm -f $(CLASSES)
	rm -rf $(DOCDIR)
	@ \
	{ $(AWK) 'noprint == 0 { print; } \
	          /^# $(DEPLINE)/ { noprint = 1; }' <Makefile; \
	  echo; echo ROOTDIR=$(ROOTDIR); echo; \
	  echo "norec.all: depend"; \
	  echo "	if [ ! -f Makefile.new ]; then $$(MAKE); fi"; \
	} >Makefile.new
	mv Makefile Makefile.bak
	mv Makefile.new Makefile
	rm -f Makefile.new Makefile.bak

distclean: 
	ls -1 */Makefile 2>/dev/null | while read f; do \
	  (cd `dirname $$f`; $(MAKE) $@); \
	done
	$(MAKE) norec.distclean

norec.maintclean: norec.distclean
	@ if [ "$(ROOTDIR)" != "." ] && [ -f ../Makefile ] && \
	  $(AWK) 'noprint == 0 { print; } \
	          /^# $(DEPLINE)/ { noprint = 1; }' \
	    <Makefile >Makefile.mine && \
	  $(AWK) 'noprint == 0 { print; } \
	          /^# $(DEPLINE)/ { noprint = 1; }' \
	    <../Makefile >Makefile.parent  && \
	  diff Makefile.mine Makefile.parent >/dev/null 2>&1; then \
	  rm -f Makefile; \
	fi
	rm -f Makefile.mine Makefile.parent

maintclean: norec.distclean
	ls -1 */Makefile 2>/dev/null | while read f; do \
	  (cd `dirname $$f`; $(MAKE) $@); \
	done
	$(MAKE) norec.maintclean

DEPLINE = Do not remove this line, makedepend depends on it

# Do not remove this line, makedepend depends on it

ROOTDIR=../../..

CLASSES += Composer.class
Composer.class: Composer.java
Composer.class: ../../../BR/unicamp/Guarana/MetaObject.java
CLASSES += Guarana.class
Guarana.class: Guarana.java
Guarana.class: ../../../BR/unicamp/Guarana/MetaObject.java
Guarana.class: ../../../BR/unicamp/Guarana/Result.java
Guarana.class: ../../../BR/unicamp/Guarana/Operation.java
Guarana.class: ../../../BR/unicamp/Guarana/MetaException.java
Guarana.class: ../../../BR/unicamp/Guarana/Message.java
Guarana.class: ../../../BR/unicamp/Guarana/InstanceReconfigure.java
CLASSES += HashWrapper.class
HashWrapper.class: HashWrapper.java
HashWrapper.class: ../../../BR/unicamp/Guarana/Guarana.java
CLASSES += InstanceReconfigure.class
InstanceReconfigure.class: InstanceReconfigure.java
InstanceReconfigure.class: ../../../BR/unicamp/Guarana/Message.java
InstanceReconfigure.class: ../../../BR/unicamp/Guarana/MetaObject.java
CLASSES += Message.class
Message.class: Message.java
CLASSES += MetaException.class
MetaException.class: MetaException.java
CLASSES += MetaObject.class
MetaObject.class: MetaObject.java
MetaObject.class: ../../../BR/unicamp/Guarana/Result.java
MetaObject.class: ../../../BR/unicamp/Guarana/Operation.java
MetaObject.class: ../../../BR/unicamp/Guarana/Message.java
MetaObject.class: ../../../BR/unicamp/Guarana/OperationFactory.java
CLASSES += MetaSequenceArray.class
MetaSequenceArray.class: MetaSequenceArray.java
MetaSequenceArray.class: ../../../BR/unicamp/Guarana/SequentialComposer.java
MetaSequenceArray.class: ../../../BR/unicamp/Guarana/Composer.java
MetaSequenceArray.class: ../../../BR/unicamp/Guarana/MetaObject.java
MetaSequenceArray.class: ../../../BR/unicamp/Guarana/OperationFactory.java
CLASSES += MetaSequenceArray$$1.class
MetaSequenceArray$$1.class: MetaSequenceArray.class
	rm -f MetaSequenceArray.class && $(MAKE) MetaSequenceArray.class
CLASSES += NewObject.class
NewObject.class: NewObject.java
NewObject.class: ../../../BR/unicamp/Guarana/Message.java
CLASSES += NewProxy.class
NewProxy.class: NewProxy.java
NewProxy.class: ../../../BR/unicamp/Guarana/NewObject.java
NewProxy.class: ../../../BR/unicamp/Guarana/Message.java
CLASSES += Operation.class
Operation.class: Operation.java
Operation.class: ../../../BR/unicamp/Guarana/Result.java
Operation.class: ../../../BR/unicamp/Guarana/Guarana.java
Operation.class: ../../../BR/unicamp/Guarana/MetaException.java
CLASSES += OperationFactory.class
OperationFactory.class: OperationFactory.java
OperationFactory.class: ../../../BR/unicamp/Guarana/Operation.java
CLASSES += OperationFactoryFilter.class
OperationFactoryFilter.class: OperationFactoryFilter.java
OperationFactoryFilter.class: ../../../BR/unicamp/Guarana/OperationFactory.java
OperationFactoryFilter.class: ../../../BR/unicamp/Guarana/Operation.java
CLASSES += OperationFactoryInternal.class
OperationFactoryInternal.class: OperationFactoryInternal.java
OperationFactoryInternal.class: ../../../BR/unicamp/Guarana/OperationFactory.java
OperationFactoryInternal.class: ../../../BR/unicamp/Guarana/Operation.java
CLASSES += Result.class
Result.class: Result.java
Result.class: ../../../BR/unicamp/Guarana/Operation.java
Result.class: ../../../BR/unicamp/Guarana/Guarana.java
CLASSES += SequentialComposer.class
SequentialComposer.class: SequentialComposer.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/Composer.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/MetaObject.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/Result.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/Operation.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/Message.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/MetaException.java
SequentialComposer.class: ../../../BR/unicamp/Guarana/OperationFactory.java

norec.all: $(CLASSES)
